mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 00:33:44 +00:00
[PM-4360] Move organization-domain and organization-user to admin console (#6630)
* Move organization-domain and organization-user to admin console
This commit is contained in:
@@ -0,0 +1,202 @@
|
||||
import { mock } from "jest-mock-extended";
|
||||
import { lastValueFrom } from "rxjs";
|
||||
|
||||
import { ApiService } from "../../../abstractions/api.service";
|
||||
import { I18nService } from "../../../platform/abstractions/i18n.service";
|
||||
import { PlatformUtilsService } from "../../../platform/abstractions/platform-utils.service";
|
||||
import { OrganizationDomainSsoDetailsResponse } from "../../abstractions/organization-domain/responses/organization-domain-sso-details.response";
|
||||
import { OrganizationDomainResponse } from "../../abstractions/organization-domain/responses/organization-domain.response";
|
||||
|
||||
import { OrgDomainApiService } from "./org-domain-api.service";
|
||||
import { OrgDomainService } from "./org-domain.service";
|
||||
import { OrganizationDomainSsoDetailsRequest } from "./requests/organization-domain-sso-details.request";
|
||||
|
||||
const mockedGetAllByOrgIdResponse: any = {
|
||||
data: [
|
||||
{
|
||||
id: "ca01a674-7f2f-45f2-8245-af6d016416b7",
|
||||
organizationId: "cb903acf-2361-4072-ae32-af6c014943b6",
|
||||
txt: "bw=EUX6UKR8A68igAJkmodwkzMiqB00u7Iyq1QqALu6jFID",
|
||||
domainName: "test.com",
|
||||
creationDate: "2022-12-16T21:36:28.68Z",
|
||||
nextRunDate: "2022-12-17T09:36:28.68Z",
|
||||
jobRunCount: 0,
|
||||
verifiedDate: null as any,
|
||||
lastCheckedDate: "2022-12-16T21:36:28.7633333Z",
|
||||
object: "organizationDomain",
|
||||
},
|
||||
{
|
||||
id: "adbd44c5-90d5-4537-97e6-af6d01644870",
|
||||
organizationId: "cb903acf-2361-4072-ae32-af6c014943b6",
|
||||
txt: "bw=Ql4fCfDacmcjwyAP9BPmvhSMTCz4PkEDm4uQ3fH01pD4",
|
||||
domainName: "test2.com",
|
||||
creationDate: "2022-12-16T21:37:10.9566667Z",
|
||||
nextRunDate: "2022-12-17T09:37:10.9566667Z",
|
||||
jobRunCount: 0,
|
||||
verifiedDate: "totally verified",
|
||||
lastCheckedDate: "2022-12-16T21:37:11.1933333Z",
|
||||
object: "organizationDomain",
|
||||
},
|
||||
{
|
||||
id: "05cf3ab8-bcfe-4b95-92e8-af6d01680942",
|
||||
organizationId: "cb903acf-2361-4072-ae32-af6c014943b6",
|
||||
txt: "bw=EQNUs77BWQHbfSiyc/9nT3wCen9z2yMn/ABCz0cNKaTx",
|
||||
domainName: "test3.com",
|
||||
creationDate: "2022-12-16T21:50:50.96Z",
|
||||
nextRunDate: "2022-12-17T09:50:50.96Z",
|
||||
jobRunCount: 0,
|
||||
verifiedDate: null,
|
||||
lastCheckedDate: "2022-12-16T21:50:51.0933333Z",
|
||||
object: "organizationDomain",
|
||||
},
|
||||
],
|
||||
continuationToken: null as any,
|
||||
object: "list",
|
||||
};
|
||||
|
||||
const mockedOrgDomainServerResponse = {
|
||||
id: "ca01a674-7f2f-45f2-8245-af6d016416b7",
|
||||
organizationId: "cb903acf-2361-4072-ae32-af6c014943b6",
|
||||
txt: "bw=EUX6UKR8A68igAJkmodwkzMiqB00u7Iyq1QqALu6jFID",
|
||||
domainName: "test.com",
|
||||
creationDate: "2022-12-16T21:36:28.68Z",
|
||||
nextRunDate: "2022-12-17T09:36:28.68Z",
|
||||
jobRunCount: 0,
|
||||
verifiedDate: null as any,
|
||||
lastCheckedDate: "2022-12-16T21:36:28.7633333Z",
|
||||
object: "organizationDomain",
|
||||
};
|
||||
|
||||
const mockedOrgDomainResponse = new OrganizationDomainResponse(mockedOrgDomainServerResponse);
|
||||
|
||||
const mockedOrganizationDomainSsoDetailsServerResponse = {
|
||||
id: "fake-guid",
|
||||
organizationIdentifier: "fake-org-identifier",
|
||||
ssoAvailable: true,
|
||||
domainName: "fake-domain-name",
|
||||
verifiedDate: "2022-12-16T21:36:28.68Z",
|
||||
};
|
||||
|
||||
const mockedOrganizationDomainSsoDetailsResponse = new OrganizationDomainSsoDetailsResponse(
|
||||
mockedOrganizationDomainSsoDetailsServerResponse
|
||||
);
|
||||
|
||||
describe("Org Domain API Service", () => {
|
||||
let orgDomainApiService: OrgDomainApiService;
|
||||
|
||||
const apiService = mock<ApiService>();
|
||||
|
||||
let orgDomainService: OrgDomainService;
|
||||
|
||||
const platformUtilService = mock<PlatformUtilsService>();
|
||||
const i18nService = mock<I18nService>();
|
||||
|
||||
beforeEach(() => {
|
||||
orgDomainService = new OrgDomainService(platformUtilService, i18nService);
|
||||
jest.resetAllMocks();
|
||||
|
||||
orgDomainApiService = new OrgDomainApiService(orgDomainService, apiService);
|
||||
});
|
||||
|
||||
it("instantiates", () => {
|
||||
expect(orgDomainApiService).not.toBeFalsy();
|
||||
});
|
||||
|
||||
it("getAllByOrgId retrieves all org domains and calls orgDomainSvc replace", () => {
|
||||
apiService.send.mockResolvedValue(mockedGetAllByOrgIdResponse);
|
||||
|
||||
expect(lastValueFrom(orgDomainService.orgDomains$)).resolves.toHaveLength(0);
|
||||
|
||||
const orgDomainSvcReplaceSpy = jest.spyOn(orgDomainService, "replace");
|
||||
|
||||
orgDomainApiService
|
||||
.getAllByOrgId("fakeOrgId")
|
||||
.then((orgDomainResponses: Array<OrganizationDomainResponse>) => {
|
||||
expect(orgDomainResponses).toHaveLength(3);
|
||||
|
||||
expect(orgDomainSvcReplaceSpy).toHaveBeenCalled();
|
||||
expect(lastValueFrom(orgDomainService.orgDomains$)).resolves.toHaveLength(3);
|
||||
});
|
||||
});
|
||||
|
||||
it("getByOrgIdAndOrgDomainId retrieves single org domain and calls orgDomainSvc upsert", () => {
|
||||
apiService.send.mockResolvedValue(mockedOrgDomainServerResponse);
|
||||
|
||||
expect(lastValueFrom(orgDomainService.orgDomains$)).resolves.toHaveLength(0);
|
||||
|
||||
const orgDomainSvcUpsertSpy = jest.spyOn(orgDomainService, "upsert");
|
||||
|
||||
orgDomainApiService
|
||||
.getByOrgIdAndOrgDomainId("fakeOrgId", "fakeDomainId")
|
||||
.then((orgDomain: OrganizationDomainResponse) => {
|
||||
expect(orgDomain.id).toEqual(mockedOrgDomainServerResponse.id);
|
||||
|
||||
expect(orgDomainSvcUpsertSpy).toHaveBeenCalled();
|
||||
expect(lastValueFrom(orgDomainService.orgDomains$)).resolves.toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
it("post success should call orgDomainSvc upsert", () => {
|
||||
apiService.send.mockResolvedValue(mockedOrgDomainServerResponse);
|
||||
|
||||
expect(lastValueFrom(orgDomainService.orgDomains$)).resolves.toHaveLength(0);
|
||||
|
||||
const orgDomainSvcUpsertSpy = jest.spyOn(orgDomainService, "upsert");
|
||||
|
||||
orgDomainApiService
|
||||
.post("fakeOrgId", mockedOrgDomainResponse)
|
||||
.then((orgDomain: OrganizationDomainResponse) => {
|
||||
expect(orgDomain.id).toEqual(mockedOrgDomainServerResponse.id);
|
||||
|
||||
expect(orgDomainSvcUpsertSpy).toHaveBeenCalled();
|
||||
expect(lastValueFrom(orgDomainService.orgDomains$)).resolves.toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
it("verify success should call orgDomainSvc upsert", () => {
|
||||
apiService.send.mockResolvedValue(mockedOrgDomainServerResponse);
|
||||
|
||||
expect(lastValueFrom(orgDomainService.orgDomains$)).resolves.toHaveLength(0);
|
||||
|
||||
const orgDomainSvcUpsertSpy = jest.spyOn(orgDomainService, "upsert");
|
||||
|
||||
orgDomainApiService
|
||||
.verify("fakeOrgId", "fakeOrgId")
|
||||
.then((orgDomain: OrganizationDomainResponse) => {
|
||||
expect(orgDomain.id).toEqual(mockedOrgDomainServerResponse.id);
|
||||
|
||||
expect(orgDomainSvcUpsertSpy).toHaveBeenCalled();
|
||||
expect(lastValueFrom(orgDomainService.orgDomains$)).resolves.toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
it("delete success should call orgDomainSvc delete", () => {
|
||||
apiService.send.mockResolvedValue(true);
|
||||
orgDomainService.upsert([mockedOrgDomainResponse]);
|
||||
expect(lastValueFrom(orgDomainService.orgDomains$)).resolves.toHaveLength(1);
|
||||
|
||||
const orgDomainSvcDeleteSpy = jest.spyOn(orgDomainService, "delete");
|
||||
|
||||
orgDomainApiService.delete("fakeOrgId", "fakeOrgId").then(() => {
|
||||
expect(orgDomainSvcDeleteSpy).toHaveBeenCalled();
|
||||
expect(lastValueFrom(orgDomainService.orgDomains$)).resolves.toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
it("getClaimedOrgDomainByEmail should call ApiService.send with correct parameters and return response", async () => {
|
||||
const email = "test@example.com";
|
||||
apiService.send.mockResolvedValue(mockedOrganizationDomainSsoDetailsServerResponse);
|
||||
|
||||
const result = await orgDomainApiService.getClaimedOrgDomainByEmail(email);
|
||||
|
||||
expect(apiService.send).toHaveBeenCalledWith(
|
||||
"POST",
|
||||
"/organizations/domain/sso/details",
|
||||
new OrganizationDomainSsoDetailsRequest(email),
|
||||
false, //anonymous
|
||||
true
|
||||
);
|
||||
|
||||
expect(result).toEqual(mockedOrganizationDomainSsoDetailsResponse);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,112 @@
|
||||
import { ApiService } from "../../../abstractions/api.service";
|
||||
import { ListResponse } from "../../../models/response/list.response";
|
||||
import { OrgDomainApiServiceAbstraction } from "../../abstractions/organization-domain/org-domain-api.service.abstraction";
|
||||
import { OrgDomainInternalServiceAbstraction } from "../../abstractions/organization-domain/org-domain.service.abstraction";
|
||||
import { OrganizationDomainSsoDetailsResponse } from "../../abstractions/organization-domain/responses/organization-domain-sso-details.response";
|
||||
import { OrganizationDomainResponse } from "../../abstractions/organization-domain/responses/organization-domain.response";
|
||||
|
||||
import { OrganizationDomainSsoDetailsRequest } from "./requests/organization-domain-sso-details.request";
|
||||
import { OrganizationDomainRequest } from "./requests/organization-domain.request";
|
||||
|
||||
export class OrgDomainApiService implements OrgDomainApiServiceAbstraction {
|
||||
constructor(
|
||||
private orgDomainService: OrgDomainInternalServiceAbstraction,
|
||||
private apiService: ApiService
|
||||
) {}
|
||||
|
||||
async getAllByOrgId(orgId: string): Promise<Array<OrganizationDomainResponse>> {
|
||||
const listResponse: ListResponse<any> = await this.apiService.send(
|
||||
"GET",
|
||||
`/organizations/${orgId}/domain`,
|
||||
null,
|
||||
true,
|
||||
true
|
||||
);
|
||||
|
||||
const orgDomains = listResponse.data.map(
|
||||
(resultOrgDomain: any) => new OrganizationDomainResponse(resultOrgDomain)
|
||||
);
|
||||
|
||||
this.orgDomainService.replace(orgDomains);
|
||||
|
||||
return orgDomains;
|
||||
}
|
||||
|
||||
async getByOrgIdAndOrgDomainId(
|
||||
orgId: string,
|
||||
orgDomainId: string
|
||||
): Promise<OrganizationDomainResponse> {
|
||||
const result = await this.apiService.send(
|
||||
"GET",
|
||||
`/organizations/${orgId}/domain/${orgDomainId}`,
|
||||
null,
|
||||
true,
|
||||
true
|
||||
);
|
||||
|
||||
const response = new OrganizationDomainResponse(result);
|
||||
|
||||
this.orgDomainService.upsert([response]);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
async post(
|
||||
orgId: string,
|
||||
orgDomainReq: OrganizationDomainRequest
|
||||
): Promise<OrganizationDomainResponse> {
|
||||
const result = await this.apiService.send(
|
||||
"POST",
|
||||
`/organizations/${orgId}/domain`,
|
||||
orgDomainReq,
|
||||
true,
|
||||
true
|
||||
);
|
||||
|
||||
const response = new OrganizationDomainResponse(result);
|
||||
|
||||
this.orgDomainService.upsert([response]);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
async verify(orgId: string, orgDomainId: string): Promise<OrganizationDomainResponse> {
|
||||
const result = await this.apiService.send(
|
||||
"POST",
|
||||
`/organizations/${orgId}/domain/${orgDomainId}/verify`,
|
||||
null,
|
||||
true,
|
||||
true
|
||||
);
|
||||
|
||||
const response = new OrganizationDomainResponse(result);
|
||||
|
||||
this.orgDomainService.upsert([response]);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
async delete(orgId: string, orgDomainId: string): Promise<any> {
|
||||
await this.apiService.send(
|
||||
"DELETE",
|
||||
`/organizations/${orgId}/domain/${orgDomainId}`,
|
||||
null,
|
||||
true,
|
||||
false
|
||||
);
|
||||
this.orgDomainService.delete([orgDomainId]);
|
||||
}
|
||||
|
||||
async getClaimedOrgDomainByEmail(email: string): Promise<OrganizationDomainSsoDetailsResponse> {
|
||||
const result = await this.apiService.send(
|
||||
"POST",
|
||||
`/organizations/domain/sso/details`,
|
||||
new OrganizationDomainSsoDetailsRequest(email),
|
||||
false, // anonymous
|
||||
true
|
||||
);
|
||||
const response = new OrganizationDomainSsoDetailsResponse(result);
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
import { mock, mockReset } from "jest-mock-extended";
|
||||
import { lastValueFrom } from "rxjs";
|
||||
|
||||
import { I18nService } from "../../../platform/abstractions/i18n.service";
|
||||
import { PlatformUtilsService } from "../../../platform/abstractions/platform-utils.service";
|
||||
import { OrganizationDomainResponse } from "../../abstractions/organization-domain/responses/organization-domain.response";
|
||||
|
||||
import { OrgDomainService } from "./org-domain.service";
|
||||
|
||||
const mockedUnverifiedDomainServerResponse = {
|
||||
creationDate: "2022-12-13T23:16:43.7066667Z",
|
||||
domainName: "bacon.com",
|
||||
id: "12eac4ea-9ed8-4dd4-85da-af6a017f9f97",
|
||||
jobRunCount: 0,
|
||||
lastCheckedDate: "2022-12-13T23:16:43.8033333Z",
|
||||
nextRunDate: "2022-12-14T11:16:43.7066667Z",
|
||||
object: "organizationDomain",
|
||||
organizationId: "e4bffa5e-6602-4bc7-a83f-af55016566ef",
|
||||
txt: "bw=eRBGgwJhZk0Kmpd8qPdSrrkSsTD006B+JgmMztk4XjDX",
|
||||
verifiedDate: null as any,
|
||||
};
|
||||
|
||||
const mockedVerifiedDomainServerResponse = {
|
||||
creationDate: "2022-12-13T23:16:43.7066667Z",
|
||||
domainName: "cat.com",
|
||||
id: "58715f70-8650-4a42-9d4a-af6a0188151b",
|
||||
jobRunCount: 0,
|
||||
lastCheckedDate: "2022-12-13T23:16:43.8033333Z",
|
||||
nextRunDate: "2022-12-14T11:16:43.7066667Z",
|
||||
object: "organizationDomain",
|
||||
organizationId: "e4bffa5e-6602-4bc7-a83f-af55016566ef",
|
||||
txt: "bw=eRBGgwJhZk0Kmpd8qPdSrrkSsTD006B+JgmMztk4XjDX",
|
||||
verifiedDate: "2022-12-13T23:16:43.7066667Z",
|
||||
};
|
||||
|
||||
const mockedExtraDomainServerResponse = {
|
||||
creationDate: "2022-12-13T23:16:43.7066667Z",
|
||||
domainName: "dog.com",
|
||||
id: "fac7cdb6-283e-4805-aa55-af6b016bf699",
|
||||
jobRunCount: 0,
|
||||
lastCheckedDate: "2022-12-13T23:16:43.8033333Z",
|
||||
nextRunDate: "2022-12-14T11:16:43.7066667Z",
|
||||
object: "organizationDomain",
|
||||
organizationId: "e4bffa5e-6602-4bc7-a83f-af55016566ef",
|
||||
txt: "bw=eRBGgwJhZk0Kmpd8qPdSrrkSsTD006B+JgmMztk4XjDX",
|
||||
verifiedDate: null as any,
|
||||
};
|
||||
|
||||
const mockedUnverifiedOrgDomainResponse = new OrganizationDomainResponse(
|
||||
mockedUnverifiedDomainServerResponse
|
||||
);
|
||||
const mockedVerifiedOrgDomainResponse = new OrganizationDomainResponse(
|
||||
mockedVerifiedDomainServerResponse
|
||||
);
|
||||
|
||||
const mockedExtraOrgDomainResponse = new OrganizationDomainResponse(
|
||||
mockedExtraDomainServerResponse
|
||||
);
|
||||
|
||||
describe("Org Domain Service", () => {
|
||||
let orgDomainService: OrgDomainService;
|
||||
|
||||
const platformUtilService = mock<PlatformUtilsService>();
|
||||
const i18nService = mock<I18nService>();
|
||||
|
||||
beforeEach(() => {
|
||||
mockReset(platformUtilService);
|
||||
mockReset(i18nService);
|
||||
|
||||
orgDomainService = new OrgDomainService(platformUtilService, i18nService);
|
||||
});
|
||||
|
||||
it("instantiates", () => {
|
||||
expect(orgDomainService).not.toBeFalsy();
|
||||
});
|
||||
|
||||
it("orgDomains$ public observable exists and instantiates w/ empty array", () => {
|
||||
expect(orgDomainService.orgDomains$).toBeDefined();
|
||||
expect(lastValueFrom(orgDomainService.orgDomains$)).resolves.toEqual([]);
|
||||
});
|
||||
|
||||
it("replace and clear work", () => {
|
||||
const newOrgDomains = [mockedUnverifiedOrgDomainResponse, mockedVerifiedOrgDomainResponse];
|
||||
|
||||
orgDomainService.replace(newOrgDomains);
|
||||
|
||||
expect(lastValueFrom(orgDomainService.orgDomains$)).resolves.toEqual(newOrgDomains);
|
||||
|
||||
orgDomainService.clearCache();
|
||||
|
||||
expect(lastValueFrom(orgDomainService.orgDomains$)).resolves.toEqual([]);
|
||||
});
|
||||
|
||||
it("get successfully retrieves org domain by id", () => {
|
||||
const orgDomains = [mockedUnverifiedOrgDomainResponse, mockedVerifiedOrgDomainResponse];
|
||||
orgDomainService.replace(orgDomains);
|
||||
|
||||
expect(orgDomainService.get(mockedVerifiedOrgDomainResponse.id)).toEqual(
|
||||
mockedVerifiedOrgDomainResponse
|
||||
);
|
||||
|
||||
expect(orgDomainService.get(mockedUnverifiedOrgDomainResponse.id)).toEqual(
|
||||
mockedUnverifiedOrgDomainResponse
|
||||
);
|
||||
});
|
||||
|
||||
it("upsert both updates an existing org domain and adds a new one", () => {
|
||||
const orgDomains = [mockedUnverifiedOrgDomainResponse, mockedVerifiedOrgDomainResponse];
|
||||
orgDomainService.replace(orgDomains);
|
||||
|
||||
const changedOrgDomain = new OrganizationDomainResponse(mockedVerifiedDomainServerResponse);
|
||||
changedOrgDomain.domainName = "changed domain name";
|
||||
|
||||
expect(mockedVerifiedOrgDomainResponse.domainName).not.toEqual(changedOrgDomain.domainName);
|
||||
|
||||
orgDomainService.upsert([changedOrgDomain]);
|
||||
|
||||
expect(orgDomainService.get(mockedVerifiedOrgDomainResponse.id).domainName).toEqual(
|
||||
changedOrgDomain.domainName
|
||||
);
|
||||
|
||||
const newOrgDomain = new OrganizationDomainResponse({
|
||||
creationDate: "2022-12-13T23:16:43.7066667Z",
|
||||
domainName: "cat.com",
|
||||
id: "magical-cat-id-number-999",
|
||||
jobRunCount: 0,
|
||||
lastCheckedDate: "2022-12-13T23:16:43.8033333Z",
|
||||
nextRunDate: "2022-12-14T11:16:43.7066667Z",
|
||||
object: "organizationDomain",
|
||||
organizationId: "e4bffa5e-6602-4bc7-a83f-af55016566ef",
|
||||
txt: "bw=eRBGgwJhZk0Kmpd8qPdSrrkSsTD006B+JgmMztk4XjDX",
|
||||
verifiedDate: null as any,
|
||||
});
|
||||
|
||||
expect(lastValueFrom(orgDomainService.orgDomains$)).resolves.toHaveLength(2);
|
||||
|
||||
orgDomainService.upsert([newOrgDomain]);
|
||||
|
||||
expect(lastValueFrom(orgDomainService.orgDomains$)).resolves.toHaveLength(3);
|
||||
|
||||
expect(orgDomainService.get(newOrgDomain.id)).toEqual(newOrgDomain);
|
||||
});
|
||||
|
||||
it("delete successfully removes multiple org domains", () => {
|
||||
const orgDomains = [
|
||||
mockedUnverifiedOrgDomainResponse,
|
||||
mockedVerifiedOrgDomainResponse,
|
||||
mockedExtraOrgDomainResponse,
|
||||
];
|
||||
orgDomainService.replace(orgDomains);
|
||||
expect(lastValueFrom(orgDomainService.orgDomains$)).resolves.toHaveLength(3);
|
||||
|
||||
orgDomainService.delete([mockedUnverifiedOrgDomainResponse.id]);
|
||||
|
||||
expect(lastValueFrom(orgDomainService.orgDomains$)).resolves.toHaveLength(2);
|
||||
expect(orgDomainService.get(mockedUnverifiedOrgDomainResponse.id)).toEqual(undefined);
|
||||
|
||||
orgDomainService.delete([mockedVerifiedOrgDomainResponse.id, mockedExtraOrgDomainResponse.id]);
|
||||
expect(lastValueFrom(orgDomainService.orgDomains$)).resolves.toHaveLength(0);
|
||||
expect(orgDomainService.get(mockedVerifiedOrgDomainResponse.id)).toEqual(undefined);
|
||||
expect(orgDomainService.get(mockedExtraOrgDomainResponse.id)).toEqual(undefined);
|
||||
});
|
||||
|
||||
it("copyDnsTxt copies DNS TXT to clipboard and shows toast", () => {
|
||||
orgDomainService.copyDnsTxt("fakeTxt");
|
||||
expect(jest.spyOn(platformUtilService, "copyToClipboard")).toHaveBeenCalled();
|
||||
expect(jest.spyOn(platformUtilService, "showToast")).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,73 @@
|
||||
import { BehaviorSubject } from "rxjs";
|
||||
|
||||
import { I18nService } from "../../../platform/abstractions/i18n.service";
|
||||
import { PlatformUtilsService } from "../../../platform/abstractions/platform-utils.service";
|
||||
import { OrgDomainInternalServiceAbstraction } from "../../abstractions/organization-domain/org-domain.service.abstraction";
|
||||
import { OrganizationDomainResponse } from "../../abstractions/organization-domain/responses/organization-domain.response";
|
||||
|
||||
export class OrgDomainService implements OrgDomainInternalServiceAbstraction {
|
||||
protected _orgDomains$: BehaviorSubject<OrganizationDomainResponse[]> = new BehaviorSubject([]);
|
||||
|
||||
orgDomains$ = this._orgDomains$.asObservable();
|
||||
|
||||
constructor(
|
||||
private platformUtilsService: PlatformUtilsService,
|
||||
private i18nService: I18nService
|
||||
) {}
|
||||
|
||||
get(orgDomainId: string): OrganizationDomainResponse {
|
||||
const orgDomains: OrganizationDomainResponse[] = this._orgDomains$.getValue();
|
||||
|
||||
return orgDomains.find((orgDomain) => orgDomain.id === orgDomainId);
|
||||
}
|
||||
|
||||
copyDnsTxt(dnsTxt: string): void {
|
||||
this.platformUtilsService.copyToClipboard(dnsTxt);
|
||||
this.platformUtilsService.showToast(
|
||||
"success",
|
||||
null,
|
||||
this.i18nService.t("valueCopied", this.i18nService.t("dnsTxtRecord"))
|
||||
);
|
||||
}
|
||||
|
||||
upsert(orgDomains: OrganizationDomainResponse[]): void {
|
||||
const existingOrgDomains: OrganizationDomainResponse[] = this._orgDomains$.getValue();
|
||||
|
||||
orgDomains.forEach((orgDomain: OrganizationDomainResponse) => {
|
||||
// Determine if passed in orgDomain exists in existing array:
|
||||
const index = existingOrgDomains.findIndex(
|
||||
(existingOrgDomain) => existingOrgDomain.id === orgDomain.id
|
||||
);
|
||||
if (index !== -1) {
|
||||
existingOrgDomains[index] = orgDomain;
|
||||
} else {
|
||||
existingOrgDomains.push(orgDomain);
|
||||
}
|
||||
});
|
||||
|
||||
this._orgDomains$.next(existingOrgDomains);
|
||||
}
|
||||
|
||||
replace(orgDomains: OrganizationDomainResponse[]): void {
|
||||
this._orgDomains$.next(orgDomains);
|
||||
}
|
||||
|
||||
clearCache(): void {
|
||||
this._orgDomains$.next([]);
|
||||
}
|
||||
|
||||
delete(orgDomainIds: string[]): void {
|
||||
const existingOrgDomains: OrganizationDomainResponse[] = this._orgDomains$.getValue();
|
||||
|
||||
orgDomainIds.forEach((orgDomainId: string) => {
|
||||
const index = existingOrgDomains.findIndex(
|
||||
(existingOrgDomain) => existingOrgDomain.id === orgDomainId
|
||||
);
|
||||
if (index !== -1) {
|
||||
existingOrgDomains.splice(index, 1);
|
||||
}
|
||||
});
|
||||
|
||||
this._orgDomains$.next(existingOrgDomains);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export class OrganizationDomainSsoDetailsRequest {
|
||||
constructor(public email: string) {}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
export class OrganizationDomainRequest {
|
||||
txt: string;
|
||||
domainName: string;
|
||||
|
||||
constructor(txt: string, domainName: string) {
|
||||
this.txt = txt;
|
||||
this.domainName = domainName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,349 @@
|
||||
import { ApiService } from "../../../abstractions/api.service";
|
||||
import { ListResponse } from "../../../models/response/list.response";
|
||||
import { OrganizationUserService } from "../../abstractions/organization-user/organization-user.service";
|
||||
import {
|
||||
OrganizationUserAcceptInitRequest,
|
||||
OrganizationUserAcceptRequest,
|
||||
OrganizationUserBulkConfirmRequest,
|
||||
OrganizationUserConfirmRequest,
|
||||
OrganizationUserInviteRequest,
|
||||
OrganizationUserResetPasswordEnrollmentRequest,
|
||||
OrganizationUserResetPasswordRequest,
|
||||
OrganizationUserUpdateGroupsRequest,
|
||||
OrganizationUserUpdateRequest,
|
||||
} from "../../abstractions/organization-user/requests";
|
||||
import {
|
||||
OrganizationUserBulkPublicKeyResponse,
|
||||
OrganizationUserBulkResponse,
|
||||
OrganizationUserDetailsResponse,
|
||||
OrganizationUserResetPasswordDetailsResponse,
|
||||
OrganizationUserUserDetailsResponse,
|
||||
} from "../../abstractions/organization-user/responses";
|
||||
|
||||
import { OrganizationUserBulkRequest } from "./requests";
|
||||
|
||||
export class OrganizationUserServiceImplementation implements OrganizationUserService {
|
||||
constructor(private apiService: ApiService) {}
|
||||
|
||||
async getOrganizationUser(
|
||||
organizationId: string,
|
||||
id: string,
|
||||
options?: {
|
||||
includeGroups?: boolean;
|
||||
}
|
||||
): Promise<OrganizationUserDetailsResponse> {
|
||||
const params = new URLSearchParams();
|
||||
|
||||
if (options?.includeGroups) {
|
||||
params.set("includeGroups", "true");
|
||||
}
|
||||
|
||||
const r = await this.apiService.send(
|
||||
"GET",
|
||||
`/organizations/${organizationId}/users/${id}?${params.toString()}`,
|
||||
null,
|
||||
true,
|
||||
true
|
||||
);
|
||||
return new OrganizationUserDetailsResponse(r);
|
||||
}
|
||||
|
||||
async getOrganizationUserGroups(organizationId: string, id: string): Promise<string[]> {
|
||||
const r = await this.apiService.send(
|
||||
"GET",
|
||||
"/organizations/" + organizationId + "/users/" + id + "/groups",
|
||||
null,
|
||||
true,
|
||||
true
|
||||
);
|
||||
return r;
|
||||
}
|
||||
|
||||
async getAllUsers(
|
||||
organizationId: string,
|
||||
options?: {
|
||||
includeCollections?: boolean;
|
||||
includeGroups?: boolean;
|
||||
}
|
||||
): Promise<ListResponse<OrganizationUserUserDetailsResponse>> {
|
||||
const params = new URLSearchParams();
|
||||
|
||||
if (options?.includeCollections) {
|
||||
params.set("includeCollections", "true");
|
||||
}
|
||||
if (options?.includeGroups) {
|
||||
params.set("includeGroups", "true");
|
||||
}
|
||||
|
||||
const r = await this.apiService.send(
|
||||
"GET",
|
||||
`/organizations/${organizationId}/users?${params.toString()}`,
|
||||
null,
|
||||
true,
|
||||
true
|
||||
);
|
||||
return new ListResponse(r, OrganizationUserUserDetailsResponse);
|
||||
}
|
||||
|
||||
async getOrganizationUserResetPasswordDetails(
|
||||
organizationId: string,
|
||||
id: string
|
||||
): Promise<OrganizationUserResetPasswordDetailsResponse> {
|
||||
const r = await this.apiService.send(
|
||||
"GET",
|
||||
"/organizations/" + organizationId + "/users/" + id + "/reset-password-details",
|
||||
null,
|
||||
true,
|
||||
true
|
||||
);
|
||||
return new OrganizationUserResetPasswordDetailsResponse(r);
|
||||
}
|
||||
|
||||
postOrganizationUserInvite(
|
||||
organizationId: string,
|
||||
request: OrganizationUserInviteRequest
|
||||
): Promise<void> {
|
||||
return this.apiService.send(
|
||||
"POST",
|
||||
"/organizations/" + organizationId + "/users/invite",
|
||||
request,
|
||||
true,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
postOrganizationUserReinvite(organizationId: string, id: string): Promise<any> {
|
||||
return this.apiService.send(
|
||||
"POST",
|
||||
"/organizations/" + organizationId + "/users/" + id + "/reinvite",
|
||||
null,
|
||||
true,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
async postManyOrganizationUserReinvite(
|
||||
organizationId: string,
|
||||
ids: string[]
|
||||
): Promise<ListResponse<OrganizationUserBulkResponse>> {
|
||||
const r = await this.apiService.send(
|
||||
"POST",
|
||||
"/organizations/" + organizationId + "/users/reinvite",
|
||||
new OrganizationUserBulkRequest(ids),
|
||||
true,
|
||||
true
|
||||
);
|
||||
return new ListResponse(r, OrganizationUserBulkResponse);
|
||||
}
|
||||
|
||||
postOrganizationUserAcceptInit(
|
||||
organizationId: string,
|
||||
id: string,
|
||||
request: OrganizationUserAcceptInitRequest
|
||||
): Promise<void> {
|
||||
return this.apiService.send(
|
||||
"POST",
|
||||
"/organizations/" + organizationId + "/users/" + id + "/accept-init",
|
||||
request,
|
||||
true,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
postOrganizationUserAccept(
|
||||
organizationId: string,
|
||||
id: string,
|
||||
request: OrganizationUserAcceptRequest
|
||||
): Promise<void> {
|
||||
return this.apiService.send(
|
||||
"POST",
|
||||
"/organizations/" + organizationId + "/users/" + id + "/accept",
|
||||
request,
|
||||
true,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
postOrganizationUserConfirm(
|
||||
organizationId: string,
|
||||
id: string,
|
||||
request: OrganizationUserConfirmRequest
|
||||
): Promise<void> {
|
||||
return this.apiService.send(
|
||||
"POST",
|
||||
"/organizations/" + organizationId + "/users/" + id + "/confirm",
|
||||
request,
|
||||
true,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
async postOrganizationUsersPublicKey(
|
||||
organizationId: string,
|
||||
ids: string[]
|
||||
): Promise<ListResponse<OrganizationUserBulkPublicKeyResponse>> {
|
||||
const r = await this.apiService.send(
|
||||
"POST",
|
||||
"/organizations/" + organizationId + "/users/public-keys",
|
||||
new OrganizationUserBulkRequest(ids),
|
||||
true,
|
||||
true
|
||||
);
|
||||
return new ListResponse(r, OrganizationUserBulkPublicKeyResponse);
|
||||
}
|
||||
|
||||
async postOrganizationUserBulkConfirm(
|
||||
organizationId: string,
|
||||
request: OrganizationUserBulkConfirmRequest
|
||||
): Promise<ListResponse<OrganizationUserBulkResponse>> {
|
||||
const r = await this.apiService.send(
|
||||
"POST",
|
||||
"/organizations/" + organizationId + "/users/confirm",
|
||||
request,
|
||||
true,
|
||||
true
|
||||
);
|
||||
return new ListResponse(r, OrganizationUserBulkResponse);
|
||||
}
|
||||
|
||||
async putOrganizationUserBulkEnableSecretsManager(
|
||||
organizationId: string,
|
||||
ids: string[]
|
||||
): Promise<void> {
|
||||
await this.apiService.send(
|
||||
"PUT",
|
||||
"/organizations/" + organizationId + "/users/enable-secrets-manager",
|
||||
new OrganizationUserBulkRequest(ids),
|
||||
true,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
putOrganizationUser(
|
||||
organizationId: string,
|
||||
id: string,
|
||||
request: OrganizationUserUpdateRequest
|
||||
): Promise<void> {
|
||||
return this.apiService.send(
|
||||
"PUT",
|
||||
"/organizations/" + organizationId + "/users/" + id,
|
||||
request,
|
||||
true,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
putOrganizationUserGroups(
|
||||
organizationId: string,
|
||||
id: string,
|
||||
request: OrganizationUserUpdateGroupsRequest
|
||||
): Promise<void> {
|
||||
return this.apiService.send(
|
||||
"PUT",
|
||||
"/organizations/" + organizationId + "/users/" + id + "/groups",
|
||||
request,
|
||||
true,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
putOrganizationUserResetPasswordEnrollment(
|
||||
organizationId: string,
|
||||
userId: string,
|
||||
request: OrganizationUserResetPasswordEnrollmentRequest
|
||||
): Promise<void> {
|
||||
return this.apiService.send(
|
||||
"PUT",
|
||||
"/organizations/" + organizationId + "/users/" + userId + "/reset-password-enrollment",
|
||||
request,
|
||||
true,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
putOrganizationUserResetPassword(
|
||||
organizationId: string,
|
||||
id: string,
|
||||
request: OrganizationUserResetPasswordRequest
|
||||
): Promise<void> {
|
||||
return this.apiService.send(
|
||||
"PUT",
|
||||
"/organizations/" + organizationId + "/users/" + id + "/reset-password",
|
||||
request,
|
||||
true,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
deleteOrganizationUser(organizationId: string, id: string): Promise<any> {
|
||||
return this.apiService.send(
|
||||
"DELETE",
|
||||
"/organizations/" + organizationId + "/users/" + id,
|
||||
null,
|
||||
true,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
async deleteManyOrganizationUsers(
|
||||
organizationId: string,
|
||||
ids: string[]
|
||||
): Promise<ListResponse<OrganizationUserBulkResponse>> {
|
||||
const r = await this.apiService.send(
|
||||
"DELETE",
|
||||
"/organizations/" + organizationId + "/users",
|
||||
new OrganizationUserBulkRequest(ids),
|
||||
true,
|
||||
true
|
||||
);
|
||||
return new ListResponse(r, OrganizationUserBulkResponse);
|
||||
}
|
||||
|
||||
revokeOrganizationUser(organizationId: string, id: string): Promise<void> {
|
||||
return this.apiService.send(
|
||||
"PUT",
|
||||
"/organizations/" + organizationId + "/users/" + id + "/revoke",
|
||||
null,
|
||||
true,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
async revokeManyOrganizationUsers(
|
||||
organizationId: string,
|
||||
ids: string[]
|
||||
): Promise<ListResponse<OrganizationUserBulkResponse>> {
|
||||
const r = await this.apiService.send(
|
||||
"PUT",
|
||||
"/organizations/" + organizationId + "/users/revoke",
|
||||
new OrganizationUserBulkRequest(ids),
|
||||
true,
|
||||
true
|
||||
);
|
||||
return new ListResponse(r, OrganizationUserBulkResponse);
|
||||
}
|
||||
|
||||
restoreOrganizationUser(organizationId: string, id: string): Promise<void> {
|
||||
return this.apiService.send(
|
||||
"PUT",
|
||||
"/organizations/" + organizationId + "/users/" + id + "/restore",
|
||||
null,
|
||||
true,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
async restoreManyOrganizationUsers(
|
||||
organizationId: string,
|
||||
ids: string[]
|
||||
): Promise<ListResponse<OrganizationUserBulkResponse>> {
|
||||
const r = await this.apiService.send(
|
||||
"PUT",
|
||||
"/organizations/" + organizationId + "/users/restore",
|
||||
new OrganizationUserBulkRequest(ids),
|
||||
true,
|
||||
true
|
||||
);
|
||||
return new ListResponse(r, OrganizationUserBulkResponse);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from "./organization-user-bulk.request";
|
||||
@@ -0,0 +1,7 @@
|
||||
export class OrganizationUserBulkRequest {
|
||||
ids: string[];
|
||||
|
||||
constructor(ids: string[]) {
|
||||
this.ids = ids == null ? [] : ids;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user