Skip to content

Commit

Permalink
Restore permission store patch process
Browse files Browse the repository at this point in the history
  • Loading branch information
TimCsaky committed Jun 5, 2024
1 parent 6bd2898 commit 9980b10
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions frontend/src/store/permissionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useToast } from '@/lib/primevue';
import { permissionService, userService } from '@/services';
import { useAppStore, useAuthStore, useConfigStore } from '@/store';
import { Permissions } from '@/utils/constants';
import { partition } from '@/utils/utils';

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

// Merge and assign
state.bucketPermissions.value = newPerms;
// patch bucketPermissions state with latest perms from COMS
const matches = (x: BucketPermission) =>
(!params.bucketId || x.bucketId === params.bucketId) &&
(!params.userId || x.userId === params.userId) &&
(!params.permCode || x.permCode === params.permCode);
const [, difference] = partition(state.bucketPermissions.value, matches);
state.bucketPermissions.value = difference.concat(newPerms);

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

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

state.objectPermissions.value = newPerms;
// patch objectPermissions state with latest perms from COMS
const matches = (x: COMSObjectPermission) =>
(!params.objectId || x.objectId === params.objectId) &&
(!params.userId || x.userId === params.userId) &&
(!params.permCode || x.permCode === params.permCode);
const [, difference] = partition(state.objectPermissions.value, matches);
state.objectPermissions.value = difference.concat(newPerms);

// Pass response back so objectStore can handle bucketPerms=true correctly
return response;
Expand Down

0 comments on commit 9980b10

Please sign in to comment.