mirror of
https://github.com/portainer/portainer.git
synced 2025-08-09 07:45:22 +02:00
fix(app): skip authorizations in CE [EE-2423] (#6431)
* feat(app): check auth on ee only * refactor(features): load edition from env var * fix(containers): show empty message if no containers
This commit is contained in:
parent
2c4c638f46
commit
b588d901cf
6 changed files with 35 additions and 19 deletions
|
@ -10,7 +10,7 @@ const state: ServiceState = {
|
|||
features: <Record<FeatureId, Edition>>{},
|
||||
};
|
||||
|
||||
export async function init(edition: Edition = Edition.CE) {
|
||||
export async function init(edition: Edition) {
|
||||
// will be loaded on runtime
|
||||
const currentEdition = edition;
|
||||
const features = {
|
||||
|
|
|
@ -33,13 +33,20 @@ export function useUser() {
|
|||
return context;
|
||||
}
|
||||
|
||||
export function useAuthorizations(authorizations: string | string[]) {
|
||||
export function useAuthorizations(
|
||||
authorizations: string | string[],
|
||||
adminOnlyCE = false
|
||||
) {
|
||||
const authorizationsArray =
|
||||
typeof authorizations === 'string' ? [authorizations] : authorizations;
|
||||
|
||||
const { user } = useUser();
|
||||
const { params } = useCurrentStateAndParams();
|
||||
|
||||
if (process.env.PORTAINER_EDITION === 'CE') {
|
||||
return !adminOnlyCE || isAdmin(user);
|
||||
}
|
||||
|
||||
const { endpointId } = params;
|
||||
if (!endpointId) {
|
||||
return false;
|
||||
|
@ -118,6 +125,6 @@ export function UserProvider({ children }: UserProviderProps) {
|
|||
}
|
||||
}
|
||||
|
||||
function isAdmin(user: UserViewModel): boolean {
|
||||
return user.Role === 1;
|
||||
function isAdmin(user?: UserViewModel | null) {
|
||||
return !!user && user.Role === 1;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue