mirror of
https://github.com/bitwarden/browser
synced 2026-02-09 05:00:10 +00:00
Add models following company architecture for risk insights generated report data
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { BaseResponse } from "@bitwarden/common/models/response/base.response";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import { RiskInsightsReportData } from "../data/risk-insights-report.data";
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import { RiskInsightsReport } from "../domain/risk-insights-report";
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import { RiskInsightsReportView } from "../view/risk-insights-report.view";
|
||||
|
||||
import { MemberDetailsApi } from "./member-details.api";
|
||||
|
||||
/**
|
||||
* Converts a RiskInsightsReport API response
|
||||
*
|
||||
* - See {@link RiskInsightsReport} for domain model
|
||||
* - See {@link RiskInsightsReportData} for data model
|
||||
* - See {@link RiskInsightsReportView} from View Model
|
||||
*/
|
||||
export class RiskInsightsReportApi extends BaseResponse {
|
||||
applicationName: string;
|
||||
passwordCount: number;
|
||||
atRiskPasswordCount: number;
|
||||
atRiskCipherIds: string[];
|
||||
memberCount: number;
|
||||
atRiskMemberCount: number;
|
||||
memberDetails: MemberDetailsApi[];
|
||||
atRiskMemberDetails: MemberDetailsApi[];
|
||||
cipherIds: string[];
|
||||
|
||||
constructor(data: any) {
|
||||
super(data);
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.applicationName = this.getResponseProperty("applicationName");
|
||||
this.passwordCount = this.getResponseProperty("passwordCount");
|
||||
this.atRiskPasswordCount = this.getResponseProperty("atRiskPasswordCount");
|
||||
this.atRiskCipherIds = this.getResponseProperty("atRiskCipherIds");
|
||||
this.memberCount = this.getResponseProperty("memberCount");
|
||||
this.atRiskMemberCount = this.getResponseProperty("atRiskMemberCount");
|
||||
this.cipherIds = this.getResponseProperty("cipherIds");
|
||||
|
||||
const memberDetails = this.getResponseProperty("memberDetails");
|
||||
if (memberDetails != null) {
|
||||
this.memberDetails = memberDetails.map((f: any) => new MemberDetailsApi(f));
|
||||
}
|
||||
const atRiskMemberDetails = this.getResponseProperty("atRiskMemberDetails");
|
||||
if (atRiskMemberDetails != null) {
|
||||
this.atRiskMemberDetails = atRiskMemberDetails.map((f: any) => new MemberDetailsApi(f));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import { RiskInsightsReportApi } from "../api/risk-insights-report.api";
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import { RiskInsightsReport } from "../domain/risk-insights-report";
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import { RiskInsightsReportView } from "../view/risk-insights-report.view";
|
||||
|
||||
import { MemberDetailsData } from "./member-details.data";
|
||||
|
||||
/**
|
||||
* Serializable data model for generated report in risk insights report
|
||||
*
|
||||
* - See {@link RiskInsightsReport} for domain model
|
||||
* - See {@link RiskInsightsReportApi} for API model
|
||||
* - See {@link RiskInsightsReportView} from View Model
|
||||
*/
|
||||
export class RiskInsightsReportData {
|
||||
applicationName: string;
|
||||
passwordCount: number;
|
||||
atRiskPasswordCount: number;
|
||||
atRiskCipherIds: string[];
|
||||
memberCount: number;
|
||||
atRiskMemberCount: number;
|
||||
memberDetails: MemberDetailsData[];
|
||||
atRiskMemberDetails: MemberDetailsData[];
|
||||
cipherIds: string[];
|
||||
|
||||
constructor(data?: RiskInsightsReportApi) {
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
this.applicationName = data.applicationName;
|
||||
this.passwordCount = data.passwordCount;
|
||||
this.atRiskPasswordCount = data.atRiskPasswordCount;
|
||||
this.atRiskCipherIds = data.atRiskCipherIds;
|
||||
this.memberCount = data.memberCount;
|
||||
this.atRiskMemberCount = data.atRiskMemberCount;
|
||||
this.memberDetails = data.memberDetails;
|
||||
this.atRiskMemberDetails = data.atRiskMemberDetails;
|
||||
this.cipherIds = data.cipherIds;
|
||||
|
||||
if (data.memberDetails != null) {
|
||||
this.memberDetails = data.memberDetails.map((m) => new MemberDetailsData(m));
|
||||
}
|
||||
if (data.atRiskMemberDetails != null) {
|
||||
this.atRiskMemberDetails = data.atRiskMemberDetails.map((m) => new MemberDetailsData(m));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import { EncString } from "@bitwarden/common/key-management/crypto/models/enc-string";
|
||||
import Domain from "@bitwarden/common/platform/models/domain/domain-base";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import { RiskInsightsReportApi } from "../api/risk-insights-report.api";
|
||||
import { RiskInsightsReportData } from "../data/risk-insights-report.data";
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import { RiskInsightsReportView } from "../view/risk-insights-report.view";
|
||||
|
||||
import { MemberDetails } from "./member-details";
|
||||
|
||||
/**
|
||||
* Domain model for generated report data in Risk Insights containing encrypted properties
|
||||
*
|
||||
* - See {@link RiskInsightsReportApi} for API model
|
||||
* - See {@link RiskInsightsReportData} for data model
|
||||
* - See {@link RiskInsightsReportView} from View Model
|
||||
*/
|
||||
export class RiskInsightsReport extends Domain {
|
||||
applicationName: EncString;
|
||||
passwordCount: EncString;
|
||||
atRiskPasswordCount: EncString;
|
||||
atRiskCipherIds: string[];
|
||||
memberCount: EncString;
|
||||
atRiskMemberCount: EncString;
|
||||
memberDetails: MemberDetails[];
|
||||
atRiskMemberDetails: MemberDetails[];
|
||||
cipherIds: string[];
|
||||
|
||||
constructor(obj?: RiskInsightsReportData) {
|
||||
super();
|
||||
if (obj == null) {
|
||||
return;
|
||||
}
|
||||
this.applicationName = new EncString(obj.applicationName);
|
||||
this.passwordCount = new EncString(obj.passwordCount);
|
||||
this.atRiskPasswordCount = new EncString(obj.atRiskPasswordCount);
|
||||
this.atRiskCipherIds = obj.atRiskCipherIds;
|
||||
this.memberCount = new EncString(obj.memberCount);
|
||||
this.atRiskMemberCount = new EncString(obj.atRiskMemberCount);
|
||||
this.cipherIds = obj.cipherIds;
|
||||
|
||||
if (obj.memberDetails != null) {
|
||||
this.memberDetails = obj.memberDetails.map((m) => new MemberDetails(m));
|
||||
}
|
||||
if (obj.atRiskMemberDetails != null) {
|
||||
this.atRiskMemberDetails = obj.atRiskMemberDetails.map((m) => new MemberDetails(m));
|
||||
}
|
||||
}
|
||||
|
||||
// [TODO] Domain level methods
|
||||
// static fromJSON(): RiskInsightsReport {}
|
||||
// decrypt(): RiskInsightsReportView {}
|
||||
// toData(): RiskInsightsReportData {}
|
||||
|
||||
// [TODO] SDK Mapping
|
||||
// toSdkRiskInsightsReport(): SdkRiskInsightsReport {}
|
||||
// static fromSdkRiskInsightsReport(obj?: SdkRiskInsightsReport): RiskInsightsReport | undefined {}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import { View } from "@bitwarden/common/models/view/view";
|
||||
import { DeepJsonify } from "@bitwarden/common/types/deep-jsonify";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import { RiskInsightsReportApi } from "../api/risk-insights-report.api";
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import { RiskInsightsReportData } from "../data/risk-insights-report.data";
|
||||
import { RiskInsightsReport } from "../domain/risk-insights-report";
|
||||
|
||||
import { MemberDetailsView } from "./member-details.view";
|
||||
|
||||
/**
|
||||
* View model for Member Details in Risk Insights containing decrypted properties
|
||||
*
|
||||
* - See {@link RiskInsightsReport} for domain model
|
||||
* - See {@link RiskInsightsReportData} for data model
|
||||
* - See {@link RiskInsightsReportApi} for API model
|
||||
*/
|
||||
export class RiskInsightsReportView implements View {
|
||||
applicationName: string = "";
|
||||
passwordCount: number = 0;
|
||||
atRiskPasswordCount: number = 0;
|
||||
atRiskCipherIds: string[] = [];
|
||||
memberCount: number = 0;
|
||||
atRiskMemberCount: number = 0;
|
||||
memberDetails: MemberDetailsView[] = [];
|
||||
atRiskMemberDetails: MemberDetailsView[] = [];
|
||||
cipherIds: string[] = [];
|
||||
|
||||
constructor(r?: RiskInsightsReport) {
|
||||
if (r == null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return this;
|
||||
}
|
||||
|
||||
static fromJSON(
|
||||
obj: Partial<DeepJsonify<RiskInsightsReportView>> | undefined,
|
||||
): RiskInsightsReportView {
|
||||
if (obj == undefined) {
|
||||
return new RiskInsightsReportView();
|
||||
}
|
||||
|
||||
const view = Object.assign(new RiskInsightsReportView(), obj) as RiskInsightsReportView;
|
||||
|
||||
view.memberDetails = obj.memberDetails?.map((m: any) => MemberDetailsView.fromJSON(m)) ?? [];
|
||||
view.atRiskMemberDetails =
|
||||
obj.atRiskMemberDetails?.map((m: any) => MemberDetailsView.fromJSON(m)) ?? [];
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
// [TODO] SDK Mapping
|
||||
// toSdkRiskInsightsReportView(): SdkRiskInsightsReportView {}
|
||||
// static fromRiskInsightsReportView(obj?: SdkRiskInsightsReportView): RiskInsightsReportView | undefined {}
|
||||
}
|
||||
Reference in New Issue
Block a user