11import ProvCluster from '@shell/models/provisioning.cattle.io.cluster' ;
2- import { DEFAULT_WORKSPACE , HCI } from '@shell/config/types' ;
2+ import { DEFAULT_WORKSPACE , HCI , MANAGEMENT , CAPI } from '@shell/config/types' ;
33import { HARVESTER_NAME as VIRTUAL } from '@shell/config/features' ;
44import { colorForState , stateDisplay , STATES_ENUM } from '@shell/plugins/dashboard-store/resource-class' ;
5-
65export default class HciCluster extends ProvCluster {
76 get isSupportedHarvester ( ) {
87 return this . _isSupportedHarvester === undefined ? true : this . _isSupportedHarvester ;
@@ -44,6 +43,13 @@ export default class HciCluster extends ProvCluster {
4443 // We do not allow users to edit Harvester clusters from Cluster Management, so we need to re-enable that action here.
4544 get _availableActions ( ) {
4645 const out = super . _availableActions ;
46+
47+ if ( ! this . canCreateAndManageCluster ) {
48+ const allowActions = [ 'goToViewYaml' , 'download' , 'viewInApi' ] ;
49+
50+ return out . filter ( ( action ) => allowActions . includes ( action . action ) ) ;
51+ }
52+
4753 const edit = out . find ( ( action ) => action . action === 'goToEdit' ) ;
4854
4955 if ( edit ) {
@@ -53,6 +59,17 @@ export default class HciCluster extends ProvCluster {
5359 return out ;
5460 }
5561
62+ get canCreateAndManageCluster ( ) {
63+ // we check MANAGEMENT.CLUSTER (management.cattle.io.cluster) to avoid standard user role to create or manage the harvester clusters.
64+ const mgmtClusterSchema = this . $rootGetters [ 'management/schemaFor' ] ( MANAGEMENT . CLUSTER ) ;
65+ const schema = this . $rootGetters [ 'management/schemaFor' ] ( CAPI . RANCHER_CLUSTER ) ;
66+
67+ const mgmtClusterCreate = ! ! mgmtClusterSchema ?. collectionMethods ?. find ( ( x ) => x . toLowerCase ( ) === 'post' ) ;
68+ const clusterCreate = ! ! schema ?. collectionMethods ?. find ( ( x ) => x . toLowerCase ( ) === 'post' ) ;
69+
70+ return clusterCreate && mgmtClusterCreate ;
71+ }
72+
5673 get stateColor ( ) {
5774 if ( ! this . isSupportedHarvester ) {
5875 return colorForState ( STATES_ENUM . DENIED ) ;
@@ -98,7 +115,8 @@ export default class HciCluster extends ProvCluster {
98115 }
99116
100117 get disableResourceDetailDrawerConfigTab ( ) {
101- return false ;
118+ // if user is not allowed to create or manage the cluster, we will disable the edit config tab in resource detail drawer.
119+ return ! this . canCreateAndManageCluster ;
102120 }
103121
104122 get fullDetailPageOverride ( ) {
0 commit comments