mirror of
https://github.com/portainer/portainer.git
synced 2025-07-25 08:19:40 +02:00
feat(ui): restrict views by role [EE-6595] (#11010)
This commit is contained in:
parent
437831fa80
commit
f5f84c5fa4
22 changed files with 338 additions and 83 deletions
|
@ -1,28 +0,0 @@
|
|||
import { RawParams, useRouter } from '@uirouter/react';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
import { useCurrentUser } from './useUser';
|
||||
|
||||
type RedirectOptions = {
|
||||
to: string;
|
||||
params?: RawParams;
|
||||
};
|
||||
|
||||
/**
|
||||
* Redirects to the given route if the user is not a Portainer admin.
|
||||
* @param to The route to redirect to (default is `'portainer.home'`).
|
||||
* @param params The params to pass to the route.
|
||||
*/
|
||||
export function useAdminOnlyRedirect(
|
||||
{ to, params }: RedirectOptions = { to: 'portainer.home' }
|
||||
) {
|
||||
const router = useRouter();
|
||||
|
||||
const { isAdmin } = useCurrentUser();
|
||||
|
||||
useEffect(() => {
|
||||
if (!isAdmin) {
|
||||
router.stateService.go(to, params);
|
||||
}
|
||||
}, [isAdmin, to, params, router.stateService]);
|
||||
}
|
|
@ -138,11 +138,6 @@ export function useIsEnvironmentAdmin({
|
|||
|
||||
/**
|
||||
* will return true if the user has the authorizations. assumes the user is authenticated and not an admin
|
||||
* @param user
|
||||
* @param authorizations
|
||||
* @param environmentId
|
||||
* @param adminOnlyCE
|
||||
* @returns
|
||||
*/
|
||||
function hasAuthorizations(
|
||||
user: User,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue