Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
2 Respostas
218 Visualizações

Hi there

The internal user group does only have read access to the res.users model per Odoo default. Still, all users can open the "preferences", which is a view of res.users. How does Odoo do that?

I tried to create a custom view on res.users, containing only 3 custom fields. If I open this view with a dynamic acion (injects user id), it will throw an access error for internal users. If I give them write acces to res.users, it will work. But why does Odoo Preferences view work without write permission?

This is my action to open my custom view. It is called with a server action, this server action is referenced in the menu item.

def action_open_session_settings(self):
return {
'type': 'ir.actions.act_window',
'res_model': 'res.users',
'name': 'Session Settings',
'view_mode': 'form',
'view_id': self.env.ref('custom_module.view_sale_workflow_session_config_form').id,
'res_id': self.env.uid,
'target': 'new',
'context': {'create': 0},
}


Thank you in advance for your help!

Avatar
Cancelar
Melhor resposta

Hi,

Odoo’s Preferences view works for internal users because it uses a simplified form view (base.view_users_form_simple_modif) with form_view_initial_mode: 'edit' in the context, allowing users to edit their own res.users record (id = user.id) via a default security rule (base.res_users_rule_own). Your custom view throws an access error because internal users lack write access to res.users unless explicitly granted, and your view/action may not be configured to bypass this.

Fix: Update your server action to include form_view_initial_mode: 'edit' and ensure create/delete are disabled:

def action_open_session_settings(self):

    return {

        'type': 'ir.actions.act_window',

        'res_model': 'res.users',

        'name': 'Session Settings',

        'view_mode': 'form',

        'view_id': self.env.ref('custom_module.view_sale_workflow_session_config_form').id,

        'res_id': self.env.uid,

        'target': 'new',

        'context': {'create': False, 'delete': False, 'form_view_initial_mode': 'edit'},

    }


Hope it helps

Avatar
Cancelar
Melhor resposta

Hello,

The Preference menu work is because it has access rules set into it. Those access rules are bound to the groups. If you activate the debug mode and open the "View Access Rights", you will see these rules

Hope this helps, best regards

Altela (altelasoftware.com)

Avatar
Cancelar
Autor

Hi there, thank you for the quick response. I cannot see your image. I checked, and the access rules are exactly the same as on my custom view. So this does not answer my question yet.