我正在使用“取消声明”菜单。该菜单仅需要访问“管理员”和“工作流程”角色而不是其他角色。
我尝试了以下代码来禁用以使其禁用,但是它不起作用。菜单仍然可以用于其他角色。
Core.Action({
id: "Core:releaseTasks",
icon: 'workflow_task_claim_cancel',
invoke: function (context) {
context.setProperties({
pool: 'release',
skipTitle: this.get('messages.skip.title'),
skipMessage: this.get('messages.skip.message'),
taskIsValidForAction: function (task) {
var assignee = task.get('assigneeUserId'),
my = context.get('user'),
admin = my.roles.CoreAdministrator || my.roles.CoreWorkflowAdministrator;
return assignee && (assignee === my.name || admin);
},
taskIsInvalidForAction: function (task) {
var assignee = task.get('assigneeUserId'),
admin = context.get('user.roles.CoreAdministrator') || context.get('user.roles.CoreWorkflowAdministrator');
return assignee && (!admin && assignee !== context.get('user').name);
}
});
return Core.Action('Core:workflow:setPool', context);
},
isValid: 'areTasks && isAssigned && isOpenTask && (isMyTask || isWorkflowAdmin)'
});
Core.Action({
id: "Core:workflow:setPool",
invoke: function (context) {
if (!context.pool) {
return Promise.reject(new Error("Must specify a `pool`"));
}
return new Promise(function (resolve, reject) {
var tasks = context.get('tasks') || [];
if (context.get('task')) {
tasks.push(context.get('task'));
}
tasks = tasks.map(function (task) {
var ct = task.get('currentTask');
if (ct) {
return ct;
}
return task;
});
var requestData = [],
skipped = [],
requested = [];
var valid = context.taskIsValidForAction || function () { return true; },
invalid = context.taskIsInvalidForAction || function () { return false; };
tasks.forEach(function (task) {
if (valid.call(context, task)) {
requestData.push({ name: 'id', value: task.get('id') });
requestData.push({ name: 'pool', value: context.pool });
requested.push(task);
} else {
if (invalid.call(context, task)) {
skipped.push(task);
}
}
});
function notifySkipped() {
if (skipped.length) {
Core.notify({
title: context.skipTitle,
message: context.skipMessage +
skipped.map(function (task) {
return '<dt>' + task.get('name') + ' [' + task.get('id') + ']</dt>';
}).join('') + '</dl>'
});
}
}
if (requested.length === 0) {
notifySkipped();
resolve();
return;
}
return (Core.services({
type: 'post',
service: 'workflow/task/assignee',
data: requestData
})
.done(function (res) {
Core.model.ingestResources(res);
resolve();
})
.fail(function (xhr, status, error) {
Core.Error.show(error);
})
.always(function () {
tasks.forEach(function (task) {
if (Ember.get(task, 'isClip')) {
Core.model.clip.clear();
}
});
Core.Tab.Workflow.getController().reloadResultSet();
Core.Tab.Workflow.getController().get('selection').clear();
notifySkipped();
resolve();
})
);
});
}
});
我需要菜单仅对CoreAdministrator和CoreWorkflowAdministrator起作用,而不对其他角色起作用。