Skip to content

Commit

Permalink
refactor: make expand on user and group listings optional
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JammingBen committed Mar 8, 2024
1 parent ca99129 commit 3c08d81
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 20 deletions.
4 changes: 3 additions & 1 deletion packages/web-app-admin-settings/src/views/Groups.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 || [])
})
Expand Down
8 changes: 6 additions & 2 deletions packages/web-app-admin-settings/src/views/Users.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down Expand Up @@ -268,7 +271,8 @@ export default defineComponent({
const usersResponse = yield clientService.graphAuthenticated.users.listUsers(
'displayName',
filter
filter,
['appRoleAssignments']
)
userSettingsStore.setUsers(usersResponse.data.value || [])
})
Expand Down
15 changes: 10 additions & 5 deletions packages/web-app-admin-settings/tests/unit/views/Users.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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']
)
})
})
Expand All @@ -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 () => {
Expand All @@ -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']
)
})
})
Expand All @@ -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']
)
})
})
Expand Down
38 changes: 26 additions & 12 deletions packages/web-client/src/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ export interface Graph {
changeOwnPassword: (currentPassword: string, newPassword: string) => AxiosPromise<void>
editUser: (userId: string, user: User) => AxiosPromise<User>
deleteUser: (userId: string) => AxiosPromise<void>
listUsers: (orderBy?: string, filter?: string) => AxiosPromise<CollectionOfUser>
listUsers: (
orderBy?: string,
filter?: string,
expand?: Array<'drive' | 'drives' | 'memberOf' | 'appRoleAssignments'>,
search?: string
) => AxiosPromise<CollectionOfUser>
createUserAppRoleAssignment: (
userId: string,
appRoleAssignment: AppRoleAssignment
Expand All @@ -70,7 +75,11 @@ export interface Graph {
) => AxiosPromise<void>
}
groups: {
listGroups: (orderBy?: string) => AxiosPromise<CollectionOfGroup>
listGroups: (
orderBy?: string,
expand?: Array<'members'>,
search?: string
) => AxiosPromise<CollectionOfGroup>
createGroup: (group: Group) => AxiosPromise<Group>
getGroup: (groupId: string) => AxiosPromise<Group>
editGroup: (groupId: string, group: Group) => AxiosPromise<void>
Expand Down Expand Up @@ -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<any>([orderBy]),
new Set<any>([]),
new Set<any>(['appRoleAssignments'])
orderBy ? new Set<any>([orderBy]) : null,
null,
expand ? new Set<any>(expand) : null
),
createUserAppRoleAssignment: (userId: string, appRoleAssignment: AppRoleAssignment) =>
userAppRoleAssignmentApiFactory.userCreateAppRoleAssignments(userId, appRoleAssignment),
Expand All @@ -176,12 +190,12 @@ export const graph = (baseURI: string, axiosClient: AxiosInstance): Graph => {
getGroup: (groupId: string) =>
groupApiFactory.getGroup(groupId, new Set<any>([]), new Set<any>(['members'])),
deleteGroup: (groupId: string) => groupApiFactory.deleteGroup(groupId),
listGroups: (orderBy?: any) =>
listGroups: (orderBy?: any, expand?: Array<'members'>, search: string = '') =>
groupsApiFactory.listGroups(
'',
new Set<any>([orderBy]),
new Set<any>([]),
new Set<any>(['members'])
search,
orderBy ? new Set<any>([orderBy]) : null,
null,
expand ? new Set<any>(expand) : null
),
addMember: (groupId: string, userId: string, server: string) =>
groupApiFactory.addMember(groupId, { '@odata.id': `${server}graph/v1.0/users/${userId}` }),
Expand Down

0 comments on commit 3c08d81

Please sign in to comment.