AnsweredAssumed Answered

How can I configure ACL to allow change to "assigned user" on Account when Account is unassigned?

Question asked by KarlMetum KarlMetum on Jun 30, 2014
Latest reply on Oct 21, 2015 by KarlMetum KarlMetum
We would like to be able to allow users to assign unassigned Accounts to themselves. 
Let's say User A goes to an account which he currently is assigned to. 
User A removes himself from the account by clearing out the "Assigned to" field. 
User B then goes to this account and changes "Assigned to" to his own name. 
How would one implement this?

In our setup users may only edit Accounts where they are owners. This is controlled by the Sugar ACL. 

I have tried with the following approach:

I added a custom button on the Account record view that triggers a "AssignToMe"-event. 

Inside custom/clients/base/views/record/record.php:

array (       
'type' => 'assignToMe',
   'event' => 'button:assign_to_me:click',
   'name' => 'assignToMe',
   'label' => 'LBL_ASSIGN_TO_ME_LABEL',
   'css_class' => 'btn btn-success',
   'showOn' => 'view',
   'acl_action' => 'view',
),

Inside custom/clients/base/fields/assignToMe/assignToMe.js:
({    
     extendsFrom: 'RowactionField',
    initialize: function(options) {
        app.view.invokeParent(this, {type: 'field', name: 'rowaction', method: 'initialize', args: [options]});
        this.type = 'rowaction';
    },
    _render: function() {
        var assigned_user = this.model.get('assigned_user_id');
        if (assigned_user) {
            this.hide();
        } else {
            this._super('_render');
        }
    },
    rowActionSelect: function() {
        if(this.isDisabled()){
            return;
        }
        this.model.set('assigned_user_id', app.user.get('id'));
        this.model.save();
        this.hide();
    }
})

The only problem is that this only works for Admin users because they are allowed to edit any Account while regular users get the error (in the console): 'ERROR[2014-6-30 14:00:12]: Not allowed to perform action "save" on this record'

In short: I would like to be able to override the ACL and allow edit of "assigned user" when "assign user" is empty.

Outcomes