Skip to content

[PM 22968] Enforce UI Restrictions When MSP/BUP Is Disabled #15752

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

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

Conversation

cyprain-okeke
Copy link
Contributor

🎟️ Tracking

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

📔 Objective

This PR introduces logic to automatically suspend a provider when their subscription becomes unpaid, and restricts client management capabilities when MSP/BUP is disabled.

🔁 Changes Introduced

  1. Automatic Provider Suspension
    When a provider’s subscription status changes to unpaid, the provider is automatically suspended, preventing further usage until payment is resolved.

  2. MSP/BUP Disabled Behavior
    When the MSP/BUP feature is disabled, the following UI and permission changes are applied for provider admins and service users:

A warning icon is displayed next to the provider name.

The following actions are disabled, with a tooltip explaining why:

  • Add new client
  • Edit client names
  • Manage client subscriptions

Unlinking clients is still allowed for provider admins.

📸 Screenshots

Screenshot 2025-07-23 at 17 54 32 Screenshot 2025-07-23 at 17 54 38 Screenshot 2025-07-23 at 17 54 50 Screenshot 2025-07-23 at 17 54 53

⏰ 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

@cyprain-okeke cyprain-okeke requested review from a team as code owners July 23, 2025 16:56
@cyprain-okeke cyprain-okeke requested a review from BTreston July 23, 2025 16:56
Copy link
Contributor

github-actions bot commented Jul 23, 2025

Logo
Checkmarx One – Scan Summary & Details97ca72a7-60a9-4608-a9cd-5f4b3a4e074d

Great job, no security vulnerabilities found in this Pull Request

Copy link

codecov bot commented Jul 23, 2025

Codecov Report

❌ Patch coverage is 2.17391% with 45 lines in your changes missing coverage. Please review.
✅ Project coverage is 37.84%. Comparing base (b358d56) to head (7cebaa6).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...ling/providers/clients/manage-clients.component.ts 0.00% 28 Missing ⚠️
...min-console/providers/clients/clients.component.ts 0.00% 15 Missing ⚠️
...in-console/providers/providers-layout.component.ts 0.00% 1 Missing ⚠️
.../billing/providers/clients/no-clients.component.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #15752   +/-   ##
=======================================
  Coverage   37.84%   37.84%           
=======================================
  Files        3309     3309           
  Lines       94014    94034   +20     
  Branches    14248    14252    +4     
=======================================
+ Hits        35579    35587    +8     
- Misses      56932    56948   +16     
+ Partials     1503     1499    -4     

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

Great work, just one change I think we need to fix up and then this should be good to go.

@@ -92,7 +118,7 @@
</bit-table-scroll>
<div *ngIf="dataSource.data.length === 0" class="tw-mt-10">
<app-no-clients
[showAddOrganizationButton]="isProviderAdmin"
[showAddOrganizationButton]="isSuspensionActive"
Copy link
Contributor

@amorask-bitwarden amorask-bitwarden Jul 24, 2025

Choose a reason for hiding this comment

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

I believe this change will start showing the Add Organization button to service users when the provider is enabled.

Copy link

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.

We still need to disable the Add Organization button and provide the tooltip when the Provider is suspended, but when the Provider is not suspended, we only want the button to show for Provider Admins.

Something like this:

<app-no-clients
      [showAddOrganizationButton]="isProviderAdmin"
      [disableAddOrganizationButton]="isSuspensionActive"
      (addNewOrganizationClicked)="createClient()"
    />

And then make the according changes in the NoClientsComponent.

Copy link
Contributor

@BTreston BTreston left a comment

Choose a reason for hiding this comment

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

We should do a little refactoring here to better support this feature. Let me know if you have questions, I'd be happy to help

Copy link
Contributor

Choose a reason for hiding this comment

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

🎨 non blocker: We should favor using @if syntax over *ngIf

Comment on lines 103 to 109
map((provider) => {
this.provider = provider;
this.isAdminOrServiceUser =
provider.type === ProviderUserType.ProviderAdmin ||
provider.type === ProviderUserType.ServiceUser;
return provider?.providerStatus === ProviderStatusType.Billable;
}),
Copy link
Contributor

Choose a reason for hiding this comment

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

