-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
53ac02d
commit 0a3c0ce
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
...e/bit-web/src/app/secrets-manager/service-accounts/guards/service-account-access.guard.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { inject } from "@angular/core"; | ||
import { ActivatedRouteSnapshot, CanActivateFn, createUrlTreeFromSnapshot } from "@angular/router"; | ||
|
||
import { ServiceAccountService } from "../service-account.service"; | ||
|
||
/** | ||
* Redirects to service accounts page if the user doesn't have access to service account. | ||
*/ | ||
export const serviceAccountAccessGuard: CanActivateFn = async (route: ActivatedRouteSnapshot) => { | ||
const serviceAccountService = inject(ServiceAccountService); | ||
|
||
try { | ||
const serviceAccount = await serviceAccountService.getByServiceAccountId( | ||
route.params.serviceAccountId, | ||
route.params.organizationId | ||
); | ||
if (serviceAccount) { | ||
return true; | ||
} | ||
} catch { | ||
return createUrlTreeFromSnapshot(route, [ | ||
"/sm", | ||
route.params.organizationId, | ||
"service-accounts", | ||
]); | ||
} | ||
return createUrlTreeFromSnapshot(route, ["/sm", route.params.organizationId, "service-accounts"]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters