Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
14385 Visualizzazioni

Hello,

I added some customed fields by classic inheritance in the res.users model, as follows :

class TrelloUsers(models.Model):
    _inherit='res.users'

    trello_api_key=fields.Char('Trello API Key')
    trello_secret_token=fields.Char('Trello Secret Token')

Then, I modified the "Preferences" view to add those fields :

<record id="trello_view_preference_form" model="ir.ui.view">
    <field name="model">res.users</field>
    <field name="inherit_id" ref="base.view_users_form_simple_modif" />
    <field name="arch" type="xml">
      <xpath expr="//group[3]" position="after">
        <group string="Trello Settings">
          <field string="API Key" name="trello_api_key" readonly="0" />
          <field string="Secret Token" name="trello_secret_token" readonly="0" />
        </group>
      </xpath>
    </field>
</record>

It aims at allowing the concerned user to specify the data in those fields. But when I try to modify those data as an employee user, instead of admin user, I get an access error stating that only admins can modify these fields.

I can’t find information about how to give a user the necessary rights to modify some fields in the res.users model, but still make sure they can’t modify data of other users.

Thanks.

Cyrille (La LibreRie)

Avatar
Abbandona
Risposta migliore

Hi,

As the logged in user if you are able to read those values, it means that you have got the read access to the model res.users, as you are getting the access right issue, it means that currently logged in user group have to no access/permission to write to the model res.users.


For currently logged in user group(if anything particular), else for the employee group, allow the write access to the model res.users.

Normally user have rights to edit their own data, make sure that there is no issue in changing the other values in the preference form. To adjust the access right issue, activate the developer mode and navigate to Settings -> Technical -> Security -> Access Control List / Record Rules and adjust the existing rule or add new one for your case.

 

Thanks

Avatar
Abbandona
Autore

The users can change the other values, but not the customed fields I added. I added a rule to give the employee group access to res.users. I does work now. Thanks for answer.

Risposta migliore

In odoo16 you must add your custom field in res.users to 

@property
def SELF_WRITEABLE_FIELDS(self):
""" The list of fields a user can write on their own user record.
In order to add fields, please override this property on model extensions.
"""
return ['signature', 'action_id', 'company_id', 'email', 'name', 'image_1920', 'lang', 'tz']

In your case, it should look like this

class Users(models.Model):
_inherit='res.users'

@property
def SELF_WRITEABLE_FIELDS(self):
return super().SELF_WRITEABLE_FIELDS + ['trello_api_key','trello_secret_token']

trello_api_key=fields.Char('Trello API Key')
    trello_secret_token=fields.Char('Trello Secret Token')
Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
0
ott 24
975
2
set 23
2404
0
feb 22
2661
1
gen 22
1742
0
apr 21
2007