We really should not be extracting values out of Observables like this. We can solve this by deconstructing this into separate Observables since its doing way too many unrelated things. It could look something like this:

    this.providerId$ = this.activatedRoute.parent.params.pipe(
      map((params) => params.providerId as ProviderId),
    );

    this.provider$ = this.providerId$.pipe(
      switchMap((providerId) => this.providerService.get$(providerId)),
    );

    this.isAdminOrServiceUser$ = this.provider$.pipe(
      map(
        (provider) =>
          provider?.type === ProviderUserType.ProviderAdmin ||
          provider?.type === ProviderUserType.ServiceUser,
      ),
    );

    this.suspensionActive$ = combineLatest([
      this.isAdminOrServiceUser$,
      this.providerPortalTakeover$,
      this.provider$.pipe(map((provider) => provider?.enabled ?? false)),
    ]).pipe(
      map(
        ([isAdminOrServiceUser, portalTakoverEnabled, providerEnabled]) =>
          isAdminOrServiceUser && portalTakoverEnabled && providerEnabled,
      ),
    );

    this.provider$
      .pipe(
        map((provider) => {
          if (provider?.providerStatus === ProviderStatusType.Billable) {
            return from(
              this.router.navigate(["../manage-client-organizations"], {
                relativeTo: this.activatedRoute,
              }),
            );
          }
          return from(this.load());
        }),
        takeUntilDestroyed(),
      )
      .subscribe();

This lets you get rid of the two getters added here in favor of having suspensionActive$ which we can use in the template with the async pipe to also add our i18n'd tooltip:

  @let isSuspensionActive = (suspensionActive$ | async);
...
<button
    type="button"
    bitButton
    [disabled]="isSuspensionActive"
    [title]="isSuspensionActive ? ('providerIsDisabled' | i18n) : '' "
    (click)="addExistingOrganization()"
    *ngIf="manageOrganizations && showAddExisting"
  >
    <i class="bwi bwi-plus bwi-fw" aria-hidden="true"></i>
    {{ "addExistingOrganization" | i18n }}
  </button>
...

Copy link
Contributor

Choose a reason for hiding this comment

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

We should really be following the same pattern in the clients.component. I would advise to align them both in the way I described in the previous file.

Copy link
Contributor

Choose a reason for hiding this comment

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

🎨 non blocking: we should use @if syntax instead of *ngIf

@cyprain-okeke cyprain-okeke requested a review from BTreston July 25, 2025 14:32
Copy link
Contributor

@BTreston BTreston left a comment

Choose a reason for hiding this comment

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

Looking much better, still have a few minor things to clean up though. Thank you for doing this!

Comment on lines 74 to 79
protected provider$ = this.providerId$.pipe(
switchMap((providerId) => {
this.providerId = providerId;
return this.providerService.get$(providerId);
}),
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
protected provider$ = this.providerId$.pipe(
switchMap((providerId) => {
this.providerId = providerId;
return this.providerService.get$(providerId);
}),
);
protected provider$ = this.providerId$.pipe(
switchMap((providerId) => this.providerService.get$(providerId)),
);

Comment on lines 126 to 129
this.provider = provider;
this.manageOrganizations =
provider.type === ProviderUserType.ProviderAdmin ||
provider.type === ProviderUserType.ServiceUser;
Copy link
Contributor

Choose a reason for hiding this comment

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

We can remove these too

[disabled]="isSuspensionActive"
[title]="isSuspensionActive ? ('providerIsDisabled' | i18n) : ''"
appA11yTitle="{{
isSuspensionActive ? ('add' | i18n) : isSuspensionActive ? ('providerIsDisabled' | i18n) : ''
Copy link
Contributor

Choose a reason for hiding this comment

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

This is confusing, if isSuspensionActive is true then we display 'add' but if its false both ternary statements evaluate to "". We never use 'providerIsDisabled'. Unless I'm reading this wrong, this doesn't seem correct.

relativeTo: this.activatedRoute,
}),
);
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

else is unnecessary here due to early return


protected provider$ = this.providerId$.pipe(
switchMap((providerId) => {
this.providerId = providerId;
Copy link
Contributor

Choose a reason for hiding this comment

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

same feedback as the other file. Use a Signal or await firstValueFrom when providerId is needed in a promise based workflow. We should only have this.providerId$ and this.provider$.

Comment on lines 173 to 174
this.isProviderAdmin = this.provider?.type === ProviderUserType.ProviderAdmin;
this.isServiceUser = this.provider?.type === ProviderUserType.ServiceUser;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can just get rid of these and directly check the properties in the template. Ex:

@let provider = (provider$ | async);
...
@if(provider?.type === ProviderUserType.ProviderAdmin){
           <button type="button" bitMenuItem (click)="remove(row)">
            <span class="tw-text-danger">
              <i aria-hidden="true" class="bwi bwi-close"></i> {{ "unlinkOrganization" | i18n }}
            </span>
          </button>
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I don't think we are even using isServiceUser, but double check me on that one.

@@ -55,6 +58,7 @@ const DisallowedPlanTypes = [
})
export class ClientsComponent {
providerId: string = "";
provider: Provider | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this, use a Signal or await firstValueFrom on the provider$ class member

Copy link
Contributor

Choose a reason for hiding this comment

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

I recognize this is a billing owned file, so consider the feedback here strongly recommended but non blocking 👍

@cyprain-okeke cyprain-okeke requested a review from BTreston July 25, 2025 17:03
Copy link

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