Skip to content

Commit 3eb52ed

Browse files
committed
Fix broken add/remove permissions method
1 parent ccf14ed commit 3eb52ed

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/roles/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,13 @@ const roles = (connection: ConnectionREST): Roles => {
106106
.then(() => true)
107107
.catch(() => false),
108108
addPermissions: (roleName: string, permissions: PermissionsInput) =>
109-
connection.postEmpty(`/authz/roles/${roleName}/add-permissions`, { permissions }),
109+
connection.postEmpty(`/authz/roles/${roleName}/add-permissions`, {
110+
permissions: Map.flattenPermissions(permissions).flatMap(Map.permissionToWeaviate),
111+
}),
110112
removePermissions: (roleName: string, permissions: PermissionsInput) =>
111-
connection.postEmpty(`/authz/roles/${roleName}/remove-permissions`, { permissions }),
113+
connection.postEmpty(`/authz/roles/${roleName}/remove-permissions`, {
114+
permissions: Map.flattenPermissions(permissions).flatMap(Map.permissionToWeaviate),
115+
}),
112116
hasPermissions: (roleName: string, permission: Permission | Permission[]) =>
113117
Promise.all(
114118
(Array.isArray(permission) ? permission : [permission])

src/roles/integration.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,35 @@ maybe('Integration testing of the roles namespace', () => {
326326
});
327327
});
328328

329+
it('should be able to add permissions to one of the created roles', async () => {
330+
await client.roles.addPermissions(
331+
'backups',
332+
weaviate.permissions.backup({ collection: 'Another-collection', manage: true })
333+
);
334+
const role = await client.roles.byName('backups');
335+
expect(role).toEqual({
336+
name: 'backups',
337+
...emptyPermissions,
338+
backupsPermissions: [
339+
{ collection: 'Some-collection', actions: ['manage_backups'] },
340+
{ collection: 'Another-collection', actions: ['manage_backups'] },
341+
],
342+
});
343+
});
344+
345+
it('should be able to remove permissions from one of the created roles', async () => {
346+
await client.roles.removePermissions(
347+
'backups',
348+
weaviate.permissions.backup({ collection: 'Another-collection', manage: true })
349+
);
350+
const role = await client.roles.byName('backups');
351+
expect(role).toEqual({
352+
name: 'backups',
353+
...emptyPermissions,
354+
backupsPermissions: [{ collection: 'Some-collection', actions: ['manage_backups'] }],
355+
});
356+
});
357+
329358
it('should delete one of the created roles', async () => {
330359
await client.roles.delete('backups');
331360
await expect(client.roles.byName('backups')).rejects.toThrowError(WeaviateUnexpectedStatusCodeError);

0 commit comments

Comments
 (0)