1
0
mirror of https://github.com/bitwarden/jslib synced 2025-12-15 15:53:51 +00:00

[Provider] Add initial support for providers (#399)

This commit is contained in:
Oscar Hinton
2021-07-15 15:07:38 +02:00
committed by GitHub
parent c9b13e4d1b
commit 9f0ca7e4d2
34 changed files with 680 additions and 5 deletions

View File

@@ -31,6 +31,9 @@ export class OrganizationData {
resetPasswordEnrolled: boolean;
userId: string;
hasPublicAndPrivateKeys: boolean;
providerId: string;
providerName: string;
isProviderUser: boolean;
constructor(response: ProfileOrganizationResponse) {
this.id = response.id;
@@ -59,5 +62,7 @@ export class OrganizationData {
this.resetPasswordEnrolled = response.resetPasswordEnrolled;
this.userId = response.userId;
this.hasPublicAndPrivateKeys = response.hasPublicAndPrivateKeys;
this.providerId = response.providerId;
this.providerName = response.providerName;
}
}

View File

@@ -0,0 +1,24 @@
import { ProfileProviderResponse } from '../response/profileProviderResponse';
import { ProviderUserStatusType } from '../../enums/providerUserStatusType';
import { ProviderUserType } from '../../enums/providerUserType';
export class ProviderData {
id: string;
name: string;
status: ProviderUserStatusType;
type: ProviderUserType;
enabled: boolean;
userId: string;
useEvents: boolean;
constructor(response: ProfileProviderResponse) {
this.id = response.id;
this.name = response.name;
this.status = response.status;
this.type = response.type;
this.enabled = response.enabled;
this.userId = response.userId;
this.useEvents = response.useEvents;
}
}

View File

@@ -32,6 +32,9 @@ export class Organization {
resetPasswordEnrolled: boolean;
userId: string;
hasPublicAndPrivateKeys: boolean;
providerId: string;
providerName: string;
isProviderUser: boolean;
constructor(obj?: OrganizationData) {
if (obj == null) {
@@ -64,6 +67,9 @@ export class Organization {
this.resetPasswordEnrolled = obj.resetPasswordEnrolled;
this.userId = obj.userId;
this.hasPublicAndPrivateKeys = obj.hasPublicAndPrivateKeys;
this.providerId = obj.providerId;
this.providerName = obj.providerName;
this.isProviderUser = obj.isProviderUser;
}
get canAccess() {

View File

@@ -0,0 +1,50 @@
import { ProviderUserStatusType } from '../../enums/providerUserStatusType';
import { ProviderUserType } from '../../enums/providerUserType';
import { ProviderData } from '../data/providerData';
export class Provider {
id: string;
name: string;
status: ProviderUserStatusType;
type: ProviderUserType;
enabled: boolean;
userId: string;
useEvents: boolean;
constructor(obj?: ProviderData) {
if (obj == null) {
return;
}
this.id = obj.id;
this.name = obj.name;
this.status = obj.status;
this.type = obj.type;
this.enabled = obj.enabled;
this.userId = obj.userId;
this.useEvents = obj.useEvents;
}
get canAccess() {
if (this.isProviderAdmin) {
return true;
}
return this.enabled && this.status === ProviderUserStatusType.Confirmed;
}
get canCreateOrganizations() {
return this.enabled && this.isProviderAdmin;
}
get canManageUsers() {
return this.isProviderAdmin;
}
get canAccessEventLogs() {
return this.isProviderAdmin;
}
get isProviderAdmin() {
return this.type === ProviderUserType.ProviderAdmin;
}
}

View File

@@ -0,0 +1,4 @@
export class ProviderAddOrganizationRequest {
organizationId: string;
key: string;
}

View File

@@ -0,0 +1,7 @@
export class ProviderSetupRequest {
name: string;
businessName: string;
billingEmail: string;
token: string;
key: string;
}

View File

@@ -0,0 +1,5 @@
export class ProviderUpdateRequest {
name: string;
businessName: string;
billingEmail: string;
}

View File

@@ -0,0 +1,3 @@
export class ProviderUserAcceptRequest {
token: string;
}

View File

@@ -0,0 +1,12 @@
type ProviderUserBulkRequestEntry = {
id: string;
key: string;
};
export class ProviderUserBulkConfirmRequest {
keys: ProviderUserBulkRequestEntry[];
constructor(keys: ProviderUserBulkRequestEntry[]) {
this.keys = keys;
}
}

View File

@@ -0,0 +1,7 @@
export class ProviderUserBulkRequest {
ids: string[];
constructor(ids: string[]) {
this.ids = ids == null ? [] : ids;
}
}

View File

@@ -0,0 +1,3 @@
export class ProviderUserConfirmRequest {
key: string;
}

View File

@@ -0,0 +1,6 @@
import { ProviderUserType } from '../../../enums/providerUserType';
export class ProviderUserInviteRequest {
emails: string[] = [];
type: ProviderUserType;
}

View File

@@ -0,0 +1,5 @@
import { ProviderUserType } from '../../../enums/providerUserType';
export class ProviderUserUpdateRequest {
type: ProviderUserType;
}

View File

@@ -7,11 +7,13 @@ export class EventResponse extends BaseResponse {
type: EventType;
userId: string;
organizationId: string;
providerId: string;
cipherId: string;
collectionId: string;
groupId: string;
policyId: string;
organizationUserId: string;
providerUserId: string;
actingUserId: string;
date: string;
deviceType: DeviceType;
@@ -22,11 +24,13 @@ export class EventResponse extends BaseResponse {
this.type = this.getResponseProperty('Type');
this.userId = this.getResponseProperty('UserId');
this.organizationId = this.getResponseProperty('OrganizationId');
this.providerId = this.getResponseProperty('ProviderId');
this.cipherId = this.getResponseProperty('CipherId');
this.collectionId = this.getResponseProperty('CollectionId');
this.groupId = this.getResponseProperty('GroupId');
this.policyId = this.getResponseProperty('PolicyId');
this.organizationUserId = this.getResponseProperty('OrganizationUserId');
this.providerUserId = this.getResponseProperty('ProviderUserId');
this.actingUserId = this.getResponseProperty('ActingUserId');
this.date = this.getResponseProperty('Date');
this.deviceType = this.getResponseProperty('DeviceType');

View File

@@ -32,6 +32,8 @@ export class ProfileOrganizationResponse extends BaseResponse {
permissions: PermissionsApi;
resetPasswordEnrolled: boolean;
userId: string;
providerId: string;
providerName: string;
constructor(response: any) {
super(response);
@@ -62,5 +64,7 @@ export class ProfileOrganizationResponse extends BaseResponse {
this.permissions = new PermissionsApi(this.getResponseProperty('permissions'));
this.resetPasswordEnrolled = this.getResponseProperty('ResetPasswordEnrolled');
this.userId = this.getResponseProperty('UserId');
this.providerId = this.getResponseProperty('ProviderId');
this.providerName = this.getResponseProperty('ProviderName');
}
}

View File

@@ -0,0 +1,70 @@
import { BaseResponse } from './baseResponse';
import { OrganizationUserStatusType } from '../../enums/organizationUserStatusType';
import { OrganizationUserType } from '../../enums/organizationUserType';
import { PermissionsApi } from '../api/permissionsApi';
export class ProfileProviderOrganizationResponse extends BaseResponse {
id: string;
name: string;
usePolicies: boolean;
useGroups: boolean;
useDirectory: boolean;
useEvents: boolean;
useTotp: boolean;
use2fa: boolean;
useApi: boolean;
useBusinessPortal: boolean;
useSso: boolean;
useResetPassword: boolean;
selfHost: boolean;
usersGetPremium: boolean;
seats: number;
maxCollections: number;
maxStorageGb?: number;
key: string;
hasPublicAndPrivateKeys: boolean;
status: OrganizationUserStatusType;
type: OrganizationUserType;
enabled: boolean;
ssoBound: boolean;
identifier: string;
permissions: PermissionsApi;
resetPasswordEnrolled: boolean;
userId: string;
providerId: string;
providerName: string;
constructor(response: any) {
super(response);
this.id = this.getResponseProperty('Id');
this.name = this.getResponseProperty('Name');
this.usePolicies = this.getResponseProperty('UsePolicies');
this.useGroups = this.getResponseProperty('UseGroups');
this.useDirectory = this.getResponseProperty('UseDirectory');
this.useEvents = this.getResponseProperty('UseEvents');
this.useTotp = this.getResponseProperty('UseTotp');
this.use2fa = this.getResponseProperty('Use2fa');
this.useApi = this.getResponseProperty('UseApi');
this.useBusinessPortal = this.getResponseProperty('UseBusinessPortal');
this.useSso = this.getResponseProperty('UseSso');
this.useResetPassword = this.getResponseProperty('UseResetPassword');
this.selfHost = this.getResponseProperty('SelfHost');
this.usersGetPremium = this.getResponseProperty('UsersGetPremium');
this.seats = this.getResponseProperty('Seats');
this.maxCollections = this.getResponseProperty('MaxCollections');
this.maxStorageGb = this.getResponseProperty('MaxStorageGb');
this.key = this.getResponseProperty('Key');
this.hasPublicAndPrivateKeys = this.getResponseProperty('HasPublicAndPrivateKeys');
this.status = this.getResponseProperty('Status');
this.type = this.getResponseProperty('Type');
this.enabled = this.getResponseProperty('Enabled');
this.ssoBound = this.getResponseProperty('SsoBound');
this.identifier = this.getResponseProperty('Identifier');
this.permissions = new PermissionsApi(this.getResponseProperty('permissions'));
this.resetPasswordEnrolled = this.getResponseProperty('ResetPasswordEnrolled');
this.userId = this.getResponseProperty('UserId');
this.providerId = this.getResponseProperty('ProviderId');
this.providerName = this.getResponseProperty('ProviderName');
}
}

View File

@@ -0,0 +1,31 @@
import { BaseResponse } from './baseResponse';
import { ProviderUserStatusType } from '../../enums/providerUserStatusType';
import { ProviderUserType } from '../../enums/providerUserType';
import { PermissionsApi } from '../api/permissionsApi';
export class ProfileProviderResponse extends BaseResponse {
id: string;
name: string;
key: string;
status: ProviderUserStatusType;
type: ProviderUserType;
enabled: boolean;
permissions: PermissionsApi;
userId: string;
useEvents: boolean;
constructor(response: any) {
super(response);
this.id = this.getResponseProperty('Id');
this.name = this.getResponseProperty('Name');
this.key = this.getResponseProperty('Key');
this.status = this.getResponseProperty('Status');
this.type = this.getResponseProperty('Type');
this.enabled = this.getResponseProperty('Enabled');
this.permissions = new PermissionsApi(this.getResponseProperty('permissions'));
this.userId = this.getResponseProperty('UserId');
this.useEvents = this.getResponseProperty('UseEvents');
}
}

View File

@@ -1,5 +1,7 @@
import { BaseResponse } from './baseResponse';
import { ProfileOrganizationResponse } from './profileOrganizationResponse';
import { ProfileProviderOrganizationResponse } from './profileProviderOrganizationResponse';
import { ProfileProviderResponse } from './profileProviderResponse';
export class ProfileResponse extends BaseResponse {
id: string;
@@ -14,6 +16,8 @@ export class ProfileResponse extends BaseResponse {
privateKey: string;
securityStamp: string;
organizations: ProfileOrganizationResponse[] = [];
providers: ProfileProviderResponse[] = [];
providerOrganizations: ProfileProviderOrganizationResponse[] = [];
constructor(response: any) {
super(response);
@@ -33,5 +37,13 @@ export class ProfileResponse extends BaseResponse {
if (organizations != null) {
this.organizations = organizations.map((o: any) => new ProfileOrganizationResponse(o));
}
const providers = this.getResponseProperty('Providers');
if (providers != null) {
this.providers = providers.map((o: any) => new ProfileProviderResponse(o));
}
const providerOrganizations = this.getResponseProperty('ProviderOrganizations');
if (providerOrganizations != null) {
this.providerOrganizations = providerOrganizations.map((o: any) => new ProfileProviderOrganizationResponse(o));
}
}
}

View File

@@ -0,0 +1,31 @@
import { BaseResponse } from '../baseResponse';
export class ProviderOrganizationResponse extends BaseResponse {
id: string;
providerId: string;
organizationId: string;
key: string;
settings: string;
creationDate: string;
revisionDate: string;
constructor(response: any) {
super(response);
this.id = this.getResponseProperty('Id');
this.providerId = this.getResponseProperty('ProviderId');
this.organizationId = this.getResponseProperty('OrganizationId');
this.key = this.getResponseProperty('Key');
this.settings = this.getResponseProperty('Settings');
this.creationDate = this.getResponseProperty('CreationDate');
this.revisionDate = this.getResponseProperty('RevisionDate');
}
}
export class ProviderOrganizationOrganizationDetailsResponse extends ProviderOrganizationResponse {
organizationName: string;
constructor(response: any) {
super(response);
this.organizationName = this.getResponseProperty('OrganizationName');
}
}

View File

@@ -0,0 +1,16 @@
import { BaseResponse } from '../baseResponse';
export class ProviderResponse extends BaseResponse {
id: string;
name: string;
businessName: string;
billingEmail: string;
constructor(response: any) {
super(response);
this.id = this.getResponseProperty('Id');
this.name = this.getResponseProperty('Name');
this.businessName = this.getResponseProperty('BusinessName');
this.billingEmail = this.getResponseProperty('BillingEmail');
}
}

View File

@@ -0,0 +1,5 @@
import { OrganizationUserBulkPublicKeyResponse } from '../organizationUserBulkPublicKeyResponse';
export class ProviderUserBulkPublicKeyResponse extends OrganizationUserBulkPublicKeyResponse {
}

View File

@@ -0,0 +1,12 @@
import { BaseResponse } from '../baseResponse';
export class ProviderUserBulkResponse extends BaseResponse {
id: string;
error: string;
constructor(response: any) {
super(response);
this.id = this.getResponseProperty('Id');
this.error = this.getResponseProperty('Error');
}
}

View File

@@ -0,0 +1,34 @@
import { BaseResponse } from '../baseResponse';
import { PermissionsApi } from '../../api/permissionsApi';
import { ProviderUserStatusType } from '../../../enums/providerUserStatusType';
import { ProviderUserType } from '../../../enums/providerUserType';
export class ProviderUserResponse extends BaseResponse {
id: string;
userId: string;
type: ProviderUserType;
status: ProviderUserStatusType;
permissions: PermissionsApi;
constructor(response: any) {
super(response);
this.id = this.getResponseProperty('Id');
this.userId = this.getResponseProperty('UserId');
this.type = this.getResponseProperty('Type');
this.status = this.getResponseProperty('Status');
this.permissions = new PermissionsApi(this.getResponseProperty('Permissions'));
}
}
export class ProviderUserUserDetailsResponse extends ProviderUserResponse {
name: string;
email: string;
constructor(response: any) {
super(response);
this.name = this.getResponseProperty('Name');
this.email = this.getResponseProperty('Email');
}
}