Skip to content

[PM-36678] Fix custom users modifying admins for restore and revoke.#7601

Draft
JimmyVo16 wants to merge 1 commit intomainfrom
ac/pm-36678/fix-fix-custom-users-modifying-admins
Draft

[PM-36678] Fix custom users modifying admins for restore and revoke.#7601
JimmyVo16 wants to merge 1 commit intomainfrom
ac/pm-36678/fix-fix-custom-users-modifying-admins

Conversation

@JimmyVo16
Copy link
Copy Markdown
Contributor

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-36678

📔 Objective

📸 Screenshots

@JimmyVo16 JimmyVo16 self-assigned this May 8, 2026

namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.Validators;

public class CustomUserActingOnAdminValidator(ICurrentContext currentContext) : ICustomUserActingOnAdminValidator
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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:

  1. Keeps the logic DRY
  2. 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)
{
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I still need to iterate on this a bit.

@@ -0,0 +1,8 @@
namespace Bit.Core.AdminConsole.Enums;

public enum OrganizationUserActionType
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 8, 2026

@codecov
Copy link
Copy Markdown

codecov Bot commented May 8, 2026

Codecov Report

❌ Patch coverage is 56.25000% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.72%. Comparing base (2d07451) to head (38556bd).

Files with missing lines Patch % Lines
...ers/Validators/CustomUserActingOnAdminValidator.cs 35.71% 16 Missing and 2 partials ⚠️
.../RevokeUser/v2/RevokeOrganizationUsersValidator.cs 81.81% 1 Missing and 1 partial ⚠️
...Features/OrganizationUsers/RevokeUser/v2/Errors.cs 0.00% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

1 participant