refactor: get value from parent class

Signed-off-by: Yi-Ya Chen <yiya.chen@suse.com>
This commit is contained in:
Yi-Ya Chen 2025-01-20 11:13:17 +08:00
parent fc2be69469
commit e95955fad6
No known key found for this signature in database
GPG Key ID: 9A2E6FBD33F68EDE

View File

@ -1,7 +1,5 @@
import pickBy from 'lodash/pickBy';
import {
CAPI, LONGHORN, POD, NODE, NORMAN
} from '@shell/config/types';
import { CAPI, LONGHORN, POD, NODE } from '@shell/config/types';
import { CAPI as CAPI_ANNOTATIONS } from '@shell/config/labels-annotations.js';
import { HCI as HCI_ANNOTATIONS } from '@pkg/harvester/config/labels-annotations';
import { clone } from '@shell/utils/object';
@ -469,35 +467,10 @@ export default class HciNode extends HarvesterResource {
return parseSi(this.reserved.memory || '0');
}
// returns the user role, either 'cluster-owner' or 'cluster-member'
async _getRoleTemplateId() {
try {
const templates = await this.$dispatch('rancher/findAll', { type: NORMAN.CLUSTER_ROLE_TEMPLATE_BINDING }, { root: true });
const currentUser = this.$rootGetters['rancher/all'](NORMAN.PRINCIPAL)?.[0];
const userRole = templates.find((template) => template.userPrincipalId === currentUser?.id);
return userRole?.roleTemplateId || 'cluster-member';
} catch (error) {
return 'cluster-member';
}
}
get canDelete() {
const nodes = this.$rootGetters['harvester/all'](NODE) || [];
const isSingleNode = nodes.length === 1;
if (isSingleNode) return false;
// access control is unavailable in standalone harvester
if (this.$rootGetters['isStandaloneHarvester']) return true;
if (this._canDelete === undefined) {
return this._getRoleTemplateId().then((id) => {
this._canDelete = id === 'cluster-owner';
});
}
return this._canDelete;
return nodes.length > 1 && super.canDelete;
}
get vlanStatuses() {