1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-19 01:33:33 +00:00

[PM-9869] Create SendFormContainer (#10147)

* Move SendV2component into send-v2 subFolder

* Create SendFormContainer and related services

* Add initial SendFormComponent which uses the SendFormContainer

* Remove AdditionalOptionsSectionComponent which will be added with a future PR

* Add libs/tools/send to root tsconfig

* Register libs/tools/send/send-ui with root jest.config.js

* Register libs/tools/send/send-ui with root tailwind.config.js

* Fix service injection on DefaultSendFormService

---------

Co-authored-by: Daniel James Smith <djsmith85@users.noreply.github.com>
This commit is contained in:
Daniel James Smith
2024-07-19 21:17:52 +02:00
committed by GitHub
parent beeb0354fd
commit 1320d96cb4
20 changed files with 630 additions and 1 deletions

View File

@@ -0,0 +1,51 @@
import { inject, Injectable } from "@angular/core";
import { combineLatest, firstValueFrom, map } from "rxjs";
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 { SendService } from "@bitwarden/common/tools/send/services/send.service.abstraction";
import { SendId } from "@bitwarden/common/types/guid";
import {
SendFormConfig,
SendFormConfigService,
SendFormMode,
} from "../abstractions/send-form-config.service";
/**
* Default implementation of the `SendFormConfigService`.
*/
@Injectable()
export class DefaultSendFormConfigService implements SendFormConfigService {
private policyService: PolicyService = inject(PolicyService);
private sendService: SendService = inject(SendService);
async buildConfig(
mode: SendFormMode,
sendId?: SendId,
sendType?: SendType,
): Promise<SendFormConfig> {
const [areSendsAllowed, send] = await firstValueFrom(
combineLatest([this.areSendsEnabled$, this.getSend(sendId)]),
);
return {
mode,
sendType: sendType,
areSendsAllowed,
originalSend: send,
};
}
private areSendsEnabled$ = this.policyService
.policyAppliesToActiveUser$(PolicyType.DisableSend)
.pipe(map((p) => !p));
private getSend(id?: SendId) {
if (id == null) {
return Promise.resolve(null);
}
return this.sendService.get$(id);
}
}

View File

@@ -0,0 +1,29 @@
import { inject, Injectable } from "@angular/core";
import { Send } from "@bitwarden/common/tools/send/models/domain/send";
import { SendView } from "@bitwarden/common/tools/send/models/view/send.view";
import { SendApiService } from "@bitwarden/common/tools/send/services/send-api.service.abstraction";
import { SendService } from "@bitwarden/common/tools/send/services/send.service.abstraction";
import { SendFormConfig } from "../abstractions/send-form-config.service";
import { SendFormService } from "../abstractions/send-form.service";
@Injectable()
export class DefaultSendFormService implements SendFormService {
private sendApiService: SendApiService = inject(SendApiService);
private sendService = inject(SendService);
async decryptSend(send: Send): Promise<SendView> {
return await send.decrypt();
}
async saveSend(
send: SendView,
file: File | ArrayBuffer,
config: SendFormConfig,
): Promise<SendView> {
const sendData = await this.sendService.encrypt(send, file, send.password, null);
const savedSend = await this.sendApiService.save(sendData);
return await savedSend.decrypt();
}
}