mirror of
https://github.com/bitwarden/browser
synced 2025-12-20 10:13:31 +00:00
* Rename service-factory folder * Move cryptographic service factories * Move crypto models * Move crypto services * Move domain base class * Platform code owners * Move desktop log services * Move log files * Establish component library ownership * Move background listeners * Move background background * Move localization to Platform * Move browser alarms to Platform * Move browser state to Platform * Move CLI state to Platform * Move Desktop native concerns to Platform * Move flag and misc to Platform * Lint fixes * Move electron state to platform * Move web state to Platform * Move lib state to Platform * Fix broken tests * Rename interface to idiomatic TS * `npm run prettier` 🤖 * Resolve review feedback * Set platform as owners of web core and shared * Expand moved services * Fix test types --------- Co-authored-by: Hinton <hinton@users.noreply.github.com>
104 lines
3.3 KiB
TypeScript
104 lines
3.3 KiB
TypeScript
import { firstValueFrom } from "rxjs";
|
|
|
|
import { ApiService } from "../../../abstractions/api.service";
|
|
import { ListResponse } from "../../../models/response/list.response";
|
|
import { StateService } from "../../../platform/abstractions/state.service";
|
|
import { Utils } from "../../../platform/misc/utils";
|
|
import { PolicyApiServiceAbstraction } from "../../abstractions/policy/policy-api.service.abstraction";
|
|
import { InternalPolicyService } from "../../abstractions/policy/policy.service.abstraction";
|
|
import { PolicyType } from "../../enums";
|
|
import { PolicyData } from "../../models/data/policy.data";
|
|
import { MasterPasswordPolicyOptions } from "../../models/domain/master-password-policy-options";
|
|
import { PolicyRequest } from "../../models/request/policy.request";
|
|
import { PolicyResponse } from "../../models/response/policy.response";
|
|
|
|
export class PolicyApiService implements PolicyApiServiceAbstraction {
|
|
constructor(
|
|
private policyService: InternalPolicyService,
|
|
private apiService: ApiService,
|
|
private stateService: StateService
|
|
) {}
|
|
|
|
async getPolicy(organizationId: string, type: PolicyType): Promise<PolicyResponse> {
|
|
const r = await this.apiService.send(
|
|
"GET",
|
|
"/organizations/" + organizationId + "/policies/" + type,
|
|
null,
|
|
true,
|
|
true
|
|
);
|
|
return new PolicyResponse(r);
|
|
}
|
|
|
|
async getPolicies(organizationId: string): Promise<ListResponse<PolicyResponse>> {
|
|
const r = await this.apiService.send(
|
|
"GET",
|
|
"/organizations/" + organizationId + "/policies",
|
|
null,
|
|
true,
|
|
true
|
|
);
|
|
return new ListResponse(r, PolicyResponse);
|
|
}
|
|
|
|
async getPoliciesByToken(
|
|
organizationId: string,
|
|
token: string,
|
|
email: string,
|
|
organizationUserId: string
|
|
): Promise<ListResponse<PolicyResponse>> {
|
|
const r = await this.apiService.send(
|
|
"GET",
|
|
"/organizations/" +
|
|
organizationId +
|
|
"/policies/token?" +
|
|
"token=" +
|
|
encodeURIComponent(token) +
|
|
"&email=" +
|
|
Utils.encodeRFC3986URIComponent(email) +
|
|
"&organizationUserId=" +
|
|
organizationUserId,
|
|
null,
|
|
false,
|
|
true
|
|
);
|
|
return new ListResponse(r, PolicyResponse);
|
|
}
|
|
|
|
async getPoliciesByInvitedUser(
|
|
organizationId: string,
|
|
userId: string
|
|
): Promise<ListResponse<PolicyResponse>> {
|
|
const r = await this.apiService.send(
|
|
"GET",
|
|
"/organizations/" + organizationId + "/policies/invited-user?" + "userId=" + userId,
|
|
null,
|
|
false,
|
|
true
|
|
);
|
|
return new ListResponse(r, PolicyResponse);
|
|
}
|
|
|
|
async getMasterPasswordPoliciesForInvitedUsers(
|
|
orgId: string
|
|
): Promise<MasterPasswordPolicyOptions> {
|
|
const userId = await this.stateService.getUserId();
|
|
const response = await this.getPoliciesByInvitedUser(orgId, userId);
|
|
const policies = await this.policyService.mapPoliciesFromToken(response);
|
|
return await firstValueFrom(this.policyService.masterPasswordPolicyOptions$(policies));
|
|
}
|
|
|
|
async putPolicy(organizationId: string, type: PolicyType, request: PolicyRequest): Promise<any> {
|
|
const r = await this.apiService.send(
|
|
"PUT",
|
|
"/organizations/" + organizationId + "/policies/" + type,
|
|
request,
|
|
true,
|
|
true
|
|
);
|
|
const response = new PolicyResponse(r);
|
|
const data = new PolicyData(response);
|
|
await this.policyService.upsert(data);
|
|
}
|
|
}
|