@@ -5,6 +5,7 @@ import { useToast } from '@/lib/primevue';
5
5
import { permissionService , userService } from '@/services' ;
6
6
import { useAppStore , useAuthStore , useConfigStore } from '@/store' ;
7
7
import { Permissions } from '@/utils/constants' ;
8
+ import { partition } from '@/utils/utils' ;
8
9
9
10
import type { Ref } from 'vue' ;
10
11
import type {
@@ -129,8 +130,13 @@ export const usePermissionStore = defineStore('permission', () => {
129
130
const response = ( await permissionService . bucketSearchPermissions ( params ) ) . data ;
130
131
const newPerms : Array < BucketPermission > = response . flatMap ( ( x : any ) => x . permissions ) ;
131
132
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 ) ;
134
140
135
141
// Pass response back so bucketStore can handle bucketPerms=true correctly
136
142
return response ;
@@ -151,7 +157,13 @@ export const usePermissionStore = defineStore('permission', () => {
151
157
152
158
const newPerms : Array < COMSObjectPermission > = response . flatMap ( ( x : any ) => x . permissions ) ;
153
159
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 ) ;
155
167
156
168
// Pass response back so objectStore can handle bucketPerms=true correctly
157
169
return response ;
0 commit comments