[PM-36678] Fix custom users modifying admins for restore and revoke.#7601
[PM-36678] Fix custom users modifying admins for restore and revoke.#7601
Conversation
|
|
||
| namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.Validators; | ||
|
|
||
| public class CustomUserActingOnAdminValidator(ICurrentContext currentContext) : ICustomUserActingOnAdminValidator |
There was a problem hiding this comment.
Hey @sven-bitwarden , this is a new pattern I’m trying out. Happy to get any feedback.
We’re obviously doing the same check in a lot of places, so I was thinking we could abstract it into a single validator.
Benefits:
- Keeps the logic DRY
- Handles both single-user and bulk-user org cases without requiring multiple async calls.
| // Probes with any admin in the batch. The rule's answer is uniform across every admin | ||
| // in the same organization, so one cached lookup covers the whole batch. | ||
| private async Task<bool> CustomUserCannotRevokeAdminAsync(IEnumerable<OrganizationUser> users) | ||
| { |
There was a problem hiding this comment.
I still need to iterate on this a bit.
| @@ -0,0 +1,8 @@ | |||
| namespace Bit.Core.AdminConsole.Enums; | |||
|
|
|||
| public enum OrganizationUserActionType | |||
There was a problem hiding this comment.
The goal of this was to allow the commands to just pass in the action, while keeping the error messages in the validator. This is mainly to reduce logic in the commands. Also, most of the messages are the same, so centralizing them is a good idea.
I thought about passing in the class type, but that would narrow the calling code to only those types. An enum seems like the easiest solution, but I’m open to ideas.
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #7601 +/- ##
==========================================
- Coverage 59.73% 59.72% -0.01%
==========================================
Files 2109 2110 +1
Lines 92752 92797 +45
Branches 8246 8252 +6
==========================================
+ Hits 55403 55425 +22
- Misses 35384 35403 +19
- Partials 1965 1969 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|



🎟️ Tracking
https://bitwarden.atlassian.net/browse/PM-36678
📔 Objective
📸 Screenshots