From 17ae5ee57c4ecd1ae59b9519b5727bb2546061cb Mon Sep 17 00:00:00 2001 From: Addison Beck Date: Tue, 14 Dec 2021 11:10:26 -0500 Subject: [PATCH] [Account Switching] [Refactor] Implement new account centric services (#1220) * [chore] updated services.module to use account services * [refactor] sorted services provided by services.module * [chore] removed references to deleted jslib services * [chore] used activeAccount over storageService for account level storage items * [chore] resolved linter warnings * Refactor activeAccountService to stateService * [bug] Remove uneeded calls to state service on logout This was causing console erros on logout. Clearing of data is handled fully in dedicated services, clearing them in state afterwards is essentially a redundant call. * [bug] Add back null locked callback to VaultTimeoutService * Move call to get showUpdateKey * [bug] Ensure HtmlStorageService does not override StateService options and locations * [bug] Adjust theme logic to pull from the new storage locations * [bug] Correct theme not sticking on refresh * [bug] Add enableFullWidth to the account model * [bug] fix theme option empty when light is selected * [bug] init state on application start * [bug] Reinit state when coming back from a lock * [style] Fix lint complaints * [bug] Clean state on logout * [chore] Resolved merge issues * [bug] Correct default for enableGravitars * Bump angular to 12. * Remove angular.json * Bump rxjs * Fix build errors, remove file-loader with asset/resource * Use contenthash * Bump jslib * Bump ngx-toastr * [chore] resolve issues from merge * [chore] resolve issues from merge * [bug] Add missing bracket * Use newer import syntax * [bug] Correct service orge * [style] Fix lint complaints * [chore] update jslib * [review] Address code review * [review] Address code review * [review] Rename providerService to webProviderService Co-authored-by: Robyn MacCallum Co-authored-by: Hinton --- .../app/organizations/manage/sso.component.ts | 6 +- .../clients/add-organization.component.ts | 18 +-- .../providers/clients/clients.component.ts | 29 +++-- .../manage/accept-provider.component.ts | 14 ++- .../app/providers/manage/events.component.ts | 28 +++-- .../app/providers/manage/manage.component.ts | 6 +- .../app/providers/manage/people.component.ts | 41 +++++-- .../providers/providers-layout.component.ts | 6 +- .../src/app/providers/providers.module.ts | 4 +- .../services/provider-guard.service.ts | 12 +- .../services/provider-type-guard.service.ts | 6 +- ...ider.service.ts => webProvider.service.ts} | 2 +- .../providers/settings/settings.component.ts | 6 +- jslib | 2 +- .../accounts/accept-emergency.component.ts | 21 +++- .../accounts/accept-organization.component.ts | 34 +++-- src/app/accounts/lock.component.ts | 11 +- src/app/accounts/login.component.ts | 18 ++- src/app/accounts/register.component.ts | 8 +- src/app/accounts/set-password.component.ts | 12 +- src/app/accounts/sso.component.ts | 17 ++- src/app/accounts/two-factor.component.ts | 11 +- .../update-temp-password.component.ts | 9 +- .../accounts/verify-email-token.component.ts | 18 +-- src/app/app.component.ts | 54 ++++---- src/app/common/base.accept.component.ts | 10 +- src/app/common/base.people.component.ts | 25 ++-- src/app/layouts/navbar.component.ts | 6 +- .../layouts/organization-layout.component.ts | 8 +- .../manage/collection-add-edit.component.ts | 14 ++- .../manage/collections.component.ts | 18 ++- .../organizations/manage/events.component.ts | 34 +++-- .../organizations/manage/groups.component.ts | 18 ++- .../organizations/manage/manage.component.ts | 6 +- .../organizations/manage/people.component.ts | 44 +++++-- .../manage/policies.component.ts | 6 +- .../manage/user-confirm.component.ts | 10 +- .../policies/master-password.component.ts | 6 +- .../policies/reset-password.component.ts | 6 +- .../organization-subscription.component.ts | 6 +- .../settings/settings.component.ts | 6 +- .../settings/two-factor-setup.component.ts | 8 +- ...families-for-enterprise-setup.component.ts | 6 +- .../exposed-passwords-report.component.ts | 13 +- .../organizations/tools/import.component.ts | 27 ++-- .../inactive-two-factor-report.component.ts | 13 +- .../reused-passwords-report.component.ts | 12 +- .../organizations/tools/tools.component.ts | 6 +- .../unsecured-websites-report.component.ts | 12 +- .../tools/weak-passwords-report.component.ts | 11 +- .../organizations/vault/add-edit.component.ts | 16 +-- .../vault/attachments.component.ts | 10 +- .../organizations/vault/ciphers.component.ts | 33 +++-- .../vault/groupings.component.ts | 13 +- .../organizations/vault/vault.component.ts | 7 +- src/app/providers/providers.component.ts | 6 +- src/app/send/add-edit.component.ts | 10 +- src/app/send/send.component.ts | 9 +- .../services/organization-guard.service.ts | 12 +- .../organization-type-guard.service.ts | 6 +- src/app/services/services.module.ts | 27 ++-- src/app/settings/account.component.ts | 8 +- src/app/settings/add-credit.component.ts | 14 ++- src/app/settings/change-email.component.ts | 19 +-- src/app/settings/change-kdf.component.ts | 21 ++-- src/app/settings/change-password.component.ts | 14 ++- .../emergency-access-attachments.component.ts | 10 +- .../emergency-access-confirm.component.ts | 8 +- .../emergency-access-takeover.component.ts | 29 +++-- .../settings/emergency-access.component.ts | 35 +++--- .../settings/emergency-add-edit.component.ts | 14 +-- src/app/settings/link-sso.component.ts | 7 +- src/app/settings/options.component.ts | 38 +++--- .../settings/organization-plans.component.ts | 6 +- src/app/settings/organizations.component.ts | 6 +- src/app/settings/premium.component.ts | 6 +- src/app/settings/profile.component.ts | 17 ++- src/app/settings/settings.component.ts | 6 +- .../settings/sponsored-families.component.ts | 14 ++- .../two-factor-authenticator.component.ts | 22 +++- .../settings/two-factor-email.component.ts | 22 +++- .../settings/two-factor-setup.component.ts | 10 +- src/app/tools/breach-report.component.ts | 6 +- src/app/tools/cipher-report.component.ts | 14 +-- .../exposed-passwords-report.component.ts | 6 +- .../inactive-two-factor-report.component.ts | 6 +- .../reused-passwords-report.component.ts | 6 +- src/app/tools/tools.component.ts | 6 +- .../unsecured-websites-report.component.ts | 7 +- .../tools/weak-passwords-report.component.ts | 8 +- src/app/vault/add-edit.component.ts | 16 ++- src/app/vault/attachments.component.ts | 11 +- src/app/vault/bulk-share.component.ts | 6 +- src/app/vault/ciphers.component.ts | 6 +- src/app/vault/groupings.component.ts | 7 +- src/app/vault/share.component.ts | 10 +- src/app/vault/vault.component.ts | 23 ++-- src/connectors/webauthn.ts | 2 +- src/services/htmlStorage.service.ts | 116 +++++++----------- src/services/webPlatformUtils.service.ts | 8 +- src/theme.js | 25 ++-- 101 files changed, 839 insertions(+), 649 deletions(-) rename bitwarden_license/src/app/providers/services/{provider.service.ts => webProvider.service.ts} (97%) diff --git a/bitwarden_license/src/app/organizations/manage/sso.component.ts b/bitwarden_license/src/app/organizations/manage/sso.component.ts index f92d46d3c7a..d5d8be0eaac 100644 --- a/bitwarden_license/src/app/organizations/manage/sso.component.ts +++ b/bitwarden_license/src/app/organizations/manage/sso.component.ts @@ -7,8 +7,8 @@ import { ActivatedRoute } from '@angular/router'; import { ApiService } from 'jslib-common/abstractions/api.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { Organization } from 'jslib-common/models/domain/organization'; @@ -81,7 +81,7 @@ export class SsoComponent implements OnInit { constructor(private fb: FormBuilder, private route: ActivatedRoute, private apiService: ApiService, private platformUtilsService: PlatformUtilsService, private i18nService: I18nService, - private userService: UserService) { } + private organizationService: OrganizationService) { } async ngOnInit() { this.route.parent.parent.params.subscribe(async params => { @@ -91,7 +91,7 @@ export class SsoComponent implements OnInit { } async load() { - this.organization = await this.userService.getOrganization(this.organizationId); + this.organization = await this.organizationService.get(this.organizationId); const ssoSettings = await this.apiService.getOrganizationSso(this.organizationId); this.data.patchValue(ssoSettings.data); diff --git a/bitwarden_license/src/app/providers/clients/add-organization.component.ts b/bitwarden_license/src/app/providers/clients/add-organization.component.ts index ef343b2a6b3..dd97c083d49 100644 --- a/bitwarden_license/src/app/providers/clients/add-organization.component.ts +++ b/bitwarden_license/src/app/providers/clients/add-organization.component.ts @@ -8,11 +8,11 @@ import { import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { ProviderService } from 'jslib-common/abstractions/provider.service'; import { ValidationService } from 'jslib-angular/services/validation.service'; -import { ProviderService } from '../services/provider.service'; +import { WebProviderService } from '../services/webProvider.service'; import { Organization } from 'jslib-common/models/domain/organization'; import { Provider } from 'jslib-common/models/domain/provider'; @@ -31,9 +31,13 @@ export class AddOrganizationComponent implements OnInit { formPromise: Promise; loading = true; - constructor(private userService: UserService, private providerService: ProviderService, - private i18nService: I18nService, private platformUtilsService: PlatformUtilsService, - private validationService: ValidationService) { } + constructor( + private providerService: ProviderService, + private webProviderService: WebProviderService, + private i18nService: I18nService, + private platformUtilsService: PlatformUtilsService, + private validationService: ValidationService + ) { } async ngOnInit() { await this.load(); @@ -44,7 +48,7 @@ export class AddOrganizationComponent implements OnInit { return; } - this.provider = await this.userService.getProvider(this.providerId); + this.provider = await this.providerService.get(this.providerId); this.loading = false; } @@ -63,7 +67,7 @@ export class AddOrganizationComponent implements OnInit { } try { - this.formPromise = this.providerService.addOrganizationToProvider(this.providerId, organization.id); + this.formPromise = this.webProviderService.addOrganizationToProvider(this.providerId, organization.id); await this.formPromise; } catch (e) { this.validationService.showError(e); diff --git a/bitwarden_license/src/app/providers/clients/clients.component.ts b/bitwarden_license/src/app/providers/clients/clients.component.ts index 7fa54d97bb6..a20e610f31d 100644 --- a/bitwarden_license/src/app/providers/clients/clients.component.ts +++ b/bitwarden_license/src/app/providers/clients/clients.component.ts @@ -11,9 +11,10 @@ import { first } from 'rxjs/operators'; import { ApiService } from 'jslib-common/abstractions/api.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { LogService } from 'jslib-common/abstractions/log.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; +import { ProviderService } from 'jslib-common/abstractions/provider.service'; import { SearchService } from 'jslib-common/abstractions/search.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { ModalService } from 'jslib-angular/services/modal.service'; import { ValidationService } from 'jslib-angular/services/validation.service'; @@ -26,7 +27,7 @@ import { ProviderOrganizationOrganizationDetailsResponse } from 'jslib-common/models/response/provider/providerOrganizationResponse'; -import { ProviderService } from '../services/provider.service'; +import { WebProviderService } from '../services/webProvider.service'; import { AddOrganizationComponent } from './add-organization.component'; @@ -54,11 +55,19 @@ export class ClientsComponent implements OnInit { protected actionPromise: Promise; private pagedClientsCount = 0; - constructor(private route: ActivatedRoute, private userService: UserService, - private apiService: ApiService, private searchService: SearchService, - private platformUtilsService: PlatformUtilsService, private i18nService: I18nService, - private validationService: ValidationService, private providerService: ProviderService, - private logService: LogService, private modalService: ModalService) { } + constructor( + private route: ActivatedRoute, + private providerService: ProviderService, + private apiService: ApiService, + private searchService: SearchService, + private platformUtilsService: PlatformUtilsService, + private i18nService: I18nService, + private validationService: ValidationService, + private webProviderService: WebProviderService, + private logService: LogService, + private modalService: ModalService, + private organizationService: OrganizationService + ) { } async ngOnInit() { this.route.parent.params.subscribe(async params => { @@ -75,8 +84,8 @@ export class ClientsComponent implements OnInit { async load() { const response = await this.apiService.getProviderClients(this.providerId); this.clients = response.data != null && response.data.length > 0 ? response.data : []; - this.manageOrganizations = (await this.userService.getProvider(this.providerId)).type === ProviderUserType.ProviderAdmin; - const candidateOrgs = (await this.userService.getAllOrganizations()).filter(o => o.isOwner && o.providerId == null); + this.manageOrganizations = (await this.providerService.get(this.providerId)).type === ProviderUserType.ProviderAdmin; + const candidateOrgs = (await this.organizationService.getAll()).filter(o => o.isOwner && o.providerId == null); const allowedOrgsIds = await Promise.all(candidateOrgs.map(o => this.apiService.getOrganization(o.id))).then(orgs => orgs.filter(o => !DisallowedPlanTypes.includes(o.planType)) .map(o => o.id)); @@ -144,7 +153,7 @@ export class ClientsComponent implements OnInit { return false; } - this.actionPromise = this.providerService.detachOrganizastion(this.providerId, organization.id); + this.actionPromise = this.webProviderService.detachOrganizastion(this.providerId, organization.id); try { await this.actionPromise; this.platformUtilsService.showToast('success', null, diff --git a/bitwarden_license/src/app/providers/manage/accept-provider.component.ts b/bitwarden_license/src/app/providers/manage/accept-provider.component.ts index 1ca394393ff..5a2585e38f9 100644 --- a/bitwarden_license/src/app/providers/manage/accept-provider.component.ts +++ b/bitwarden_license/src/app/providers/manage/accept-provider.component.ts @@ -8,7 +8,6 @@ import { ApiService } from 'jslib-common/abstractions/api.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { StateService } from 'jslib-common/abstractions/state.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { ProviderUserAcceptRequest } from 'jslib-common/models/request/provider/providerUserAcceptRequest'; @Component({ @@ -22,10 +21,15 @@ export class AcceptProviderComponent extends BaseAcceptComponent { requiredParameters = ['providerId', 'providerUserId', 'token']; - constructor(router: Router, i18nService: I18nService, route: ActivatedRoute, - userService: UserService, stateService: StateService, private apiService: ApiService, - platformUtilService: PlatformUtilsService) { - super(router, platformUtilService, i18nService, route, userService, stateService); + constructor( + router: Router, + i18nService: I18nService, + route: ActivatedRoute, + stateService: StateService, + private apiService: ApiService, + platformUtilService: PlatformUtilsService, + ) { + super(router, platformUtilService, i18nService, route, stateService); } async authedHandler(qParams: any) { diff --git a/bitwarden_license/src/app/providers/manage/events.component.ts b/bitwarden_license/src/app/providers/manage/events.component.ts index 00648b08c6d..7b59562e6a3 100644 --- a/bitwarden_license/src/app/providers/manage/events.component.ts +++ b/bitwarden_license/src/app/providers/manage/events.component.ts @@ -9,7 +9,7 @@ import { ExportService } from 'jslib-common/abstractions/export.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { LogService } from 'jslib-common/abstractions/log.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { ProviderService } from 'jslib-common/abstractions/provider.service'; import { UserNamePipe } from 'jslib-angular/pipes/user-name.pipe'; @@ -30,17 +30,31 @@ export class EventsComponent extends BaseEventsComponent implements OnInit { private providerUsersUserIdMap = new Map(); private providerUsersIdMap = new Map(); - constructor(private apiService: ApiService, private route: ActivatedRoute, eventService: EventService, - i18nService: I18nService, private userService: UserService, exportService: ExportService, - platformUtilsService: PlatformUtilsService, private router: Router, logService: LogService, - private userNamePipe: UserNamePipe) { - super(eventService, i18nService, exportService, platformUtilsService, logService); + constructor( + private apiService: ApiService, + private route: ActivatedRoute, + eventService: EventService, + i18nService: I18nService, + private providerService: ProviderService, + exportService: ExportService, + platformUtilsService: PlatformUtilsService, + private router: Router, + logService: LogService, + private userNamePipe: UserNamePipe, + ) { + super( + eventService, + i18nService, + exportService, + platformUtilsService, + logService, + ); } async ngOnInit() { this.route.parent.parent.params.subscribe(async params => { this.providerId = params.providerId; - const provider = await this.userService.getProvider(this.providerId); + const provider = await this.providerService.get(this.providerId); if (provider == null || !provider.useEvents) { this.router.navigate(['/providers', this.providerId]); return; diff --git a/bitwarden_license/src/app/providers/manage/manage.component.ts b/bitwarden_license/src/app/providers/manage/manage.component.ts index 708f22064ea..3246892aee4 100644 --- a/bitwarden_license/src/app/providers/manage/manage.component.ts +++ b/bitwarden_license/src/app/providers/manage/manage.component.ts @@ -4,7 +4,7 @@ import { } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { ProviderService } from 'jslib-common/abstractions/provider.service'; import { Provider } from 'jslib-common/models/domain/provider'; @@ -16,11 +16,11 @@ export class ManageComponent implements OnInit { provider: Provider; accessEvents = false; - constructor(private route: ActivatedRoute, private userService: UserService) { } + constructor(private route: ActivatedRoute, private providerService: ProviderService) { } ngOnInit() { this.route.parent.params.subscribe(async params => { - this.provider = await this.userService.getProvider(params.providerId); + this.provider = await this.providerService.get(params.providerId); this.accessEvents = this.provider.useEvents; }); } diff --git a/bitwarden_license/src/app/providers/manage/people.component.ts b/bitwarden_license/src/app/providers/manage/people.component.ts index 4fb4582801a..1584cd7a4e2 100644 --- a/bitwarden_license/src/app/providers/manage/people.component.ts +++ b/bitwarden_license/src/app/providers/manage/people.component.ts @@ -13,9 +13,9 @@ import { CryptoService } from 'jslib-common/abstractions/crypto.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { LogService } from 'jslib-common/abstractions/log.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; +import { ProviderService } from 'jslib-common/abstractions/provider.service'; import { SearchService } from 'jslib-common/abstractions/search.service'; -import { StorageService } from 'jslib-common/abstractions/storage.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { ModalService } from 'jslib-angular/services/modal.service'; import { ValidationService } from 'jslib-angular/services/validation.service'; @@ -58,20 +58,41 @@ export class PeopleComponent extends BasePeopleComponent { this.providerId = params.providerId; - const provider = await this.userService.getProvider(this.providerId); + const provider = await this.providerService.get(this.providerId); if (!provider.canManageUsers) { this.router.navigate(['../'], { relativeTo: this.route }); diff --git a/bitwarden_license/src/app/providers/providers-layout.component.ts b/bitwarden_license/src/app/providers/providers-layout.component.ts index 6bc6ed73306..fed1deff62b 100644 --- a/bitwarden_license/src/app/providers/providers-layout.component.ts +++ b/bitwarden_license/src/app/providers/providers-layout.component.ts @@ -1,7 +1,7 @@ import { Component } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { ProviderService } from 'jslib-common/abstractions/provider.service'; import { Provider } from 'jslib-common/models/domain/provider'; @@ -14,7 +14,7 @@ export class ProvidersLayoutComponent { provider: Provider; private providerId: string; - constructor(private route: ActivatedRoute, private userService: UserService) { } + constructor(private route: ActivatedRoute, private providerService: ProviderService) { } ngOnInit() { document.body.classList.remove('layout_frontend'); @@ -25,7 +25,7 @@ export class ProvidersLayoutComponent { } async load() { - this.provider = await this.userService.getProvider(this.providerId); + this.provider = await this.providerService.get(this.providerId); } get showMenuBar() { diff --git a/bitwarden_license/src/app/providers/providers.module.ts b/bitwarden_license/src/app/providers/providers.module.ts index 9eddcd24264..378ad0d2c3b 100644 --- a/bitwarden_license/src/app/providers/providers.module.ts +++ b/bitwarden_license/src/app/providers/providers.module.ts @@ -7,7 +7,7 @@ import { ModalService } from 'jslib-angular/services/modal.service'; import { ProviderGuardService } from './services/provider-guard.service'; import { ProviderTypeGuardService } from './services/provider-type-guard.service'; -import { ProviderService } from './services/provider.service'; +import { WebProviderService } from './services/webProvider.service'; import { ProvidersLayoutComponent } from './providers-layout.component'; import { ProvidersRoutingModule } from './providers-routing.module'; @@ -57,7 +57,7 @@ import { OssModule } from 'src/app/oss.module'; UserAddEditComponent, ], providers: [ - ProviderService, + WebProviderService, ProviderGuardService, ProviderTypeGuardService, ], diff --git a/bitwarden_license/src/app/providers/services/provider-guard.service.ts b/bitwarden_license/src/app/providers/services/provider-guard.service.ts index 65d2df8cba8..0f3ab8cf4e8 100644 --- a/bitwarden_license/src/app/providers/services/provider-guard.service.ts +++ b/bitwarden_license/src/app/providers/services/provider-guard.service.ts @@ -7,15 +7,19 @@ import { import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { ProviderService } from 'jslib-common/abstractions/provider.service'; @Injectable() export class ProviderGuardService implements CanActivate { - constructor(private userService: UserService, private router: Router, - private platformUtilsService: PlatformUtilsService, private i18nService: I18nService) { } + constructor( + private router: Router, + private platformUtilsService: PlatformUtilsService, + private i18nService: I18nService, + private providerService: ProviderService, + ) { } async canActivate(route: ActivatedRouteSnapshot) { - const provider = await this.userService.getProvider(route.params.providerId); + const provider = await this.providerService.get(route.params.providerId); if (provider == null) { this.router.navigate(['/']); return false; diff --git a/bitwarden_license/src/app/providers/services/provider-type-guard.service.ts b/bitwarden_license/src/app/providers/services/provider-type-guard.service.ts index c2f9c3e4c3f..9a104180416 100644 --- a/bitwarden_license/src/app/providers/services/provider-type-guard.service.ts +++ b/bitwarden_license/src/app/providers/services/provider-type-guard.service.ts @@ -5,16 +5,16 @@ import { Router, } from '@angular/router'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { ProviderService } from 'jslib-common/abstractions/provider.service'; import { Permissions } from 'jslib-common/enums/permissions'; @Injectable() export class ProviderTypeGuardService implements CanActivate { - constructor(private userService: UserService, private router: Router) { } + constructor(private providerService: ProviderService, private router: Router) { } async canActivate(route: ActivatedRouteSnapshot) { - const provider = await this.userService.getProvider(route.params.providerId); + const provider = await this.providerService.get(route.params.providerId); const permissions = route.data == null ? null : route.data.permissions as Permissions[]; if ( diff --git a/bitwarden_license/src/app/providers/services/provider.service.ts b/bitwarden_license/src/app/providers/services/webProvider.service.ts similarity index 97% rename from bitwarden_license/src/app/providers/services/provider.service.ts rename to bitwarden_license/src/app/providers/services/webProvider.service.ts index 2f60fffdc39..1dc1ec34eee 100644 --- a/bitwarden_license/src/app/providers/services/provider.service.ts +++ b/bitwarden_license/src/app/providers/services/webProvider.service.ts @@ -7,7 +7,7 @@ import { SyncService } from 'jslib-common/abstractions/sync.service'; import { ProviderAddOrganizationRequest } from 'jslib-common/models/request/provider/providerAddOrganizationRequest'; @Injectable() -export class ProviderService { +export class WebProviderService { constructor(private cryptoService: CryptoService, private syncService: SyncService, private apiService: ApiService) {} async addOrganizationToProvider(providerId: string, organizationId: string) { diff --git a/bitwarden_license/src/app/providers/settings/settings.component.ts b/bitwarden_license/src/app/providers/settings/settings.component.ts index 0b8f2820ed0..c57abaa4468 100644 --- a/bitwarden_license/src/app/providers/settings/settings.component.ts +++ b/bitwarden_license/src/app/providers/settings/settings.component.ts @@ -2,19 +2,19 @@ import { Component } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { ProviderService } from 'jslib-common/abstractions/provider.service'; @Component({ selector: 'provider-settings', templateUrl: 'settings.component.html', }) export class SettingsComponent { - constructor(private route: ActivatedRoute, private userService: UserService, + constructor(private route: ActivatedRoute, private providerService: ProviderService, private platformUtilsService: PlatformUtilsService) { } ngOnInit() { this.route.parent.params.subscribe(async params => { - const provider = await this.userService.getProvider(params.providerId); + const provider = await this.providerService.get(params.providerId); }); } } diff --git a/jslib b/jslib index 8fc3cf50d29..f90b3456d5b 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 8fc3cf50d2967212ffbbf0d57cac71d0774aa2a8 +Subproject commit f90b3456d5b3782c44c55a49b125ebda0b1cddc4 diff --git a/src/app/accounts/accept-emergency.component.ts b/src/app/accounts/accept-emergency.component.ts index b44013724fb..4c395ce3229 100644 --- a/src/app/accounts/accept-emergency.component.ts +++ b/src/app/accounts/accept-emergency.component.ts @@ -8,7 +8,6 @@ import { ApiService } from 'jslib-common/abstractions/api.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { StateService } from 'jslib-common/abstractions/state.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { EmergencyAccessAcceptRequest } from 'jslib-common/models/request/emergencyAccessAcceptRequest'; import { BaseAcceptComponent } from '../common/base.accept.component'; @@ -24,11 +23,21 @@ export class AcceptEmergencyComponent extends BaseAcceptComponent { protected failedShortMessage = 'emergencyInviteAcceptFailedShort'; protected failedMessage = 'emergencyInviteAcceptFailed'; - constructor(router: Router, platformUtilsService: PlatformUtilsService, - i18nService: I18nService, route: ActivatedRoute, - private apiService: ApiService, userService: UserService, - stateService: StateService) { - super(router, platformUtilsService, i18nService, route, userService, stateService); + constructor( + router: Router, + platformUtilsService: PlatformUtilsService, + i18nService: I18nService, + route: ActivatedRoute, + private apiService: ApiService, + stateService: StateService + ) { + super( + router, + platformUtilsService, + i18nService, + route, + stateService + ); } async authedHandler(qParams: any): Promise { diff --git a/src/app/accounts/accept-organization.component.ts b/src/app/accounts/accept-organization.component.ts index 508a8862f1c..3b4dc83e52b 100644 --- a/src/app/accounts/accept-organization.component.ts +++ b/src/app/accounts/accept-organization.component.ts @@ -11,7 +11,6 @@ import { LogService } from 'jslib-common/abstractions/log.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { PolicyService } from 'jslib-common/abstractions/policy.service'; import { StateService } from 'jslib-common/abstractions/state.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { OrganizationUserAcceptRequest } from 'jslib-common/models/request/organizationUserAcceptRequest'; import { OrganizationUserResetPasswordEnrollmentRequest } from 'jslib-common/models/request/organizationUserResetPasswordEnrollmentRequest'; @@ -29,12 +28,24 @@ export class AcceptOrganizationComponent extends BaseAcceptComponent { protected requiredParameters: string[] = ['organizationId', 'organizationUserId', 'token']; - constructor(router: Router, platformUtilsService: PlatformUtilsService, - i18nService: I18nService, route: ActivatedRoute, - private apiService: ApiService, userService: UserService, - stateService: StateService, private cryptoService: CryptoService, - private policyService: PolicyService, private logService: LogService) { - super(router, platformUtilsService, i18nService, route, userService, stateService); + constructor( + router: Router, + platformUtilsService: PlatformUtilsService, + i18nService: I18nService, + route: ActivatedRoute, + private apiService: ApiService, + stateService: StateService, + private cryptoService: CryptoService, + private policyService: PolicyService, + private logService: LogService + ) { + super( + router, + platformUtilsService, + i18nService, + route, + stateService + ); } async authedHandler(qParams: any): Promise { @@ -60,10 +71,7 @@ export class AcceptOrganizationComponent extends BaseAcceptComponent { const resetRequest = new OrganizationUserResetPasswordEnrollmentRequest(); resetRequest.resetPasswordKey = encryptedKey.encryptedString; - // Get User Id - const userId = await this.userService.getUserId(); - - return this.apiService.putOrganizationUserResetPasswordEnrollment(qParams.organizationId, userId, resetRequest); + return this.apiService.putOrganizationUserResetPasswordEnrollment(qParams.organizationId, await this.stateService.getUserId(), resetRequest); }); } else { this.actionPromise = this.apiService.postOrganizationUserAccept(qParams.organizationId, @@ -74,7 +82,7 @@ export class AcceptOrganizationComponent extends BaseAcceptComponent { this.platformUtilService.showToast('success', this.i18nService.t('inviteAccepted'), this.i18nService.t('inviteAcceptedDesc'), {timeout: 10000}); - await this.stateService.remove('orgInvitation'); + await this.stateService.setOrganizationInvitation(null); this.router.navigate(['/vault']); } @@ -84,7 +92,7 @@ export class AcceptOrganizationComponent extends BaseAcceptComponent { // Fix URL encoding of space issue with Angular this.orgName = this.orgName.replace(/\+/g, ' '); } - await this.stateService.save('orgInvitation', qParams); + await this.stateService.setOrganizationInvitation(qParams); } private async performResetPasswordAutoEnroll(qParams: any): Promise { diff --git a/src/app/accounts/lock.component.ts b/src/app/accounts/lock.component.ts index 28d1dcad228..68914c24b45 100644 --- a/src/app/accounts/lock.component.ts +++ b/src/app/accounts/lock.component.ts @@ -13,8 +13,6 @@ import { LogService } from 'jslib-common/abstractions/log.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { StateService } from 'jslib-common/abstractions/state.service'; -import { StorageService } from 'jslib-common/abstractions/storage.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { VaultTimeoutService } from 'jslib-common/abstractions/vaultTimeout.service'; import { RouterService } from '../services/router.service'; @@ -28,19 +26,18 @@ import { LockComponent as BaseLockComponent } from 'jslib-angular/components/loc export class LockComponent extends BaseLockComponent { constructor(router: Router, i18nService: I18nService, platformUtilsService: PlatformUtilsService, messagingService: MessagingService, - userService: UserService, cryptoService: CryptoService, - storageService: StorageService, vaultTimeoutService: VaultTimeoutService, + cryptoService: CryptoService, vaultTimeoutService: VaultTimeoutService, environmentService: EnvironmentService, private routerService: RouterService, stateService: StateService, apiService: ApiService, logService: LogService, keyConnectorService: KeyConnectorService, ngZone: NgZone) { - super(router, i18nService, platformUtilsService, messagingService, userService, cryptoService, - storageService, vaultTimeoutService, environmentService, stateService, apiService, logService, + super(router, i18nService, platformUtilsService, messagingService, cryptoService, + vaultTimeoutService, environmentService, stateService, apiService, logService, keyConnectorService, ngZone); } async ngOnInit() { await super.ngOnInit(); - this.onSuccessfulSubmit = () => { + this.onSuccessfulSubmit = async () => { const previousUrl = this.routerService.getPreviousUrl(); if (previousUrl !== '/' && previousUrl.indexOf('lock') === -1) { this.successRoute = previousUrl; diff --git a/src/app/accounts/login.component.ts b/src/app/accounts/login.component.ts index ad8078156a0..a83a14e97bc 100644 --- a/src/app/accounts/login.component.ts +++ b/src/app/accounts/login.component.ts @@ -19,7 +19,6 @@ import { PasswordGenerationService } from 'jslib-common/abstractions/passwordGen import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { PolicyService } from 'jslib-common/abstractions/policy.service'; import { StateService } from 'jslib-common/abstractions/state.service'; -import { StorageService } from 'jslib-common/abstractions/storage.service'; import { LoginComponent as BaseLoginComponent } from 'jslib-angular/components/login.component'; @@ -34,8 +33,7 @@ export class LoginComponent extends BaseLoginComponent { showResetPasswordAutoEnrollWarning = false; constructor(authService: AuthService, router: Router, - i18nService: I18nService, private route: ActivatedRoute, - storageService: StorageService, stateService: StateService, + i18nService: I18nService, private route: ActivatedRoute, stateService: StateService, platformUtilsService: PlatformUtilsService, environmentService: EnvironmentService, passwordGenerationService: PasswordGenerationService, cryptoFunctionService: CryptoFunctionService, private apiService: ApiService, private policyService: PolicyService, logService: LogService, @@ -44,7 +42,7 @@ export class LoginComponent extends BaseLoginComponent { platformUtilsService, i18nService, stateService, environmentService, passwordGenerationService, cryptoFunctionService, - storageService, logService, ngZone); + logService, ngZone); this.onSuccessfulLoginNavigate = this.goAfterLogIn; } @@ -54,16 +52,16 @@ export class LoginComponent extends BaseLoginComponent { this.email = qParams.email; } if (qParams.premium != null) { - this.stateService.save('loginRedirect', { route: '/settings/premium' }); + this.stateService.setLoginRedirect({ route: '/settings/premium' }); } else if (qParams.org != null) { - this.stateService.save('loginRedirect', + this.stateService.setLoginRedirect( { route: '/settings/create-organization', qParams: { plan: qParams.org } }); } // Are they coming from an email for sponsoring a families organization if (qParams.sponsorshipToken != null) { // After logging in redirect them to setup the families sponsorship - this.stateService.save('loginRedirect', { + this.stateService.setLoginRedirect({ route: '/setup/families-for-enterprise', qParams: { token: qParams.sponsorshipToken }, }); @@ -71,7 +69,7 @@ export class LoginComponent extends BaseLoginComponent { await super.ngOnInit(); }); - const invite = await this.stateService.get('orgInvitation'); + const invite = await this.stateService.getOrganizationInvitation(); if (invite != null) { let policyList: Policy[] = null; try { @@ -91,10 +89,10 @@ export class LoginComponent extends BaseLoginComponent { } async goAfterLogIn() { - const loginRedirect = await this.stateService.get('loginRedirect'); + const loginRedirect = await this.stateService.getLoginRedirect(); if (loginRedirect != null) { this.router.navigate([loginRedirect.route], { queryParams: loginRedirect.qParams }); - await this.stateService.remove('loginRedirect'); + await this.stateService.setLoginRedirect(null); } else { this.router.navigate([this.successRoute]); } diff --git a/src/app/accounts/register.component.ts b/src/app/accounts/register.component.ts index 29d2ec4032a..d0a93771917 100644 --- a/src/app/accounts/register.component.ts +++ b/src/app/accounts/register.component.ts @@ -53,11 +53,11 @@ export class RegisterComponent extends BaseRegisterComponent { this.email = qParams.email; } if (qParams.premium != null) { - this.stateService.save('loginRedirect', { route: '/settings/premium' }); + this.stateService.setLoginRedirect({ route: '/settings/premium' }); } else if (qParams.org != null) { this.showCreateOrgMessage = true; this.referenceData.flow = qParams.org; - this.stateService.save('loginRedirect', + this.stateService.setLoginRedirect( { route: '/settings/create-organization', qParams: { plan: qParams.org } }); } if (qParams.layout != null) { @@ -71,7 +71,7 @@ export class RegisterComponent extends BaseRegisterComponent { // Are they coming from an email for sponsoring a families organization if (qParams.sponsorshipToken != null) { // After logging in redirect them to setup the families sponsorship - this.stateService.save('loginRedirect', { + this.stateService.setLoginRedirect({ route: '/setup/families-for-enterprise', qParams: { token: qParams.sponsorshipToken }, }); @@ -80,7 +80,7 @@ export class RegisterComponent extends BaseRegisterComponent { this.referenceData.id = null; } }); - const invite = await this.stateService.get('orgInvitation'); + const invite = await this.stateService.getOrganizationInvitation(); if (invite != null) { try { const policies = await this.apiService.getPoliciesByToken(invite.organizationId, invite.token, diff --git a/src/app/accounts/set-password.component.ts b/src/app/accounts/set-password.component.ts index 395432136df..fe8387e6df3 100644 --- a/src/app/accounts/set-password.component.ts +++ b/src/app/accounts/set-password.component.ts @@ -11,8 +11,8 @@ import { MessagingService } from 'jslib-common/abstractions/messaging.service'; import { PasswordGenerationService } from 'jslib-common/abstractions/passwordGeneration.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { PolicyService } from 'jslib-common/abstractions/policy.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { SyncService } from 'jslib-common/abstractions/sync.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { SetPasswordComponent as BaseSetPasswordComponent, @@ -25,10 +25,10 @@ import { export class SetPasswordComponent extends BaseSetPasswordComponent { constructor(apiService: ApiService, i18nService: I18nService, cryptoService: CryptoService, messagingService: MessagingService, - userService: UserService, passwordGenerationService: PasswordGenerationService, - platformUtilsService: PlatformUtilsService, policyService: PolicyService, router: Router, - syncService: SyncService, route: ActivatedRoute) { - super(i18nService, cryptoService, messagingService, userService, passwordGenerationService, - platformUtilsService, policyService, router, apiService, syncService, route); + passwordGenerationService: PasswordGenerationService, platformUtilsService: PlatformUtilsService, + policyService: PolicyService, router: Router, + syncService: SyncService, route: ActivatedRoute, stateService: StateService) { + super(i18nService, cryptoService, messagingService, passwordGenerationService, + platformUtilsService, policyService, router, apiService, syncService, route, stateService); } } diff --git a/src/app/accounts/sso.component.ts b/src/app/accounts/sso.component.ts index 76914ea259b..90d2afff815 100644 --- a/src/app/accounts/sso.component.ts +++ b/src/app/accounts/sso.component.ts @@ -15,12 +15,9 @@ import { LogService } from 'jslib-common/abstractions/log.service'; import { PasswordGenerationService } from 'jslib-common/abstractions/passwordGeneration.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { StateService } from 'jslib-common/abstractions/state.service'; -import { StorageService } from 'jslib-common/abstractions/storage.service'; import { SsoComponent as BaseSsoComponent } from 'jslib-angular/components/sso.component'; -const IdentifierStorageKey = 'ssoOrgIdentifier'; - @Component({ selector: 'app-sso', templateUrl: 'sso.component.html', @@ -28,11 +25,11 @@ const IdentifierStorageKey = 'ssoOrgIdentifier'; export class SsoComponent extends BaseSsoComponent { constructor(authService: AuthService, router: Router, i18nService: I18nService, route: ActivatedRoute, - storageService: StorageService, stateService: StateService, - platformUtilsService: PlatformUtilsService, apiService: ApiService, - cryptoFunctionService: CryptoFunctionService, environmentService: EnvironmentService, - passwordGenerationService: PasswordGenerationService, logService: LogService) { - super(authService, router, i18nService, route, storageService, stateService, platformUtilsService, + stateService: StateService, platformUtilsService: PlatformUtilsService, + apiService: ApiService, cryptoFunctionService: CryptoFunctionService, + environmentService: EnvironmentService, passwordGenerationService: PasswordGenerationService, + logService: LogService) { + super(authService, router, i18nService, route, stateService, platformUtilsService, apiService, cryptoFunctionService, environmentService, passwordGenerationService, logService); this.redirectUri = window.location.origin + '/sso-connector.html'; this.clientId = 'web'; @@ -44,7 +41,7 @@ export class SsoComponent extends BaseSsoComponent { if (qParams.identifier != null) { this.identifier = qParams.identifier; } else { - const storedIdentifier = await this.storageService.get(IdentifierStorageKey); + const storedIdentifier = await this.stateService.getSsoOrgIdentifier(); if (storedIdentifier != null) { this.identifier = storedIdentifier; } @@ -53,7 +50,7 @@ export class SsoComponent extends BaseSsoComponent { } async submit() { - await this.storageService.save(IdentifierStorageKey, this.identifier); + await this.stateService.setSsoOrganizationIdentifier(this.identifier); if (this.clientId === 'browser') { document.cookie = `ssoHandOffMessage=${this.i18nService.t('ssoHandOff')};SameSite=strict`; } diff --git a/src/app/accounts/two-factor.component.ts b/src/app/accounts/two-factor.component.ts index 75363b3d95d..db29a0bedf4 100644 --- a/src/app/accounts/two-factor.component.ts +++ b/src/app/accounts/two-factor.component.ts @@ -13,9 +13,9 @@ import { ApiService } from 'jslib-common/abstractions/api.service'; import { AuthService } from 'jslib-common/abstractions/auth.service'; import { EnvironmentService } from 'jslib-common/abstractions/environment.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; +import { LogService } from 'jslib-common/abstractions/log.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { StateService } from 'jslib-common/abstractions/state.service'; -import { StorageService } from 'jslib-common/abstractions/storage.service'; import { ModalService } from 'jslib-angular/services/modal.service'; @@ -23,7 +23,6 @@ import { TwoFactorProviderType } from 'jslib-common/enums/twoFactorProviderType' import { TwoFactorComponent as BaseTwoFactorComponent } from 'jslib-angular/components/two-factor.component'; -import { LogService } from 'jslib-common/abstractions/log.service'; import { TwoFactorOptionsComponent } from './two-factor-options.component'; @Component({ @@ -37,9 +36,9 @@ export class TwoFactorComponent extends BaseTwoFactorComponent { i18nService: I18nService, apiService: ApiService, platformUtilsService: PlatformUtilsService, stateService: StateService, environmentService: EnvironmentService, private modalService: ModalService, - storageService: StorageService, route: ActivatedRoute, logService: LogService) { + route: ActivatedRoute, logService: LogService) { super(authService, router, i18nService, apiService, platformUtilsService, window, environmentService, - stateService, storageService, route, logService); + stateService, route, logService); this.onSuccessfulLoginNavigate = this.goAfterLogIn; } @@ -57,10 +56,10 @@ export class TwoFactorComponent extends BaseTwoFactorComponent { } async goAfterLogIn() { - const loginRedirect = await this.stateService.get('loginRedirect'); + const loginRedirect = await this.stateService.getLoginRedirect(); if (loginRedirect != null) { this.router.navigate([loginRedirect.route], { queryParams: loginRedirect.qParams }); - await this.stateService.remove('loginRedirect'); + await this.stateService.setLoginRedirect(null); } else { this.router.navigate([this.successRoute], { queryParams: { diff --git a/src/app/accounts/update-temp-password.component.ts b/src/app/accounts/update-temp-password.component.ts index f1767ffd3aa..5d4d9c29900 100644 --- a/src/app/accounts/update-temp-password.component.ts +++ b/src/app/accounts/update-temp-password.component.ts @@ -9,9 +9,9 @@ import { PasswordGenerationService } from 'jslib-common/abstractions/passwordGen import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { PolicyService } from 'jslib-common/abstractions/policy.service'; import { SyncService } from 'jslib-common/abstractions/sync.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { UpdateTempPasswordComponent as BaseUpdateTempPasswordComponent } from 'jslib-angular/components/update-temp-password.component'; +import { StateService } from 'jslib-common/abstractions/state.service'; @Component({ selector: 'app-update-temp-password', @@ -21,10 +21,9 @@ import { UpdateTempPasswordComponent as BaseUpdateTempPasswordComponent } from ' export class UpdateTempPasswordComponent extends BaseUpdateTempPasswordComponent { constructor(i18nService: I18nService, platformUtilsService: PlatformUtilsService, passwordGenerationService: PasswordGenerationService, policyService: PolicyService, - cryptoService: CryptoService, userService: UserService, - messagingService: MessagingService, apiService: ApiService, - syncService: SyncService, logService: LogService) { + cryptoService: CryptoService, messagingService: MessagingService, + apiService: ApiService, logService: LogService, stateService: StateService, syncService: SyncService) { super(i18nService, platformUtilsService, passwordGenerationService, policyService, cryptoService, - userService, messagingService, apiService, syncService, logService); + messagingService, apiService, stateService, syncService, logService); } } diff --git a/src/app/accounts/verify-email-token.component.ts b/src/app/accounts/verify-email-token.component.ts index 4664727d934..c588a983114 100644 --- a/src/app/accounts/verify-email-token.component.ts +++ b/src/app/accounts/verify-email-token.component.ts @@ -13,7 +13,7 @@ import { ApiService } from 'jslib-common/abstractions/api.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { LogService } from 'jslib-common/abstractions/log.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { VerifyEmailRequest } from 'jslib-common/models/request/verifyEmailRequest'; @@ -22,10 +22,15 @@ import { VerifyEmailRequest } from 'jslib-common/models/request/verifyEmailReque templateUrl: 'verify-email-token.component.html', }) export class VerifyEmailTokenComponent implements OnInit { - constructor(private router: Router, private platformUtilsService: PlatformUtilsService, - private i18nService: I18nService, private route: ActivatedRoute, - private apiService: ApiService, private userService: UserService, - private logService: LogService) { } + constructor( + private router: Router, + private platformUtilsService: PlatformUtilsService, + private i18nService: I18nService, + private route: ActivatedRoute, + private apiService: ApiService, + private logService: LogService, + private stateService: StateService + ) { } ngOnInit() { this.route.queryParams.pipe(first()).subscribe(async qParams => { @@ -33,8 +38,7 @@ export class VerifyEmailTokenComponent implements OnInit { try { await this.apiService.postAccountVerifyEmailToken( new VerifyEmailRequest(qParams.userId, qParams.token)); - const authed = await this.userService.isAuthenticated(); - if (authed) { + if (await this.stateService.getIsAuthenticated()) { await this.apiService.refreshIdentityToken(); } this.platformUtilsService.showToast('success', null, this.i18nService.t('emailVerified')); diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 256aafc7639..3129ba84dd3 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -33,11 +33,8 @@ import { StateService } from 'jslib-common/abstractions/state.service'; import { StorageService } from 'jslib-common/abstractions/storage.service'; import { SyncService } from 'jslib-common/abstractions/sync.service'; import { TokenService } from 'jslib-common/abstractions/token.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { VaultTimeoutService } from 'jslib-common/abstractions/vaultTimeout.service'; -import { ConstantsService } from 'jslib-common/services/constants.service'; - import { PolicyListService } from './services/policy-list.service'; import { RouterService } from './services/router.service'; @@ -65,20 +62,32 @@ export class AppComponent implements OnDestroy, OnInit { private isIdle = false; constructor( - private broadcasterService: BroadcasterService, private userService: UserService, - private tokenService: TokenService, private folderService: FolderService, - private settingsService: SettingsService, private syncService: SyncService, - private passwordGenerationService: PasswordGenerationService, private cipherService: CipherService, - private authService: AuthService, private router: Router, - private toastrService: ToastrService, private i18nService: I18nService, - private platformUtilsService: PlatformUtilsService, private ngZone: NgZone, - private vaultTimeoutService: VaultTimeoutService, private storageService: StorageService, - private cryptoService: CryptoService, private collectionService: CollectionService, - private sanitizer: DomSanitizer, private searchService: SearchService, - private notificationsService: NotificationsService, private routerService: RouterService, - private stateService: StateService, private eventService: EventService, - private policyService: PolicyService, protected policyListService: PolicyListService, - private keyConnectorService: KeyConnectorService) { } + private broadcasterService: BroadcasterService, + private tokenService: TokenService, + private folderService: FolderService, + private settingsService: SettingsService, + private syncService: SyncService, + private passwordGenerationService: PasswordGenerationService, + private cipherService: CipherService, + private authService: AuthService, + private router: Router, + private toastrService: ToastrService, + private i18nService: I18nService, + private platformUtilsService: PlatformUtilsService, + private ngZone: NgZone, + private vaultTimeoutService: VaultTimeoutService, + private cryptoService: CryptoService, + private collectionService: CollectionService, + private sanitizer: DomSanitizer, + private searchService: SearchService, + private notificationsService: NotificationsService, + private routerService: RouterService, + private stateService: StateService, + private eventService: EventService, + private policyService: PolicyService, + protected policyListService: PolicyListService, + private keyConnectorService: KeyConnectorService + ) { } ngOnInit() { this.ngZone.runOutsideAngular(() => { @@ -193,21 +202,18 @@ export class AppComponent implements OnDestroy, OnInit { private async logOut(expired: boolean) { await this.eventService.uploadEvents(); - const userId = await this.userService.getUserId(); - + const userId = await this.stateService.getUserId(); await Promise.all([ this.eventService.clearEvents(), this.syncService.setLastSync(new Date(0)), this.tokenService.clearToken(), this.cryptoService.clearKeys(), - this.userService.clear(), this.settingsService.clear(userId), this.cipherService.clear(userId), this.folderService.clear(userId), this.collectionService.clear(userId), this.policyService.clear(userId), this.passwordGenerationService.clear(), - this.stateService.purge(), this.keyConnectorService.clear(), ]); @@ -218,6 +224,7 @@ export class AppComponent implements OnDestroy, OnInit { this.i18nService.t('loginExpired')); } + await this.stateService.clean({ userId: userId }); Swal.close(); this.router.navigate(['/']); }); @@ -230,8 +237,7 @@ export class AppComponent implements OnDestroy, OnInit { } this.lastActivity = now; - this.storageService.save(ConstantsService.lastActiveKey, now); - + this.stateService.setLastActive(now); // Idle states if (this.isIdle) { this.isIdle = false; @@ -284,7 +290,7 @@ export class AppComponent implements OnDestroy, OnInit { } private async setFullWidth() { - const enableFullWidth = await this.storageService.get('enableFullWidth'); + const enableFullWidth = await this.stateService.getEnableFullWidth(); if (enableFullWidth) { document.body.classList.add('full-width'); } else { diff --git a/src/app/common/base.accept.component.ts b/src/app/common/base.accept.component.ts index d149ca9fddd..0e246488c2a 100644 --- a/src/app/common/base.accept.component.ts +++ b/src/app/common/base.accept.component.ts @@ -12,7 +12,6 @@ import { first } from 'rxjs/operators'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { StateService } from 'jslib-common/abstractions/state.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; @Directive() export abstract class BaseAcceptComponent implements OnInit { @@ -27,19 +26,18 @@ export abstract class BaseAcceptComponent implements OnInit { constructor(protected router: Router, protected platformUtilService: PlatformUtilsService, protected i18nService: I18nService, protected route: ActivatedRoute, - protected userService: UserService, protected stateService: StateService) { } + protected stateService: StateService) { } abstract authedHandler(qParams: any): Promise; abstract unauthedHandler(qParams: any): Promise; ngOnInit() { this.route.queryParams.pipe(first()).subscribe(async qParams => { - await this.stateService.remove('loginRedirect'); - + await this.stateService.setLoginRedirect(null); let error = this.requiredParameters.some(e => qParams?.[e] == null || qParams[e] === ''); let errorMessage: string = null; if (!error) { - this.authed = await this.userService.isAuthenticated(); + this.authed = await this.stateService.getIsAuthenticated(); if (this.authed) { try { @@ -49,7 +47,7 @@ export abstract class BaseAcceptComponent implements OnInit { errorMessage = e.message; } } else { - await this.stateService.save('loginRedirect', { + await this.stateService.setLoginRedirect({ route: this.getRedirectRoute(), qParams: qParams, }); diff --git a/src/app/common/base.people.component.ts b/src/app/common/base.people.component.ts index 25085ca9c70..2f89989da99 100644 --- a/src/app/common/base.people.component.ts +++ b/src/app/common/base.people.component.ts @@ -4,18 +4,16 @@ import { ViewContainerRef } from '@angular/core'; -import { ValidationService } from 'jslib-angular/services/validation.service'; import { ApiService } from 'jslib-common/abstractions/api.service'; import { CryptoService } from 'jslib-common/abstractions/crypto.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { LogService } from 'jslib-common/abstractions/log.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { SearchService } from 'jslib-common/abstractions/search.service'; -import { StorageService } from 'jslib-common/abstractions/storage.service'; - -import { ConstantsService } from 'jslib-common/services/constants.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { ModalService } from 'jslib-angular/services/modal.service'; +import { ValidationService } from 'jslib-angular/services/validation.service'; import { SearchPipe } from 'jslib-angular/pipes/search.pipe'; import { UserNamePipe } from 'jslib-angular/pipes/user-name.pipe'; @@ -88,12 +86,19 @@ export abstract class BasePeopleComponent>; @@ -247,7 +252,7 @@ export abstract class BasePeopleComponent(ConstantsService.autoConfirmFingerprints); + const autoConfirm = await this.stateService.getAutoConfirmFingerPrints(); if (autoConfirm == null || !autoConfirm) { const [modal] = await this.modalService.openViewRef(UserConfirmComponent, this.confirmModalRef, comp => { comp.name = this.userNamePipe.transform(user); diff --git a/src/app/layouts/navbar.component.ts b/src/app/layouts/navbar.component.ts index ec1f72d4d6d..1c9341d8aee 100644 --- a/src/app/layouts/navbar.component.ts +++ b/src/app/layouts/navbar.component.ts @@ -5,9 +5,9 @@ import { import { MessagingService } from 'jslib-common/abstractions/messaging.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; +import { ProviderService } from 'jslib-common/abstractions/provider.service'; import { SyncService } from 'jslib-common/abstractions/sync.service'; import { TokenService } from 'jslib-common/abstractions/token.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { Provider } from 'jslib-common/models/domain/provider'; @@ -22,7 +22,7 @@ export class NavbarComponent implements OnInit { providers: Provider[] = []; constructor(private messagingService: MessagingService, private platformUtilsService: PlatformUtilsService, - private tokenService: TokenService, private userService: UserService, private syncService: SyncService) { + private tokenService: TokenService, private providerService: ProviderService, private syncService: SyncService) { this.selfHosted = this.platformUtilsService.isSelfHost(); } @@ -37,7 +37,7 @@ export class NavbarComponent implements OnInit { if (await this.syncService.getLastSync() == null) { await this.syncService.fullSync(false); } - this.providers = await this.userService.getAllProviders(); + this.providers = await this.providerService.getAll(); } lock() { diff --git a/src/app/layouts/organization-layout.component.ts b/src/app/layouts/organization-layout.component.ts index b9e0a63f5ef..80c709d77ce 100644 --- a/src/app/layouts/organization-layout.component.ts +++ b/src/app/layouts/organization-layout.component.ts @@ -7,8 +7,8 @@ import { import { ActivatedRoute } from '@angular/router'; -import { BroadcasterService } from 'jslib-common/abstractions/broadcaster.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { BroadcasterService } from 'jslib-angular/services/broadcaster.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { Organization } from 'jslib-common/models/domain/organization'; @@ -23,7 +23,7 @@ export class OrganizationLayoutComponent implements OnInit, OnDestroy { businessTokenPromise: Promise; private organizationId: string; - constructor(private route: ActivatedRoute, private userService: UserService, + constructor(private route: ActivatedRoute, private organizationService: OrganizationService, private broadcasterService: BroadcasterService, private ngZone: NgZone) { } ngOnInit() { @@ -48,7 +48,7 @@ export class OrganizationLayoutComponent implements OnInit, OnDestroy { } async load() { - this.organization = await this.userService.getOrganization(this.organizationId); + this.organization = await this.organizationService.get(this.organizationId); } get showMenuBar() { diff --git a/src/app/organizations/manage/collection-add-edit.component.ts b/src/app/organizations/manage/collection-add-edit.component.ts index fc973a9f468..df7fdf1bfd9 100644 --- a/src/app/organizations/manage/collection-add-edit.component.ts +++ b/src/app/organizations/manage/collection-add-edit.component.ts @@ -10,8 +10,8 @@ import { ApiService } from 'jslib-common/abstractions/api.service'; import { CryptoService } from 'jslib-common/abstractions/crypto.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { LogService } from 'jslib-common/abstractions/log.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { EncString } from 'jslib-common/models/domain/encString'; import { SymmetricCryptoKey } from 'jslib-common/models/domain/symmetricCryptoKey'; @@ -45,13 +45,17 @@ export class CollectionAddEditComponent implements OnInit { private orgKey: SymmetricCryptoKey; - constructor(private apiService: ApiService, private i18nService: I18nService, + constructor( + private apiService: ApiService, + private i18nService: I18nService, private platformUtilsService: PlatformUtilsService, - private cryptoService: CryptoService, private userService: UserService, - private logService: LogService) { } + private cryptoService: CryptoService, + private logService: LogService, + private organizationService: OrganizationService + ) { } async ngOnInit() { - const organization = await this.userService.getOrganization(this.organizationId); + const organization = await this.organizationService.get(this.organizationId); this.accessGroups = organization.useGroups; this.editMode = this.loading = this.collectionId != null; if (this.accessGroups) { diff --git a/src/app/organizations/manage/collections.component.ts b/src/app/organizations/manage/collections.component.ts index d43252d74a1..c312002640c 100644 --- a/src/app/organizations/manage/collections.component.ts +++ b/src/app/organizations/manage/collections.component.ts @@ -12,9 +12,9 @@ import { ApiService } from 'jslib-common/abstractions/api.service'; import { CollectionService } from 'jslib-common/abstractions/collection.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { LogService } from 'jslib-common/abstractions/log.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { SearchService } from 'jslib-common/abstractions/search.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { ModalService } from 'jslib-angular/services/modal.service'; @@ -53,11 +53,17 @@ export class CollectionsComponent implements OnInit { private pagedCollectionsCount = 0; - constructor(private apiService: ApiService, private route: ActivatedRoute, - private collectionService: CollectionService, private modalService: ModalService, + constructor( + private apiService: ApiService, + private route: ActivatedRoute, + private collectionService: CollectionService, + private modalService: ModalService, private i18nService: I18nService, - private platformUtilsService: PlatformUtilsService, private userService: UserService, - private searchService: SearchService, private logService: LogService) { } + private platformUtilsService: PlatformUtilsService, + private searchService: SearchService, + private logService: LogService, + private organizationService: OrganizationService, + ) { } async ngOnInit() { this.route.parent.parent.params.subscribe(async params => { @@ -70,7 +76,7 @@ export class CollectionsComponent implements OnInit { } async load() { - this.organization = await this.userService.getOrganization(this.organizationId); + this.organization = await this.organizationService.get(this.organizationId); this.canCreate = this.organization.canCreateNewCollections; const decryptCollections = async (r: ListResponse) => { diff --git a/src/app/organizations/manage/events.component.ts b/src/app/organizations/manage/events.component.ts index cfaaa800feb..92bff2e3d6c 100644 --- a/src/app/organizations/manage/events.component.ts +++ b/src/app/organizations/manage/events.component.ts @@ -10,8 +10,9 @@ import { ApiService } from 'jslib-common/abstractions/api.service'; import { ExportService } from 'jslib-common/abstractions/export.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { LogService } from 'jslib-common/abstractions/log.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { ProviderService } from 'jslib-common/abstractions/provider.service'; import { Organization } from 'jslib-common/models/domain/organization'; import { EventResponse } from 'jslib-common/models/response/eventResponse'; @@ -31,17 +32,32 @@ export class EventsComponent extends BaseEventsComponent implements OnInit { private orgUsersUserIdMap = new Map(); - constructor(private apiService: ApiService, private route: ActivatedRoute, eventService: EventService, - i18nService: I18nService, private userService: UserService, - exportService: ExportService, platformUtilsService: PlatformUtilsService, private router: Router, - logService: LogService, private userNamePipe: UserNamePipe) { - super(eventService, i18nService, exportService, platformUtilsService, logService); + constructor( + private apiService: ApiService, + private route: ActivatedRoute, + eventService: EventService, + i18nService: I18nService, + exportService: ExportService, + platformUtilsService: PlatformUtilsService, + private router: Router, + logService: LogService, + private userNamePipe: UserNamePipe, + private organizationService: OrganizationService, + private providerService: ProviderService, + ) { + super( + eventService, + i18nService, + exportService, + platformUtilsService, + logService + ); } async ngOnInit() { this.route.parent.parent.params.subscribe(async params => { this.organizationId = params.organizationId; - this.organization = await this.userService.getOrganization(this.organizationId); + this.organization = await this.organizationService.get(this.organizationId); if (this.organization == null || !this.organization.useEvents) { this.router.navigate(['/organizations', this.organizationId]); return; @@ -60,8 +76,8 @@ export class EventsComponent extends BaseEventsComponent implements OnInit { if (this.organization.providerId != null) { try { - const provider = await this.userService.getProvider(this.organization.providerId); - if (provider != null && (await this.userService.getProvider(this.organization.providerId)).canManageUsers) { + const provider = await this.providerService.get(this.organization.providerId); + if (provider != null && (await this.providerService.get(this.organization.providerId)).canManageUsers) { const providerUsersResponse = await this.apiService.getProviderUsers(this.organization.providerId); providerUsersResponse.data.forEach(u => { const name = this.userNamePipe.transform(u); diff --git a/src/app/organizations/manage/groups.component.ts b/src/app/organizations/manage/groups.component.ts index 6cbf75766ef..9d79245973a 100644 --- a/src/app/organizations/manage/groups.component.ts +++ b/src/app/organizations/manage/groups.component.ts @@ -14,9 +14,9 @@ import { first } from 'rxjs/operators'; import { ApiService } from 'jslib-common/abstractions/api.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { LogService } from 'jslib-common/abstractions/log.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { SearchService } from 'jslib-common/abstractions/search.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { ModalService } from 'jslib-angular/services/modal.service'; @@ -46,16 +46,22 @@ export class GroupsComponent implements OnInit { private pagedGroupsCount = 0; - constructor(private apiService: ApiService, private route: ActivatedRoute, - private i18nService: I18nService, private modalService: ModalService, + constructor( + private apiService: ApiService, + private route: ActivatedRoute, + private i18nService: I18nService, + private modalService: ModalService, private platformUtilsService: PlatformUtilsService, - private userService: UserService, private router: Router, - private searchService: SearchService, private logService: LogService) { } + private router: Router, + private searchService: SearchService, + private logService: LogService, + private organizationService: OrganizationService, + ) { } async ngOnInit() { this.route.parent.parent.params.subscribe(async params => { this.organizationId = params.organizationId; - const organization = await this.userService.getOrganization(this.organizationId); + const organization = await this.organizationService.get(this.organizationId); if (organization == null || !organization.useGroups) { this.router.navigate(['/organizations', this.organizationId]); return; diff --git a/src/app/organizations/manage/manage.component.ts b/src/app/organizations/manage/manage.component.ts index fc760f63ded..19cbbe47fe9 100644 --- a/src/app/organizations/manage/manage.component.ts +++ b/src/app/organizations/manage/manage.component.ts @@ -4,7 +4,7 @@ import { } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { Organization } from 'jslib-common/models/domain/organization'; @@ -19,11 +19,11 @@ export class ManageComponent implements OnInit { accessEvents: boolean = false; accessSso: boolean = false; - constructor(private route: ActivatedRoute, private userService: UserService) {} + constructor(private route: ActivatedRoute, private organizationService: OrganizationService) {} ngOnInit() { this.route.parent.params.subscribe(async params => { - this.organization = await this.userService.getOrganization(params.organizationId); + this.organization = await this.organizationService.get(params.organizationId); this.accessPolicies = this.organization.usePolicies; this.accessSso = this.organization.useSso; this.accessEvents = this.organization.useEvents; diff --git a/src/app/organizations/manage/people.component.ts b/src/app/organizations/manage/people.component.ts index 2c68cd5d4d3..3e38b6b2b8a 100644 --- a/src/app/organizations/manage/people.component.ts +++ b/src/app/organizations/manage/people.component.ts @@ -18,12 +18,12 @@ import { ApiService } from 'jslib-common/abstractions/api.service'; import { CryptoService } from 'jslib-common/abstractions/crypto.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { LogService } from 'jslib-common/abstractions/log.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { PolicyService } from 'jslib-common/abstractions/policy.service'; import { SearchService } from 'jslib-common/abstractions/search.service'; -import { StorageService } from 'jslib-common/abstractions/storage.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { SyncService } from 'jslib-common/abstractions/sync.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { ModalService } from 'jslib-angular/services/modal.service'; @@ -78,21 +78,43 @@ export class PeopleComponent extends BasePeopleComponent { this.organizationId = params.organizationId; - const organization = await this.userService.getOrganization(this.organizationId); + const organization = await this.organizationService.get(this.organizationId); if (!organization.canManageUsers) { this.router.navigate(['../collections'], { relativeTo: this.route }); return; diff --git a/src/app/organizations/manage/policies.component.ts b/src/app/organizations/manage/policies.component.ts index 8b66795219a..c4bbff52061 100644 --- a/src/app/organizations/manage/policies.component.ts +++ b/src/app/organizations/manage/policies.component.ts @@ -14,7 +14,7 @@ import { first } from 'rxjs/operators'; import { PolicyType } from 'jslib-common/enums/policyType'; import { ApiService } from 'jslib-common/abstractions/api.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { ModalService } from 'jslib-angular/services/modal.service'; @@ -43,13 +43,13 @@ export class PoliciesComponent implements OnInit { private policiesEnabledMap: Map = new Map(); constructor(private apiService: ApiService, private route: ActivatedRoute, - private modalService: ModalService, private userService: UserService, + private modalService: ModalService, private organizationService: OrganizationService, private policyListService: PolicyListService, private router: Router) { } async ngOnInit() { this.route.parent.parent.params.subscribe(async params => { this.organizationId = params.organizationId; - this.organization = await this.userService.getOrganization(this.organizationId); + this.organization = await this.organizationService.get(this.organizationId); if (this.organization == null || !this.organization.usePolicies) { this.router.navigate(['/organizations', this.organizationId]); return; diff --git a/src/app/organizations/manage/user-confirm.component.ts b/src/app/organizations/manage/user-confirm.component.ts index 2c7dbab3865..6bcd2927bae 100644 --- a/src/app/organizations/manage/user-confirm.component.ts +++ b/src/app/organizations/manage/user-confirm.component.ts @@ -6,11 +6,9 @@ import { Output, } from '@angular/core'; -import { ConstantsService } from 'jslib-common/services/constants.service'; - import { CryptoService } from 'jslib-common/abstractions/crypto.service'; import { LogService } from 'jslib-common/abstractions/log.service'; -import { StorageService } from 'jslib-common/abstractions/storage.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; @Component({ selector: 'app-user-confirm', @@ -27,8 +25,8 @@ export class UserConfirmComponent implements OnInit { fingerprint: string; formPromise: Promise; - constructor(private cryptoService: CryptoService, private storageService: StorageService, - private logService: LogService) { } + constructor(private cryptoService: CryptoService, private logService: LogService, + private stateService: StateService) { } async ngOnInit() { try { @@ -50,7 +48,7 @@ export class UserConfirmComponent implements OnInit { } if (this.dontAskAgain) { - await this.storageService.save(ConstantsService.autoConfirmFingerprints, true); + await this.stateService.setAutoConfirmFingerprints(true); } this.onConfirmedUser.emit(); diff --git a/src/app/organizations/policies/master-password.component.ts b/src/app/organizations/policies/master-password.component.ts index 2f2b22999b5..4fbb837dbd4 100644 --- a/src/app/organizations/policies/master-password.component.ts +++ b/src/app/organizations/policies/master-password.component.ts @@ -2,7 +2,7 @@ import { Component } from '@angular/core'; import { FormBuilder } from '@angular/forms'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PolicyType } from 'jslib-common/enums/policyType'; @@ -33,7 +33,7 @@ export class MasterPasswordPolicyComponent extends BasePolicyComponent { passwordScores: { name: string; value: number; }[]; showKeyConnectorInfo: boolean = false; - constructor(private fb: FormBuilder, i18nService: I18nService, private userService: UserService) { + constructor(private fb: FormBuilder, i18nService: I18nService, private organizationService: OrganizationService) { super(); this.passwordScores = [ @@ -48,7 +48,7 @@ export class MasterPasswordPolicyComponent extends BasePolicyComponent { async ngOnInit() { super.ngOnInit(); - const organization = await this.userService.getOrganization(this.policyResponse.organizationId); + const organization = await this.organizationService.get(this.policyResponse.organizationId); this.showKeyConnectorInfo = organization.keyConnectorEnabled; } } diff --git a/src/app/organizations/policies/reset-password.component.ts b/src/app/organizations/policies/reset-password.component.ts index 0c3ee2675bb..a7000cb44ec 100644 --- a/src/app/organizations/policies/reset-password.component.ts +++ b/src/app/organizations/policies/reset-password.component.ts @@ -1,6 +1,6 @@ import { Component } from '@angular/core'; import { FormBuilder } from '@angular/forms'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PolicyType } from 'jslib-common/enums/policyType'; @@ -32,13 +32,13 @@ export class ResetPasswordPolicyComponent extends BasePolicyComponent { defaultTypes: { name: string; value: string; }[]; showKeyConnectorInfo: boolean = false; - constructor(private fb: FormBuilder, private userService: UserService) { + constructor(private fb: FormBuilder, private organizationService: OrganizationService) { super(); } async ngOnInit() { super.ngOnInit(); - const organization = await this.userService.getOrganization(this.policyResponse.organizationId); + const organization = await this.organizationService.get(this.policyResponse.organizationId); this.showKeyConnectorInfo = organization.keyConnectorEnabled; } } diff --git a/src/app/organizations/settings/organization-subscription.component.ts b/src/app/organizations/settings/organization-subscription.component.ts index dceeec7c3e7..2fda26f93bb 100644 --- a/src/app/organizations/settings/organization-subscription.component.ts +++ b/src/app/organizations/settings/organization-subscription.component.ts @@ -11,8 +11,8 @@ import { ApiService } from 'jslib-common/abstractions/api.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { LogService } from 'jslib-common/abstractions/log.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { PlanType } from 'jslib-common/enums/planType'; @@ -44,7 +44,7 @@ export class OrganizationSubscriptionComponent implements OnInit { constructor(private apiService: ApiService, private platformUtilsService: PlatformUtilsService, private i18nService: I18nService, private messagingService: MessagingService, private route: ActivatedRoute, - private userService: UserService, private logService: LogService) { + private organizationService: OrganizationService, private logService: LogService) { this.selfHosted = platformUtilsService.isSelfHost(); } @@ -62,7 +62,7 @@ export class OrganizationSubscriptionComponent implements OnInit { } this.loading = true; - this.userOrg = await this.userService.getOrganization(this.organizationId); + this.userOrg = await this.organizationService.get(this.organizationId); this.sub = await this.apiService.getOrganizationSubscription(this.organizationId); this.loading = false; } diff --git a/src/app/organizations/settings/settings.component.ts b/src/app/organizations/settings/settings.component.ts index 5caafd11cf5..9c9731557ba 100644 --- a/src/app/organizations/settings/settings.component.ts +++ b/src/app/organizations/settings/settings.component.ts @@ -1,8 +1,8 @@ import { Component } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; @Component({ selector: 'app-org-settings', @@ -12,13 +12,13 @@ export class SettingsComponent { access2fa = false; selfHosted: boolean; - constructor(private route: ActivatedRoute, private userService: UserService, + constructor(private route: ActivatedRoute, private organizationService: OrganizationService, private platformUtilsService: PlatformUtilsService) { } ngOnInit() { this.route.parent.params.subscribe(async params => { this.selfHosted = await this.platformUtilsService.isSelfHost(); - const organization = await this.userService.getOrganization(params.organizationId); + const organization = await this.organizationService.get(params.organizationId); this.access2fa = organization.use2fa; }); } diff --git a/src/app/organizations/settings/two-factor-setup.component.ts b/src/app/organizations/settings/two-factor-setup.component.ts index d29692660c1..8fab3e8b193 100644 --- a/src/app/organizations/settings/two-factor-setup.component.ts +++ b/src/app/organizations/settings/two-factor-setup.component.ts @@ -4,7 +4,7 @@ import { ActivatedRoute } from '@angular/router'; import { ApiService } from 'jslib-common/abstractions/api.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service'; import { PolicyService } from 'jslib-common/abstractions/policy.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { ModalService } from 'jslib-angular/services/modal.service'; @@ -18,10 +18,10 @@ import { TwoFactorSetupComponent as BaseTwoFactorSetupComponent } from '../../se templateUrl: '../../settings/two-factor-setup.component.html', }) export class TwoFactorSetupComponent extends BaseTwoFactorSetupComponent { - constructor(apiService: ApiService, userService: UserService, + constructor(apiService: ApiService, modalService: ModalService, messagingService: MessagingService, - policyService: PolicyService, private route: ActivatedRoute) { - super(apiService, userService, modalService, messagingService, policyService); + policyService: PolicyService, private route: ActivatedRoute, stateService: StateService) { + super(apiService, modalService, messagingService, policyService, stateService); } async ngOnInit() { diff --git a/src/app/organizations/sponsorships/families-for-enterprise-setup.component.ts b/src/app/organizations/sponsorships/families-for-enterprise-setup.component.ts index aa19b8cd422..f48d1a37085 100644 --- a/src/app/organizations/sponsorships/families-for-enterprise-setup.component.ts +++ b/src/app/organizations/sponsorships/families-for-enterprise-setup.component.ts @@ -16,8 +16,8 @@ import { ValidationService } from 'jslib-angular/services/validation.service'; import { ApiService } from 'jslib-common/abstractions/api.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { SyncService } from 'jslib-common/abstractions/sync.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { PlanSponsorshipType } from 'jslib-common/enums/planSponsorshipType'; import { PlanType } from 'jslib-common/enums/planType'; @@ -65,7 +65,7 @@ export class FamiliesForEnterpriseSetupComponent implements OnInit { constructor(private router: Router, private platformUtilsService: PlatformUtilsService, private i18nService: I18nService, private route: ActivatedRoute, private apiService: ApiService, private syncService: SyncService, - private validationService: ValidationService, private userService: UserService, + private validationService: ValidationService, private organizationService: OrganizationService, private modalService: ModalService) { } async ngOnInit() { @@ -85,7 +85,7 @@ export class FamiliesForEnterpriseSetupComponent implements OnInit { this.badToken = !await this.apiService.postPreValidateSponsorshipToken(this.token); this.loading = false; - this.existingFamilyOrganizations = (await this.userService.getAllOrganizations()) + this.existingFamilyOrganizations = (await this.organizationService.getAll()) .filter(o => o.planProductType === ProductType.Families); if (this.existingFamilyOrganizations.length === 0) { diff --git a/src/app/organizations/tools/exposed-passwords-report.component.ts b/src/app/organizations/tools/exposed-passwords-report.component.ts index 33e3aa695cc..6cbf8f2e305 100644 --- a/src/app/organizations/tools/exposed-passwords-report.component.ts +++ b/src/app/organizations/tools/exposed-passwords-report.component.ts @@ -4,8 +4,9 @@ import { ActivatedRoute } from '@angular/router'; import { AuditService } from 'jslib-common/abstractions/audit.service'; import { CipherService } from 'jslib-common/abstractions/cipher.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PasswordRepromptService } from 'jslib-common/abstractions/passwordReprompt.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { ModalService } from 'jslib-angular/services/modal.service'; @@ -16,6 +17,7 @@ import { import { Cipher } from 'jslib-common/models/domain/cipher'; import { CipherView } from 'jslib-common/models/view/cipherView'; + @Component({ selector: 'app-exposed-passwords-report', templateUrl: '../../tools/exposed-passwords-report.component.html', @@ -24,15 +26,16 @@ export class ExposedPasswordsReportComponent extends BaseExposedPasswordsReportC manageableCiphers: Cipher[]; constructor(cipherService: CipherService, auditService: AuditService, - modalService: ModalService, messagingService: MessagingService, - userService: UserService, passwordRepromptService: PasswordRepromptService, private route: ActivatedRoute) { - super(cipherService, auditService, modalService, messagingService, userService, passwordRepromptService); + modalService: ModalService, messagingService: MessagingService, stateService: StateService, + private organizationService: OrganizationService, private route: ActivatedRoute, + passwordRepromptService: PasswordRepromptService) { + super(cipherService, auditService, modalService, messagingService, stateService, passwordRepromptService); } ngOnInit() { const dynamicSuper = Object.getPrototypeOf(this.constructor.prototype); this.route.parent.parent.params.subscribe(async params => { - this.organization = await this.userService.getOrganization(params.organizationId); + this.organization = await this.organizationService.get(params.organizationId); this.manageableCiphers = await this.cipherService.getAll(); // TODO: We should do something about this, calling super in an async function is bad dynamicSuper.ngOnInit(); diff --git a/src/app/organizations/tools/import.component.ts b/src/app/organizations/tools/import.component.ts index 0d0a0cbb5c1..c90feea714c 100644 --- a/src/app/organizations/tools/import.component.ts +++ b/src/app/organizations/tools/import.component.ts @@ -7,9 +7,9 @@ import { import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { ImportService } from 'jslib-common/abstractions/import.service'; import { LogService } from 'jslib-common/abstractions/log.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { PolicyService } from 'jslib-common/abstractions/policy.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { ImportComponent as BaseImportComponent } from '../../tools/import.component'; @@ -20,11 +20,24 @@ import { ImportComponent as BaseImportComponent } from '../../tools/import.compo export class ImportComponent extends BaseImportComponent { organizationName: string; - constructor(i18nService: I18nService, - importService: ImportService, router: Router, private route: ActivatedRoute, - platformUtilsService: PlatformUtilsService, policyService: PolicyService, - private userService: UserService, logService: LogService) { - super(i18nService, importService, router, platformUtilsService, policyService, logService); + constructor( + i18nService: I18nService, + importService: ImportService, + router: Router, + private route: ActivatedRoute, + platformUtilsService: PlatformUtilsService, + policyService: PolicyService, + private organizationService: OrganizationService, + logService: LogService + ) { + super( + i18nService, + importService, + router, + platformUtilsService, + policyService, + logService + ); } async ngOnInit() { @@ -34,7 +47,7 @@ export class ImportComponent extends BaseImportComponent { await super.ngOnInit(); this.importBlockedByPolicy = false; }); - const organization = await this.userService.getOrganization(this.organizationId); + const organization = await this.organizationService.get(this.organizationId); this.organizationName = organization.name; } diff --git a/src/app/organizations/tools/inactive-two-factor-report.component.ts b/src/app/organizations/tools/inactive-two-factor-report.component.ts index 8ee65303dae..37cecb7d413 100644 --- a/src/app/organizations/tools/inactive-two-factor-report.component.ts +++ b/src/app/organizations/tools/inactive-two-factor-report.component.ts @@ -4,8 +4,9 @@ import { ActivatedRoute } from '@angular/router'; import { CipherService } from 'jslib-common/abstractions/cipher.service'; import { LogService } from 'jslib-common/abstractions/log.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PasswordRepromptService } from 'jslib-common/abstractions/passwordReprompt.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { ModalService } from 'jslib-angular/services/modal.service'; @@ -15,20 +16,22 @@ import { import { CipherView } from 'jslib-common/models/view/cipherView'; + @Component({ selector: 'app-inactive-two-factor-report', templateUrl: '../../tools/inactive-two-factor-report.component.html', }) export class InactiveTwoFactorReportComponent extends BaseInactiveTwoFactorReportComponent { constructor(cipherService: CipherService, modalService: ModalService, - messagingService: MessagingService, userService: UserService, - private route: ActivatedRoute, logService: LogService, passwordRepromptService: PasswordRepromptService) { - super(cipherService, modalService, messagingService, userService, logService, passwordRepromptService); + messagingService: MessagingService, stateService: StateService, + private route: ActivatedRoute, logService: LogService, passwordRepromptService: PasswordRepromptService, + private organizationService: OrganizationService) { + super(cipherService, modalService, messagingService, stateService, logService, passwordRepromptService); } async ngOnInit() { this.route.parent.parent.params.subscribe(async params => { - this.organization = await this.userService.getOrganization(params.organizationId); + this.organization = await this.organizationService.get(params.organizationId); await super.ngOnInit(); }); } diff --git a/src/app/organizations/tools/reused-passwords-report.component.ts b/src/app/organizations/tools/reused-passwords-report.component.ts index b9a18f1ed79..3a46b33e99b 100644 --- a/src/app/organizations/tools/reused-passwords-report.component.ts +++ b/src/app/organizations/tools/reused-passwords-report.component.ts @@ -3,8 +3,9 @@ import { ActivatedRoute } from '@angular/router'; import { CipherService } from 'jslib-common/abstractions/cipher.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PasswordRepromptService } from 'jslib-common/abstractions/passwordReprompt.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { ModalService } from 'jslib-angular/services/modal.service'; @@ -24,14 +25,15 @@ export class ReusedPasswordsReportComponent extends BaseReusedPasswordsReportCom manageableCiphers: Cipher[]; constructor(cipherService: CipherService, modalService: ModalService, - messagingService: MessagingService, userService: UserService, passwordRepromptService: PasswordRepromptService, - private route: ActivatedRoute) { - super(cipherService, modalService, messagingService, userService, passwordRepromptService); + messagingService: MessagingService, stateService: StateService, + private route: ActivatedRoute, private organizationService: OrganizationService, + passwordRepromptService: PasswordRepromptService) { + super(cipherService, modalService, messagingService, stateService, passwordRepromptService); } async ngOnInit() { this.route.parent.parent.params.subscribe(async params => { - this.organization = await this.userService.getOrganization(params.organizationId); + this.organization = await this.organizationService.get(params.organizationId); this.manageableCiphers = await this.cipherService.getAll(); await super.ngOnInit(); }); diff --git a/src/app/organizations/tools/tools.component.ts b/src/app/organizations/tools/tools.component.ts index 91f67eb0e06..436e8e27b33 100644 --- a/src/app/organizations/tools/tools.component.ts +++ b/src/app/organizations/tools/tools.component.ts @@ -4,7 +4,7 @@ import { ActivatedRoute } from '@angular/router'; import { Organization } from 'jslib-common/models/domain/organization'; import { MessagingService } from 'jslib-common/abstractions/messaging.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; @Component({ selector: 'app-org-tools', @@ -15,12 +15,12 @@ export class ToolsComponent { accessReports = false; loading = true; - constructor(private route: ActivatedRoute, private userService: UserService, + constructor(private route: ActivatedRoute, private organizationService: OrganizationService, private messagingService: MessagingService) { } ngOnInit() { this.route.parent.params.subscribe(async params => { - this.organization = await this.userService.getOrganization(params.organizationId); + this.organization = await this.organizationService.get(params.organizationId); // TODO: Maybe we want to just make sure they are not on a free plan? Just compare useTotp for now // since all paid plans include useTotp this.accessReports = this.organization.useTotp; diff --git a/src/app/organizations/tools/unsecured-websites-report.component.ts b/src/app/organizations/tools/unsecured-websites-report.component.ts index 081c883960d..907099f7665 100644 --- a/src/app/organizations/tools/unsecured-websites-report.component.ts +++ b/src/app/organizations/tools/unsecured-websites-report.component.ts @@ -3,8 +3,9 @@ import { ActivatedRoute } from '@angular/router'; import { CipherService } from 'jslib-common/abstractions/cipher.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PasswordRepromptService } from 'jslib-common/abstractions/passwordReprompt.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { ModalService } from 'jslib-angular/services/modal.service'; @@ -20,14 +21,15 @@ import { CipherView } from 'jslib-common/models/view/cipherView'; }) export class UnsecuredWebsitesReportComponent extends BaseUnsecuredWebsitesReportComponent { constructor(cipherService: CipherService, modalService: ModalService, - messagingService: MessagingService, userService: UserService, passwordRepromptService: PasswordRepromptService, - private route: ActivatedRoute) { - super(cipherService, modalService, messagingService, userService, passwordRepromptService); + messagingService: MessagingService, stateService: StateService, + private route: ActivatedRoute, private organizationService: OrganizationService, + passwordRepromptService: PasswordRepromptService) { + super(cipherService, modalService, messagingService, stateService, passwordRepromptService); } async ngOnInit() { this.route.parent.parent.params.subscribe(async params => { - this.organization = await this.userService.getOrganization(params.organizationId); + this.organization = await this.organizationService.get(params.organizationId); await super.ngOnInit(); }); } diff --git a/src/app/organizations/tools/weak-passwords-report.component.ts b/src/app/organizations/tools/weak-passwords-report.component.ts index f58623a4691..16cab63bff6 100644 --- a/src/app/organizations/tools/weak-passwords-report.component.ts +++ b/src/app/organizations/tools/weak-passwords-report.component.ts @@ -3,9 +3,10 @@ import { ActivatedRoute } from '@angular/router'; import { CipherService } from 'jslib-common/abstractions/cipher.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PasswordGenerationService } from 'jslib-common/abstractions/passwordGeneration.service'; import { PasswordRepromptService } from 'jslib-common/abstractions/passwordReprompt.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { ModalService } from 'jslib-angular/services/modal.service'; @@ -26,14 +27,14 @@ export class WeakPasswordsReportComponent extends BaseWeakPasswordsReportCompone constructor(cipherService: CipherService, passwordGenerationService: PasswordGenerationService, modalService: ModalService, messagingService: MessagingService, - userService: UserService, passwordRepromptService: PasswordRepromptService, private route: ActivatedRoute) { - super(cipherService, passwordGenerationService, modalService, messagingService, userService, - passwordRepromptService); + stateService: StateService, private route: ActivatedRoute, + private organizationService: OrganizationService, passwordRepromptService: PasswordRepromptService) { + super(cipherService, passwordGenerationService, modalService, messagingService, stateService, passwordRepromptService); } async ngOnInit() { this.route.parent.parent.params.subscribe(async params => { - this.organization = await this.userService.getOrganization(params.organizationId); + this.organization = await this.organizationService.get(params.organizationId); this.manageableCiphers = await this.cipherService.getAll(); await super.ngOnInit(); }); diff --git a/src/app/organizations/vault/add-edit.component.ts b/src/app/organizations/vault/add-edit.component.ts index 2c335e3abdf..956e8bc3cfc 100644 --- a/src/app/organizations/vault/add-edit.component.ts +++ b/src/app/organizations/vault/add-edit.component.ts @@ -9,13 +9,13 @@ import { FolderService } from 'jslib-common/abstractions/folder.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { LogService } from 'jslib-common/abstractions/log.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PasswordGenerationService } from 'jslib-common/abstractions/passwordGeneration.service'; import { PasswordRepromptService } from 'jslib-common/abstractions/passwordReprompt.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { PolicyService } from 'jslib-common/abstractions/policy.service'; import { StateService } from 'jslib-common/abstractions/state.service'; import { TotpService } from 'jslib-common/abstractions/totp.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { CipherData } from 'jslib-common/models/data/cipherData'; import { Cipher } from 'jslib-common/models/domain/cipher'; @@ -36,14 +36,14 @@ export class AddEditComponent extends BaseAddEditComponent { constructor(cipherService: CipherService, folderService: FolderService, i18nService: I18nService, platformUtilsService: PlatformUtilsService, auditService: AuditService, stateService: StateService, - userService: UserService, collectionService: CollectionService, - totpService: TotpService, passwordGenerationService: PasswordGenerationService, - private apiService: ApiService, messagingService: MessagingService, - eventService: EventService, policyService: PolicyService, logService: LogService, - passwordRepromptService: PasswordRepromptService) { + collectionService: CollectionService, totpService: TotpService, + passwordGenerationService: PasswordGenerationService, private apiService: ApiService, + messagingService: MessagingService, eventService: EventService, + policyService: PolicyService, logService: LogService, + passwordRepromptService: PasswordRepromptService, organizationService: OrganizationService) { super(cipherService, folderService, i18nService, platformUtilsService, auditService, stateService, - userService, collectionService, totpService, passwordGenerationService, messagingService, - eventService, policyService, passwordRepromptService, logService); + collectionService, totpService, passwordGenerationService, messagingService, + eventService, policyService, organizationService, logService, passwordRepromptService); } protected allowOwnershipAssignment() { diff --git a/src/app/organizations/vault/attachments.component.ts b/src/app/organizations/vault/attachments.component.ts index c3ce87fc825..5b914da0d47 100644 --- a/src/app/organizations/vault/attachments.component.ts +++ b/src/app/organizations/vault/attachments.component.ts @@ -6,7 +6,7 @@ import { CryptoService } from 'jslib-common/abstractions/crypto.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { LogService } from 'jslib-common/abstractions/log.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { CipherData } from 'jslib-common/models/data/cipherData'; import { Cipher } from 'jslib-common/models/domain/cipher'; @@ -25,11 +25,9 @@ export class AttachmentsComponent extends BaseAttachmentsComponent { organization: Organization; constructor(cipherService: CipherService, i18nService: I18nService, - cryptoService: CryptoService, userService: UserService, - platformUtilsService: PlatformUtilsService, apiService: ApiService, - logService: LogService) { - super(cipherService, i18nService, cryptoService, userService, platformUtilsService, apiService, - logService); + cryptoService: CryptoService, stateService: StateService, + platformUtilsService: PlatformUtilsService, apiService: ApiService, logService: LogService) { + super(cipherService, i18nService, cryptoService, stateService, platformUtilsService, apiService, logService); } protected async reupload(attachment: AttachmentView) { diff --git a/src/app/organizations/vault/ciphers.component.ts b/src/app/organizations/vault/ciphers.component.ts index 05c832b8441..5aea97371ae 100644 --- a/src/app/organizations/vault/ciphers.component.ts +++ b/src/app/organizations/vault/ciphers.component.ts @@ -12,10 +12,11 @@ import { LogService } from 'jslib-common/abstractions/log.service'; import { PasswordRepromptService } from 'jslib-common/abstractions/passwordReprompt.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { SearchService } from 'jslib-common/abstractions/search.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { TotpService } from 'jslib-common/abstractions/totp.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { Organization } from 'jslib-common/models/domain/organization'; + import { CipherView } from 'jslib-common/models/view/cipherView'; import { CiphersComponent as BaseCiphersComponent } from '../../vault/ciphers.component'; @@ -32,13 +33,29 @@ export class CiphersComponent extends BaseCiphersComponent { protected allCiphers: CipherView[] = []; - constructor(searchService: SearchService, i18nService: I18nService, - platformUtilsService: PlatformUtilsService, cipherService: CipherService, - private apiService: ApiService, eventService: EventService, totpService: TotpService, - userService: UserService, passwordRepromptService: PasswordRepromptService, - logService: LogService) { - super(searchService, i18nService, platformUtilsService, cipherService, - eventService, totpService, userService, passwordRepromptService, logService); + constructor( + searchService: SearchService, + i18nService: I18nService, + platformUtilsService: PlatformUtilsService, + cipherService: CipherService, + private apiService: ApiService, + eventService: EventService, + totpService: TotpService, + passwordRepromptService: PasswordRepromptService, + logService: LogService, + stateService: StateService, + ) { + super( + searchService, + i18nService, + platformUtilsService, + cipherService, + eventService, + totpService, + stateService, + passwordRepromptService, + logService + ); } async load(filter: (cipher: CipherView) => boolean = null) { diff --git a/src/app/organizations/vault/groupings.component.ts b/src/app/organizations/vault/groupings.component.ts index fc9dc8d0b5a..d0f6fcd10e2 100644 --- a/src/app/organizations/vault/groupings.component.ts +++ b/src/app/organizations/vault/groupings.component.ts @@ -4,8 +4,7 @@ import { ApiService } from 'jslib-common/abstractions/api.service'; import { CollectionService } from 'jslib-common/abstractions/collection.service'; import { FolderService } from 'jslib-common/abstractions/folder.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; -import { StorageService } from 'jslib-common/abstractions/storage.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { CollectionData } from 'jslib-common/models/data/collectionData'; import { Collection } from 'jslib-common/models/domain/collection'; @@ -23,9 +22,9 @@ export class GroupingsComponent extends BaseGroupingsComponent { organization: Organization; constructor(collectionService: CollectionService, folderService: FolderService, - storageService: StorageService, userService: UserService, - private apiService: ApiService, private i18nService: I18nService) { - super(collectionService, folderService, storageService, userService); + stateService: StateService, private apiService: ApiService, + private i18nService: I18nService) { + super(collectionService, folderService, stateService); } async loadCollections() { @@ -52,8 +51,8 @@ export class GroupingsComponent extends BaseGroupingsComponent { this.nestedCollections = await this.collectionService.getAllNested(this.collections); } - collapse(grouping: CollectionView) { - super.collapse(grouping, 'org_'); + async collapse(grouping: CollectionView) { + await super.collapse(grouping, 'org_'); } isCollapsed(grouping: CollectionView) { diff --git a/src/app/organizations/vault/vault.component.ts b/src/app/organizations/vault/vault.component.ts index 7326c941c57..ac819128d66 100644 --- a/src/app/organizations/vault/vault.component.ts +++ b/src/app/organizations/vault/vault.component.ts @@ -17,9 +17,9 @@ import { first } from 'rxjs/operators'; import { BroadcasterService } from 'jslib-common/abstractions/broadcaster.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { SyncService } from 'jslib-common/abstractions/sync.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { ModalService } from 'jslib-angular/services/modal.service'; @@ -55,7 +55,7 @@ export class VaultComponent implements OnInit, OnDestroy { deleted: boolean = false; trashCleanupWarning: string = null; - constructor(private route: ActivatedRoute, private userService: UserService, + constructor(private route: ActivatedRoute, private organizationService: OrganizationService, private router: Router, private changeDetectorRef: ChangeDetectorRef, private syncService: SyncService, private i18nService: I18nService, private modalService: ModalService, private messagingService: MessagingService, @@ -66,9 +66,8 @@ export class VaultComponent implements OnInit, OnDestroy { this.trashCleanupWarning = this.i18nService.t( this.platformUtilsService.isSelfHost() ? 'trashCleanupWarningSelfHosted' : 'trashCleanupWarning' ); - this.route.parent.params.pipe(first()).subscribe(async params => { - this.organization = await this.userService.getOrganization(params.organizationId); + this.organization = await this.organizationService.get(params.organizationId); this.groupingsComponent.organization = this.organization; this.ciphersComponent.organization = this.organization; diff --git a/src/app/providers/providers.component.ts b/src/app/providers/providers.component.ts index 3a08ca30b39..af05cb6e28c 100644 --- a/src/app/providers/providers.component.ts +++ b/src/app/providers/providers.component.ts @@ -5,7 +5,7 @@ import { } from '@angular/core'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { ProviderService } from 'jslib-common/abstractions/provider.service'; import { Provider } from 'jslib-common/models/domain/provider'; @@ -22,7 +22,7 @@ export class ProvidersComponent implements OnInit { loaded: boolean = false; actionPromise: Promise; - constructor(private userService: UserService, private i18nService: I18nService) { } + constructor(private providerService: ProviderService, private i18nService: I18nService) { } async ngOnInit() { document.body.classList.remove('layout_frontend'); @@ -30,7 +30,7 @@ export class ProvidersComponent implements OnInit { } async load() { - const providers = await this.userService.getAllProviders(); + const providers = await this.providerService.getAll(); providers.sort(Utils.getSortFunction(this.i18nService, 'name')); this.providers = providers; this.loaded = true; diff --git a/src/app/send/add-edit.component.ts b/src/app/send/add-edit.component.ts index abdfee89a2c..21ffc7a0ad3 100644 --- a/src/app/send/add-edit.component.ts +++ b/src/app/send/add-edit.component.ts @@ -4,14 +4,14 @@ import { Component } from '@angular/core'; import { EnvironmentService } from 'jslib-common/abstractions/environment.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; +import { LogService } from 'jslib-common/abstractions/log.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { PolicyService } from 'jslib-common/abstractions/policy.service'; import { SendService } from 'jslib-common/abstractions/send.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { AddEditComponent as BaseAddEditComponent } from 'jslib-angular/components/send/add-edit.component'; -import { LogService } from 'jslib-common/abstractions/log.service'; @Component({ selector: 'app-send-add-edit', @@ -20,11 +20,11 @@ import { LogService } from 'jslib-common/abstractions/log.service'; export class AddEditComponent extends BaseAddEditComponent { constructor(i18nService: I18nService, platformUtilsService: PlatformUtilsService, environmentService: EnvironmentService, datePipe: DatePipe, - sendService: SendService, userService: UserService, + sendService: SendService, stateService: StateService, messagingService: MessagingService, policyService: PolicyService, logService: LogService) { - super(i18nService, platformUtilsService, environmentService, datePipe, sendService, userService, - messagingService, policyService, logService); + super(i18nService, platformUtilsService, environmentService, datePipe, sendService, + messagingService, policyService, logService, stateService); } async copyLinkToClipboard(link: string): Promise { diff --git a/src/app/send/send.component.ts b/src/app/send/send.component.ts index a50dd5a98aa..a104e86a394 100644 --- a/src/app/send/send.component.ts +++ b/src/app/send/send.component.ts @@ -19,7 +19,6 @@ import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.se import { PolicyService } from 'jslib-common/abstractions/policy.service'; import { SearchService } from 'jslib-common/abstractions/search.service'; import { SendService } from 'jslib-common/abstractions/send.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { ModalService } from 'jslib-angular/services/modal.service'; @@ -34,11 +33,11 @@ export class SendComponent extends BaseSendComponent { constructor(sendService: SendService, i18nService: I18nService, platformUtilsService: PlatformUtilsService, environmentService: EnvironmentService, - ngZone: NgZone, searchService: SearchService, policyService: PolicyService, userService: UserService, - private modalService: ModalService, private broadcasterService: BroadcasterService, - logService: LogService) { + ngZone: NgZone, searchService: SearchService, + policyService: PolicyService, private modalService: ModalService, + private broadcasterService: BroadcasterService, logService: LogService) { super(sendService, i18nService, platformUtilsService, environmentService, ngZone, searchService, - policyService, userService, logService); + policyService, logService); } async ngOnInit() { diff --git a/src/app/services/organization-guard.service.ts b/src/app/services/organization-guard.service.ts index 6c12d27d540..ccea704c847 100644 --- a/src/app/services/organization-guard.service.ts +++ b/src/app/services/organization-guard.service.ts @@ -6,16 +6,20 @@ import { } from '@angular/router'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; @Injectable() export class OrganizationGuardService implements CanActivate { - constructor(private userService: UserService, private router: Router, - private platformUtilsService: PlatformUtilsService, private i18nService: I18nService) { } + constructor( + private router: Router, + private platformUtilsService: PlatformUtilsService, + private i18nService: I18nService, + private organizationService: OrganizationService, + ) { } async canActivate(route: ActivatedRouteSnapshot) { - const org = await this.userService.getOrganization(route.params.organizationId); + const org = await this.organizationService.get(route.params.organizationId); if (org == null) { this.router.navigate(['/']); return false; diff --git a/src/app/services/organization-type-guard.service.ts b/src/app/services/organization-type-guard.service.ts index 2f490f29d9b..6aa62777b49 100644 --- a/src/app/services/organization-type-guard.service.ts +++ b/src/app/services/organization-type-guard.service.ts @@ -5,16 +5,16 @@ import { Router, } from '@angular/router'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { Permissions } from 'jslib-common/enums/permissions'; @Injectable() export class OrganizationTypeGuardService implements CanActivate { - constructor(private userService: UserService, private router: Router) { } + constructor(private organizationService: OrganizationService, private router: Router) { } async canActivate(route: ActivatedRouteSnapshot) { - const org = await this.userService.getOrganization(route.params.organizationId); + const org = await this.organizationService.get(route.params.organizationId); const permissions = route.data == null ? null : route.data.permissions as Permissions[]; if ( diff --git a/src/app/services/services.module.ts b/src/app/services/services.module.ts index 3de28cf67ad..248f2b6fa17 100644 --- a/src/app/services/services.module.ts +++ b/src/app/services/services.module.ts @@ -22,7 +22,6 @@ import { JslibServicesModule } from 'jslib-angular/services/jslib-services.modul import { ModalService as ModalServiceAbstraction } from 'jslib-angular/services/modal.service'; import { AuthService } from 'jslib-common/services/auth.service'; -import { ConstantsService } from 'jslib-common/services/constants.service'; import { ContainerService } from 'jslib-common/services/container.service'; import { CryptoService } from 'jslib-common/services/crypto.service'; import { EventService as EventLoggingService } from 'jslib-common/services/event.service'; @@ -57,6 +56,7 @@ export function initFactory(window: Window, storageService: StorageServiceAbstra platformUtilsService: PlatformUtilsServiceAbstraction, cryptoService: CryptoServiceAbstraction): Function { return async () => { await (storageService as HtmlStorageService).init(); + await stateService.init(); const urls = process.env.URLS as Urls; urls.base ??= window.location.origin; @@ -65,7 +65,7 @@ export function initFactory(window: Window, storageService: StorageServiceAbstra setTimeout(() => notificationsService.init(), 3000); vaultTimeoutService.init(true); - const locale = await storageService.get(ConstantsService.localeKey); + const locale = await stateService.getLocale(); await i18nService.init(locale); eventLoggingService.init(true); authService.init(); @@ -74,17 +74,13 @@ export function initFactory(window: Window, storageService: StorageServiceAbstra // Initial theme is set in index.html which must be updated if there are any changes to theming logic platformUtilsService.onDefaultSystemThemeChange(async sysTheme => { - const bwTheme = await storageService.get(ConstantsService.themeKey); + const bwTheme = await stateService.getTheme(); if (bwTheme === ThemeType.System) { htmlEl.classList.remove('theme_' + ThemeType.Light, 'theme_' + ThemeType.Dark); htmlEl.classList.add('theme_' + sysTheme); } }); - stateService.save(ConstantsService.disableFaviconKey, - await storageService.get(ConstantsService.disableFaviconKey)); - stateService.save('enableGravatars', await storageService.get('enableGravatars')); - const containerService = new ContainerService(cryptoService); containerService.attachToWindow(window); }; @@ -130,13 +126,13 @@ export function initFactory(window: Window, storageService: StorageServiceAbstra { provide: PlatformUtilsServiceAbstraction, useFactory: (i18nService: I18nServiceAbstraction, messagingService: MessagingServiceAbstraction, - logService: LogService, injector: Injector) => new WebPlatformUtilsService(i18nService, - messagingService, logService, () => injector.get(StorageServiceAbstraction)), + logService: LogService, stateService: StateServiceAbstraction) => new WebPlatformUtilsService(i18nService, + messagingService, logService, stateService), deps: [ I18nServiceAbstraction, MessagingServiceAbstraction, LogService, - Injector, // TODO: Get rid of circular dependency! + StateServiceAbstraction, ], }, { provide: MessagingServiceAbstraction, useClass: BroadcasterMessagingService }, @@ -156,19 +152,12 @@ export function initFactory(window: Window, storageService: StorageServiceAbstra }, { provide: CryptoServiceAbstraction, - useFactory: (storageService: StorageServiceAbstraction, secureStorageService: StorageServiceAbstraction, - cryptoFunctionService: CryptoFunctionServiceAbstraction, - platformUtilsService: PlatformUtilsServiceAbstraction, logService: LogService) => { - const storageImplementation = platformUtilsService.isDev() ? storageService : secureStorageService; - return new CryptoService(storageService, storageImplementation, cryptoFunctionService, - platformUtilsService, logService); - }, + useClass: CryptoService, deps: [ - StorageServiceAbstraction, - 'SECURE_STORAGE', CryptoFunctionServiceAbstraction, PlatformUtilsServiceAbstraction, LogService, + StateServiceAbstraction, ], }, ], diff --git a/src/app/settings/account.component.ts b/src/app/settings/account.component.ts index cef60b7f5bb..2054e7145c7 100644 --- a/src/app/settings/account.component.ts +++ b/src/app/settings/account.component.ts @@ -11,7 +11,7 @@ import { PurgeVaultComponent } from './purge-vault.component'; import { ApiService } from 'jslib-common/abstractions/api.service'; import { KeyConnectorService } from 'jslib-common/abstractions/keyConnector.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { ModalService } from 'jslib-angular/services/modal.service'; @@ -31,7 +31,7 @@ export class AccountComponent { showChangeEmail = true; constructor(private modalService: ModalService, private apiService: ApiService, - private userService: UserService, private keyConnectorService: KeyConnectorService) { } + private keyConnectorService: KeyConnectorService, private stateService: StateService) { } async ngOnInit() { this.showChangeEmail = this.showChangeKdf = this.showChangePassword = @@ -51,7 +51,7 @@ export class AccountComponent { } async viewUserApiKey() { - const entityId = await this.userService.getUserId(); + const entityId = await this.stateService.getUserId(); await this.modalService.openViewRef(ApiKeyComponent, this.viewUserApiKeyModalRef, comp => { comp.keyType = 'user'; comp.entityId = entityId; @@ -65,7 +65,7 @@ export class AccountComponent { } async rotateUserApiKey() { - const entityId = await this.userService.getUserId(); + const entityId = await this.stateService.getUserId(); await this.modalService.openViewRef(ApiKeyComponent, this.rotateUserApiKeyModalRef, comp => { comp.keyType = 'user'; comp.isRotation = true; diff --git a/src/app/settings/add-credit.component.ts b/src/app/settings/add-credit.component.ts index 68f2f1576bb..4b351d5ce7c 100644 --- a/src/app/settings/add-credit.component.ts +++ b/src/app/settings/add-credit.component.ts @@ -11,8 +11,9 @@ import { import { ApiService } from 'jslib-common/abstractions/api.service'; import { PayPalConfig } from 'jslib-common/abstractions/environment.service'; import { LogService } from 'jslib-common/abstractions/log.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { PaymentMethodType } from 'jslib-common/enums/paymentMethodType'; @@ -45,8 +46,9 @@ export class AddCreditComponent implements OnInit { private name: string; private email: string; - constructor(private userService: UserService, private apiService: ApiService, - private platformUtilsService: PlatformUtilsService, private logService: LogService) { + constructor(private stateService: StateService, private apiService: ApiService, + private platformUtilsService: PlatformUtilsService, private organizationService: OrganizationService, + private logService: LogService) { const payPalConfig = process.env.PAYPAL_CONFIG as PayPalConfig; this.ppButtonFormAction = payPalConfig.buttonAction; this.ppButtonBusinessId = payPalConfig.businessId; @@ -58,7 +60,7 @@ export class AddCreditComponent implements OnInit { this.creditAmount = '20.00'; } this.ppButtonCustomField = 'organization_id:' + this.organizationId; - const org = await this.userService.getOrganization(this.organizationId); + const org = await this.organizationService.get(this.organizationId); if (org != null) { this.subject = org.name; this.name = org.name; @@ -67,8 +69,8 @@ export class AddCreditComponent implements OnInit { if (this.creditAmount == null) { this.creditAmount = '10.00'; } - this.userId = await this.userService.getUserId(); - this.subject = await this.userService.getEmail(); + this.userId = await this.stateService.getUserId(); + this.subject = await this.stateService.getEmail(); this.email = this.subject; this.ppButtonCustomField = 'user_id:' + this.userId; } diff --git a/src/app/settings/change-email.component.ts b/src/app/settings/change-email.component.ts index 9464e2afb58..653b87494fa 100644 --- a/src/app/settings/change-email.component.ts +++ b/src/app/settings/change-email.component.ts @@ -9,7 +9,7 @@ import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { LogService } from 'jslib-common/abstractions/log.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { EmailRequest } from 'jslib-common/models/request/emailRequest'; import { EmailTokenRequest } from 'jslib-common/models/request/emailTokenRequest'; @@ -29,10 +29,15 @@ export class ChangeEmailComponent implements OnInit { formPromise: Promise; - constructor(private apiService: ApiService, private i18nService: I18nService, - private platformUtilsService: PlatformUtilsService, private cryptoService: CryptoService, - private messagingService: MessagingService, private userService: UserService, - private logService: LogService) { } + constructor( + private apiService: ApiService, + private i18nService: I18nService, + private platformUtilsService: PlatformUtilsService, + private cryptoService: CryptoService, + private messagingService: MessagingService, + private logService: LogService, + private stateService: StateService, + ) { } async ngOnInit() { const twoFactorProviders = await this.apiService.getTwoFactorProviders(); @@ -64,8 +69,8 @@ export class ChangeEmailComponent implements OnInit { request.token = this.token; request.newEmail = this.newEmail; request.masterPasswordHash = await this.cryptoService.hashPassword(this.masterPassword, null); - const kdf = await this.userService.getKdf(); - const kdfIterations = await this.userService.getKdfIterations(); + const kdf = await this.stateService.getKdfType(); + const kdfIterations = await this.stateService.getKdfIterations(); const newKey = await this.cryptoService.makeKey(this.masterPassword, this.newEmail, kdf, kdfIterations); request.newMasterPasswordHash = await this.cryptoService.hashPassword(this.masterPassword, newKey); const newEncKey = await this.cryptoService.remakeEncKey(newKey); diff --git a/src/app/settings/change-kdf.component.ts b/src/app/settings/change-kdf.component.ts index f95329e59f8..c4d4aded8de 100644 --- a/src/app/settings/change-kdf.component.ts +++ b/src/app/settings/change-kdf.component.ts @@ -9,7 +9,7 @@ import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { LogService } from 'jslib-common/abstractions/log.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { KdfRequest } from 'jslib-common/models/request/kdfRequest'; @@ -26,18 +26,23 @@ export class ChangeKdfComponent implements OnInit { kdfOptions: any[] = []; formPromise: Promise; - constructor(private apiService: ApiService, private i18nService: I18nService, - private platformUtilsService: PlatformUtilsService, private cryptoService: CryptoService, - private messagingService: MessagingService, private userService: UserService, - private logService: LogService) { + constructor( + private apiService: ApiService, + private i18nService: I18nService, + private platformUtilsService: PlatformUtilsService, + private cryptoService: CryptoService, + private messagingService: MessagingService, + private logService: LogService, + private stateService: StateService, + ) { this.kdfOptions = [ { name: 'PBKDF2 SHA-256', value: KdfType.PBKDF2_SHA256 }, ]; } async ngOnInit() { - this.kdf = await this.userService.getKdf(); - this.kdfIterations = await this.userService.getKdfIterations(); + this.kdf = await this.stateService.getKdfType(); + this.kdfIterations = await this.stateService.getKdfIterations(); } async submit() { @@ -51,7 +56,7 @@ export class ChangeKdfComponent implements OnInit { request.kdf = this.kdf; request.kdfIterations = this.kdfIterations; request.masterPasswordHash = await this.cryptoService.hashPassword(this.masterPassword, null); - const email = await this.userService.getEmail(); + const email = await this.stateService.getEmail(); const newKey = await this.cryptoService.makeKey(this.masterPassword, email, this.kdf, this.kdfIterations); request.newMasterPasswordHash = await this.cryptoService.hashPassword(this.masterPassword, newKey); const newEncKey = await this.cryptoService.remakeEncKey(newKey); diff --git a/src/app/settings/change-password.component.ts b/src/app/settings/change-password.component.ts index e76f5c6f1cd..f5f773d3b38 100644 --- a/src/app/settings/change-password.component.ts +++ b/src/app/settings/change-password.component.ts @@ -6,12 +6,13 @@ import { CryptoService } from 'jslib-common/abstractions/crypto.service'; import { FolderService } from 'jslib-common/abstractions/folder.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PasswordGenerationService } from 'jslib-common/abstractions/passwordGeneration.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { PolicyService } from 'jslib-common/abstractions/policy.service'; import { SendService } from 'jslib-common/abstractions/send.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { SyncService } from 'jslib-common/abstractions/sync.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { ChangePasswordComponent as BaseChangePasswordComponent, @@ -41,12 +42,13 @@ export class ChangePasswordComponent extends BaseChangePasswordComponent { constructor(i18nService: I18nService, cryptoService: CryptoService, messagingService: MessagingService, - userService: UserService, passwordGenerationService: PasswordGenerationService, + stateService: StateService, passwordGenerationService: PasswordGenerationService, platformUtilsService: PlatformUtilsService, policyService: PolicyService, private folderService: FolderService, private cipherService: CipherService, - private syncService: SyncService, private apiService: ApiService, private sendService: SendService) { - super(i18nService, cryptoService, messagingService, userService, passwordGenerationService, - platformUtilsService, policyService); + private syncService: SyncService, private apiService: ApiService, + private sendService: SendService, private organizationService: OrganizationService) { + super(i18nService, cryptoService, messagingService, passwordGenerationService, + platformUtilsService, policyService, stateService); } async rotateEncKeyClicked() { @@ -206,7 +208,7 @@ export class ChangePasswordComponent extends BaseChangePasswordComponent { } private async updateAllResetPasswordKeys(encKey: SymmetricCryptoKey) { - const orgs = await this.userService.getAllOrganizations(); + const orgs = await this.organizationService.getAll(); for (const org of orgs) { // If not already enrolled, skip diff --git a/src/app/settings/emergency-access-attachments.component.ts b/src/app/settings/emergency-access-attachments.component.ts index ad69500dfd8..fa35d197634 100644 --- a/src/app/settings/emergency-access-attachments.component.ts +++ b/src/app/settings/emergency-access-attachments.component.ts @@ -6,7 +6,7 @@ import { CryptoService } from 'jslib-common/abstractions/crypto.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { LogService } from 'jslib-common/abstractions/log.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { AttachmentView } from 'jslib-common/models/view/attachmentView'; @@ -21,11 +21,9 @@ export class EmergencyAccessAttachmentsComponent extends BaseAttachmentsComponen canAccessAttachments = true; constructor(cipherService: CipherService, i18nService: I18nService, - cryptoService: CryptoService, userService: UserService, - platformUtilsService: PlatformUtilsService, apiService: ApiService, - logService: LogService) { - super(cipherService, i18nService, cryptoService, userService, platformUtilsService, apiService, window, - logService); + cryptoService: CryptoService, stateService: StateService, + platformUtilsService: PlatformUtilsService, apiService: ApiService, logService: LogService) { + super(cipherService, i18nService, cryptoService, platformUtilsService, apiService, window, logService, stateService); } protected async init() { diff --git a/src/app/settings/emergency-access-confirm.component.ts b/src/app/settings/emergency-access-confirm.component.ts index 2be2bb79575..c5c7acad25b 100644 --- a/src/app/settings/emergency-access-confirm.component.ts +++ b/src/app/settings/emergency-access-confirm.component.ts @@ -6,12 +6,10 @@ import { Output, } from '@angular/core'; -import { ConstantsService } from 'jslib-common/services/constants.service'; - import { ApiService } from 'jslib-common/abstractions/api.service'; import { CryptoService } from 'jslib-common/abstractions/crypto.service'; import { LogService } from 'jslib-common/abstractions/log.service'; -import { StorageService } from 'jslib-common/abstractions/storage.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { Utils } from 'jslib-common/misc/utils'; @@ -31,7 +29,7 @@ export class EmergencyAccessConfirmComponent implements OnInit { fingerprint: string; constructor(private apiService: ApiService, private cryptoService: CryptoService, - private storageService: StorageService, private logService: LogService) { } + private stateService: StateService, private logService: LogService) { } async ngOnInit() { try { @@ -55,7 +53,7 @@ export class EmergencyAccessConfirmComponent implements OnInit { } if (this.dontAskAgain) { - await this.storageService.save(ConstantsService.autoConfirmFingerprints, true); + await this.stateService.setAutoConfirmFingerprints(true); } try { diff --git a/src/app/settings/emergency-access-takeover.component.ts b/src/app/settings/emergency-access-takeover.component.ts index 342c2d48cf4..9153bb261f1 100644 --- a/src/app/settings/emergency-access-takeover.component.ts +++ b/src/app/settings/emergency-access-takeover.component.ts @@ -14,7 +14,7 @@ import { MessagingService } from 'jslib-common/abstractions/messaging.service'; import { PasswordGenerationService } from 'jslib-common/abstractions/passwordGeneration.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { PolicyService } from 'jslib-common/abstractions/policy.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { KdfType } from 'jslib-common/enums/kdfType'; import { PolicyData } from 'jslib-common/models/data/policyData'; @@ -39,13 +39,26 @@ export class EmergencyAccessTakeoverComponent extends ChangePasswordComponent im formPromise: Promise; - constructor(i18nService: I18nService, cryptoService: CryptoService, - messagingService: MessagingService, userService: UserService, + constructor( + i18nService: I18nService, + cryptoService: CryptoService, + messagingService: MessagingService, + stateService: StateService, passwordGenerationService: PasswordGenerationService, - platformUtilsService: PlatformUtilsService, policyService: PolicyService, - private apiService: ApiService, private logService: LogService) { - super(i18nService, cryptoService, messagingService, userService, passwordGenerationService, - platformUtilsService, policyService); + platformUtilsService: PlatformUtilsService, + policyService: PolicyService, + private apiService: ApiService, + private logService: LogService + ) { + super( + i18nService, + cryptoService, + messagingService, + passwordGenerationService, + platformUtilsService, + policyService, + stateService, + ); } async ngOnInit() { @@ -54,7 +67,7 @@ export class EmergencyAccessTakeoverComponent extends ChangePasswordComponent im const policies = response.data.map((policyResponse: PolicyResponse) => new Policy(new PolicyData(policyResponse))); this.enforcedPolicyOptions = await this.policyService.getMasterPasswordPolicyOptions(policies); } - } + } async submit() { if (!await this.strongPassword()) { diff --git a/src/app/settings/emergency-access.component.ts b/src/app/settings/emergency-access.component.ts index 5310716ac47..1cc0f4ac003 100644 --- a/src/app/settings/emergency-access.component.ts +++ b/src/app/settings/emergency-access.component.ts @@ -10,16 +10,17 @@ import { CryptoService } from 'jslib-common/abstractions/crypto.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { LogService } from 'jslib-common/abstractions/log.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; -import { StorageService } from 'jslib-common/abstractions/storage.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; + +import { EmergencyAccessConfirmRequest } from 'jslib-common/models/request/emergencyAccessConfirmRequest'; + +import { EmergencyAccessGranteeDetailsResponse, EmergencyAccessGrantorDetailsResponse } from 'jslib-common/models/response/emergencyAccessResponse'; import { EmergencyAccessStatusType } from 'jslib-common/enums/emergencyAccessStatusType'; import { EmergencyAccessType } from 'jslib-common/enums/emergencyAccessType'; import { Utils } from 'jslib-common/misc/utils'; -import { EmergencyAccessConfirmRequest } from 'jslib-common/models/request/emergencyAccessConfirmRequest'; -import { EmergencyAccessGranteeDetailsResponse, EmergencyAccessGrantorDetailsResponse } from 'jslib-common/models/response/emergencyAccessResponse'; -import { ConstantsService } from 'jslib-common/services/constants.service'; import { UserNamePipe } from 'jslib-angular/pipes/user-name.pipe'; @@ -35,7 +36,7 @@ import { ModalService } from 'jslib-angular/services/modal.service'; }) export class EmergencyAccessComponent implements OnInit { @ViewChild('addEdit', { read: ViewContainerRef, static: true }) addEditModalRef: ViewContainerRef; - @ViewChild('takeoverTemplate', { read: ViewContainerRef, static: true}) takeoverModalRef: ViewContainerRef; + @ViewChild('takeoverTemplate', { read: ViewContainerRef, static: true }) takeoverModalRef: ViewContainerRef; @ViewChild('confirmTemplate', { read: ViewContainerRef, static: true }) confirmModalRef: ViewContainerRef; canAccessPremium: boolean; @@ -46,16 +47,22 @@ export class EmergencyAccessComponent implements OnInit { actionPromise: Promise; isOrganizationOwner: boolean; - constructor(private apiService: ApiService, private i18nService: I18nService, - private modalService: ModalService, private platformUtilsService: PlatformUtilsService, + constructor( + private apiService: ApiService, + private i18nService: I18nService, + private modalService: ModalService, + private platformUtilsService: PlatformUtilsService, private cryptoService: CryptoService, - private storageService: StorageService, private userService: UserService, - private messagingService: MessagingService, private userNamePipe: UserNamePipe, - private logService: LogService) { } + private messagingService: MessagingService, + private userNamePipe: UserNamePipe, + private logService: LogService, + private stateService: StateService, + private organizationService: OrganizationService, + ) { } async ngOnInit() { - this.canAccessPremium = await this.userService.canAccessPremium(); - const orgs = await this.userService.getAllOrganizations(); + this.canAccessPremium = await this.stateService.getCanAccessPremium(); + const orgs = await this.organizationService.getAll(); this.isOrganizationOwner = orgs.some(o => o.isOwner); this.load(); } @@ -111,7 +118,7 @@ export class EmergencyAccessComponent implements OnInit { return; } - const autoConfirm = await this.storageService.get(ConstantsService.autoConfirmFingerprints); + const autoConfirm = await this.stateService.getAutoConfirmFingerPrints(); if (autoConfirm == null || !autoConfirm) { const [modal] = await this.modalService.openViewRef(EmergencyAccessConfirmComponent, this.confirmModalRef, comp => { comp.name = this.userNamePipe.transform(contact); diff --git a/src/app/settings/emergency-add-edit.component.ts b/src/app/settings/emergency-add-edit.component.ts index 69ed4074112..32fec6d28fe 100644 --- a/src/app/settings/emergency-add-edit.component.ts +++ b/src/app/settings/emergency-add-edit.component.ts @@ -8,13 +8,13 @@ import { FolderService } from 'jslib-common/abstractions/folder.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { LogService } from 'jslib-common/abstractions/log.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PasswordGenerationService } from 'jslib-common/abstractions/passwordGeneration.service'; import { PasswordRepromptService } from 'jslib-common/abstractions/passwordReprompt.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { PolicyService } from 'jslib-common/abstractions/policy.service'; import { StateService } from 'jslib-common/abstractions/state.service'; import { TotpService } from 'jslib-common/abstractions/totp.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { Cipher } from 'jslib-common/models/domain/cipher'; @@ -30,14 +30,14 @@ export class EmergencyAddEditComponent extends BaseAddEditComponent { constructor(cipherService: CipherService, folderService: FolderService, i18nService: I18nService, platformUtilsService: PlatformUtilsService, - auditService: AuditService, stateService: StateService, - userService: UserService, collectionService: CollectionService, + auditService: AuditService, stateService: StateService, collectionService: CollectionService, totpService: TotpService, passwordGenerationService: PasswordGenerationService, - messagingService: MessagingService, eventService: EventService, policyService: PolicyService, - logService: LogService, passwordRepromptService: PasswordRepromptService) { + messagingService: MessagingService, eventService: EventService, + policyService: PolicyService, passwordRepromptService: PasswordRepromptService, + organizationService: OrganizationService, logService: LogService) { super(cipherService, folderService, i18nService, platformUtilsService, auditService, stateService, - userService, collectionService, totpService, passwordGenerationService, messagingService, - eventService, policyService, passwordRepromptService, logService); + collectionService, totpService, passwordGenerationService, messagingService, + eventService, policyService, organizationService, logService, passwordRepromptService); } async load() { diff --git a/src/app/settings/link-sso.component.ts b/src/app/settings/link-sso.component.ts index 6beb833e345..e762d3d6b35 100644 --- a/src/app/settings/link-sso.component.ts +++ b/src/app/settings/link-sso.component.ts @@ -14,7 +14,6 @@ import { LogService } from 'jslib-common/abstractions/log.service'; import { PasswordGenerationService } from 'jslib-common/abstractions/passwordGeneration.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { StateService } from 'jslib-common/abstractions/state.service'; -import { StorageService } from 'jslib-common/abstractions/storage.service'; import { SsoComponent } from 'jslib-angular/components/sso.component'; @@ -32,11 +31,9 @@ export class LinkSsoComponent extends SsoComponent implements AfterContentInit { apiService: ApiService, authService: AuthService, router: Router, route: ActivatedRoute, cryptoFunctionService: CryptoFunctionService, passwordGenerationService: PasswordGenerationService, - storageService: StorageService, stateService: StateService, environmentService: EnvironmentService, - logService: LogService) { + stateService: StateService, environmentService: EnvironmentService, logService: LogService) { super(authService, router, - i18nService, route, - storageService, stateService, + i18nService, route, stateService, platformUtilsService, apiService, cryptoFunctionService, environmentService, passwordGenerationService, logService); diff --git a/src/app/settings/options.component.ts b/src/app/settings/options.component.ts index e4dd01c013e..952abe4d3e9 100644 --- a/src/app/settings/options.component.ts +++ b/src/app/settings/options.component.ts @@ -8,11 +8,8 @@ import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { StateService } from 'jslib-common/abstractions/state.service'; -import { StorageService } from 'jslib-common/abstractions/storage.service'; import { VaultTimeoutService } from 'jslib-common/abstractions/vaultTimeout.service'; -import { ConstantsService } from 'jslib-common/services/constants.service'; - import { ThemeType } from 'jslib-common/enums/themeType'; import { Utils } from 'jslib-common/misc/utils'; @@ -36,10 +33,13 @@ export class OptionsComponent implements OnInit { private startingLocale: string; private startingTheme: string; - constructor(private storageService: StorageService, private stateService: StateService, + constructor( + private stateService: StateService, private i18nService: I18nService, - private vaultTimeoutService: VaultTimeoutService, private platformUtilsService: PlatformUtilsService, - private messagingService: MessagingService) { + private vaultTimeoutService: VaultTimeoutService, + private platformUtilsService: PlatformUtilsService, + private messagingService: MessagingService + ) { this.vaultTimeouts = [ { name: i18nService.t('oneMinute'), value: 1 }, { name: i18nService.t('fiveMinutes'), value: 5 }, @@ -65,7 +65,7 @@ export class OptionsComponent implements OnInit { localeOptions.splice(0, 0, { name: i18nService.t('default'), value: null }); this.localeOptions = localeOptions; this.themeOptions = [ - { name: i18nService.t('themeLight'), value: null }, + { name: i18nService.t('themeLight'), value: ThemeType.Light }, { name: i18nService.t('themeDark'), value: ThemeType.Dark }, { name: i18nService.t('themeSystem'), value: ThemeType.System }, ]; @@ -73,12 +73,12 @@ export class OptionsComponent implements OnInit { async ngOnInit() { this.vaultTimeout.setValue(await this.vaultTimeoutService.getVaultTimeout()); - this.vaultTimeoutAction = await this.storageService.get(ConstantsService.vaultTimeoutActionKey); - this.disableIcons = await this.storageService.get(ConstantsService.disableFaviconKey); - this.enableGravatars = await this.storageService.get('enableGravatars'); - this.enableFullWidth = await this.storageService.get('enableFullWidth'); - this.locale = this.startingLocale = await this.storageService.get(ConstantsService.localeKey); - this.theme = this.startingTheme = await this.storageService.get(ConstantsService.themeKey); + this.vaultTimeoutAction = await this.stateService.getVaultTimeoutAction(); + this.disableIcons = await this.stateService.getDisableFavicon(); + this.enableGravatars = await this.stateService.getEnableGravitars(); + this.enableFullWidth = await this.stateService.getEnableFullWidth(); + this.locale = await this.stateService.getLocale() ?? this.startingLocale; + this.theme = await this.stateService.getTheme() ?? this.startingTheme; } async submit() { @@ -88,21 +88,19 @@ export class OptionsComponent implements OnInit { } await this.vaultTimeoutService.setVaultTimeoutOptions(this.vaultTimeout.value, this.vaultTimeoutAction); - await this.storageService.save(ConstantsService.disableFaviconKey, this.disableIcons); - await this.stateService.save(ConstantsService.disableFaviconKey, this.disableIcons); - await this.storageService.save('enableGravatars', this.enableGravatars); - await this.stateService.save('enableGravatars', this.enableGravatars); - await this.storageService.save('enableFullWidth', this.enableFullWidth); + await this.stateService.setDisableFavicon(this.disableIcons); + await this.stateService.setEnableGravitars(this.enableGravatars); + await this.stateService.setEnableFullWidth(this.enableFullWidth); this.messagingService.send('setFullWidth'); if (this.theme !== this.startingTheme) { - await this.storageService.save(ConstantsService.themeKey, this.theme); + await this.stateService.setTheme(this.theme); this.startingTheme = this.theme; const effectiveTheme = await this.platformUtilsService.getEffectiveTheme(); const htmlEl = window.document.documentElement; htmlEl.classList.remove('theme_' + ThemeType.Light, 'theme_' + ThemeType.Dark); htmlEl.classList.add('theme_' + effectiveTheme); } - await this.storageService.save(ConstantsService.localeKey, this.locale); + await this.stateService.setLocale(this.locale); if (this.locale !== this.startingLocale) { window.location.reload(); } else { diff --git a/src/app/settings/organization-plans.component.ts b/src/app/settings/organization-plans.component.ts index 60ccf461fd6..144280b47e8 100644 --- a/src/app/settings/organization-plans.component.ts +++ b/src/app/settings/organization-plans.component.ts @@ -12,10 +12,10 @@ import { ApiService } from 'jslib-common/abstractions/api.service'; import { CryptoService } from 'jslib-common/abstractions/crypto.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { LogService } from 'jslib-common/abstractions/log.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { PolicyService } from 'jslib-common/abstractions/policy.service'; import { SyncService } from 'jslib-common/abstractions/sync.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { PaymentComponent } from './payment.component'; import { TaxInfoComponent } from './tax-info.component'; @@ -73,7 +73,7 @@ export class OrganizationPlansComponent implements OnInit { constructor(private apiService: ApiService, private i18nService: I18nService, private platformUtilsService: PlatformUtilsService, private cryptoService: CryptoService, private router: Router, private syncService: SyncService, - private policyService: PolicyService, private userService: UserService, private logService: LogService) { + private policyService: PolicyService, private organizationService: OrganizationService, private logService: LogService) { this.selfHosted = platformUtilsService.isSelfHost(); } @@ -307,7 +307,7 @@ export class OrganizationPlansComponent implements OnInit { request.billingAddressPostalCode = this.taxComponent.taxInfo.postalCode; // Retrieve org info to backfill pub/priv key if necessary - const org = await this.userService.getOrganization(this.organizationId); + const org = await this.organizationService.get(this.organizationId); if (!org.hasPublicAndPrivateKeys) { const orgShareKey = await this.cryptoService.getOrgKey(this.organizationId); const orgKeys = await this.cryptoService.makeKeyPair(orgShareKey); diff --git a/src/app/settings/organizations.component.ts b/src/app/settings/organizations.component.ts index 44f6b81a6e6..b9c53dbe6dd 100644 --- a/src/app/settings/organizations.component.ts +++ b/src/app/settings/organizations.component.ts @@ -8,10 +8,10 @@ import { ApiService } from 'jslib-common/abstractions/api.service'; import { CryptoService } from 'jslib-common/abstractions/crypto.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { LogService } from 'jslib-common/abstractions/log.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { PolicyService } from 'jslib-common/abstractions/policy.service'; import { SyncService } from 'jslib-common/abstractions/sync.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { Organization } from 'jslib-common/models/domain/organization'; import { Policy } from 'jslib-common/models/domain/policy'; @@ -34,7 +34,7 @@ export class OrganizationsComponent implements OnInit { loaded: boolean = false; actionPromise: Promise; - constructor(private userService: UserService, private platformUtilsService: PlatformUtilsService, + constructor(private organizationService: OrganizationService, private platformUtilsService: PlatformUtilsService, private i18nService: I18nService, private apiService: ApiService, private syncService: SyncService, private cryptoService: CryptoService, private policyService: PolicyService, @@ -48,7 +48,7 @@ export class OrganizationsComponent implements OnInit { } async load() { - const orgs = await this.userService.getAllOrganizations(); + const orgs = await this.organizationService.getAll(); orgs.sort(Utils.getSortFunction(this.i18nService, 'name')); this.organizations = orgs; this.policies = await this.policyService.getAll(PolicyType.ResetPassword); diff --git a/src/app/settings/premium.component.ts b/src/app/settings/premium.component.ts index fc66df02954..e48db6099ff 100644 --- a/src/app/settings/premium.component.ts +++ b/src/app/settings/premium.component.ts @@ -10,9 +10,9 @@ import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { LogService } from 'jslib-common/abstractions/log.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { SyncService } from 'jslib-common/abstractions/sync.service'; import { TokenService } from 'jslib-common/abstractions/token.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { PaymentComponent } from './payment.component'; import { TaxInfoComponent } from './tax-info.component'; @@ -37,12 +37,12 @@ export class PremiumComponent implements OnInit { private platformUtilsService: PlatformUtilsService, private tokenService: TokenService, private router: Router, private messagingService: MessagingService, private syncService: SyncService, - private userService: UserService, private logService: LogService) { + private logService: LogService, private stateService: StateService) { this.selfHosted = platformUtilsService.isSelfHost(); } async ngOnInit() { - this.canAccessPremium = await this.userService.canAccessPremium(); + this.canAccessPremium = await this.stateService.getCanAccessPremium(); const premium = await this.tokenService.getPremium(); if (premium) { this.router.navigate(['/settings/subscription']); diff --git a/src/app/settings/profile.component.ts b/src/app/settings/profile.component.ts index afc6e980518..37a6c98cef8 100644 --- a/src/app/settings/profile.component.ts +++ b/src/app/settings/profile.component.ts @@ -9,7 +9,7 @@ import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { KeyConnectorService } from 'jslib-common/abstractions/keyConnector.service'; import { LogService } from 'jslib-common/abstractions/log.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { UpdateProfileRequest } from 'jslib-common/models/request/updateProfileRequest'; @@ -27,15 +27,20 @@ export class ProfileComponent implements OnInit { formPromise: Promise; - constructor(private apiService: ApiService, private i18nService: I18nService, - private platformUtilsService: PlatformUtilsService, private userService: UserService, - private cryptoService: CryptoService, private logService: LogService, - private keyConnectorService: KeyConnectorService) { } + constructor( + private apiService: ApiService, + private i18nService: I18nService, + private platformUtilsService: PlatformUtilsService, + private cryptoService: CryptoService, + private logService: LogService, + private keyConnectorService: KeyConnectorService, + private stateService: StateService, + ) { } async ngOnInit() { this.profile = await this.apiService.getProfile(); this.loading = false; - const fingerprint = await this.cryptoService.getFingerprint(await this.userService.getUserId()); + const fingerprint = await this.cryptoService.getFingerprint(await this.stateService.getUserId()); if (fingerprint != null) { this.fingerprint = fingerprint.join('-'); } diff --git a/src/app/settings/settings.component.ts b/src/app/settings/settings.component.ts index ebc036a76fd..26ef7c97d82 100644 --- a/src/app/settings/settings.component.ts +++ b/src/app/settings/settings.component.ts @@ -6,9 +6,9 @@ import { } from '@angular/core'; import { BroadcasterService } from 'jslib-common/abstractions/broadcaster.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { TokenService } from 'jslib-common/abstractions/token.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; const BroadcasterSubscriptionId = 'SettingsComponent'; @@ -23,7 +23,7 @@ export class SettingsComponent implements OnInit, OnDestroy { constructor(private tokenService: TokenService, private broadcasterService: BroadcasterService, private ngZone: NgZone, private platformUtilsService: PlatformUtilsService, - private userService: UserService) { } + private organizationService: OrganizationService) { } async ngOnInit() { this.broadcasterService.subscribe(BroadcasterSubscriptionId, async (message: any) => { @@ -47,6 +47,6 @@ export class SettingsComponent implements OnInit, OnDestroy { async load() { this.premium = await this.tokenService.getPremium(); - this.hasFamilySponsorshipAvailable = await this.userService.canManageSponsorships(); + this.hasFamilySponsorshipAvailable = await this.organizationService.canManageSponsorships(); } } diff --git a/src/app/settings/sponsored-families.component.ts b/src/app/settings/sponsored-families.component.ts index 57071c0a358..25319bd3d73 100644 --- a/src/app/settings/sponsored-families.component.ts +++ b/src/app/settings/sponsored-families.component.ts @@ -4,9 +4,9 @@ import { } from '@angular/core'; import { ApiService } from 'jslib-common/abstractions/api.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { SyncService } from 'jslib-common/abstractions/sync.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { PlanSponsorshipType } from 'jslib-common/enums/planSponsorshipType'; import { Organization } from 'jslib-common/models/domain/organization'; @@ -26,9 +26,13 @@ export class SponsoredFamiliesComponent implements OnInit { // Conditional display properties formPromise: Promise; - constructor(private userService: UserService, private apiService: ApiService, - private i18nService: I18nService, private platformUtilsService: PlatformUtilsService, - private syncService: SyncService) { } + constructor( + private apiService: ApiService, + private i18nService: I18nService, + private platformUtilsService: PlatformUtilsService, + private syncService: SyncService, + private organizationService: OrganizationService, + ) { } async ngOnInit() { await this.load(); @@ -58,7 +62,7 @@ export class SponsoredFamiliesComponent implements OnInit { await this.syncService.fullSync(true); } - const allOrgs = await this.userService.getAllOrganizations(); + const allOrgs = await this.organizationService.getAll(); this.availableSponsorshipOrgs = allOrgs.filter(org => org.familySponsorshipAvailable); this.activeSponsorshipOrgs = allOrgs.filter(org => org.familySponsorshipFriendlyName !== null); diff --git a/src/app/settings/two-factor-authenticator.component.ts b/src/app/settings/two-factor-authenticator.component.ts index b8582d289b7..0f8eb46d5e5 100644 --- a/src/app/settings/two-factor-authenticator.component.ts +++ b/src/app/settings/two-factor-authenticator.component.ts @@ -8,7 +8,7 @@ import { ApiService } from 'jslib-common/abstractions/api.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { LogService } from 'jslib-common/abstractions/log.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { UserVerificationService } from 'jslib-common/abstractions/userVerification.service'; import { UpdateTwoFactorAuthenticatorRequest } from 'jslib-common/models/request/updateTwoFactorAuthenticatorRequest'; @@ -30,11 +30,21 @@ export class TwoFactorAuthenticatorComponent extends TwoFactorBaseComponent impl private qrScript: HTMLScriptElement; - constructor(apiService: ApiService, i18nService: I18nService, + constructor( + apiService: ApiService, + i18nService: I18nService, userVerificationService: UserVerificationService, - platformUtilsService: PlatformUtilsService, logService: LogService, - private userService: UserService) { - super(apiService, i18nService, platformUtilsService, logService, userVerificationService); + platformUtilsService: PlatformUtilsService, + logService: LogService, + private stateService: StateService + ) { + super( + apiService, + i18nService, + platformUtilsService, + logService, + userVerificationService + ); this.qrScript = window.document.createElement('script'); this.qrScript.src = 'scripts/qrious.min.js'; this.qrScript.async = true; @@ -77,7 +87,7 @@ export class TwoFactorAuthenticatorComponent extends TwoFactorBaseComponent impl this.token = null; this.enabled = response.enabled; this.key = response.key; - const email = await this.userService.getEmail(); + const email = await this.stateService.getEmail(); window.setTimeout(() => { const qr = new (window as any).QRious({ element: document.getElementById('qr'), diff --git a/src/app/settings/two-factor-email.component.ts b/src/app/settings/two-factor-email.component.ts index 60f633cca46..2215ea4d2f9 100644 --- a/src/app/settings/two-factor-email.component.ts +++ b/src/app/settings/two-factor-email.component.ts @@ -4,7 +4,7 @@ import { ApiService } from 'jslib-common/abstractions/api.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { LogService } from 'jslib-common/abstractions/log.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { UserVerificationService } from 'jslib-common/abstractions/userVerification.service'; import { TwoFactorEmailRequest } from 'jslib-common/models/request/twoFactorEmailRequest'; @@ -27,11 +27,21 @@ export class TwoFactorEmailComponent extends TwoFactorBaseComponent { formPromise: Promise; emailPromise: Promise; - constructor(apiService: ApiService, i18nService: I18nService, + constructor( + apiService: ApiService, + i18nService: I18nService, platformUtilsService: PlatformUtilsService, - logService: LogService, userVerificationService: UserVerificationService, - private userService: UserService) { - super(apiService, i18nService, platformUtilsService, logService, userVerificationService); + logService: LogService, + userVerificationService: UserVerificationService, + private stateService: StateService, + ) { + super( + apiService, + i18nService, + platformUtilsService, + logService, + userVerificationService + ); } auth(authResponse: any) { @@ -76,7 +86,7 @@ export class TwoFactorEmailComponent extends TwoFactorBaseComponent { this.email = response.email; this.enabled = response.enabled; if (!this.enabled && (this.email == null || this.email === '')) { - this.email = await this.userService.getEmail(); + this.email = await this.stateService.getEmail(); } } } diff --git a/src/app/settings/two-factor-setup.component.ts b/src/app/settings/two-factor-setup.component.ts index b6b5aef52c6..4722d95640b 100644 --- a/src/app/settings/two-factor-setup.component.ts +++ b/src/app/settings/two-factor-setup.component.ts @@ -9,7 +9,7 @@ import { import { ApiService } from 'jslib-common/abstractions/api.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service'; import { PolicyService } from 'jslib-common/abstractions/policy.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { TwoFactorProviders } from 'jslib-common/services/auth.service'; @@ -46,12 +46,12 @@ export class TwoFactorSetupComponent implements OnInit { loading = true; modal: ModalRef; - constructor(protected apiService: ApiService, protected userService: UserService, - protected modalService: ModalService, protected messagingService: MessagingService, - protected policyService: PolicyService) { } + constructor(protected apiService: ApiService, protected modalService: ModalService, + protected messagingService: MessagingService, protected policyService: PolicyService, + private stateService: StateService) { } async ngOnInit() { - this.canAccessPremium = await this.userService.canAccessPremium(); + this.canAccessPremium = await this.stateService.getCanAccessPremium(); for (const key in TwoFactorProviders) { if (!TwoFactorProviders.hasOwnProperty(key)) { diff --git a/src/app/tools/breach-report.component.ts b/src/app/tools/breach-report.component.ts index a7a0bee3a69..a4d75bc0c16 100644 --- a/src/app/tools/breach-report.component.ts +++ b/src/app/tools/breach-report.component.ts @@ -4,7 +4,7 @@ import { } from '@angular/core'; import { AuditService } from 'jslib-common/abstractions/audit.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { BreachAccountResponse } from 'jslib-common/models/response/breachAccountResponse'; @Component({ @@ -18,10 +18,10 @@ export class BreachReportComponent implements OnInit { breachedAccounts: BreachAccountResponse[] = []; formPromise: Promise; - constructor(private auditService: AuditService, private userService: UserService) { } + constructor(private auditService: AuditService, private stateService: StateService) { } async ngOnInit() { - this.username = await this.userService.getEmail(); + this.username = await this.stateService.getEmail(); } async submit() { diff --git a/src/app/tools/cipher-report.component.ts b/src/app/tools/cipher-report.component.ts index 5dd05283938..1384123f8aa 100644 --- a/src/app/tools/cipher-report.component.ts +++ b/src/app/tools/cipher-report.component.ts @@ -11,11 +11,11 @@ import { Organization } from 'jslib-common/models/domain/organization'; import { AddEditComponent as OrgAddEditComponent } from '../organizations/vault/add-edit.component'; import { AddEditComponent } from '../vault/add-edit.component'; -import { CipherRepromptType } from 'jslib-common/enums/cipherRepromptType'; - import { MessagingService } from 'jslib-common/abstractions/messaging.service'; import { PasswordRepromptService } from 'jslib-common/abstractions/passwordReprompt.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; + +import { CipherRepromptType } from 'jslib-common/enums/cipherRepromptType'; import { ModalService } from 'jslib-angular/services/modal.service'; @@ -28,9 +28,9 @@ export class CipherReportComponent { ciphers: CipherView[] = []; organization: Organization; - constructor(private modalService: ModalService, protected userService: UserService, - protected messagingService: MessagingService, protected passwordRepromptService: PasswordRepromptService, - public requiresPaid: boolean) { } + constructor(private modalService: ModalService, protected messagingService: MessagingService, + public requiresPaid: boolean, private stateService: StateService, + protected passwordRepromptService: PasswordRepromptService) { } async load() { this.loading = true; @@ -80,7 +80,7 @@ export class CipherReportComponent { return false; } } else { - const accessPremium = await this.userService.canAccessPremium(); + const accessPremium = await this.stateService.getCanAccessPremium(); if (this.requiresPaid && !accessPremium) { this.messagingService.send('premiumRequired'); this.loading = false; diff --git a/src/app/tools/exposed-passwords-report.component.ts b/src/app/tools/exposed-passwords-report.component.ts index af5c8e3a799..44c7bf0dbb8 100644 --- a/src/app/tools/exposed-passwords-report.component.ts +++ b/src/app/tools/exposed-passwords-report.component.ts @@ -7,7 +7,7 @@ import { AuditService } from 'jslib-common/abstractions/audit.service'; import { CipherService } from 'jslib-common/abstractions/cipher.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service'; import { PasswordRepromptService } from 'jslib-common/abstractions/passwordReprompt.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { ModalService } from 'jslib-angular/services/modal.service'; @@ -26,8 +26,8 @@ export class ExposedPasswordsReportComponent extends CipherReportComponent imple constructor(protected cipherService: CipherService, protected auditService: AuditService, modalService: ModalService, messagingService: MessagingService, - userService: UserService, passwordRepromptService: PasswordRepromptService) { - super(modalService, userService, messagingService, passwordRepromptService, true); + stateService: StateService, passwordRepromptService: PasswordRepromptService) { + super(modalService, messagingService, true, stateService, passwordRepromptService); } ngOnInit() { diff --git a/src/app/tools/inactive-two-factor-report.component.ts b/src/app/tools/inactive-two-factor-report.component.ts index 3ec41367107..d7e913a22b9 100644 --- a/src/app/tools/inactive-two-factor-report.component.ts +++ b/src/app/tools/inactive-two-factor-report.component.ts @@ -7,7 +7,7 @@ import { CipherService } from 'jslib-common/abstractions/cipher.service'; import { LogService } from 'jslib-common/abstractions/log.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service'; import { PasswordRepromptService } from 'jslib-common/abstractions/passwordReprompt.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { ModalService } from 'jslib-angular/services/modal.service'; @@ -28,9 +28,9 @@ export class InactiveTwoFactorReportComponent extends CipherReportComponent impl cipherDocs = new Map(); constructor(protected cipherService: CipherService, modalService: ModalService, - messagingService: MessagingService, userService: UserService, private logService: LogService, + messagingService: MessagingService, stateService: StateService, private logService: LogService, passwordRepromptService: PasswordRepromptService) { - super(modalService, userService, messagingService, passwordRepromptService, true); + super(modalService, messagingService, true, stateService, passwordRepromptService); } async ngOnInit() { diff --git a/src/app/tools/reused-passwords-report.component.ts b/src/app/tools/reused-passwords-report.component.ts index d699699fd83..fc19660d0c9 100644 --- a/src/app/tools/reused-passwords-report.component.ts +++ b/src/app/tools/reused-passwords-report.component.ts @@ -6,7 +6,7 @@ import { import { CipherService } from 'jslib-common/abstractions/cipher.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service'; import { PasswordRepromptService } from 'jslib-common/abstractions/passwordReprompt.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { ModalService } from 'jslib-angular/services/modal.service'; @@ -24,9 +24,9 @@ export class ReusedPasswordsReportComponent extends CipherReportComponent implem passwordUseMap: Map; constructor(protected cipherService: CipherService, modalService: ModalService, - messagingService: MessagingService, userService: UserService, + messagingService: MessagingService, stateService: StateService, passwordRepromptService: PasswordRepromptService) { - super(modalService, userService, messagingService, passwordRepromptService, true); + super(modalService, messagingService, true, stateService, passwordRepromptService); } async ngOnInit() { diff --git a/src/app/tools/tools.component.ts b/src/app/tools/tools.component.ts index f4b5edf0e6c..f917169c2fa 100644 --- a/src/app/tools/tools.component.ts +++ b/src/app/tools/tools.component.ts @@ -4,7 +4,7 @@ import { } from '@angular/core'; import { MessagingService } from 'jslib-common/abstractions/messaging.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; @Component({ selector: 'app-tools', @@ -13,10 +13,10 @@ import { UserService } from 'jslib-common/abstractions/user.service'; export class ToolsComponent implements OnInit { canAccessPremium = false; - constructor(private userService: UserService, private messagingService: MessagingService) { } + constructor(private stateService: StateService, private messagingService: MessagingService) { } async ngOnInit() { - this.canAccessPremium = await this.userService.canAccessPremium(); + this.canAccessPremium = await this.stateService.getCanAccessPremium(); } premiumRequired() { diff --git a/src/app/tools/unsecured-websites-report.component.ts b/src/app/tools/unsecured-websites-report.component.ts index 8715cdc84e0..82991e10332 100644 --- a/src/app/tools/unsecured-websites-report.component.ts +++ b/src/app/tools/unsecured-websites-report.component.ts @@ -6,7 +6,7 @@ import { import { CipherService } from 'jslib-common/abstractions/cipher.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service'; import { PasswordRepromptService } from 'jslib-common/abstractions/passwordReprompt.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { ModalService } from 'jslib-angular/services/modal.service'; @@ -22,8 +22,9 @@ import { CipherReportComponent } from './cipher-report.component'; }) export class UnsecuredWebsitesReportComponent extends CipherReportComponent implements OnInit { constructor(protected cipherService: CipherService, modalService: ModalService, - messagingService: MessagingService, userService: UserService, passwordRepromptService: PasswordRepromptService) { - super(modalService, userService, messagingService, passwordRepromptService, true); + messagingService: MessagingService, stateService: StateService, + passwordRepromptService: PasswordRepromptService) { + super(modalService, messagingService, true, stateService, passwordRepromptService); } async ngOnInit() { diff --git a/src/app/tools/weak-passwords-report.component.ts b/src/app/tools/weak-passwords-report.component.ts index 39fed5fc084..8ccde8ce5db 100644 --- a/src/app/tools/weak-passwords-report.component.ts +++ b/src/app/tools/weak-passwords-report.component.ts @@ -7,7 +7,7 @@ import { CipherService } from 'jslib-common/abstractions/cipher.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service'; import { PasswordGenerationService } from 'jslib-common/abstractions/passwordGeneration.service'; import { PasswordRepromptService } from 'jslib-common/abstractions/passwordReprompt.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { ModalService } from 'jslib-angular/services/modal.service'; @@ -28,9 +28,9 @@ export class WeakPasswordsReportComponent extends CipherReportComponent implemen private passwordStrengthCache = new Map(); constructor(protected cipherService: CipherService, protected passwordGenerationService: PasswordGenerationService, - modalService: ModalService, messagingService: MessagingService, userService: UserService, - passwordRepromptService: PasswordRepromptService) { - super(modalService, userService, messagingService, passwordRepromptService, true); + modalService: ModalService, messagingService: MessagingService, + stateService: StateService, passwordRepromptService: PasswordRepromptService) { + super(modalService, messagingService, true, stateService, passwordRepromptService); } async ngOnInit() { diff --git a/src/app/vault/add-edit.component.ts b/src/app/vault/add-edit.component.ts index 36e1aaa1a34..6d5d4542c0b 100644 --- a/src/app/vault/add-edit.component.ts +++ b/src/app/vault/add-edit.component.ts @@ -11,13 +11,13 @@ import { FolderService } from 'jslib-common/abstractions/folder.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { LogService } from 'jslib-common/abstractions/log.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PasswordGenerationService } from 'jslib-common/abstractions/passwordGeneration.service'; import { PasswordRepromptService } from 'jslib-common/abstractions/passwordReprompt.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { PolicyService } from 'jslib-common/abstractions/policy.service'; import { StateService } from 'jslib-common/abstractions/state.service'; import { TotpService } from 'jslib-common/abstractions/totp.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { AddEditComponent as BaseAddEditComponent } from 'jslib-angular/components/add-edit.component'; import { LoginUriView } from 'jslib-common/models/view/loginUriView'; @@ -43,14 +43,12 @@ export class AddEditComponent extends BaseAddEditComponent { constructor(cipherService: CipherService, folderService: FolderService, i18nService: I18nService, platformUtilsService: PlatformUtilsService, auditService: AuditService, stateService: StateService, - userService: UserService, collectionService: CollectionService, - protected totpService: TotpService, protected passwordGenerationService: PasswordGenerationService, - protected messagingService: MessagingService, eventService: EventService, - protected policyService: PolicyService, passwordRepromptService: PasswordRepromptService, - logService: LogService) { + collectionService: CollectionService, protected totpService: TotpService, + protected passwordGenerationService: PasswordGenerationService, protected messagingService: MessagingService, + eventService: EventService, protected policyService: PolicyService, organizationService: OrganizationService, logService: LogService, + passwordRepromptService: PasswordRepromptService) { super(cipherService, folderService, i18nService, platformUtilsService, auditService, stateService, - userService, collectionService, messagingService, eventService, policyService, passwordRepromptService, - logService); + collectionService, messagingService, eventService, policyService, logService, passwordRepromptService, organizationService); } async ngOnInit() { @@ -60,7 +58,7 @@ export class AddEditComponent extends BaseAddEditComponent { this.hasPasswordHistory = this.cipher.hasPasswordHistory; this.cleanUp(); - this.canAccessPremium = await this.userService.canAccessPremium(); + this.canAccessPremium = await this.stateService.getCanAccessPremium(); if (this.cipher.type === CipherType.Login && this.cipher.login.totp && (this.cipher.organizationUseTotp || this.canAccessPremium)) { await this.totpUpdateCode(); diff --git a/src/app/vault/attachments.component.ts b/src/app/vault/attachments.component.ts index 28da5ab68e4..0d8d5372ed2 100644 --- a/src/app/vault/attachments.component.ts +++ b/src/app/vault/attachments.component.ts @@ -6,7 +6,7 @@ import { CryptoService } from 'jslib-common/abstractions/crypto.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { LogService } from 'jslib-common/abstractions/log.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { AttachmentView } from 'jslib-common/models/view/attachmentView'; @@ -20,11 +20,10 @@ export class AttachmentsComponent extends BaseAttachmentsComponent { viewOnly = false; constructor(cipherService: CipherService, i18nService: I18nService, - cryptoService: CryptoService, userService: UserService, - platformUtilsService: PlatformUtilsService, apiService: ApiService, - logService: LogService) { - super(cipherService, i18nService, cryptoService, userService, platformUtilsService, apiService, window, - logService); + cryptoService: CryptoService, stateService: StateService, + platformUtilsService: PlatformUtilsService, apiService: ApiService, logService: LogService) { + super(cipherService, i18nService, cryptoService, platformUtilsService, apiService, window, logService, + stateService); } protected async reupload(attachment: AttachmentView) { diff --git a/src/app/vault/bulk-share.component.ts b/src/app/vault/bulk-share.component.ts index 1944a7b9bf2..3a801ea0ffe 100644 --- a/src/app/vault/bulk-share.component.ts +++ b/src/app/vault/bulk-share.component.ts @@ -10,8 +10,8 @@ import { CipherService } from 'jslib-common/abstractions/cipher.service'; import { CollectionService } from 'jslib-common/abstractions/collection.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { LogService } from 'jslib-common/abstractions/log.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { CipherView } from 'jslib-common/models/view/cipherView'; import { CollectionView } from 'jslib-common/models/view/collectionView'; @@ -37,14 +37,14 @@ export class BulkShareComponent implements OnInit { constructor(private cipherService: CipherService, private platformUtilsService: PlatformUtilsService, private i18nService: I18nService, private collectionService: CollectionService, - private userService: UserService, private logService: LogService) { } + private organizationService: OrganizationService, private logService: LogService) { } async ngOnInit() { this.shareableCiphers = this.ciphers.filter(c => !c.hasOldAttachments && c.organizationId == null); this.nonShareableCount = this.ciphers.length - this.shareableCiphers.length; const allCollections = await this.collectionService.getAllDecrypted(); this.writeableCollections = allCollections.filter(c => !c.readOnly); - this.organizations = await this.userService.getAllOrganizations(); + this.organizations = await this.organizationService.getAll(); if (this.organizationId == null && this.organizations.length > 0) { this.organizationId = this.organizations[0].id; } diff --git a/src/app/vault/ciphers.component.ts b/src/app/vault/ciphers.component.ts index 82091be7b84..0d494a57fb3 100644 --- a/src/app/vault/ciphers.component.ts +++ b/src/app/vault/ciphers.component.ts @@ -13,8 +13,8 @@ import { LogService } from 'jslib-common/abstractions/log.service'; import { PasswordRepromptService } from 'jslib-common/abstractions/passwordReprompt.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { SearchService } from 'jslib-common/abstractions/search.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { TotpService } from 'jslib-common/abstractions/totp.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { CiphersComponent as BaseCiphersComponent } from 'jslib-angular/components/ciphers.component'; @@ -50,13 +50,13 @@ export class CiphersComponent extends BaseCiphersComponent implements OnDestroy constructor(searchService: SearchService, protected i18nService: I18nService, protected platformUtilsService: PlatformUtilsService, protected cipherService: CipherService, protected eventService: EventService, - protected totpService: TotpService, protected userService: UserService, + protected totpService: TotpService, protected stateService: StateService, protected passwordRepromptService: PasswordRepromptService, private logService: LogService) { super(searchService); } async ngOnInit() { - this.userHasPremiumAccess = await this.userService.canAccessPremium(); + this.userHasPremiumAccess = await this.stateService.getCanAccessPremium(); } ngOnDestroy() { diff --git a/src/app/vault/groupings.component.ts b/src/app/vault/groupings.component.ts index b9bd8ee8f8c..5c46a0793c0 100644 --- a/src/app/vault/groupings.component.ts +++ b/src/app/vault/groupings.component.ts @@ -6,8 +6,7 @@ import { import { CollectionService } from 'jslib-common/abstractions/collection.service'; import { FolderService } from 'jslib-common/abstractions/folder.service'; -import { StorageService } from 'jslib-common/abstractions/storage.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { GroupingsComponent as BaseGroupingsComponent } from 'jslib-angular/components/groupings.component'; @@ -22,8 +21,8 @@ export class GroupingsComponent extends BaseGroupingsComponent { searchPlaceholder: string = null; constructor(collectionService: CollectionService, folderService: FolderService, - storageService: StorageService, userService: UserService) { - super(collectionService, folderService, storageService, userService); + stateService: StateService) { + super(collectionService, folderService, stateService); } searchTextChanged() { diff --git a/src/app/vault/share.component.ts b/src/app/vault/share.component.ts index 63d0aa84c98..95aa7c2296d 100644 --- a/src/app/vault/share.component.ts +++ b/src/app/vault/share.component.ts @@ -6,8 +6,8 @@ import { import { CipherService } from 'jslib-common/abstractions/cipher.service'; import { CollectionService } from 'jslib-common/abstractions/collection.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { CollectionView } from 'jslib-common/models/view/collectionView'; @@ -20,10 +20,10 @@ import { LogService } from 'jslib-common/abstractions/log.service'; }) export class ShareComponent extends BaseShareComponent implements OnDestroy { constructor(collectionService: CollectionService, platformUtilsService: PlatformUtilsService, - i18nService: I18nService, userService: UserService, - cipherService: CipherService, logService: LogService) { - super(collectionService, platformUtilsService, i18nService, userService, cipherService, - logService); + i18nService: I18nService, cipherService: CipherService, + organizationService: OrganizationService, logService: LogService) { + super(collectionService, platformUtilsService, i18nService, cipherService, + logService, organizationService); } ngOnDestroy() { diff --git a/src/app/vault/vault.component.ts b/src/app/vault/vault.component.ts index b8ad74d4a87..2b7b57b3e7d 100644 --- a/src/app/vault/vault.component.ts +++ b/src/app/vault/vault.component.ts @@ -32,10 +32,12 @@ import { BroadcasterService } from 'jslib-common/abstractions/broadcaster.servic import { CryptoService } from 'jslib-common/abstractions/crypto.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service'; +import { OrganizationService } from 'jslib-common/abstractions/organization.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; +import { ProviderService } from 'jslib-common/abstractions/provider.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { SyncService } from 'jslib-common/abstractions/sync.service'; import { TokenService } from 'jslib-common/abstractions/token.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; import { ModalService } from 'jslib-angular/services/modal.service'; @@ -74,9 +76,10 @@ export class VaultComponent implements OnInit, OnDestroy { private router: Router, private changeDetectorRef: ChangeDetectorRef, private i18nService: I18nService, private modalService: ModalService, private tokenService: TokenService, private cryptoService: CryptoService, - private messagingService: MessagingService, private userService: UserService, - private platformUtilsService: PlatformUtilsService, private broadcasterService: BroadcasterService, - private ngZone: NgZone) { } + private messagingService: MessagingService, private platformUtilsService: PlatformUtilsService, + private broadcasterService: BroadcasterService, private ngZone: NgZone, + private stateService: StateService, private organizationService: OrganizationService, + private providerService: ProviderService) { } async ngOnInit() { this.showVerifyEmail = !(await this.tokenService.getEmailVerified()); @@ -88,20 +91,20 @@ export class VaultComponent implements OnInit, OnDestroy { this.route.queryParams.pipe(first()).subscribe(async params => { await this.syncService.fullSync(false); - this.showUpdateKey = !(await this.cryptoService.hasEncKey()); - const canAccessPremium = await this.userService.canAccessPremium(); + const canAccessPremium = await this.stateService.getCanAccessPremium(); this.showPremiumCallout = !this.showVerifyEmail && !canAccessPremium && !this.platformUtilsService.isSelfHost(); - this.showProviders = (await this.userService.getAllProviders()).length > 0; + this.showProviders = (await this.providerService.getAll()).length > 0; - const allOrgs = await this.userService.getAllOrganizations(); + const allOrgs = await this.organizationService.getAll(); this.showRedeemSponsorship = allOrgs.some(o => o.familySponsorshipAvailable) && !allOrgs.some(o => o.familySponsorshipFriendlyName != null); await Promise.all([ this.groupingsComponent.load(), this.organizationsComponent.load(), ]); + this.showUpdateKey = !(await this.cryptoService.hasEncKey()); if (params == null) { this.groupingsComponent.selectedAll = true; @@ -215,12 +218,12 @@ export class VaultComponent implements OnInit, OnDestroy { } async editCipherAttachments(cipher: CipherView) { - const canAccessPremium = await this.userService.canAccessPremium(); + const canAccessPremium = await this.stateService.getCanAccessPremium(); if (cipher.organizationId == null && !canAccessPremium) { this.messagingService.send('premiumRequired'); return; } else if (cipher.organizationId != null) { - const org = await this.userService.getOrganization(cipher.organizationId); + const org = await this.organizationService.get(cipher.organizationId); if (org != null && (org.maxStorageGb == null || org.maxStorageGb === 0)) { this.messagingService.send('upgradeOrganization', { organizationId: cipher.organizationId }); return; diff --git a/src/connectors/webauthn.ts b/src/connectors/webauthn.ts index 783724448d1..5aa04e780bc 100644 --- a/src/connectors/webauthn.ts +++ b/src/connectors/webauthn.ts @@ -83,7 +83,7 @@ function parseParametersV2() { btnText: string; btnReturnText: string; callbackUri?: string; - mobile?: boolean + mobile?: boolean; } = null; try { dataObj = JSON.parse(b64Decode(getQsParam('data'))); diff --git a/src/services/htmlStorage.service.ts b/src/services/htmlStorage.service.ts index b3dd95de566..00546c030f8 100644 --- a/src/services/htmlStorage.service.ts +++ b/src/services/htmlStorage.service.ts @@ -1,45 +1,40 @@ import { Injectable } from '@angular/core'; -import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { StorageService } from 'jslib-common/abstractions/storage.service'; -import { ConstantsService } from 'jslib-common/services/constants.service'; + +import { HtmlStorageLocation } from 'jslib-common/enums/htmlStorageLocation'; + +import { GlobalState } from 'jslib-common/models/domain/globalState'; +import { State } from 'jslib-common/models/domain/state'; +import { StorageOptions } from 'jslib-common/models/domain/storageOptions'; @Injectable() export class HtmlStorageService implements StorageService { - private localStorageKeys = new Set(['appId', 'anonymousAppId', 'rememberedEmail', 'passwordGenerationOptions', - ConstantsService.disableFaviconKey, 'rememberEmail', 'enableGravatars', 'enableFullWidth', - ConstantsService.localeKey, ConstantsService.autoConfirmFingerprints, - ConstantsService.vaultTimeoutKey, ConstantsService.vaultTimeoutActionKey, ConstantsService.ssoCodeVerifierKey, - ConstantsService.ssoStateKey, 'ssoOrgIdentifier', ConstantsService.themeKey]); - private localStorageStartsWithKeys = ['twoFactorToken_', ConstantsService.collapsedGroupingsKey + '_']; - private memoryStorageStartsWithKeys = ['ciphers_', 'folders_', 'collections_', 'settings_', 'lastSync_']; - private memoryStorage = new Map(); - constructor(private platformUtilsService: PlatformUtilsService) { } - - async init() { - // LockOption -> VaultTimeout (uses the same legacy string value for backwards compat) - const vaultTimeout = await this.get(ConstantsService.vaultTimeoutKey); - if (vaultTimeout == null && !this.platformUtilsService.isDev()) { - await this.save(ConstantsService.vaultTimeoutKey, 15); - } - - // Default Action to lock - const vaultTimeoutAction = await this.get(ConstantsService.vaultTimeoutActionKey); - if (vaultTimeoutAction == null) { - await this.save(ConstantsService.vaultTimeoutActionKey, 'lock'); - } + get defaultOptions(): StorageOptions { + return { htmlStorageLocation: HtmlStorageLocation.Session }; } - get(key: string): Promise { + async init() { + const state = await this.get('state', { htmlStorageLocation: HtmlStorageLocation.Local }) ?? new State(); + state.globals = state.globals ?? new GlobalState(); + state.globals.vaultTimeout = state.globals.vaultTimeout ?? 15; + state.globals.vaultTimeoutAction = state.globals.vaultTimeoutAction ?? 'lock'; + await this.save('state', state, { htmlStorageLocation: HtmlStorageLocation.Local }); + } + + get(key: string, options: StorageOptions = this.defaultOptions): Promise { let json: string = null; - if (this.isLocalStorage(key)) { - json = window.localStorage.getItem(key); - } else if (this.isMemoryStorage(key)) { - json = this.memoryStorage.get(key); - } else { - json = window.sessionStorage.getItem(key); + switch (options.htmlStorageLocation) { + case HtmlStorageLocation.Local: + json = window.localStorage.getItem(key); + break; + case HtmlStorageLocation.Session: + default: + json = window.sessionStorage.getItem(key); + break; } + if (json != null) { const obj = JSON.parse(json); return Promise.resolve(obj as T); @@ -47,13 +42,13 @@ export class HtmlStorageService implements StorageService { return Promise.resolve(null); } - async has(key: string): Promise { - return await this.get(key) != null; + async has(key: string, options: StorageOptions = this.defaultOptions): Promise { + return await this.get(key, options) != null; } - save(key: string, obj: any): Promise { + save(key: string, obj: any, options: StorageOptions = this.defaultOptions): Promise { if (obj == null) { - return this.remove(key); + return this.remove(key, options); } if (obj instanceof Set) { @@ -61,45 +56,28 @@ export class HtmlStorageService implements StorageService { } const json = JSON.stringify(obj); - if (this.isLocalStorage(key)) { - window.localStorage.setItem(key, json); - } else if (this.isMemoryStorage(key)) { - this.memoryStorage.set(key, json); - } else { - window.sessionStorage.setItem(key, json); + switch (options.htmlStorageLocation) { + case HtmlStorageLocation.Local: + window.localStorage.setItem(key, json); + break; + case HtmlStorageLocation.Session: + default: + window.sessionStorage.setItem(key, json); + break; } return Promise.resolve(); } - remove(key: string): Promise { - if (this.isLocalStorage(key)) { - window.localStorage.removeItem(key); - } else if (this.isMemoryStorage(key)) { - this.memoryStorage.delete(key); - } else { - window.sessionStorage.removeItem(key); + remove(key: string, options: StorageOptions = this.defaultOptions): Promise { + switch (options.htmlStorageLocation) { + case HtmlStorageLocation.Local: + window.localStorage.removeItem(key); + break; + case HtmlStorageLocation.Session: + default: + window.sessionStorage.removeItem(key); + break; } return Promise.resolve(); } - - private isLocalStorage(key: string): boolean { - if (this.localStorageKeys.has(key)) { - return true; - } - for (const swKey of this.localStorageStartsWithKeys) { - if (key.startsWith(swKey)) { - return true; - } - } - return false; - } - - private isMemoryStorage(key: string): boolean { - for (const swKey of this.memoryStorageStartsWithKeys) { - if (key.startsWith(swKey)) { - return true; - } - } - return false; - } } diff --git a/src/services/webPlatformUtils.service.ts b/src/services/webPlatformUtils.service.ts index 13f754c061e..dd7d81a0921 100644 --- a/src/services/webPlatformUtils.service.ts +++ b/src/services/webPlatformUtils.service.ts @@ -7,9 +7,7 @@ import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { LogService } from 'jslib-common/abstractions/log.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; -import { StorageService } from 'jslib-common/abstractions/storage.service'; - -import { ConstantsService } from 'jslib-common/services/constants.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; export class WebPlatformUtilsService implements PlatformUtilsService { identityClientId: string = 'web'; @@ -18,7 +16,7 @@ export class WebPlatformUtilsService implements PlatformUtilsService { private prefersColorSchemeDark = window.matchMedia('(prefers-color-scheme: dark)'); constructor(private i18nService: I18nService, private messagingService: MessagingService, - private logService: LogService, private storageService: () => StorageService) { } + private logService: LogService, private stateService: StateService) { } getDevice(): DeviceType { if (this.browserCache != null) { @@ -293,7 +291,7 @@ export class WebPlatformUtilsService implements PlatformUtilsService { } async getEffectiveTheme(): Promise { - const theme = await this.storageService().get(ConstantsService.themeKey); + const theme = await this.stateService.getTheme(); if (theme === ThemeType.Dark) { return ThemeType.Dark; } else if (theme === ThemeType.System) { diff --git a/src/theme.js b/src/theme.js index 9e0aa4078c3..f1171ab5130 100644 --- a/src/theme.js +++ b/src/theme.js @@ -6,17 +6,20 @@ const htmlEl = document.documentElement; let theme = defaultTheme; - const savedTheme = window.localStorage.getItem('theme'); - if (savedTheme != null) { - if (savedTheme.indexOf('system') > -1) { - theme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'; - } else if (savedTheme.indexOf('dark') > -1) { - theme = 'dark'; + const stateJson = window.localStorage.getItem('state'); + if (stateJson != null) { + const globals = JSON.parse(stateJson).globals; + if (globals != null && globals.theme != null) { + if (globals.theme.indexOf('system') > -1) { + theme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'; + } else if (globals.theme.indexOf('dark') > -1) { + theme = 'dark'; + } + } + + if (!htmlEl.classList.contains('theme_' + theme)) { + htmlEl.classList.remove('theme_' + defaultTheme); + htmlEl.classList.add('theme_' + theme); } } - - if (!htmlEl.classList.contains('theme_' + theme)) { - htmlEl.classList.remove('theme_' + defaultTheme); - htmlEl.classList.add('theme_' + theme); - } })();