2018-06-08 23:08:19 +02:00
|
|
|
import {
|
|
|
|
Component,
|
2019-01-24 14:54:33 +01:00
|
|
|
NgZone,
|
|
|
|
OnDestroy,
|
2018-07-03 21:11:58 +02:00
|
|
|
OnInit,
|
2018-06-08 23:08:19 +02:00
|
|
|
} from '@angular/core';
|
2020-07-07 20:32:22 +02:00
|
|
|
|
2018-07-03 21:11:58 +02:00
|
|
|
import { ActivatedRoute } from '@angular/router';
|
|
|
|
|
2019-01-24 14:54:33 +01:00
|
|
|
import { BroadcasterService } from 'jslib/angular/services/broadcaster.service';
|
|
|
|
|
2020-07-07 20:32:22 +02:00
|
|
|
import { ApiService } from 'jslib/abstractions/api.service';
|
2020-06-16 16:35:25 +02:00
|
|
|
import { EnvironmentService } from 'jslib/abstractions/environment.service';
|
2020-07-07 20:32:22 +02:00
|
|
|
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
2020-06-25 22:30:45 +02:00
|
|
|
import { UserService } from 'jslib/abstractions/user.service';
|
2018-07-03 21:11:58 +02:00
|
|
|
|
|
|
|
import { Organization } from 'jslib/models/domain/organization';
|
2018-06-08 23:08:19 +02:00
|
|
|
|
2019-01-24 14:54:33 +01:00
|
|
|
const BroadcasterSubscriptionId = 'OrganizationLayoutComponent';
|
|
|
|
|
2018-06-08 23:08:19 +02:00
|
|
|
@Component({
|
|
|
|
selector: 'app-organization-layout',
|
|
|
|
templateUrl: 'organization-layout.component.html',
|
|
|
|
})
|
2019-01-24 14:54:33 +01:00
|
|
|
export class OrganizationLayoutComponent implements OnInit, OnDestroy {
|
2018-07-03 21:11:58 +02:00
|
|
|
organization: Organization;
|
2021-01-12 21:31:22 +01:00
|
|
|
businessTokenPromise: Promise<any>;
|
2018-07-03 21:11:58 +02:00
|
|
|
private organizationId: string;
|
2021-01-12 21:31:22 +01:00
|
|
|
private businessUrl: string;
|
2018-07-03 21:11:58 +02:00
|
|
|
|
2019-01-24 14:54:33 +01:00
|
|
|
constructor(private route: ActivatedRoute, private userService: UserService,
|
2020-07-07 20:32:22 +02:00
|
|
|
private broadcasterService: BroadcasterService, private ngZone: NgZone,
|
|
|
|
private apiService: ApiService, private platformUtilsService: PlatformUtilsService,
|
|
|
|
private environmentService: EnvironmentService) { }
|
2018-07-03 21:11:58 +02:00
|
|
|
|
|
|
|
ngOnInit() {
|
2021-01-12 21:31:22 +01:00
|
|
|
this.businessUrl = 'https://portal.bitwarden.com';
|
2020-06-16 16:35:25 +02:00
|
|
|
if (this.environmentService.enterpriseUrl != null) {
|
2021-01-12 21:31:22 +01:00
|
|
|
this.businessUrl = this.environmentService.enterpriseUrl;
|
2020-06-16 16:35:25 +02:00
|
|
|
} else if (this.environmentService.baseUrl != null) {
|
2021-01-12 21:31:22 +01:00
|
|
|
this.businessUrl = this.environmentService.baseUrl + '/portal';
|
2020-06-16 16:35:25 +02:00
|
|
|
}
|
|
|
|
|
2018-07-06 22:36:51 +02:00
|
|
|
document.body.classList.remove('layout_frontend');
|
2018-07-03 21:11:58 +02:00
|
|
|
this.route.params.subscribe(async (params) => {
|
|
|
|
this.organizationId = params.organizationId;
|
|
|
|
await this.load();
|
|
|
|
});
|
2019-01-24 14:54:33 +01:00
|
|
|
this.broadcasterService.subscribe(BroadcasterSubscriptionId, (message: any) => {
|
|
|
|
this.ngZone.run(async () => {
|
|
|
|
switch (message.command) {
|
|
|
|
case 'updatedOrgLicense':
|
|
|
|
await this.load();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
|
2018-07-03 21:11:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async load() {
|
|
|
|
this.organization = await this.userService.getOrganization(this.organizationId);
|
|
|
|
}
|
2020-07-07 20:32:22 +02:00
|
|
|
|
2021-01-12 21:31:22 +01:00
|
|
|
async goToBusinessPortal() {
|
|
|
|
if (this.businessTokenPromise != null) {
|
2020-07-07 20:32:22 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
2021-01-12 21:31:22 +01:00
|
|
|
this.businessTokenPromise = this.apiService.getEnterprisePortalSignInToken();
|
|
|
|
const token = await this.businessTokenPromise;
|
2020-07-07 20:32:22 +02:00
|
|
|
if (token != null) {
|
|
|
|
const userId = await this.userService.getUserId();
|
2021-01-12 21:31:22 +01:00
|
|
|
this.platformUtilsService.launchUri(this.businessUrl + '/login?userId=' + userId +
|
2020-07-07 20:32:22 +02:00
|
|
|
'&token=' + (window as any).encodeURIComponent(token) + '&organizationId=' + this.organization.id);
|
|
|
|
}
|
|
|
|
} catch { }
|
2021-01-12 21:31:22 +01:00
|
|
|
this.businessTokenPromise = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
get showMenuBar() {
|
|
|
|
return this.showManageTab || this.showToolsTab || this.organization.isOwner;
|
|
|
|
}
|
|
|
|
|
|
|
|
get showManageTab(): boolean {
|
|
|
|
return this.organization.canManageUsers ||
|
|
|
|
this.organization.canManageAssignedCollections ||
|
|
|
|
this.organization.canManageAllCollections ||
|
|
|
|
this.organization.canManageGroups ||
|
|
|
|
this.organization.canManagePolicies ||
|
|
|
|
this.organization.canAccessEventLogs;
|
|
|
|
}
|
|
|
|
|
|
|
|
get showToolsTab(): boolean {
|
|
|
|
return this.organization.canAccessImportExport || this.organization.canAccessReports;
|
|
|
|
}
|
|
|
|
|
|
|
|
get showBusinessPortalButton(): boolean {
|
|
|
|
return this.organization.useBusinessPortal && this.organization.canAccessBusinessPortal;
|
|
|
|
}
|
|
|
|
|
|
|
|
get toolsRoute(): string {
|
|
|
|
return this.organization.canAccessImportExport ?
|
|
|
|
'tools/import' :
|
|
|
|
'tools/exposed-passwords-report';
|
|
|
|
}
|
|
|
|
|
|
|
|
get manageRoute(): string {
|
|
|
|
let route: string;
|
|
|
|
switch (true) {
|
|
|
|
case this.organization.canManageUsers:
|
|
|
|
route = 'manage/people';
|
|
|
|
break;
|
|
|
|
case this.organization.canManageAssignedCollections || this.organization.canManageAllCollections:
|
|
|
|
route = 'manage/collections';
|
|
|
|
break;
|
|
|
|
case this.organization.canManageGroups:
|
|
|
|
route = 'manage/groups';
|
|
|
|
break;
|
|
|
|
case this.organization.canManagePolicies:
|
|
|
|
route = 'manage/policies';
|
|
|
|
break;
|
|
|
|
case this.organization.canAccessEventLogs:
|
|
|
|
route = 'manage/events';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return route;
|
2020-07-07 20:32:22 +02:00
|
|
|
}
|
2018-07-03 21:11:58 +02:00
|
|
|
}
|