ui: peer permission handling (#13724)

* Request peering permissions when peerings is active

* Update peering ability to use peering resource

* fix canDelete peer permission to check write permission

* use super call in abilities.peer#canDelete
This commit is contained in:
Michael Klein 2022-07-12 17:16:47 +02:00 committed by GitHub
parent a6634db4a5
commit 75768a2039
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View File

@ -4,7 +4,7 @@ import { inject as service } from '@ember/service';
export default class PeerAbility extends BaseAbility {
@service('env') env;
resource = 'operator';
resource = 'peering';
segmented = false;
get isLinkable() {
@ -12,7 +12,7 @@ export default class PeerAbility extends BaseAbility {
}
get canDelete() {
// TODO: Need to confirm these states
return !['DELETING', 'TERMINATED', 'UNDEFINED'].includes(this.item.State);
return !['DELETING', 'TERMINATED', 'UNDEFINED'].includes(this.item.State) && super.canDelete;
}
get canUse() {

View File

@ -57,6 +57,16 @@ const REQUIRED_PERMISSIONS = [
Access: 'write',
},
];
const PEERING_PERMISSIONS = [
{
Resource: 'peering',
Access: 'read',
},
{
Resource: 'peering',
Access: 'write',
},
];
export default class PermissionService extends RepositoryService {
@service('env') env;
@service('abilities') _can;
@ -146,7 +156,7 @@ export default class PermissionService extends RepositoryService {
@dataSource('/:partition/:nspace/:dc/permissions')
async findAll(params) {
params.resources = REQUIRED_PERMISSIONS;
params.resources = this.permissionsToRequest;
this.permissions = await this.findByPermissions(params);
/**/
// Temporarily revert to pre-1.10 UI functionality by overwriting frontend
@ -162,4 +172,12 @@ export default class PermissionService extends RepositoryService {
/**/
return this.permissions;
}
get permissionsToRequest() {
if (this._can.can('use peers')) {
return [...REQUIRED_PERMISSIONS, ...PEERING_PERMISSIONS];
} else {
return REQUIRED_PERMISSIONS;
}
}
}