fix: disable delete action

Signed-off-by: Yi-Ya Chen <yiya.chen@suse.com>
(cherry picked from commit c791399a61264615f25b5e047e5e4c4eea3a8b91)
This commit is contained in:
Yi-Ya Chen 2025-01-13 12:41:08 +08:00 committed by Mergify
parent 752cf2e93a
commit 1cb16f0c74

View File

@ -3,7 +3,7 @@ import ResourceTable from '@shell/components/ResourceTable';
import Loading from '@shell/components/Loading';
import { STATE, NAME, AGE } from '@shell/config/table-headers';
import {
CAPI, METRIC, NODE, SCHEMA, LONGHORN, POD
CAPI, METRIC, NODE, SCHEMA, LONGHORN, POD, MANAGEMENT, NORMAN
} from '@shell/config/types';
import { allHash } from '@shell/utils/promise';
import metricPoller from '@shell/mixins/metric-poller';
@ -62,8 +62,42 @@ export default {
_hash.machines = this.$store.dispatch(`${ inStore }/findAll`, { type: CAPI.MACHINE });
}
if (
this.$store.getters['rancher/schemaFor'](NORMAN.PRINCIPAL) &&
this.$store.getters['rancher/schemaFor'](NORMAN.CLUSTER_ROLE_TEMPLATE_BINDING)
) {
_hash.normanPrincipal = this.$store.dispatch('rancher/findAll', { type: NORMAN.PRINCIPAL });
_hash.clusterRoleTemplateBinding = this.$store.dispatch(`management/findAll`, { type: MANAGEMENT.CLUSTER_ROLE_TEMPLATE_BINDING });
}
const hash = await allHash(_hash);
// Remove delete action if current user role is cluster member
if (hash.normanPrincipal && hash.clusterRoleTemplateBinding) {
const role = hash.clusterRoleTemplateBinding.find(
(template) => template.userPrincipalName === hash.normanPrincipal[0]?.id
);
const isClusterMember = role?.roleTemplateName === 'cluster-member';
if (isClusterMember) {
hash.nodes = hash.nodes.map((node) => {
const updatedActions = node.availableActions.map((action) => {
return action.action === 'promptRemove' ? { ...action, enabled: false } : action;
});
// keep availableActions non-enumerable
Object.defineProperty(node, 'availableActions', {
value: updatedActions,
writable: true,
enumerable: false,
configurable: true,
});
return node;
});
}
}
this.rows = hash.nodes;
},