diff --git a/src/abstractions/api.service.ts b/src/abstractions/api.service.ts index daad664cb2..db6f351637 100644 --- a/src/abstractions/api.service.ts +++ b/src/abstractions/api.service.ts @@ -12,6 +12,7 @@ import { CipherResponse } from '../models/response/cipherResponse'; import { FolderResponse } from '../models/response/folderResponse'; import { IdentityTokenResponse } from '../models/response/identityTokenResponse'; import { IdentityTwoFactorResponse } from '../models/response/identityTwoFactorResponse'; +import { ProfileResponse } from '../models/response/profileResponse'; import { SyncResponse } from '../models/response/syncResponse'; export abstract class ApiService { @@ -25,6 +26,7 @@ export abstract class ApiService { postIdentityToken: (request: TokenRequest) => Promise; refreshIdentityToken: () => Promise; postTwoFactorEmail: (request: TwoFactorEmailRequest) => Promise; + getProfile: () => Promise; getAccountRevisionDate: () => Promise; postPasswordHint: (request: PasswordHintRequest) => Promise; postRegister: (request: RegisterRequest) => Promise; diff --git a/src/enums/organizationUserStatusType.ts b/src/enums/organizationUserStatusType.ts new file mode 100644 index 0000000000..eae4a0a636 --- /dev/null +++ b/src/enums/organizationUserStatusType.ts @@ -0,0 +1,5 @@ +export enum OrganizationUserStatusType { + Invited = 0, + Accepted = 1, + Confirmed = 2, +} diff --git a/src/enums/organizationUserType.ts b/src/enums/organizationUserType.ts new file mode 100644 index 0000000000..217c0b450e --- /dev/null +++ b/src/enums/organizationUserType.ts @@ -0,0 +1,5 @@ +export enum OrganizationUserType { + Owner = 0, + Admin = 1, + User = 2, +} diff --git a/src/models/response/profileOrganizationResponse.ts b/src/models/response/profileOrganizationResponse.ts index 05b2b980b5..7ea65f87e9 100644 --- a/src/models/response/profileOrganizationResponse.ts +++ b/src/models/response/profileOrganizationResponse.ts @@ -1,27 +1,36 @@ +import { OrganizationUserStatusType } from '../../enums/organizationUserStatusType'; +import { OrganizationUserType } from '../../enums/organizationUserType'; + export class ProfileOrganizationResponse { id: string; name: string; useGroups: boolean; useDirectory: boolean; + useEvents: boolean; useTotp: boolean; + use2fa: boolean; seats: number; maxCollections: number; maxStorageGb?: number; key: string; - status: number; // TODO: map to enum - type: number; // TODO: map to enum + status: OrganizationUserStatusType; + type: OrganizationUserType; + enabled: boolean; constructor(response: any) { this.id = response.Id; this.name = response.Name; this.useGroups = response.UseGroups; this.useDirectory = response.UseDirectory; + this.useEvents = response.UseEvents; this.useTotp = response.UseTotp; + this.use2fa = response.Use2fa; this.seats = response.Seats; this.maxCollections = response.MaxCollections; this.maxStorageGb = response.MaxStorageGb; this.key = response.Key; this.status = response.Status; this.type = response.Type; + this.enabled = response.Enabled; } } diff --git a/src/services/api.service.ts b/src/services/api.service.ts index be3a93d674..b4274465a6 100644 --- a/src/services/api.service.ts +++ b/src/services/api.service.ts @@ -19,6 +19,7 @@ import { ErrorResponse } from '../models/response/errorResponse'; import { FolderResponse } from '../models/response/folderResponse'; import { IdentityTokenResponse } from '../models/response/identityTokenResponse'; import { IdentityTwoFactorResponse } from '../models/response/identityTwoFactorResponse'; +import { ProfileResponse } from '../models/response/profileResponse'; import { SyncResponse } from '../models/response/syncResponse'; export class ApiService implements ApiServiceAbstraction { @@ -134,6 +135,26 @@ export class ApiService implements ApiServiceAbstraction { // Account APIs + async getProfile(): Promise { + const authHeader = await this.handleTokenState(); + const response = await fetch(new Request(this.baseUrl + '/accounts/profile', { + cache: 'no-cache', + headers: new Headers({ + 'Accept': 'application/json', + 'Authorization': authHeader, + 'Device-Type': this.deviceType, + }), + })); + + if (response.status === 200) { + const responseJson = await response.json(); + return new ProfileResponse(responseJson); + } else { + const error = await this.handleError(response, false); + return Promise.reject(error); + } + } + async getAccountRevisionDate(): Promise { const authHeader = await this.handleTokenState(); const response = await fetch(new Request(this.baseUrl + '/accounts/revision-date', {