-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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-18087] Add cipher permissions to response models #5418
base: ac/pm-18086/add-authorization-methods
Are you sure you want to change the base?
[PM-18087] Add cipher permissions to response models #5418
Conversation
This change introduces organization ability context to various cipher response models across multiple controllers. The modifications include: - Updating CipherResponseModel to include permissions based on user and organization ability - Modifying CiphersController methods to fetch and pass organization abilities - Updating SyncController to include organization abilities in sync response - Adding organization ability context to EmergencyAccessController response generation
This change simplifies the EmergencyAccessController by removing unnecessary organization ability fetching and passing. Since emergency access only retrieves personal ciphers, the organization ability context is no longer needed in the response generation.
Remove unnecessary JsonConstructor attribute and simplify constructor initialization for EmergencyAccessViewResponseModel
New Issues (22)Checkmarx found the following issues in this Pull Request
Fixed Issues (228)Great job! The following issues were fixed in this Pull Request
|
Extract methods to simplify organization ability fetching for ciphers, reducing code duplication and improving readability. Added two private helper methods: - GetOrganizationAbilityAsync: Retrieves organization ability for a single cipher - GetManyOrganizationAbilitiesAsync: Retrieves organization abilities for multiple ciphers
Modify test methods to: - Replace GetProperUserId with GetUserByPrincipalAsync - Use User object instead of separate userId - Update mocking to return User object - Ensure user ID is correctly set in test scenarios
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## ac/pm-18086/add-authorization-methods #5418 +/- ##
=========================================================================
- Coverage 44.22% 44.21% -0.02%
=========================================================================
Files 1501 1502 +1
Lines 69379 69478 +99
Branches 6248 6253 +5
=========================================================================
+ Hits 30685 30720 +35
- Misses 37370 37434 +64
Partials 1324 1324 ☔ View full report in Codecov by Sentry. |
Delete = NormalCipherPermissions.CanDelete(user, cipher, organizationAbility), | ||
Restore = NormalCipherPermissions.CanRestore(user, cipher, organizationAbility) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: this is probably better encapsulated in the ctor for the CipherPermissionsResponseModel
.
cipher.OrganizationId.HasValue && organizationAbilities.TryGetValue(cipher.OrganizationId.Value, out var organizationAbility) ? | ||
organizationAbility : null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pattern is repeated a few times in different forms: "if it's an organizational cipher, find and pass in the orgAbility, otherwise null". It works but the caller has to know a bit too much about what's required and how to get it. Maybe that's just a limitation of passing all this into the static method vs. dependency injection. It did make me wonder whether we should pass in the IApplicationCacheService
directly, or the dict of OrganizationAbilities
, to push the detail down into the response model. But I'm not sure.
|
🎟️ Tracking
https://bitwarden.atlassian.net/browse/PM-18087
📔 Objective
CipherPermissionsResponseModel
to explicitly communicate cipher permissionsDelete
andRestore
boolean propertiesNormalCipherPermissions
to calculate these valuesCipherResponseModel
to include the new permissions propertyOrganizationAbility
parameter to relevant response model constructors to support permission calculationsImplementation Details
OrganizationAbility
for organizational ciphers📸 Screenshots
⏰ Reminders before review
🦮 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