Action Button disabled when there is no write access

77 views
Skip to first unread message

Khurram Shahzad

unread,
Mar 21, 2017, 6:58:23 AM3/21/17
to try...@googlegroups.com
Dear All,

I have created a model and given 'read' and 'write'  access to a user. I have placed an action button on this model's form view so that user can start a wizard which uses the ID of the model to do something. The user can see the button enabled and can start the wizard by clicking it.

Now. what we want is to disallow the user to 'change' the record. For this, we removed 'write' access from the user. As a side effect, the action button was also disabled. How can we keep this action button enabled with read only access on the model?

--
 
Regards,
Khurram.

Sergi Almacellas Abellana

unread,
Mar 21, 2017, 7:06:09 AM3/21/17
to try...@googlegroups.com
El 21/03/17 a les 11:58, Khurram Shahzad ha escrit:
> Dear All,

Hi Khurram,
You should explicitly gran access to this button to the user [1]. If no
access rules exist for the button only users with write access on the
model are allowed to click it[2]

Hope it helps!


[1]
http://doc.tryton.org/4.2/trytond/doc/topics/access_rights.html?highlight=button#button
[2]
http://hg.tryton.org/trytond/file/dc9bcb369211/trytond/model/modelview.py#l596

--
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk

Khurram Shahzad

unread,
Mar 21, 2017, 8:54:18 AM3/21/17
to try...@googlegroups.com
Dear Sergi,
Thanks a lot.

I opened Admin -> Model -> Model Access -> Buttons and tried to create a new record but I can not enter the values for Model and Name. The only thing I can select is the group which is not sufficient to save the record. Is this the right place to add access rule for buttons? Or, I should define these rules in the xml files?
--
 
Regards,
Khurram.

Sergi Almacellas Abellana

unread,
Mar 21, 2017, 9:17:12 AM3/21/17
to try...@googlegroups.com
El 21/03/17 a les 13:54, Khurram Shahzad ha escrit:
> I opened Admin -> Model -> Model Access -> Buttons and tried to create a
> new record but I can not enter the values for Model and Name. The only
> thing I can select is the group which is not sufficient to save the
> record. Is this the right place to add access rule for buttons?
Yes, it is the right place.

Or, I
> should define these rules in the xml files?
I normally define the button rules on the xml on the same module where
the button is added and don't modify them on the user interface.

Indeed, once the button is defined you can add new groups to allow them
to access the button.

Cédric Krier

unread,
Mar 21, 2017, 9:40:05 AM3/21/17
to try...@googlegroups.com
On 2017-03-21 14:17, Sergi Almacellas Abellana wrote:
> El 21/03/17 a les 13:54, Khurram Shahzad ha escrit:
> > should define these rules in the xml files?
> I normally define the button rules on the xml on the same module where the
> button is added and don't modify them on the user interface.

Creating button from the UI is disabled because there is a unique
constraint on it and we do not want to have module installation failing
because user has created duplicated button.
But maybe we should have a test to ensure that all buttons a registered
in ir.model.button?

--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

Khurram Shahzad

unread,
Mar 21, 2017, 1:20:49 PM3/21/17
to try...@googlegroups.com
Dear Sergi and Cedric,

Thanks for your support. I added following record in the xml file:

<record model="ir.model.button" id="record_round_button">
            <field name="name">recordrounding</field>
            <field name="model" search="[('model', '=', 'gnuhealth.inpatient.registration')]"/>           
        </record>

and in .py:

 cls._buttons.update({               
        'recordrounding': {
                    'invisible': Not(Equal(Eval('state'), 'hospitalized')),
                    },})


@classmethod
    @ModelView.button_action('health_proc.act_create_inpatient_rounding')
    def recordrounding(cls, registrations):
        pass

When I updated the module, a record appeared in the list from Admin -> Model -> Model Access -> Buttons. I updated this record and allowed access to two groups.

But, still a user having access to one of these groups sees this button disabled.

Any other configuration is required?
 
Regards,
Khurram.

Cédric Krier

unread,
Mar 21, 2017, 1:50:06 PM3/21/17
to try...@googlegroups.com
On 2017-03-21 22:20, Khurram Shahzad wrote:
> When I updated the module, a record appeared in the list from Admin ->
> Model -> Model Access -> Buttons. I updated this record and allowed access
> to two groups.
>
> But, still a user having access to one of these groups sees this button
> disabled.
>
> Any other configuration is required?

This behaviour is only available since 4.2. In prior version you need to
have write access to use buttons.

Khurram Shahzad

unread,
Mar 21, 2017, 11:10:21 PM3/21/17
to try...@googlegroups.com

On Tue, Mar 21, 2017 at 10:49 PM, Cédric Krier <cedric...@b2ck.com> wrote:
On 2017-03-21 22:20, Khurram Shahzad wrote:
> When I updated the module, a record appeared in the list from Admin ->
> Model -> Model Access -> Buttons. I updated this record and allowed access
> to two groups.
>
> But, still a user having access to one of these groups sees this button
> disabled.
>
> Any other configuration is required?

This behaviour is only available since 4.2. In prior version you need to
have write access to use buttons.

Oops! But, Thanks for the information.
 
Regards,
Khurram.

Sergi Almacellas Abellana

unread,
Mar 22, 2017, 8:37:26 AM3/22/17
to try...@googlegroups.com
El 21/03/17 a les 14:37, Cédric Krier ha escrit:
> But maybe we should have a test to ensure that all buttons a registered
> in ir.model.button?
I think it will be a good addition (and if IIRC it's not the first time
we discuss about it). So I created https://bugs.tryton.org/issue6389
Reply all
Reply to author
Forward
0 new messages