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-12490] Extract OrganizationService.EnableAsync into commands #5321

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

Conversation

r-tome
Copy link
Contributor

@r-tome r-tome commented Jan 24, 2025

🎟️ Tracking

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

📔 Objective

Extract OrganizationService.EnableAsync to OrganizationEnableCommand.

Add unit tests for OrganizationEnableCommand.

⏰ 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

@r-tome r-tome force-pushed the ac/pm-12490/create-organization-enable-command branch from d3b751a to 4c3c230 Compare January 24, 2025 12:58
Copy link

codecov bot commented Jan 24, 2025

Codecov Report

Attention: Patch coverage is 74.19355% with 8 lines in your changes missing coverage. Please review.

Project coverage is 44.39%. Comparing base (669c253) to head (bf7871c).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...ervices/Implementations/PaymentSucceededHandler.cs 0.00% 4 Missing ⚠️
...ices/Implementations/SubscriptionUpdatedHandler.cs 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5321      +/-   ##
==========================================
+ Coverage   44.37%   44.39%   +0.02%     
==========================================
  Files        1487     1489       +2     
  Lines       68595    68602       +7     
  Branches     6179     6179              
==========================================
+ Hits        30438    30459      +21     
+ Misses      36838    36824      -14     
  Partials     1319     1319              

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

@r-tome r-tome marked this pull request as ready for review January 24, 2025 13:49
@r-tome r-tome requested review from a team as code owners January 24, 2025 13:49
@r-tome r-tome requested a review from JimmyVo16 January 24, 2025 13:49
Copy link
Contributor

github-actions bot commented Jan 24, 2025

Logo
Checkmarx One – Scan Summary & Detailsf68406ea-1603-42ec-a4bf-3215e8d8ce69

Great job, no security vulnerabilities found in this Pull Request

Copy link
Contributor

@amorask-bitwarden amorask-bitwarden left a comment

Choose a reason for hiding this comment

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

👍 from Billing

jonashendrickx
jonashendrickx previously approved these changes Jan 27, 2025
# Conflicts:
#	src/Core/AdminConsole/Services/IOrganizationService.cs
#	src/Core/AdminConsole/Services/Implementations/OrganizationService.cs
#	src/Core/OrganizationFeatures/OrganizationServiceCollectionExtensions.cs
@r-tome
Copy link
Contributor Author

r-tome commented Jan 28, 2025

I had to fix a few merge conflicts

Copy link
Contributor

@JimmyVo16 JimmyVo16 left a comment

Choose a reason for hiding this comment

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

Everything looks good, just one minor request with the test code.

@r-tome r-tome requested a review from JimmyVo16 January 29, 2025 10:44
JimmyVo16
JimmyVo16 previously approved these changes Jan 29, 2025
Copy link
Contributor

@cturnbull-bitwarden cturnbull-bitwarden left a comment

Choose a reason for hiding this comment

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

🎉

Comment on lines 20 to 44
public async Task EnableAsync(Guid organizationId)
{
var organization = await _organizationRepository.GetByIdAsync(organizationId);
if (organization is { Enabled: false })
{
organization.Enabled = true;

await _organizationRepository.ReplaceAsync(organization);
await _applicationCacheService.UpsertOrganizationAbilityAsync(organization);
}
}

public async Task EnableAsync(Guid organizationId, DateTime? expirationDate)
{
var organization = await _organizationRepository.GetByIdAsync(organizationId);
if (organization is { Enabled: false, Gateway: not null })
{
organization.Enabled = true;
organization.ExpirationDate = expirationDate;
organization.RevisionDate = DateTime.UtcNow;

await _organizationRepository.ReplaceAsync(organization);
await _applicationCacheService.UpsertOrganizationAbilityAsync(organization);
}
}
Copy link
Contributor

@cturnbull-bitwarden cturnbull-bitwarden Feb 3, 2025

Choose a reason for hiding this comment

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

Just leaving a non-blocking drive-by-nit ⛏️ before approving! Looking at these two methods, it feels like they can be combined into a single method. I don't have all the context around this, so there's probably a reason they're not! Something like this is what I was imagining:

public async Task EnableAsync(Guid organizationId, DateTime? expirationDate = null)
{
    var organization = await _organizationRepository.GetByIdAsync(organizationId);
    if (organization is null || organization.Enabled || expirationDate is not null && organization.Gateway is null)
    {
        return;
    }

    organization.Enabled = true;

    if (expirationDate is not null && organization.Gateway is not null)
    {
        organization.ExpirationDate = expirationDate;
        organization.RevisionDate = DateTime.UtcNow;
    }

    await _organizationRepository.ReplaceAsync(organization);
    await _applicationCacheService.UpsertOrganizationAbilityAsync(organization);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good thinking! I've pushed a commit with your suggestion. I also added an extra unit test just to make sure we're not breaking anything.

jonashendrickx
jonashendrickx previously approved these changes Feb 4, 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.

5 participants