1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-08 15:25:22 +02:00

fix(sidebar): show authorized links [EE-3610] (#7152)

This commit is contained in:
Chaim Lev-Ari 2022-07-22 04:14:31 +02:00 committed by GitHub
parent 005c48b1ad
commit 9a92b97b7e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 57 additions and 41 deletions

View file

@ -186,23 +186,6 @@ angular
},
};
var k8sendpoint = {
name: 'portainer.k8sendpoint',
url: '/:id',
};
const endpointKubernetesConfiguration = {
name: 'portainer.k8sendpoint.kubernetesConfig',
url: '/configure',
views: {
'content@': {
templateUrl: '../kubernetes/views/configure/configure.html',
controller: 'KubernetesConfigureController',
controllerAs: 'ctrl',
},
},
};
var edgeDeviceCreation = {
name: 'portainer.endpoints.newEdgeDevice',
url: '/newEdgeDevice',
@ -484,14 +467,12 @@ angular
$stateRegistryProvider.register(logout);
$stateRegistryProvider.register(endpoints);
$stateRegistryProvider.register(endpoint);
$stateRegistryProvider.register(k8sendpoint);
$stateRegistryProvider.register(endpointAccess);
$stateRegistryProvider.register(endpointKVM);
$stateRegistryProvider.register(edgeDeviceCreation);
$stateRegistryProvider.register(deviceImport);
$stateRegistryProvider.register(addFDOProfile);
$stateRegistryProvider.register(editFDOProfile);
$stateRegistryProvider.register(endpointKubernetesConfiguration);
$stateRegistryProvider.register(groups);
$stateRegistryProvider.register(group);
$stateRegistryProvider.register(groupAccess);

View file

@ -47,6 +47,7 @@ export function useUser() {
export function useAuthorizations(
authorizations: string | string[],
forceEnvironmentId?: EnvironmentId,
adminOnlyCE = false
) {
const { user } = useUser();
@ -58,7 +59,12 @@ export function useAuthorizations(
return false;
}
return hasAuthorizations(user, authorizations, endpointId, adminOnlyCE);
return hasAuthorizations(
user,
authorizations,
forceEnvironmentId || endpointId,
adminOnlyCE
);
}
export function isEnvironmentAdmin(
@ -114,15 +120,21 @@ export function hasAuthorizations(
interface AuthorizedProps {
authorizations: string | string[];
environmentId?: EnvironmentId;
adminOnlyCE?: boolean;
}
export function Authorized({
authorizations,
environmentId,
adminOnlyCE = false,
children,
}: PropsWithChildren<AuthorizedProps>) {
const isAllowed = useAuthorizations(authorizations, adminOnlyCE);
const isAllowed = useAuthorizations(
authorizations,
environmentId,
adminOnlyCE
);
return isAllowed ? <>{children}</> : null;
}

View file

@ -168,7 +168,7 @@ angular
EndpointService.createLocalKubernetesEndpoint(name, tagIds)
.then(function success(result) {
Notifications.success('Environment created', name);
$state.go('portainer.k8sendpoint.kubernetesConfig', { id: result.Id });
$state.go('kubernetes.cluster.setup', { endpoinId: result.Id });
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to create environment');
@ -282,7 +282,7 @@ angular
$state.go('portainer.endpoints.endpoint', { id: endpoint.Id });
break;
case PortainerEndpointTypes.AgentOnKubernetesEnvironment:
$state.go('portainer.k8sendpoint.kubernetesConfig', { id: endpoint.Id });
$state.go('kubernetes.cluster.setup', { endpoinId: endpoint.Id });
break;
default:
$state.go('portainer.endpoints', {}, { reload: true });

View file

@ -79,7 +79,7 @@
<span class="small text-muted">
<i class="fa fa-tools blue-icon" aria-hidden="true" style="margin-right: 2px"></i>
You should configure the features available in this Kubernetes environment in the
<a ui-sref="portainer.k8sendpoint.kubernetesConfig({id: endpoint.Id})">Kubernetes configuration</a> view.
<a ui-sref="kubernetes.cluster.setup({endpointId: endpoint.Id})">Kubernetes configuration</a> view.
</span>
</information-panel>
</div>

View file

@ -94,7 +94,7 @@ class InitEndpointController {
try {
this.state.actionInProgress = true;
const endpoint = await this.EndpointService.createLocalKubernetesEndpoint();
this.$state.go('portainer.k8sendpoint.kubernetesConfig', { id: endpoint.Id });
this.$state.go('kubernetes.cluster.setup', { endpointId: endpoint.Id });
} catch (err) {
this.Notifications.error('Failure', err, 'Unable to connect to the Kubernetes environment');
} finally {
@ -130,8 +130,8 @@ class InitEndpointController {
null,
null
);
const routeName = endpoint.Type === PortainerEndpointTypes.AgentOnKubernetesEnvironment ? 'portainer.k8sendpoint.kubernetesConfig' : 'portainer.home';
this.$state.go(routeName, { id: endpoint.Id });
const routeName = endpoint.Type === PortainerEndpointTypes.AgentOnKubernetesEnvironment ? 'kubernetes.cluster.setup' : 'portainer.home';
this.$state.go(routeName, { endpointId: endpoint.Id });
} catch (err) {
this.Notifications.error('Failure', err, 'Unable to connect to the Docker environment');
} finally {