Skip to content

Commit 99b1b80

Browse files
committed
fix(roles): bring back assignedUserIds method to avoid breaking changes
Add deprecation notice to it.
1 parent e257301 commit 99b1b80

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/roles/index.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,25 @@ export interface Roles {
3434
* @returns {Promise<Role | null>} The role if it exists, or null if it does not.
3535
*/
3636
byName: (roleName: string) => Promise<Role | null>;
37+
38+
/**
39+
* Retrieve the user IDs assigned to a role.
40+
*
41+
* @param {string} roleName The name of the role to retrieve the assigned user IDs for.
42+
* @returns {Promise<string[]>} The user IDs assigned to the role.
43+
*
44+
* @deprecated: Use `userAssignments` instead.
45+
*/
46+
assignedUserIds: (roleName: string) => Promise<string[]>;
3747
/**
3848
* Retrieve the user IDs assigned to a role. Each user has a qualifying user type,
3949
* e.g. `'db_user' | 'db_env_user' | 'oidc'`.
4050
*
51+
* Note, unlike `assignedUserIds`, this method may return multiple entries for the same username,
52+
* if OIDC authentication is enabled: once with 'db_*' and once with 'oidc' user type.
53+
*
4154
* @param {string} roleName The name of the role to retrieve the assigned user IDs for.
42-
* @returns {Promise<string[]>} The user IDs assigned to the role.
55+
* @returns {Promise<UserAssignment[]>} User IDs and user types assigned to the role.
4356
*/
4457
userAssignments: (roleName: string) => Promise<UserAssignment[]>;
4558
/**
@@ -95,6 +108,7 @@ const roles = (connection: ConnectionREST): Roles => {
95108
listAll: () => connection.get<WeaviateRole[]>('/authz/roles').then(Map.roles),
96109
byName: (roleName: string) =>
97110
connection.get<WeaviateRole>(`/authz/roles/${roleName}`).then(Map.roleFromWeaviate),
111+
assignedUserIds: (roleName: string) => connection.get<string[]>(`/authz/roles/${roleName}/users`),
98112
userAssignments: (roleName: string) =>
99113
connection
100114
.get<WeaviateAssignedUser[]>(`/authz/roles/${roleName}/user-assignments`, true)

src/roles/integration.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ requireAtLeast(
322322
30,
323323
0
324324
)('namespaced users', () => {
325-
it('retrieves assigned users with namespace', async () => {
325+
it('retrieves assigned users with/without namespace', async () => {
326326
await client.roles.create('landlord', {
327327
collection: 'Buildings',
328328
tenant: 'john-doe',
@@ -342,6 +342,10 @@ requireAtLeast(
342342
])
343343
);
344344

345+
// Legacy
346+
const assignedUsers = await client.roles.assignedUserIds('landlord');
347+
expect(assignedUsers).toEqual(['Innkeeper', 'custom-user']);
348+
345349
await client.users.db.delete('Innkeeper');
346350
await client.roles.delete('landlord');
347351
});

0 commit comments

Comments
 (0)