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

pull/7326/head
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

@ -322,8 +322,20 @@ angular.module('portainer.kubernetes', ['portainer.app', registriesModule, custo
},
};
const endpointKubernetesConfiguration = {
name: 'kubernetes.cluster.setup',
url: '/configure',
views: {
'content@': {
templateUrl: './views/configure/configure.html',
controller: 'KubernetesConfigureController',
controllerAs: 'ctrl',
},
},
};
const endpointKubernetesSecurityConstraint = {
name: 'portainer.k8sendpoint.securityConstraint',
name: 'kubernetes.cluster.securityConstraint',
url: '/securityConstraint',
views: {
'content@': {
@ -362,6 +374,7 @@ angular.module('portainer.kubernetes', ['portainer.app', registriesModule, custo
$stateRegistryProvider.register(volume);
$stateRegistryProvider.register(registries);
$stateRegistryProvider.register(registriesAccess);
$stateRegistryProvider.register(endpointKubernetesConfiguration);
$stateRegistryProvider.register(endpointKubernetesSecurityConstraint);
},
]);

View File

@ -2,7 +2,7 @@
<div ng-if="$ctrl.isAdmin()" class="small" ng-show="$ctrl.serviceType === $ctrl.KubernetesApplicationPublishingTypes.LOAD_BALANCER && !$ctrl.loadbalancerEnabled">
<p style="margin-top: 10px">
<pr-icon icon="'alert-circle'" mode="'primary'" feather="true"></pr-icon> No Load balancer is available in this cluster, click
<a ui-sref="portainer.k8sendpoint.kubernetesConfig({id: $ctrl.state.endpointId})">here</a> to configure load balancer.
<a ui-sref="kubernetes.cluster.setup">here</a> to configure load balancer.
</p>
</div>
<div ng-if="!$ctrl.isAdmin()" class="small" ng-show="$ctrl.serviceType === $ctrl.KubernetesApplicationPublishingTypes.LOAD_BALANCER && !$ctrl.loadbalancerEnabled">

View File

@ -56,7 +56,7 @@
<div ng-if="$ctrl.isAdmin()" class="small">
<p style="margin-top: 10px">
<pr-icon icon="'alert-triangle'" mode="'warning'" feather="true"></pr-icon> Ingress is not configured in this namespace, select another namespace or click
<a ui-sref="portainer.k8sendpoint.kubernetesConfig({id: $ctrl.state.endpointId})">here</a> to configure ingress.
<a ui-sref="kubernetes.cluster.setup">here</a> to configure ingress.
</p>
</div>
<div ng-if="!$ctrl.isAdmin()" class="small">

View File

@ -1033,7 +1033,7 @@
<p ng-if="!ctrl.isAdmin"> This feature is currently disabled and must be enabled by an administrator user. </p>
<p ng-if="ctrl.isAdmin">
Server metrics features must be enabled in the
<a ui-sref="portainer.k8sendpoint.kubernetesConfig({id: ctrl.endpoint.Id})" class="ctrl.isAdmin">environment configuration view</a>.
<a ui-sref="kubernetes.cluster.setup" class="ctrl.isAdmin">environment configuration view</a>.
</p>
</div>
</div>

View File

@ -269,7 +269,7 @@ class KubernetesConfigureController {
actionInProgress: false,
displayConfigureClassPanel: {},
viewReady: false,
endpointId: this.$state.params.id,
endpointId: this.$state.params.endpointId,
duplicates: {
ingressClasses: new KubernetesFormValidationReferences(),
},

View File

@ -186,8 +186,7 @@
<div class="form-group" ng-if="$ctrl.formValues.IngressClasses.length === 0">
<div class="col-sm-12 small text-muted">
The ingress feature must be enabled in the
<a ui-sref="portainer.k8sendpoint.kubernetesConfig({id: $ctrl.endpoint.Id})">environment configuration view</a> to be able to register ingresses inside this
namespace.
<a ui-sref="kubernetes.cluster.setup">environment configuration view</a> to be able to register ingresses inside this namespace.
</div>
</div>

View File

@ -152,8 +152,7 @@
<div class="form-group" ng-if="ctrl.formValues.IngressClasses.length === 0">
<div class="col-sm-12 small text-muted">
The ingress feature must be enabled in the
<a ui-sref="portainer.k8sendpoint.kubernetesConfig({id: ctrl.endpoint.Id})">environment configuration view</a> to be able to register ingresses inside this
namespace.
<a ui-sref="kubernetes.cluster.setup">environment configuration view</a> to be able to register ingresses inside this namespace.
</div>
</div>

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 {

View File

@ -180,6 +180,7 @@ export function DockerSidebar({ environmentId, environment }: Props) {
<Authorized
authorizations="PortainerEndpointUpdateSettings"
adminOnlyCE
environmentId={environmentId}
>
<SidebarItem
to="docker.featuresConfiguration"

View File

@ -47,7 +47,10 @@ export function KubernetesSidebar({ environmentId }: Props) {
data-cy="k8sSidebar-namespaces"
/>
<Authorized authorizations="HelmInstallChart">
<Authorized
authorizations="HelmInstallChart"
environmentId={environmentId}
>
<SidebarItem
to="kubernetes.templates.helm"
params={{ endpointId: environmentId }}
@ -86,18 +89,26 @@ export function KubernetesSidebar({ environmentId }: Props) {
params={{ endpointId: environmentId }}
data-cy="k8sSidebar-cluster"
>
<Authorized authorizations="K8sClusterSetupRW" adminOnlyCE>
<Authorized
authorizations="K8sClusterSetupRW"
adminOnlyCE
environmentId={environmentId}
>
<SidebarItem
to="portainer.k8sendpoint.kubernetesConfig"
to="kubernetes.cluster.setup"
params={{ id: environmentId }}
label="Setup"
data-cy="k8sSidebar-setup"
/>
</Authorized>
<Authorized authorizations="K8sClusterSetupRW" adminOnlyCE>
<Authorized
authorizations="K8sClusterSetupRW"
adminOnlyCE
environmentId={environmentId}
>
<SidebarItem
to="portainer.k8sendpoint.securityConstraint"
to="kubernetes.cluster.securityConstraint"
params={{ id: environmentId }}
label="Security constraints"
data-cy="k8sSidebar-securityConstraints"