Skip to content

Commit

Permalink
Fix adding multiple users to buckets and objects
Browse files Browse the repository at this point in the history
Giving permissions to one user will no longer remove other users
without permissions from the permissions list. For objects and buckets

When user is added to permissions, they automatically have read perms
Modified files:
	BucketPermission.vue
	BucketPermissionAddUser.vue
	ObjectPermission.vue
	ObjectPermissionAddUser.vue
	permissionStore.ts
  • Loading branch information
wilwong89 committed Dec 8, 2023
1 parent 97cb7d2 commit 9c14383
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 54 deletions.
5 changes: 4 additions & 1 deletion frontend/src/components/bucket/BucketPermission.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ onBeforeMount(async () => {
</Button>
</div>
<div v-else>
<BucketPermissionAddUser @cancel-search-users="cancelSearchUsers" />
<BucketPermissionAddUser
:bucket-id="props.bucketId"
@cancel-search-users="cancelSearchUsers"
/>
</div>

<DataTable
Expand Down
26 changes: 9 additions & 17 deletions frontend/src/components/bucket/BucketPermissionAddUser.vue
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
<script setup lang="ts">
import { storeToRefs } from 'pinia';
import SearchUsers from '@/components/form/SearchUsers.vue';
import { useConfigStore, usePermissionStore } from '@/store';
import { Permissions } from '@/utils/constants';
import { usePermissionStore } from '@/store';
import type { User } from '@/types';
type Props = {
bucketId: string;
};
const props = withDefaults(defineProps<Props>(), {});
// Store
const { getConfig } = storeToRefs(useConfigStore());
const permissionStore = usePermissionStore();
// Actions
const onAdd = (selectedUser: User) => {
const idp = getConfig.value.idpList.find((idp: any) => idp.idp === selectedUser?.idp);
permissionStore.addBucketUser({
userId: selectedUser.userId,
idpName: idp?.name,
elevatedRights: idp?.elevatedRights,
fullName: selectedUser.fullName,
create: false,
read: false,
update: false,
delete: false,
manage: false
});
permissionStore.addBucketPermission(props.bucketId, selectedUser.userId, Permissions.READ);
};
</script>

Expand Down
5 changes: 4 additions & 1 deletion frontend/src/components/object/ObjectPermission.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ onBeforeMount(() => {
</Button>
</div>
<div v-else>
<ObjectPermissionAddUser @cancel-search-users="cancelSearchUsers" />
<ObjectPermissionAddUser
:object-id="props.objectId"
@cancel-search-users="cancelSearchUsers"
/>
</div>

<DataTable
Expand Down
26 changes: 9 additions & 17 deletions frontend/src/components/object/ObjectPermissionAddUser.vue
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
<script setup lang="ts">
import { storeToRefs } from 'pinia';
import SearchUsers from '@/components/form/SearchUsers.vue';
import { useConfigStore, usePermissionStore } from '@/store';
import { Permissions } from '@/utils/constants';
import { usePermissionStore } from '@/store';
import type { User } from '@/types';
type Props = {
objectId: string;
};
const props = withDefaults(defineProps<Props>(), {});
// Store
const { getConfig } = storeToRefs(useConfigStore());
const permissionStore = usePermissionStore();
// Actions
const onAdd = (selectedUser: User) => {
const idp = getConfig.value.idpList.find((idp: any) => idp.idp === selectedUser?.idp);
permissionStore.addObjectUser({
userId: selectedUser.userId,
idpName: idp?.name,
elevatedRights: idp?.elevatedRights,
fullName: selectedUser.fullName,
create: false,
read: false,
update: false,
delete: false,
manage: false
});
permissionStore.addObjectPermission(props.objectId, selectedUser.userId, Permissions.READ);
};
</script>

Expand Down
18 changes: 0 additions & 18 deletions frontend/src/store/permissionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,6 @@ export const usePermissionStore = defineStore('permission', () => {
}
}

function addBucketUser(user: UserPermissions) {
try {
getters.getMappedBucketToUserPermissions.value.push(user);
} catch (error: any) {
toast.error('Adding bucket user', error);
}
}

async function addObjectPermission(objectId: string, userId: string, permCode: string) {
try {
appStore.beginIndeterminateLoading();
Expand All @@ -92,14 +84,6 @@ export const usePermissionStore = defineStore('permission', () => {
}
}

function addObjectUser(user: UserPermissions) {
try {
getters.getMappedObjectToUserPermissions.value.push(user);
} catch (error: any) {
toast.error('Adding object user', error);
}
}

async function deleteBucketPermission(bucketId: string, userId: string, permCode: string) {
try {
appStore.beginIndeterminateLoading();
Expand Down Expand Up @@ -327,9 +311,7 @@ export const usePermissionStore = defineStore('permission', () => {

// Actions
addBucketPermission,
addBucketUser,
addObjectPermission,
addObjectUser,
deleteBucketPermission,
deleteObjectPermission,
fetchBucketPermissions,
Expand Down

0 comments on commit 9c14383

Please sign in to comment.