Skip to content

Commit

Permalink
do compare and update user to permission mapping in store
Browse files Browse the repository at this point in the history
store mapped users for multiple objects/buckets
Rather than replacing map<bucket/user>ToUserPermissions
every time context changes, compare existing data and patch as required
reduces network calls
  • Loading branch information
TimCsaky committed Feb 15, 2024
1 parent fd64478 commit 55263ca
Show file tree
Hide file tree
Showing 7 changed files with 233 additions and 132 deletions.
21 changes: 14 additions & 7 deletions frontend/src/components/bucket/BucketPermission.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ const cancelSearchUsers = () => {
};
const removeBucketUser = (userId: string) => {
const managers = getMappedBucketToUserPermissions.value.filter((x: UserPermissions) => x.manage);
const managers = getMappedBucketToUserPermissions
.value(props.bucketId)
.filter((x: UserPermissions) => x.manage && x.id === props.bucketId);
if (managers.length === 1 && managers[0].userId === userId) {
removeManageAlert.show();
} else {
Expand All @@ -46,16 +48,18 @@ const updateBucketPermission = (value: boolean, userId: string, permCode: string
if (value) {
permissionStore.addBucketPermission(props.bucketId, userId, permCode);
} else {
const managers = getMappedBucketToUserPermissions.value.filter((x: UserPermissions) => x.manage);
const managers = getMappedBucketToUserPermissions
.value(props.bucketId)
.filter((x: UserPermissions) => x.manage && x.id === props.bucketId);
// Disallow removable of final MANAGE permission
if (permCode === Permissions.MANAGE && !managers.length) {
removeManageAlert.show();
// Set the value back as clicking will automatically change it
const perm: UserPermissions = getMappedBucketToUserPermissions.value.find(
(x: UserPermissions) => x.userId === userId
) as UserPermissions;
const perm: UserPermissions = getMappedBucketToUserPermissions
.value(props.bucketId)
.find((x: UserPermissions) => x.userId === userId && x.id === props.bucketId) as UserPermissions;
perm.manage = true;
} else {
permissionStore.deleteBucketPermission(props.bucketId, userId, permCode);
Expand Down Expand Up @@ -84,11 +88,14 @@ onBeforeMount(async () => {
</Button>
</div>
<div v-else>
<BucketPermissionAddUser @cancel-search-users="cancelSearchUsers" />
<BucketPermissionAddUser
@cancel-search-users="cancelSearchUsers"
:bucket-id="props.bucketId"
/>
</div>

<DataTable
:value="getMappedBucketToUserPermissions"
:value="getMappedBucketToUserPermissions(props.bucketId)"
data-key="bucketId"
class="p-datatable-sm"
responsive-layout="scroll"
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/components/bucket/BucketPermissionAddUser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { useConfigStore, usePermissionStore } from '@/store';
import type { User } from '@/types';
// Props
const props = withDefaults(defineProps<{ bucketId: string }>(), {});
// Store
const { getConfig } = storeToRefs(useConfigStore());
const permissionStore = usePermissionStore();
Expand All @@ -15,6 +18,7 @@ const onAdd = (selectedUser: User) => {
const idp = getConfig.value.idpList.find((idp: any) => idp.idp === selectedUser?.idp);
permissionStore.addBucketUser({
id: props.bucketId,
userId: selectedUser.userId,
idpName: idp?.name,
elevatedRights: idp?.elevatedRights,
Expand All @@ -30,7 +34,7 @@ const onAdd = (selectedUser: User) => {

<template>
<SearchUsers
:permissions="permissionStore.getMappedBucketToUserPermissions"
:permissions="permissionStore.getMappedBucketToUserPermissions(bucketId)"
@add-user="onAdd"
/>
</template>
7 changes: 5 additions & 2 deletions frontend/src/components/object/ObjectPermission.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,14 @@ onBeforeMount(() => {
</Button>
</div>
<div v-else>
<ObjectPermissionAddUser @cancel-search-users="cancelSearchUsers" />
<ObjectPermissionAddUser
@cancel-search-users="cancelSearchUsers"
:object-id="props.objectId"
/>
</div>

<DataTable
:value="getMappedObjectToUserPermissions"
:value="getMappedObjectToUserPermissions(objectId)"
data-key="userId"
class="p-datatable-sm"
responsive-layout="scroll"
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/components/object/ObjectPermissionAddUser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { useConfigStore, usePermissionStore } from '@/store';
import type { User } from '@/types';
// Props
const props = withDefaults(defineProps<{ objectId: string }>(), {});
// Store
const { getConfig } = storeToRefs(useConfigStore());
const permissionStore = usePermissionStore();
Expand All @@ -15,6 +18,7 @@ const onAdd = (selectedUser: User) => {
const idp = getConfig.value.idpList.find((idp: any) => idp.idp === selectedUser?.idp);
permissionStore.addObjectUser({
id: props.objectId,
userId: selectedUser.userId,
idpName: idp?.name,
elevatedRights: idp?.elevatedRights,
Expand All @@ -30,7 +34,7 @@ const onAdd = (selectedUser: User) => {

<template>
<SearchUsers
:permissions="permissionStore.getMappedObjectToUserPermissions"
:permissions="permissionStore.getMappedObjectToUserPermissions(props.objectId)"
@add-user="onAdd"
/>
</template>
Loading

0 comments on commit 55263ca

Please sign in to comment.