From 3c08d81594504a72871457e1d07215c8d08bd0d9 Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Fri, 8 Mar 2024 08:58:33 +0100 Subject: [PATCH] refactor: make expand on user and group listings optional The endpoints for listing users and groups will be used for fetching potential sharees in the future. Regular users (non-admins) are not allowed to expand these requests though, hence we need to make the expand option optional. --- .../src/views/Groups.vue | 4 +- .../src/views/Users.vue | 8 +++- .../tests/unit/views/Users.spec.ts | 15 +++++--- packages/web-client/src/graph.ts | 38 +++++++++++++------ 4 files changed, 45 insertions(+), 20 deletions(-) diff --git a/packages/web-app-admin-settings/src/views/Groups.vue b/packages/web-app-admin-settings/src/views/Groups.vue index 1c88f0d27ff..d086b5c56f3 100644 --- a/packages/web-app-admin-settings/src/views/Groups.vue +++ b/packages/web-app-admin-settings/src/views/Groups.vue @@ -96,7 +96,9 @@ export default defineComponent({ const createGroupAction = computed(() => unref(createGroupActions)[0]) const loadResourcesTask = useTask(function* (signal) { - const response = yield clientService.graphAuthenticated.groups.listGroups('displayName') + const response = yield clientService.graphAuthenticated.groups.listGroups('displayName', [ + 'members' + ]) groupSettingsStore.setGroups(response.data.value || []) }) diff --git a/packages/web-app-admin-settings/src/views/Users.vue b/packages/web-app-admin-settings/src/views/Users.vue index b6b0ccdcf5c..e2c08b05e60 100644 --- a/packages/web-app-admin-settings/src/views/Users.vue +++ b/packages/web-app-admin-settings/src/views/Users.vue @@ -230,7 +230,10 @@ export default defineComponent({ let editQuotaActionEventToken: string const loadGroupsTask = useTask(function* (signal) { - const groupsResponse = yield clientService.graphAuthenticated.groups.listGroups('displayName') + const groupsResponse = yield clientService.graphAuthenticated.groups.listGroups( + 'displayName', + ['members'] + ) groups.value = groupsResponse.data.value }) @@ -268,7 +271,8 @@ export default defineComponent({ const usersResponse = yield clientService.graphAuthenticated.users.listUsers( 'displayName', - filter + filter, + ['appRoleAssignments'] ) userSettingsStore.setUsers(usersResponse.data.value || []) }) diff --git a/packages/web-app-admin-settings/tests/unit/views/Users.spec.ts b/packages/web-app-admin-settings/tests/unit/views/Users.spec.ts index aae3a469e13..b6fe42e46ae 100644 --- a/packages/web-app-admin-settings/tests/unit/views/Users.spec.ts +++ b/packages/web-app-admin-settings/tests/unit/views/Users.spec.ts @@ -196,7 +196,8 @@ describe('Users view', () => { expect(clientService.graphAuthenticated.users.listUsers).toHaveBeenNthCalledWith( 2, 'displayName', - "(memberOf/any(m:m/id eq '1'))" + "(memberOf/any(m:m/id eq '1'))", + ['appRoleAssignments'] ) }) it('does filter initially if group ids are given via query param', async () => { @@ -210,7 +211,8 @@ describe('Users view', () => { await wrapper.vm.loadResourcesTask.last expect(clientService.graphAuthenticated.users.listUsers).toHaveBeenCalledWith( 'displayName', - "(memberOf/any(m:m/id eq '1') or memberOf/any(m:m/id eq '2'))" + "(memberOf/any(m:m/id eq '1') or memberOf/any(m:m/id eq '2'))", + ['appRoleAssignments'] ) }) }) @@ -228,7 +230,8 @@ describe('Users view', () => { expect(clientService.graphAuthenticated.users.listUsers).toHaveBeenNthCalledWith( 2, 'displayName', - "(appRoleAssignments/any(m:m/appRoleId eq '1'))" + "(appRoleAssignments/any(m:m/appRoleId eq '1'))", + ['appRoleAssignments'] ) }) it('does filter initially if role ids are given via query param', async () => { @@ -242,7 +245,8 @@ describe('Users view', () => { await wrapper.vm.loadResourcesTask.last expect(clientService.graphAuthenticated.users.listUsers).toHaveBeenCalledWith( 'displayName', - "(appRoleAssignments/any(m:m/appRoleId eq '1') or appRoleAssignments/any(m:m/appRoleId eq '2'))" + "(appRoleAssignments/any(m:m/appRoleId eq '1') or appRoleAssignments/any(m:m/appRoleId eq '2'))", + ['appRoleAssignments'] ) }) }) @@ -258,7 +262,8 @@ describe('Users view', () => { await wrapper.vm.loadResourcesTask.last expect(clientService.graphAuthenticated.users.listUsers).toHaveBeenCalledWith( 'displayName', - "contains(displayName,'Albert')" + "contains(displayName,'Albert')", + ['appRoleAssignments'] ) }) }) diff --git a/packages/web-client/src/graph.ts b/packages/web-client/src/graph.ts index 6b1c1a8caea..eba3f89dfbd 100644 --- a/packages/web-client/src/graph.ts +++ b/packages/web-client/src/graph.ts @@ -59,7 +59,12 @@ export interface Graph { changeOwnPassword: (currentPassword: string, newPassword: string) => AxiosPromise editUser: (userId: string, user: User) => AxiosPromise deleteUser: (userId: string) => AxiosPromise - listUsers: (orderBy?: string, filter?: string) => AxiosPromise + listUsers: ( + orderBy?: string, + filter?: string, + expand?: Array<'drive' | 'drives' | 'memberOf' | 'appRoleAssignments'>, + search?: string + ) => AxiosPromise createUserAppRoleAssignment: ( userId: string, appRoleAssignment: AppRoleAssignment @@ -70,7 +75,11 @@ export interface Graph { ) => AxiosPromise } groups: { - listGroups: (orderBy?: string) => AxiosPromise + listGroups: ( + orderBy?: string, + expand?: Array<'members'>, + search?: string + ) => AxiosPromise createGroup: (group: Group) => AxiosPromise getGroup: (groupId: string) => AxiosPromise editGroup: (groupId: string, group: Group) => AxiosPromise @@ -157,13 +166,18 @@ export const graph = (baseURI: string, axiosClient: AxiosInstance): Graph => { meChangepasswordApiFactory.changeOwnPassword({ currentPassword, newPassword }), editUser: (userId: string, user: User) => userApiFactory.updateUser(userId, user), deleteUser: (userId: string) => userApiFactory.deleteUser(userId), - listUsers: (orderBy?: any, filter?: string) => + listUsers: ( + orderBy?: any, + filter?: string, + expand?: Array<'drive' | 'drives' | 'memberOf' | 'appRoleAssignments'>, + search: string = '' + ) => usersApiFactory.listUsers( - '', + search, filter, - new Set([orderBy]), - new Set([]), - new Set(['appRoleAssignments']) + orderBy ? new Set([orderBy]) : null, + null, + expand ? new Set(expand) : null ), createUserAppRoleAssignment: (userId: string, appRoleAssignment: AppRoleAssignment) => userAppRoleAssignmentApiFactory.userCreateAppRoleAssignments(userId, appRoleAssignment), @@ -176,12 +190,12 @@ export const graph = (baseURI: string, axiosClient: AxiosInstance): Graph => { getGroup: (groupId: string) => groupApiFactory.getGroup(groupId, new Set([]), new Set(['members'])), deleteGroup: (groupId: string) => groupApiFactory.deleteGroup(groupId), - listGroups: (orderBy?: any) => + listGroups: (orderBy?: any, expand?: Array<'members'>, search: string = '') => groupsApiFactory.listGroups( - '', - new Set([orderBy]), - new Set([]), - new Set(['members']) + search, + orderBy ? new Set([orderBy]) : null, + null, + expand ? new Set(expand) : null ), addMember: (groupId: string, userId: string, server: string) => groupApiFactory.addMember(groupId, { '@odata.id': `${server}graph/v1.0/users/${userId}` }),