Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: make expand on user and group listings optional #10566

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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