mirror of
https://github.com/bitwarden/clients.git
synced 2026-11-16 07:03:29 +00:00
PM-43629-remove-password-permission
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
[sends]="filteredSends()"
|
||||
[loading]="loading()"
|
||||
[disableSend]="disableSend()"
|
||||
[sendAuthRequired]="sendAuthRequired()"
|
||||
[listState]="listState()"
|
||||
[searchText]="currentSearchText()"
|
||||
(editSend)="onEditSend($event)"
|
||||
|
||||
@@ -82,6 +82,10 @@ export class SendComponent {
|
||||
initialValue: false,
|
||||
});
|
||||
|
||||
protected readonly sendAuthRequired = toSignal(this.sendPolicyService.sendAuthRequired$, {
|
||||
initialValue: false,
|
||||
});
|
||||
|
||||
protected readonly listState = toSignal(
|
||||
combineLatest([
|
||||
this.sendItemsService.emptyList$,
|
||||
@@ -154,7 +158,7 @@ export class SendComponent {
|
||||
}
|
||||
|
||||
protected async onRemoveAuth(send: SendView): Promise<void> {
|
||||
if (this.disableSend()) {
|
||||
if (this.disableSend() || this.sendAuthRequired() || send.disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
[sends]="filteredSends()"
|
||||
[loading]="loading()"
|
||||
[disableSend]="disableSend()"
|
||||
[sendAuthRequired]="sendAuthRequired()"
|
||||
[listState]="listState()"
|
||||
[searchText]="currentSearchText()"
|
||||
(editSend)="editSend($event)"
|
||||
|
||||
@@ -124,6 +124,10 @@ export class SendComponent implements OnDestroy {
|
||||
{ initialValue: false },
|
||||
);
|
||||
|
||||
protected readonly sendAuthRequired = toSignal(this.sendPolicyService.sendAuthRequired$, {
|
||||
initialValue: false,
|
||||
});
|
||||
|
||||
protected readonly loading = toSignal(this.sendItemsService.loading$, { initialValue: true });
|
||||
|
||||
protected readonly listState = toSignal(
|
||||
@@ -361,7 +365,7 @@ export class SendComponent implements OnDestroy {
|
||||
}
|
||||
|
||||
protected async onRemoveAuth(send: SendView): Promise<void> {
|
||||
if (this.disableSend()) {
|
||||
if (this.disableSend() || this.sendAuthRequired() || send.disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@
|
||||
showToast
|
||||
></button>
|
||||
} @else {
|
||||
@if (editing()) {
|
||||
@if (editing() && canRemoveAuth()) {
|
||||
<button
|
||||
class="tw-border-l-0 last:tw-rounded-r focus-visible:tw-border-l focus-visible:tw-ml-[-1px]"
|
||||
type="button"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { DatePipe } from "@angular/common";
|
||||
import { signal } from "@angular/core";
|
||||
import { ComponentFixture, TestBed } from "@angular/core/testing";
|
||||
import { ReactiveFormsModule } from "@angular/forms";
|
||||
import { mock } from "jest-mock-extended";
|
||||
@@ -16,6 +17,7 @@ import {
|
||||
isDatePreset,
|
||||
SendDeletionDatePreset,
|
||||
} from "@bitwarden/common/tools/models/send-deletion-date-preset";
|
||||
import { SendView } from "@bitwarden/common/tools/send/models/view/send.view";
|
||||
import { SendApiService } from "@bitwarden/common/tools/send/services/send-api.service.abstraction";
|
||||
import { AuthType } from "@bitwarden/common/tools/send/types/auth-type";
|
||||
import { SendType } from "@bitwarden/common/tools/send/types/send-type";
|
||||
@@ -23,6 +25,7 @@ import { DialogService, ToastService } from "@bitwarden/components";
|
||||
import { CredentialGeneratorService } from "@bitwarden/generator-core";
|
||||
import { LogService } from "@bitwarden/logging";
|
||||
|
||||
import { SendPolicyService } from "../../../services/send-policy.service";
|
||||
import { SendFormGenerationService } from "../../abstractions/send-form-generation.service";
|
||||
import { SendFormService } from "../../abstractions/send-form.service";
|
||||
import { SendFormContainer } from "../../send-form-container";
|
||||
@@ -116,6 +119,37 @@ describe("SendDetailsComponent", () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
describe("canRemoveAuth", () => {
|
||||
const originalSendView = mockSendFormService.originalSendView;
|
||||
|
||||
afterEach(() => {
|
||||
(mockSendFormService as any).originalSendView = originalSendView;
|
||||
});
|
||||
|
||||
function canRemoveAuth(sendAuthRequired: boolean, sendDisabled: boolean) {
|
||||
(TestBed.inject(SendPolicyService) as any).sendAuthRequired$ = of(sendAuthRequired);
|
||||
const send = new SendView();
|
||||
send.authType = AuthType.Password;
|
||||
send.deletionDate = new Date("2030-01-01T12:00:00Z");
|
||||
send.disabled = sendDisabled;
|
||||
(mockSendFormService as any).originalSendView = signal(send);
|
||||
|
||||
return TestBed.createComponent(SendDetailsComponent).componentInstance["canRemoveAuth"]();
|
||||
}
|
||||
|
||||
it("allows removing authentication when policy doesn't require it", () => {
|
||||
expect(canRemoveAuth(false, false)).toBe(true);
|
||||
});
|
||||
|
||||
it("does not allow removing authentication when policy requires it", () => {
|
||||
expect(canRemoveAuth(true, false)).toBe(false);
|
||||
});
|
||||
|
||||
it("does not allow removing authentication from a Send that doesn't comply with policy", () => {
|
||||
expect(canRemoveAuth(false, true)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
it("should initialize authType to None if no password or emails", () => {
|
||||
expect(component.sendDetailsForm.value.authType).toBe(AuthType.None);
|
||||
});
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
inject,
|
||||
computed,
|
||||
} from "@angular/core";
|
||||
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
|
||||
import { takeUntilDestroyed, toSignal } from "@angular/core/rxjs-interop";
|
||||
import {
|
||||
FormBuilder,
|
||||
FormControl,
|
||||
@@ -145,6 +145,18 @@ export class SendDetailsComponent implements OnInit {
|
||||
private sendPolicyService = inject(SendPolicyService);
|
||||
private orgService = inject(OrganizationService);
|
||||
|
||||
private readonly sendAuthRequired = toSignal(this.sendPolicyService.sendAuthRequired$, {
|
||||
initialValue: false,
|
||||
});
|
||||
|
||||
/**
|
||||
* Whether the user may remove the Send's authentication. Not allowed when policy requires
|
||||
* authentication or when the Send doesn't comply with policy.
|
||||
*/
|
||||
protected readonly canRemoveAuth = computed(
|
||||
() => !this.sendAuthRequired() && !this.sendFormService.originalSendView()?.disabled,
|
||||
);
|
||||
|
||||
availableAuthTypes$ = combineLatest([
|
||||
this.hasPremium$,
|
||||
this.sendPolicyService.whoCanAccess$,
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
<tools-send-table
|
||||
[dataSource]="dataSource"
|
||||
[disableSend]="disableSend()"
|
||||
[sendAuthRequired]="sendAuthRequired()"
|
||||
(editSend)="onEditSend($event)"
|
||||
(copySend)="onCopySend($event)"
|
||||
(removeAuth)="onRemoveAuth($event)"
|
||||
|
||||
@@ -53,6 +53,7 @@ export class SendListComponent {
|
||||
readonly sends = input.required<SendView[]>();
|
||||
readonly loading = input<boolean>(false);
|
||||
readonly disableSend = input<boolean>(false);
|
||||
readonly sendAuthRequired = input<boolean>(false);
|
||||
readonly listState = input<SendListState | null>(null);
|
||||
readonly searchText = input<string>("");
|
||||
readonly hideSearchBar = input<boolean>(false);
|
||||
|
||||
@@ -98,7 +98,9 @@
|
||||
<bit-icon name="bwi-clone" fixedWidth />
|
||||
{{ "copySendLink" | i18n }}
|
||||
</button>
|
||||
@if (s.authType !== authType.None && !disableSend()) {
|
||||
@if (
|
||||
s.authType !== authType.None && !s.disabled && !disableSend() && !sendAuthRequired()
|
||||
) {
|
||||
<button type="button" bitMenuItem (click)="onRemoveAuth(s)">
|
||||
<bit-icon name="bwi-close" fixedWidth />
|
||||
{{ removeSendAuthI18nKeys(s.authType).label | i18n }}
|
||||
|
||||
@@ -59,11 +59,12 @@ describe("SendTableComponent", () => {
|
||||
return Object.assign(send, overrides);
|
||||
}
|
||||
|
||||
async function renderWithSend(send: SendView, disableSend = false) {
|
||||
async function renderWithSend(send: SendView, disableSend = false, sendAuthRequired = false) {
|
||||
const dataSource = new TableDataSource<SendView>();
|
||||
dataSource.data = [send];
|
||||
fixture.componentRef.setInput("dataSource", dataSource);
|
||||
fixture.componentRef.setInput("disableSend", disableSend);
|
||||
fixture.componentRef.setInput("sendAuthRequired", sendAuthRequired);
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
fixture.detectChanges();
|
||||
@@ -119,6 +120,30 @@ describe("SendTableComponent", () => {
|
||||
expect(items).not.toContain("removeEmailVerification");
|
||||
});
|
||||
|
||||
it("hides the remove option when policy requires Sends to have authentication", async () => {
|
||||
await renderWithSend(
|
||||
createSend({ authType: AuthType.Password, password: "hash" }),
|
||||
false,
|
||||
true,
|
||||
);
|
||||
|
||||
const items = openMenuItems();
|
||||
|
||||
expect(items).toContain("copySendLink");
|
||||
expect(items).not.toContain("removePassword");
|
||||
});
|
||||
|
||||
it("hides the remove option for Sends that don't comply with policy", async () => {
|
||||
await renderWithSend(
|
||||
createSend({ authType: AuthType.Password, password: "hash", disabled: true }),
|
||||
);
|
||||
|
||||
const items = openMenuItems();
|
||||
|
||||
expect(items).toContain("copySendLink");
|
||||
expect(items).not.toContain("removePassword");
|
||||
});
|
||||
|
||||
it("emits removeAuth with the Send when the remove option is clicked", async () => {
|
||||
const send = createSend({ authType: AuthType.Email });
|
||||
await renderWithSend(send);
|
||||
|
||||
@@ -59,6 +59,12 @@ export class SendTableComponent {
|
||||
*/
|
||||
readonly disableSend = input(false);
|
||||
|
||||
/**
|
||||
* Whether policy requires Sends to keep their password or email verification.
|
||||
* When true, the "Remove password" / "Remove email verification" option is hidden from the action menu.
|
||||
*/
|
||||
readonly sendAuthRequired = input(false);
|
||||
|
||||
/**
|
||||
* Emitted when a user clicks on a Send item to edit it.
|
||||
* The clicked SendView is passed as the event payload.
|
||||
@@ -74,7 +80,8 @@ export class SendTableComponent {
|
||||
/**
|
||||
* Emitted when a user clicks the "Remove password" / "Remove email verification" action.
|
||||
* The SendView is passed as the event payload for authentication removal.
|
||||
* This action is only available if the Send has authentication and Send is not disabled.
|
||||
* This action is only available if the Send has authentication, Send is not disabled, policy
|
||||
* doesn't require authentication, and the Send is compliant with policy.
|
||||
*/
|
||||
readonly removeAuth = output<SendView>();
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import { Policy } from "@bitwarden/common/admin-console/models/domain/policy";
|
||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||
import { mockAccountServiceWith } from "@bitwarden/common/spec";
|
||||
import { WhoCanAccessType } from "@bitwarden/common/tools/models/send-who-can-access-type";
|
||||
import { SendType } from "@bitwarden/common/tools/send/types/send-type";
|
||||
import { PolicyId, UserId } from "@bitwarden/common/types/guid";
|
||||
|
||||
@@ -102,6 +103,28 @@ describe("SendPolicyService", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("sendAuthRequired$", () => {
|
||||
it.each([
|
||||
[WhoCanAccessType.PasswordProtected, true],
|
||||
[WhoCanAccessType.SpecificPeople, true],
|
||||
[WhoCanAccessType.Any, false],
|
||||
])("emits %s → %s", async (whoCanAccess, expected) => {
|
||||
policyServiceMock.policiesByType$
|
||||
.calledWith(PolicyType.SendControls, userId)
|
||||
.mockReturnValue(of([makePolicy({ whoCanAccess })]));
|
||||
|
||||
expect(await firstValueFrom(service.sendAuthRequired$)).toBe(expected);
|
||||
});
|
||||
|
||||
it("emits false when no Send Controls policy sets who can access", async () => {
|
||||
policyServiceMock.policiesByType$
|
||||
.calledWith(PolicyType.SendControls, userId)
|
||||
.mockReturnValue(of([]));
|
||||
|
||||
expect(await firstValueFrom(service.sendAuthRequired$)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("disableHideEmail$", () => {
|
||||
it("emits true when SendControls policy has disableHideEmail: true", async () => {
|
||||
policyServiceMock.policiesByType$
|
||||
|
||||
@@ -73,6 +73,14 @@ export class SendPolicyService {
|
||||
shareReplay({ bufferSize: 1, refCount: true }),
|
||||
);
|
||||
|
||||
/**
|
||||
* Emits `true` when a Send Controls policy requires Sends to be protected by a password or
|
||||
* email verification, so the user can't remove a Send's authentication.
|
||||
*/
|
||||
readonly sendAuthRequired$: Observable<boolean> = this.whoCanAccess$.pipe(
|
||||
map((whoCanAccess) => whoCanAccess != null && whoCanAccess !== WhoCanAccessType.Any),
|
||||
);
|
||||
|
||||
readonly allowedDomains$: Observable<string[] | null> = this.activeUserId$.pipe(
|
||||
switchMap((userId) =>
|
||||
this.policyService.policiesByType$(PolicyType.SendControls, userId).pipe(
|
||||
|
||||
Reference in New Issue
Block a user