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-19332] Create InitPendingOrganizationCommand #5584

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

BTreston
Copy link
Contributor

@BTreston BTreston commented Mar 31, 2025

🎟️ Tracking

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

📔 Objective

Simple lift and shift of the InitPendingOrg method into a command.

📸 Screenshots

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team

🦮 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

private async Task<bool> CanUpdateAsync(Guid organizationId)
{
var organization = _currentContext.GetOrganization(organizationId);
if (organization != null)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not fully sure which checks here would really be best

Copy link
Contributor

Logo
Checkmarx One – Scan Summary & Detailsc95dd93e-20e6-4c66-ac02-386a8b446ba6

Fixed Issues (4)

Great job! The following issues were fixed in this Pull Request

Severity Issue Source File / Package
MEDIUM CSRF /src/Api/AdminConsole/Controllers/GroupsController.cs: 164
MEDIUM CSRF /bitwarden_license/src/Scim/Controllers/v2/GroupsController.cs: 86
MEDIUM CSRF /src/Api/AdminConsole/Public/Controllers/GroupsController.cs: 133
MEDIUM CSRF /bitwarden_license/src/Scim/Controllers/v2/GroupsController.cs: 96

@@ -173,6 +174,7 @@ private static void AddOrganizationUserCommandsQueries(this IServiceCollection s

services.AddScoped<IAuthorizationHandler, OrganizationUserUserMiniDetailsAuthorizationHandler>();
services.AddScoped<IAuthorizationHandler, OrganizationUserUserDetailsAuthorizationHandler>();
services.AddScoped<IAuthorizationHandler, OrganizationAuthorizationHandler>();
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 don't think this goes here... Which method should contain this, AddOrganizationAuthCommands?

@BTreston BTreston requested review from jrmccannon and eliykat March 31, 2025 19:25
@BTreston
Copy link
Contributor Author

@jrmccannon @eliykat Adding you both to this draft for some initial thoughts on this. Not super familiar with dotnet authorization so please feel free to correct me on anything that's just plain wrong. Ignore the current lack of tests and abundance of failures

@jrmccannon
Copy link
Contributor

I would say lets hold off on adding any CommanResult code at this point. Lets do a full copy paste of the code into a Command. Then do a refactor of the existing code to be wrapped in the command result pattern. This will make it easy to follow code changes and isolate those changes.

@eliykat
Copy link
Member

eliykat commented Apr 2, 2025

I agree with Jared. Let's do a simple cut & paste first just to physically move the existing code and update callers. Then once that's merged into main we can revisit the rewrite here.

Copy link

codecov bot commented Apr 2, 2025

Codecov Report

Attention: Patch coverage is 97.82609% with 1 line in your changes missing coverage. Please review.

Project coverage is 45.04%. Comparing base (e7abb07) to head (7ddc9fd).
Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
...Console/Controllers/OrganizationUsersController.cs 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5584      +/-   ##
==========================================
+ Coverage   44.90%   45.04%   +0.14%     
==========================================
  Files        1559     1563       +4     
  Lines       71128    71513     +385     
  Branches     6353     6403      +50     
==========================================
+ Hits        31942    32216     +274     
- Misses      37835    37931      +96     
- Partials     1351     1366      +15     

☔ 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.

await _collectionRepository.CreateAsync(defaultCollection, null, defaultOwnerAccess);
}

return new CommandResult();
Copy link
Contributor

Choose a reason for hiding this comment

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

If you're going to return a CommandResult. Then I would suggest you return a Success<InitializePendingOrganizationResponse> and create a new empty record model InitializePendingOrganizationResponse.

This way if we want to return something later, we can simply add a property to the model and populate it.

Copy link

sonarqubecloud bot commented Apr 2, 2025

@BTreston BTreston requested a review from jrmccannon April 3, 2025 14:58
@BTreston BTreston marked this pull request as ready for review April 3, 2025 14:58
@BTreston BTreston requested a review from a team as a code owner April 3, 2025 14:58
Task ReplaceAndUpdateCacheAsync(Organization org, EventType? orgEvent = null);

void ValidatePasswordManagerPlan(Models.StaticStore.Plan plan, OrganizationUpgrade upgrade);
void ValidateSecretsManagerPlan(Models.StaticStore.Plan plan, OrganizationUpgrade upgrade);
Task ValidateOrganizationUserUpdatePermissions(Guid organizationId, OrganizationUserType newType,
OrganizationUserType? oldType, Permissions permissions);
Task ValidateOrganizationCustomPermissionsEnabledAsync(Guid organizationId, OrganizationUserType newType);
Task ValidateSignUpPoliciesAsync(Guid ownerId);
Copy link
Member

@eliykat eliykat Apr 8, 2025

Choose a reason for hiding this comment

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

This method is just a single policy check - I don't think it needs to be reused. I suggest copying it into the new command rather than exposing it as public here. One less tie back to OrganizationService. (It's also what we did in the cloud org signup command)

@eliykat eliykat changed the title [PM-19332] [PM-19332] Create InitPendingOrganizationCommand Apr 8, 2025
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.

3 participants