Updates to new Horizon action API

Replaces initScope (deprecated and removed) with initAction
in resource action definitions, which also fixes policy
rule checks for these actions.

Change-Id: I09fd02baee6bd223ffbd0f29790e501fe4787f40
Closes-Bug: 1750384
This commit is contained in:
mareklycka 2018-08-01 18:00:26 +02:00
parent e41d74a03d
commit 66953e66c2
8 changed files with 32 additions and 28 deletions

View File

@ -98,7 +98,7 @@
};
var service = {
initScope: initScope,
initAction: initAction,
allowed: allowed,
perform: perform
};
@ -107,7 +107,7 @@
/////////////////
function initScope() {
function initAction() {
dnsServiceEnabled = serviceCatalog.ifTypeEnabled('dns');
}

View File

@ -72,7 +72,7 @@
};
var service = {
initScope: initScope,
initAction: initAction,
allowed: allowed,
perform: perform
};
@ -81,7 +81,7 @@
/////////////////
function initScope() {
function initAction() {
dnsServiceEnabled = serviceCatalog.ifTypeEnabled('dns');
}

View File

@ -59,7 +59,7 @@
};
var service = {
initScope: initScope,
initAction: initAction,
allowed: allowed,
perform: perform
};
@ -68,7 +68,7 @@
/////////////////
function initScope() {
function initAction() {
createRecordSetPolicy = policy.ifAllowed({rules: [['dns', 'create_recordset']]});
dnsServiceEnabled = serviceCatalog.ifTypeEnabled('dns');
}

View File

@ -56,12 +56,12 @@
deleteModal,
toast
) {
var scope, context, deletePromise;
var context, deletePromise;
var notAllowedMessage = gettext("You are not allowed to delete record sets: %s");
var allowedRecordsets = [];
var service = {
initScope: initScope,
initAction: initAction,
allowed: allowed,
perform: perform
};
@ -70,17 +70,18 @@
//////////////
function initScope(newScope) {
scope = newScope;
function initAction() {
context = { };
deletePromise = policy.ifAllowed({rules: [['dns', 'delete_recordset']]});
}
function perform(items) {
function perform(items, scope) {
var recordsets = angular.isArray(items) ? items : [items];
context.labels = labelize(recordsets.length);
context.deleteEntity = deleteRecordSet;
return $qExtensions.allSettled(recordsets.map(checkPermission)).then(afterCheck);
return $qExtensions
.allSettled(recordsets.map(checkPermission))
.then(afterCheck.bind(this, scope));
}
function allowed(recordset) {
@ -100,7 +101,7 @@
return {promise: allowed(recordset), context: recordset};
}
function afterCheck(result) {
function afterCheck(scope, result) {
var outcome = $q.reject(); // Reject the promise by default
if (result.fail.length > 0) {
toast.add('error', getMessage(notAllowedMessage, result.fail));

View File

@ -63,7 +63,7 @@
};
var service = {
initScope: initScope,
initAction: initAction,
allowed: allowed,
perform: perform
};
@ -72,7 +72,7 @@
/////////////////
function initScope() {
function initAction() {
updateRecordSetPolicy = policy.ifAllowed({rules: [['dns', 'update_recordset']]});
dnsServiceEnabled = serviceCatalog.ifTypeEnabled('dns');
}

View File

@ -57,7 +57,7 @@
};
var service = {
initScope: initScope,
initAction: initAction,
allowed: allowed,
perform: perform
};
@ -66,7 +66,7 @@
/////////////////
function initScope() {
function initAction() {
createZonePolicy = policy.ifAllowed({rules: [['dns', 'create_zone']]});
dnsServiceEnabled = serviceCatalog.ifTypeEnabled('dns');
}

View File

@ -56,11 +56,11 @@
toast,
resourceType
) {
var scope, context, deleteZonePromise;
var context, deleteZonePromise;
var notAllowedMessage = gettext("You are not allowed to delete zones: %s");
var service = {
initScope: initScope,
initAction: initAction,
allowed: allowed,
perform: perform
};
@ -69,17 +69,20 @@
//////////////
function initScope(newScope) {
scope = newScope;
context = { };
deleteZonePromise = policy.ifAllowed({rules: [['dns', 'delete_zone']]});
function initAction() {
context = { };
deleteZonePromise = policy.ifAllowed({rules: [['dns', 'delete_zone']]});
}
function perform(items) {
function perform(items, scope) {
var zones = angular.isArray(items) ? items : [items];
context.labels = labelize(zones.length);
context.deleteEntity = deleteZone;
return $qExtensions.allSettled(zones.map(checkPermission)).then(afterCheck);
return $qExtensions
.allSettled(zones.map(checkPermission))
.then(
afterCheck.bind(this, scope)
);
}
function allowed(zone) {
@ -100,7 +103,7 @@
return {promise: allowed(zone), context: zone};
}
function afterCheck(result) {
function afterCheck(scope, result) {
var outcome = $q.reject(); // Reject the promise by default
if (result.fail.length > 0) {
toast.add('error', getMessage(notAllowedMessage, result.fail));

View File

@ -59,7 +59,7 @@
};
var service = {
initScope: initScope,
initAction: initAction,
allowed: allowed,
perform: perform
};
@ -68,7 +68,7 @@
/////////////////
function initScope() {
function initAction() {
updateZonePolicy = policy.ifAllowed({rules: [['dns', 'update_zone']]});
dnsServiceEnabled = serviceCatalog.ifTypeEnabled('dns');
}