Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix adding multiple users to buckets and objects #151

Merged
merged 6 commits into from
Dec 13, 2023

Conversation

wilwong89
Copy link
Contributor

@wilwong89 wilwong89 commented Dec 8, 2023

Description

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

Types of changes

Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have read the CONTRIBUTING doc
  • I have checked that unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

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
Copy link

github-actions bot commented Dec 8, 2023

Coverage Report (Application)

Totals Coverage
Statements: 70.67% ( 53 / 75 )
Methods: 62.5% ( 5 / 8 )
Lines: 81.63% ( 40 / 49 )
Branches: 44.44% ( 8 / 18 )

Copy link

github-actions bot commented Dec 8, 2023

Coverage Report (Frontend)

Totals Coverage
Statements: 32.61% ( 598 / 1834 )
Methods: 29.62% ( 117 / 395 )
Lines: 39.48% ( 426 / 1079 )
Branches: 15.28% ( 55 / 360 )

frontend/src/store/permissionStore.ts Outdated Show resolved Hide resolved
frontend/src/store/permissionStore.ts Outdated Show resolved Hide resolved
frontend/src/store/permissionStore.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@TimCsaky TimCsaky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor comments.
i guess the issue with empty rows being removed is that after a checbox is selected, the datatable always resets to whatever permissions are in the store.
Not sure how to solve that, maybe an array of added users (without a ticked permission) could be added to the component's local state and that is merged into the datatable data.

const afterPerms = [...state.mappedObjectToUserPermissions.value];

const results = initialPerms.filter(({ userId: id1 }) => !afterPerms.some(({ userId: id2 }) => id2 === id1));
state.mappedObjectToUserPermissions.value = state.mappedObjectToUserPermissions.value.concat(results);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wonder if this before and after comparison is necessary. i think line 91 await permissionService.objectAddPermissions(objectId, [{ userId, permCode: Permissions.READ }]); returns the full details of the permission added

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The data returned by line 91 does not return the full details, it returns a different object that is slightly different. For example, the data returned does not have the name or email fields and if the previous user permission did not already have the READ perm code and another (non-READ) perm code is added, the data returned suggests that only READ was updated.

@@ -293,13 +309,23 @@ export const usePermissionStore = defineStore('permission', () => {
} catch (error: any) {
toast.error('Removing bucket user', error);
} finally {
await fetchBucketPermissions();
await mapBucketToUserPermissions(bucketId);
await removeBucketUserPermsHandler(bucketId, userId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same with these.. not sure if you need the new handler function.. maybe you can drop this permission from the store here.
line 307:
deletedPermission = await permissionService.bucketDeletePermission(bucketId, { userId, permCode: value });

 state.mappedBucketToUserPermissions.value = state.mappedBucketToUserPermissions.value.filter(p => p.id !== deletedPermission.id)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using your method to read the deleted permission and then dropping it from the local state requires storing an array of deleted permissions returned form line, iteratively checking that list and removing to remove the permissions from the local state, and then finally another check to see if all permissions were removed from an entry in the local list before removing the entry entirely. I think instead the current method of doing a simple diff from before and after is the better method.

@TimCsaky TimCsaky merged commit 5b84682 into master Dec 13, 2023
18 checks passed
@jujaga jujaga deleted the fix/add-multi-users branch December 13, 2023 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants