Skip to content

Commit cd7fbe9

Browse files
authored
Merge pull request #209 from bcgov/bug/perm-background
Restore permission store patch process
2 parents 6bd2898 + 9980b10 commit cd7fbe9

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

frontend/src/store/permissionStore.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useToast } from '@/lib/primevue';
55
import { permissionService, userService } from '@/services';
66
import { useAppStore, useAuthStore, useConfigStore } from '@/store';
77
import { Permissions } from '@/utils/constants';
8+
import { partition } from '@/utils/utils';
89

910
import type { Ref } from 'vue';
1011
import type {
@@ -129,8 +130,13 @@ export const usePermissionStore = defineStore('permission', () => {
129130
const response = (await permissionService.bucketSearchPermissions(params)).data;
130131
const newPerms: Array<BucketPermission> = response.flatMap((x: any) => x.permissions);
131132

132-
// Merge and assign
133-
state.bucketPermissions.value = newPerms;
133+
// patch bucketPermissions state with latest perms from COMS
134+
const matches = (x: BucketPermission) =>
135+
(!params.bucketId || x.bucketId === params.bucketId) &&
136+
(!params.userId || x.userId === params.userId) &&
137+
(!params.permCode || x.permCode === params.permCode);
138+
const [, difference] = partition(state.bucketPermissions.value, matches);
139+
state.bucketPermissions.value = difference.concat(newPerms);
134140

135141
// Pass response back so bucketStore can handle bucketPerms=true correctly
136142
return response;
@@ -151,7 +157,13 @@ export const usePermissionStore = defineStore('permission', () => {
151157

152158
const newPerms: Array<COMSObjectPermission> = response.flatMap((x: any) => x.permissions);
153159

154-
state.objectPermissions.value = newPerms;
160+
// patch objectPermissions state with latest perms from COMS
161+
const matches = (x: COMSObjectPermission) =>
162+
(!params.objectId || x.objectId === params.objectId) &&
163+
(!params.userId || x.userId === params.userId) &&
164+
(!params.permCode || x.permCode === params.permCode);
165+
const [, difference] = partition(state.objectPermissions.value, matches);
166+
state.objectPermissions.value = difference.concat(newPerms);
155167

156168
// Pass response back so objectStore can handle bucketPerms=true correctly
157169
return response;

0 commit comments

Comments
 (0)