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

Object Permissions #23

Merged
merged 10 commits into from
Jan 26, 2023
Merged

Object Permissions #23

merged 10 commits into from
Jan 26, 2023

Conversation

loneil
Copy link
Contributor

@loneil loneil commented Jan 16, 2023

Description

Allow users to set object permissions on files they have manage permissions for. The "Add User" part is on an upcoming ticket.

image

Don't show the actions on a file that you don't have the corresponding permission for.

Additionally a fix for
https://apps.nrs.gov.bc.ca/int/jira/browse/SHOWCASE-3012

Types of changes

New feature (non-breaking change which adds functionality)

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

There's probably some efficiencies that can be done here. This is mostly the same code as the bucket permissions screen and table, but with enough changes I couldn't quickly figure out how to generalize it. There's some differences between the 2 things.
Possibly could be refactored to a common component and/or composable, but need to be sure the behavior would stay the same.

At the very least the component SCSS should be extracted out so that it's not duplicated. Would need to decide if above path would be looked at, if not, move to global scss for this type of checkbox table.

@github-actions
Copy link

github-actions bot commented Jan 16, 2023

Coverage Report (Frontend)

Totals Coverage
Statements: 43.68% ( 38 / 87 )
Methods: 25% ( 6 / 24 )
Lines: 53.85% ( 28 / 52 )
Branches: 36.36% ( 4 / 11 )

@github-actions
Copy link

Coverage Report (Application)

Totals Coverage
Statements: 75% ( 51 / 68 )
Methods: 62.5% ( 5 / 8 )
Lines: 82.61% ( 38 / 46 )
Branches: 57.14% ( 8 / 14 )

frontend/src/store/objectStore.ts Show resolved Hide resolved
frontend/src/store/objectStore.ts Show resolved Hide resolved
frontend/src/store/objectStore.ts Show resolved Hide resolved
frontend/src/store/objectStore.ts Show resolved Hide resolved
frontend/src/store/objectStore.ts Show resolved Hide resolved
@codeclimate
Copy link

codeclimate bot commented Jan 16, 2023

Code Climate has analyzed commit 39051a3 and detected 11 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 1
Duplication 10

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 67.0% (-15.5% change).

View more on Code Climate.

@loneil loneil force-pushed the feature/objectPermissionUi branch from 39051a3 to 16ecd0d Compare January 19, 2023 19:20
@loneil loneil changed the title WIP Object Permissions Jan 23, 2023
Comment on lines +48 to +50
await Promise.all([
bucketStore.getBucketPermissionsForUser(route.query.bucketId?.toString() || ''),
objectStore.listObjects({ bucketId: route.query.bucketId })
Copy link
Contributor Author

Choose a reason for hiding this comment

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

So if you directly navigate to a object list landing page, you will have your perms for that bucket populated.

@loneil loneil force-pushed the feature/objectPermissionUi branch from d617137 to 4e34a6f Compare January 23, 2023 23:01
Copy link
Member

@jujaga jujaga left a comment

Choose a reason for hiding this comment

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

Semantically looks good. Just a few comments for consideration.

frontend/src/components/object/ObjectPermission.vue Outdated Show resolved Hide resolved
frontend/src/services/objectService.ts Outdated Show resolved Hide resolved
frontend/src/services/permissionService.ts Outdated Show resolved Hide resolved
Comment on lines +185 to +193
for (const [, value] of Object.entries(Permissions)) {
await objectService.deletePermission(bucketId, {
userId,
permCode: value,
});
}
Copy link
Member

Choose a reason for hiding this comment

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

Two thoughts:

  1. If we're only using the values and don't need the key/value pairing, we should probably be using Object.values() instead.
for (const value of Object.values(Permissions)) {
  1. Since this looks like a general async dispatcher pattern, it may be better to wrap this into a Promise.all() for synchronization purposes:
await Promise.all(
  Object.values(Permissions)
    .map(perm => objectService.deletePermission(bucketId, {
      userId,
      permCode: value,
    }));
);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Used the same logic as in existing bucketStore removeBucketUser.
Think there's possibly a way to take in the service method and have this permission logic extracted to a common util function (for buckets and objects). So someone could take a look at that at some point and implement your logic above for both (ideally in one palce)

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.

a lot of good stuff in here!

frontend/src/components/object/ObjectTable.vue Outdated Show resolved Hide resolved

// Add the permissions to each object list item
Copy link
Contributor

Choose a reason for hiding this comment

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

i think in line 77 we are removing the perms and then adding them again here in line 91. not sure if that could be optimized.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the line 77 being referred to is just stashing the specific IDs from the permissions to fetch the objects? So not removing them?
(file has changed since so line 77 might be something else from original comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

my point was: we are looping through permResponse in line 77, the perms can be added there instead of doing another loop. only mention this because for a bucket full of objects this could impact the speed

@TimCsaky
Copy link
Contributor

TimCsaky commented Jan 24, 2023

just ran this in the browser and it's looking good.
couple more minor things we will probably have to look at later:

  • i was able to remove myself (remove user) from the list of users with permissions. But then i still see the file in objects table. i think i still had the read permission before i clicked the remove button.
  • there's some kind of flickering when the objects table is refreshed, i wonder if there's a black or missing css background somewhere.

update:

  • re: removing myself, it's probably an issue with inconsistent data state. not concerned right now
  • re: flickering table, it's just the 'loading overlay' from primeview (p.datatable-loading-overlay)
    this feels resolved

Signed-off-by: Lucas ONeil <[email protected]>
Signed-off-by: Lucas ONeil <[email protected]>
Remove extra merge line

Signed-off-by: Lucas ONeil <[email protected]>
Signed-off-by: Lucas ONeil <[email protected]>
Signed-off-by: Lucas ONeil <[email protected]>
@loneil loneil force-pushed the feature/objectPermissionUi branch from 4e34a6f to b57f8d1 Compare January 26, 2023 04:43
Signed-off-by: Lucas ONeil <[email protected]>
Signed-off-by: Lucas ONeil <[email protected]>
Signed-off-by: Lucas ONeil <[email protected]>
@TimCsaky TimCsaky merged commit f101d7e into master Jan 26, 2023
@kamorel kamorel deleted the feature/objectPermissionUi branch February 2, 2023 00:13
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.

4 participants