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

[PM-13839][PM-13840] Admin Console Collections #11649

Merged
merged 14 commits into from
Nov 7, 2024

Conversation

nick-livefront
Copy link
Collaborator

@nick-livefront nick-livefront commented Oct 21, 2024

🎟️ Tracking

PM-13839
PM-13840
PM-13887

Associated Server PR

📔 Objective

  • When viewing in Admin Console
    • all collections an item belongs to should be shown, even if I don't have access to the collection
  • When editing in Admin Console
    • Only collections I have edit+ access to that an item belongs to (assuming "owners and admins can manage all collections and items" is off)
    • When "owners and admins can manage all collections" is on, then all collections can be edited

📸 Screenshots

Update Cipher with Admin/owner can Edit on, then Show when admin/owner is off
admin-console-collections.mov

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

Copy link

codecov bot commented Oct 21, 2024

Codecov Report

Attention: Patch coverage is 47.61905% with 11 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@eb67b73). Learn more about missing BASE report.
Report is 3 commits behind head on main.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...ipher-form/services/default-cipher-form.service.ts 14.28% 6 Missing ⚠️
libs/common/src/vault/services/cipher.service.ts 0.00% 3 Missing ⚠️
libs/common/src/services/api.service.ts 0.00% 1 Missing ⚠️
...ibs/vault/src/cipher-view/cipher-view.component.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #11649   +/-   ##
=======================================
  Coverage        ?   33.54%           
=======================================
  Files           ?     2814           
  Lines           ?    87435           
  Branches        ?    16675           
=======================================
  Hits            ?    29333           
  Misses          ?    55797           
  Partials        ?     2305           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

github-actions bot commented Oct 21, 2024

Logo
Checkmarx One – Scan Summary & Detailsf7dd3414-9b8d-4958-bef1-1c7b4e6d8590

No New Or Fixed Issues Found

…ng any other edits

- This handles the case where a cipher is moving from unassigned to assigned and needs to have a collection to save any other edits
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This change from saving the collections before any other edits was made in part of PM-13887. I was seeing errors with saving edits before assigning to the collection.

Copy link
Member

@shane-melton shane-melton left a comment

Choose a reason for hiding this comment

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

One small edge case we need to check and then this looks good!

// Then save the new collection changes separately
encryptedCipher.collectionIds = cipher.collectionIds;
savedCipher = await this.cipherService.saveCollectionsWithServer(encryptedCipher);
savedCipher = await this.cipherService.updateWithServer(encryptedCipher, config.admin);
Copy link
Member

Choose a reason for hiding this comment

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

⚠️ There's a really specific edge case where the user may un-assign themselves from a cipher by removing the last editable collection from the cipher. If this happens, the call to cipherService.updateWithServer will fail due to a lack of permissions after first updating the collections. You'd only run into this if the access all items as admin setting was off and you removed a the last editable collection.

I believe to avoid this, we can still save the collections first. But, when the original cipher is unassigned, we need to update the call to updateWithServer to have a check for an unassigned original cipher.

e.g.

updateWithServer(encryptedCipher, config.admin || originalCollectionIds.size === 0)

This will use the admin endpoint for both of the scenarios that require it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As always, great catch 🤯 e6c5032

Copy link
Member

Choose a reason for hiding this comment

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

Agh, I misspoke in my comment above, sorry. We should still update the cipher first.

That way if a user makes a change to the cipher AND unassigns themselves, the change to cipher is still persisted. Otherwise, the user is going to unassign themselves and then fail to update the cipher because they no longer have access.

If the cipher is originally unassigned, we can update the cipher first by making the change described above and also updating the call to use the saveCollectionsWithServerAdmin() method to account for the unassigned permissions.

Copy link
Member

@shane-melton shane-melton Oct 29, 2024

Choose a reason for hiding this comment

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

(We should eventually just encapsulate this “admin / not admin” logic internally within the CipherService to avoid this headache repeatedly. But, I don’t think we need to do that here and now, as there will likely be other consequences we’ll have to consider that outside of scope.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think I finally wrapped my head around all of the permutations that can happen here 😅 And I was able to get those situations rolling locally so I feel better about that too.

e70380e & 679ceb2

- handling the case where the user  un-assigns themselves from a cipher
Comment on lines 261 to 262
c.canEditItems(organization) &&
(this.partialEdit || !c.readOnly || this.config.admin)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@shane-melton The logic behind canEditItems and !c.readOnly || this.config.admin overlaps. Do you think it's better to be explicit here with referencing the config? Or should I update the logic to

c.organizationId === orgId && c.canEditItems(organization) && this.partialEdit

Copy link
Member

Choose a reason for hiding this comment

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

I think its okay to be explicit and reference the config.

With that said, I do think we want to re-arrange these conditions so that partialEdit still supersedes the edit-ability of a collection because the control is disabled.

c.organizationId === orgId && (this.partialEdit || c.canEditItems(organization) || this.config.admin)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍 fea33b1

shane-melton
shane-melton previously approved these changes Oct 31, 2024
Copy link
Member

@shane-melton shane-melton left a comment

Choose a reason for hiding this comment

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

Changes look good to me! Really nice work on this!

@shane-melton shane-melton dismissed their stale review October 31, 2024 18:49

Failing tests

@shane-melton shane-melton self-requested a review October 31, 2024 18:49
Copy link
Member

@shane-melton shane-melton left a comment

Choose a reason for hiding this comment

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

Oops, looks like we have some failing tests

Comment on lines +249 to +251
} else {
collectionsControl.enable();
this.showCollectionsControl = true;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@shane-melton Calling this change out. The "should enable/show collection control when an organization is selected" unit test caught the case where orgId is falsy but then truthy. I don't believe that this would happen in the UI but through the logic it's possible so I added the enable/show logic here.

Copy link
Member

Choose a reason for hiding this comment

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

That should be fine and I agree, I don't think it should come up in use, but better safe than sorry!

shane-melton
shane-melton previously approved these changes Nov 1, 2024
Comment on lines +286 to +298
let cipher: Cipher;

// When the form config is used within the Admin Console, retrieve the cipher from the admin endpoint
if (this.formConfig.isAdminConsole) {
const cipherResponse = await this.apiService.getCipherAdmin(cipherView.id);
const cipherData = new CipherData(cipherResponse);
cipher = new Cipher(cipherData);
} else {
cipher = await this.cipherService.get(cipherView.id);
}

// Store the updated cipher so any following edits use the most up to date cipher
this.formConfig.originalCipher = cipher;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This logic stems from defect: PM-14449.

When a cipher was edited within the Admin console and the user doesn't have "direct" access, the cipherService will return null. In this case the getCipherAdmin should be used to refetch the cipher

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

edit-after-edit.mov

Copy link
Member

Choose a reason for hiding this comment

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

Good catch!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

😅 We can all thank Brad!

@nick-livefront nick-livefront merged commit b42741f into main Nov 7, 2024
63 of 64 checks passed
@nick-livefront nick-livefront deleted the vault/pm-13839-13840/admin-console-collections branch November 7, 2024 16:22
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.

2 participants