mirror of
https://github.com/bitwarden/browser
synced 2026-01-30 08:13:44 +00:00
Separates policy response model for individual policy data
This commit is contained in:
@@ -6,7 +6,7 @@ import { Constructor } from "type-fest";
|
||||
import { PolicyType } from "@bitwarden/common/admin-console/enums";
|
||||
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
|
||||
import { PolicyRequest } from "@bitwarden/common/admin-console/models/request/policy.request";
|
||||
import { PolicyResponse } from "@bitwarden/common/admin-console/models/response/policy.response";
|
||||
import { PolicyStatusResponse } from "@bitwarden/common/admin-console/models/response/policy-status.response";
|
||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||
import { DialogConfig, DialogRef, DialogService } from "@bitwarden/components";
|
||||
|
||||
@@ -80,7 +80,7 @@ export abstract class BasePolicyEditDefinition {
|
||||
export abstract class BasePolicyEditComponent implements OnInit {
|
||||
// FIXME(https://bitwarden.atlassian.net/browse/CL-903): Migrate to Signals
|
||||
// eslint-disable-next-line @angular-eslint/prefer-signals
|
||||
@Input() policyResponse: PolicyResponse | undefined;
|
||||
@Input() policyResponse: PolicyStatusResponse | undefined;
|
||||
// FIXME(https://bitwarden.atlassian.net/browse/CL-903): Migrate to Signals
|
||||
// eslint-disable-next-line @angular-eslint/prefer-signals
|
||||
@Input() policy: BasePolicyEditDefinition | undefined;
|
||||
|
||||
@@ -4,7 +4,7 @@ import { By } from "@angular/platform-browser";
|
||||
import { mock } from "jest-mock-extended";
|
||||
|
||||
import { PolicyType } from "@bitwarden/common/admin-console/enums";
|
||||
import { PolicyResponse } from "@bitwarden/common/admin-console/models/response/policy.response";
|
||||
import { PolicyStatusResponse } from "@bitwarden/common/admin-console/models/response/policy-status.response";
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
|
||||
import {
|
||||
@@ -42,8 +42,7 @@ describe("RemoveUnlockWithPinPolicyComponent", () => {
|
||||
});
|
||||
|
||||
it("input selected on load when policy enabled", async () => {
|
||||
component.policyResponse = new PolicyResponse({
|
||||
id: "policy1",
|
||||
component.policyResponse = new PolicyStatusResponse({
|
||||
organizationId: "org1",
|
||||
type: PolicyType.RemoveUnlockWithPin,
|
||||
enabled: true,
|
||||
@@ -63,8 +62,7 @@ describe("RemoveUnlockWithPinPolicyComponent", () => {
|
||||
});
|
||||
|
||||
it("input not selected on load when policy disabled", async () => {
|
||||
component.policyResponse = new PolicyResponse({
|
||||
id: "policy1",
|
||||
component.policyResponse = new PolicyStatusResponse({
|
||||
organizationId: "org1",
|
||||
type: PolicyType.RemoveUnlockWithPin,
|
||||
enabled: false,
|
||||
@@ -84,8 +82,7 @@ describe("RemoveUnlockWithPinPolicyComponent", () => {
|
||||
});
|
||||
|
||||
it("turn on message label", async () => {
|
||||
component.policyResponse = new PolicyResponse({
|
||||
id: "policy1",
|
||||
component.policyResponse = new PolicyStatusResponse({
|
||||
organizationId: "org1",
|
||||
type: PolicyType.RemoveUnlockWithPin,
|
||||
enabled: false,
|
||||
|
||||
@@ -3,10 +3,11 @@ import { PolicyType } from "../../enums";
|
||||
import { MasterPasswordPolicyOptions } from "../../models/domain/master-password-policy-options";
|
||||
import { Policy } from "../../models/domain/policy";
|
||||
import { PolicyRequest } from "../../models/request/policy.request";
|
||||
import { PolicyStatusResponse } from "../../models/response/policy-status.response";
|
||||
import { PolicyResponse } from "../../models/response/policy.response";
|
||||
|
||||
export abstract class PolicyApiServiceAbstraction {
|
||||
abstract getPolicy: (organizationId: string, type: PolicyType) => Promise<PolicyResponse>;
|
||||
abstract getPolicy: (organizationId: string, type: PolicyType) => Promise<PolicyStatusResponse>;
|
||||
abstract getPolicies: (organizationId: string) => Promise<ListResponse<PolicyResponse>>;
|
||||
|
||||
abstract getPoliciesByToken: (
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { BaseResponse } from "../../../models/response/base.response";
|
||||
import { PolicyType } from "../../enums";
|
||||
|
||||
export class PolicyStatusResponse extends BaseResponse {
|
||||
organizationId: string;
|
||||
type: PolicyType;
|
||||
data: any;
|
||||
enabled: boolean;
|
||||
canToggleState: boolean;
|
||||
|
||||
constructor(response: any) {
|
||||
super(response);
|
||||
this.organizationId = this.getResponseProperty("OrganizationId");
|
||||
this.type = this.getResponseProperty("Type");
|
||||
this.data = this.getResponseProperty("Data");
|
||||
this.enabled = this.getResponseProperty("Enabled");
|
||||
this.canToggleState = this.getResponseProperty("CanToggleState") ?? true;
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import { PolicyData } from "../../models/data/policy.data";
|
||||
import { MasterPasswordPolicyOptions } from "../../models/domain/master-password-policy-options";
|
||||
import { Policy } from "../../models/domain/policy";
|
||||
import { PolicyRequest } from "../../models/request/policy.request";
|
||||
import { PolicyStatusResponse } from "../../models/response/policy-status.response";
|
||||
import { PolicyResponse } from "../../models/response/policy.response";
|
||||
|
||||
export class PolicyApiService implements PolicyApiServiceAbstraction {
|
||||
@@ -23,7 +24,7 @@ export class PolicyApiService implements PolicyApiServiceAbstraction {
|
||||
private accountService: AccountService,
|
||||
) {}
|
||||
|
||||
async getPolicy(organizationId: string, type: PolicyType): Promise<PolicyResponse> {
|
||||
async getPolicy(organizationId: string, type: PolicyType): Promise<PolicyStatusResponse> {
|
||||
const r = await this.apiService.send(
|
||||
"GET",
|
||||
"/organizations/" + organizationId + "/policies/" + type,
|
||||
|
||||
Reference in New Issue
Block a user