1
0
mirror of https://github.com/bitwarden/browser synced 2026-01-03 09:03:32 +00:00

[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 <robyntmaccallum@gmail.com>
Co-authored-by: Hinton <oscar@oscarhinton.com>
This commit is contained in:
Addison Beck
2021-12-14 11:10:26 -05:00
committed by GitHub
parent 71075cf878
commit 17ae5ee57c
101 changed files with 839 additions and 649 deletions

View File

@@ -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);

View File

@@ -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<any>;
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);

View File

@@ -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<any>;
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,

View File

@@ -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) {

View File

@@ -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<string, any>();
private providerUsersIdMap = new Map<string, any>();
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;

View File

@@ -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;
});
}

View File

@@ -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<ProviderUserUserDetails
providerId: string;
accessEvents = false;
constructor(apiService: ApiService, private route: ActivatedRoute,
i18nService: I18nService, modalService: ModalService,
constructor(
apiService: ApiService,
private route: ActivatedRoute,
i18nService: I18nService,
modalService: ModalService,
platformUtilsService: PlatformUtilsService,
cryptoService: CryptoService, private userService: UserService, private router: Router,
storageService: StorageService, searchService: SearchService, validationService: ValidationService,
logService: LogService, searchPipe: SearchPipe, userNamePipe: UserNamePipe) {
super(apiService, searchService, i18nService, platformUtilsService, cryptoService,
storageService, validationService, modalService, logService, searchPipe, userNamePipe);
cryptoService: CryptoService,
private router: Router,
searchService: SearchService,
validationService: ValidationService,
logService: LogService,
searchPipe: SearchPipe,
userNamePipe: UserNamePipe,
stateService: StateService,
private providerService: ProviderService,
) {
super(
apiService,
searchService,
i18nService,
platformUtilsService,
cryptoService,
validationService,
modalService,
logService,
searchPipe,
userNamePipe,
stateService,
);
}
ngOnInit() {
this.route.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.canManageUsers) {
this.router.navigate(['../'], { relativeTo: this.route });

View File

@@ -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() {

View File

@@ -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,
],

View File

@@ -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;

View File

@@ -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 (

View File

@@ -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) {

View File

@@ -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);
});
}
}