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-12504] - hide create send button and send tab when sends are disabled #11186

Merged
merged 6 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions apps/browser/src/platform/popup/layout/popup-layout.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import { RouterModule } from "@angular/router";
import { Meta, StoryObj, applicationConfig, moduleMetadata } from "@storybook/angular";

import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";

Check warning on line 6 in apps/browser/src/platform/popup/layout/popup-layout.stories.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/platform/popup/layout/popup-layout.stories.ts#L6

Added line #L6 was not covered by tests
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { SendService } from "@bitwarden/common/tools/send/services/send.service.abstraction";

Check warning on line 8 in apps/browser/src/platform/popup/layout/popup-layout.stories.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/platform/popup/layout/popup-layout.stories.ts#L8

Added line #L8 was not covered by tests
import {
AvatarModule,
BadgeModule,
Expand Down Expand Up @@ -318,6 +320,30 @@
});
},
},
{
provide: PolicyService,
useFactory: () => {
return {

Check warning on line 326 in apps/browser/src/platform/popup/layout/popup-layout.stories.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/platform/popup/layout/popup-layout.stories.ts#L326

Added line #L326 was not covered by tests
policyAppliesToActiveUser$: () => {
return {
pipe: () => ({
subscribe: () => ({}),

Check warning on line 330 in apps/browser/src/platform/popup/layout/popup-layout.stories.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/platform/popup/layout/popup-layout.stories.ts#L328-L330

Added lines #L328 - L330 were not covered by tests
}),
};
},
};
},
},
{
provide: SendService,
useFactory: () => {
return {

Check warning on line 340 in apps/browser/src/platform/popup/layout/popup-layout.stories.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/platform/popup/layout/popup-layout.stories.ts#L340

Added line #L340 was not covered by tests
sends$: () => {
return { pipe: () => ({}) };

Check warning on line 342 in apps/browser/src/platform/popup/layout/popup-layout.stories.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/platform/popup/layout/popup-layout.stories.ts#L342

Added line #L342 was not covered by tests
},
};
},
},
],
}),
applicationConfig({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,41 @@
import { CommonModule } from "@angular/common";
import { Component } from "@angular/core";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";

Check warning on line 3 in apps/browser/src/platform/popup/layout/popup-tab-navigation.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/platform/popup/layout/popup-tab-navigation.component.ts#L3

Added line #L3 was not covered by tests
import { RouterModule } from "@angular/router";
import { filter, map, switchMap } from "rxjs";

Check warning on line 5 in apps/browser/src/platform/popup/layout/popup-tab-navigation.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/platform/popup/layout/popup-tab-navigation.component.ts#L5

Added line #L5 was not covered by tests

import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
import { PolicyType } from "@bitwarden/common/admin-console/enums";
import { SendService } from "@bitwarden/common/tools/send/services/send.service.abstraction";

Check warning on line 9 in apps/browser/src/platform/popup/layout/popup-tab-navigation.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/platform/popup/layout/popup-tab-navigation.component.ts#L7-L9

Added lines #L7 - L9 were not covered by tests
import { LinkModule } from "@bitwarden/components";

const allNavButtons = [

Check warning on line 12 in apps/browser/src/platform/popup/layout/popup-tab-navigation.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/platform/popup/layout/popup-tab-navigation.component.ts#L12

Added line #L12 was not covered by tests
{
label: "Vault",
page: "/tabs/vault",
iconKey: "lock",
iconKeyActive: "lock-f",
},
{
label: "Generator",
page: "/tabs/generator",
iconKey: "generate",
iconKeyActive: "generate-f",
},
{
label: "Send",
page: "/tabs/send",
iconKey: "send",
iconKeyActive: "send-f",
},
{
label: "Settings",
page: "/tabs/settings",
iconKey: "cog",
iconKeyActive: "cog-f",
},
];

@Component({
selector: "popup-tab-navigation",
templateUrl: "popup-tab-navigation.component.html",
Expand All @@ -14,30 +46,23 @@
},
})
export class PopupTabNavigationComponent {
navButtons = [
{
label: "Vault",
page: "/tabs/vault",
iconKey: "lock",
iconKeyActive: "lock-f",
},
{
label: "Generator",
page: "/tabs/generator",
iconKey: "generate",
iconKeyActive: "generate-f",
},
{
label: "Send",
page: "/tabs/send",
iconKey: "send",
iconKeyActive: "send-f",
},
{
label: "Settings",
page: "/tabs/settings",
iconKey: "cog",
iconKeyActive: "cog-f",
},
];
navButtons = allNavButtons;

Check warning on line 49 in apps/browser/src/platform/popup/layout/popup-tab-navigation.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/platform/popup/layout/popup-tab-navigation.component.ts#L49

Added line #L49 was not covered by tests
constructor(
private policyService: PolicyService,
private sendService: SendService,

Check warning on line 52 in apps/browser/src/platform/popup/layout/popup-tab-navigation.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/platform/popup/layout/popup-tab-navigation.component.ts#L52

Added line #L52 was not covered by tests
Copy link
Contributor

@vleague2 vleague2 Sep 25, 2024

Choose a reason for hiding this comment

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

I know I just approved but then I thought to check Storybook -- there are stories for the popup layout components, which are now throwing console errors because these services are not mocked in the story. Could you update that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@vleague2 Nice catch!

) {
this.policyService

Check warning on line 54 in apps/browser/src/platform/popup/layout/popup-tab-navigation.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/platform/popup/layout/popup-tab-navigation.component.ts#L54

Added line #L54 was not covered by tests
.policyAppliesToActiveUser$(PolicyType.DisableSend)
.pipe(
filter((policyAppliesToActiveUser) => policyAppliesToActiveUser),
switchMap(() => this.sendService.sends$),
map((sends) => sends.length > 1),

Check warning on line 59 in apps/browser/src/platform/popup/layout/popup-tab-navigation.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/platform/popup/layout/popup-tab-navigation.component.ts#L57-L59

Added lines #L57 - L59 were not covered by tests
takeUntilDestroyed(),
)
.subscribe((hasSends) => {
this.navButtons = hasSends
? allNavButtons
: allNavButtons.filter((b) => b.page !== "/tabs/send");

Check warning on line 65 in apps/browser/src/platform/popup/layout/popup-tab-navigation.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/platform/popup/layout/popup-tab-navigation.component.ts#L65

Added line #L65 was not covered by tests
});
}
}
19 changes: 11 additions & 8 deletions apps/browser/src/tools/popup/send-v2/send-v2.component.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
<popup-page>
<popup-header slot="header" [pageTitle]="'send' | i18n">
<ng-container slot="end">
<tools-new-send-dropdown></tools-new-send-dropdown>

<tools-new-send-dropdown *ngIf="!sendsDisabled"></tools-new-send-dropdown>
<app-pop-out></app-pop-out>
<app-current-account></app-current-account>
</ng-container>
</popup-header>
<div slot="above-scroll-area" class="tw-p-4">
<bit-callout *ngIf="sendsDisabled" [title]="'sendDisabled' | i18n">
{{ "sendDisabledWarning" | i18n }}
</bit-callout>
<ng-container *ngIf="!sendsDisabled">
<tools-send-search></tools-send-search>
<app-send-list-filters></app-send-list-filters>
</ng-container>
</div>

<div
*ngIf="listState === sendState.Empty"
Expand All @@ -15,7 +23,7 @@
<bit-no-items [icon]="noItemIcon" class="tw-text-main">
<ng-container slot="title">{{ "sendsNoItemsTitle" | i18n }}</ng-container>
<ng-container slot="description">{{ "sendsNoItemsMessage" | i18n }}</ng-container>
<tools-new-send-dropdown slot="button"></tools-new-send-dropdown>
<tools-new-send-dropdown *ngIf="!sendsDisabled" slot="button"></tools-new-send-dropdown>
</bit-no-items>
</div>

Expand All @@ -31,9 +39,4 @@
</div>
<app-send-list-items-container [headerText]="title | i18n" [sends]="sends$ | async" />
</ng-container>

<div slot="above-scroll-area" class="tw-p-4" *ngIf="listState !== sendState.Empty">
<tools-send-search></tools-send-search>
<app-send-list-filters></app-send-list-filters>
</div>
</popup-page>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { of, BehaviorSubject } from "rxjs";

import { JslibModule } from "@bitwarden/angular/jslib.module";
import { SearchService } from "@bitwarden/common/abstractions/search.service";
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
import { AvatarService } from "@bitwarden/common/auth/abstractions/avatar.service";
Expand Down Expand Up @@ -46,6 +47,7 @@ describe("SendV2Component", () => {
let sendListFiltersServiceFilters$: BehaviorSubject<{ sendType: SendType | null }>;
let sendItemsServiceEmptyList$: BehaviorSubject<boolean>;
let sendItemsServiceNoFilteredResults$: BehaviorSubject<boolean>;
let policyService: MockProxy<PolicyService>;

beforeEach(async () => {
sendListFiltersServiceFilters$ = new BehaviorSubject({ sendType: null });
Expand All @@ -60,6 +62,9 @@ describe("SendV2Component", () => {
latestSearchText$: of(""),
});

policyService = mock<PolicyService>();
policyService.policyAppliesToActiveUser$.mockReturnValue(of(true)); // Return `true` by default

sendListFiltersService = new SendListFiltersService(mock(), new FormBuilder());

sendListFiltersService.filters$ = sendListFiltersServiceFilters$;
Expand Down Expand Up @@ -104,6 +109,7 @@ describe("SendV2Component", () => {
{ provide: I18nService, useValue: { t: (key: string) => key } },
{ provide: SendListFiltersService, useValue: sendListFiltersService },
{ provide: PopupRouterCacheService, useValue: mock<PopupRouterCacheService>() },
{ provide: PolicyService, useValue: policyService },
],
}).compileComponents();

Expand Down
15 changes: 14 additions & 1 deletion apps/browser/src/tools/popup/send-v2/send-v2.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import { RouterLink } from "@angular/router";
import { combineLatest } from "rxjs";

import { JslibModule } from "@bitwarden/angular/jslib.module";
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
import { PolicyType } from "@bitwarden/common/admin-console/enums";
import { SendType } from "@bitwarden/common/tools/send/enums/send-type";
import { ButtonModule, Icons, NoItemsModule } from "@bitwarden/components";
import { ButtonModule, CalloutModule, Icons, NoItemsModule } from "@bitwarden/components";
import {
NoSendsIcon,
NewSendDropdownComponent,
Expand All @@ -31,6 +33,7 @@ export enum SendState {
templateUrl: "send-v2.component.html",
standalone: true,
imports: [
CalloutModule,
PopupPageComponent,
PopupHeaderComponent,
PopOutComponent,
Expand Down Expand Up @@ -61,9 +64,12 @@ export class SendV2Component implements OnInit, OnDestroy {

protected noResultsIcon = Icons.NoResults;

protected sendsDisabled = false;

constructor(
protected sendItemsService: SendItemsService,
protected sendListFiltersService: SendListFiltersService,
private policyService: PolicyService,
) {
combineLatest([
this.sendItemsService.emptyList$,
Expand All @@ -90,6 +96,13 @@ export class SendV2Component implements OnInit, OnDestroy {

this.listState = null;
});

this.policyService
.policyAppliesToActiveUser$(PolicyType.DisableSend)
.pipe(takeUntilDestroyed())
.subscribe((sendsDisabled) => {
this.sendsDisabled = sendsDisabled;
});
}

ngOnInit(): void {}
Expand Down
Loading