Disable the menu button for particular User

#1

I’m having the menu for “cancel claim”. This menu needs to access only for the “admin” and “workflow” role person not other role persons.

I have tried the below code to disable to make the disable, but it’s not working. still the menu is working for the other roles.

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)'
});

I need the menu needs to work only for the CoreAdministrator and CoreWorkflowAdministrator, not other roles.

0 Likes

#2

This code doesn’t make much sense to me. It looks highly custom to your app. Is there an Ember question? I don’t think Ember itself will solve your problem.

Have you considered using an abilities addon like ember-can? The DSL/API might prove to be easier to reason about.

2 Likes

#3

I agree. In general in Ember someone has usually solved your problem before you. In this case, use the ember-can addon.

It’s rare to need to roll your own architectural services in Ember. Before doing so, ask in the forums for a generic solution, or just google. 90% of the time you won’t need to do the work yourself.

0 Likes

#4

@Twinkletoes, @sukima I think the main problem is that @Boo is using Ember 1.4 (at least based on information provided in some previous threads, maybe up to 1.13 now?) so any modern addon will be unusable.

Unfortunately very few people in this board are likely to be able to help with such an old version of Ember and the few who could would probaby need a lot more context or even access to the entire codebase.

0 Likes

#5

ember-can was usable back in the 1.10-1.13 era, as I was using it back then. But it assumed that folks were using ember-cli. @Boo do you have any additional details on things? Generally making a button go away is something that is easiest to do with the help of the templating layer instead of strictly in JS …

0 Likes