-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
sm-org-enabled.guard.ts
29 lines (23 loc) · 1.08 KB
/
sm-org-enabled.guard.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { inject } from "@angular/core";
import { ActivatedRouteSnapshot, CanActivateFn, createUrlTreeFromSnapshot } from "@angular/router";
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction";
/**
* Redirects from root `/sm` to first organization with access to SM
*/
export const organizationEnabledGuard: CanActivateFn = async (route: ActivatedRouteSnapshot) => {
const syncService = inject(SyncService);
const orgService = inject(OrganizationService);
/** Workaround to avoid service initialization race condition. */
if ((await syncService.getLastSync()) == null) {
await syncService.fullSync(false);
}
const org = await orgService.get(route.params.organizationId);
if (org == null || !org.canAccessSecretsManager) {
return createUrlTreeFromSnapshot(route, ["/"]);
}
if (!org.enabled) {
return createUrlTreeFromSnapshot(route, ["/sm", org.id, "organization-suspended"]);
}
return true;
};