Skip to content
Tutorials Center
My learning

Topics

Lesson 25 of 39 ยท Security and Access

Users and Groups

Understand Odoo security basics: res.users, res.groups, implied groups, categories, the superuser and how groups connect to menus, views and access rights.

Every business system must answer the question "who may do what?". Odoo answers it in layers, and the base layer is the group. A user belongs to groups; menus, views, fields, model access rights and record rules are all attached to groups. Learn this layer first and the other security lessons (Access Rights, Record Rules) become easy.

The real Odoo ORM cannot run here, so Odoo code is read-only and the examples use Python stand-ins, including a resolver that follows implied groups the way Odoo does.

Users

A user is a record of res.users. Each user is attached to a partner (res.partner, the person or company record), has a login and password, a language, a time zone, allowed companies and a set of groups in group_ids (named groups_id in Odoo 17 and earlier). There are two kinds:

  • Internal users work in the backend (sales people, accountants). They consume a licence in Enterprise.
  • Portal and public users are customers and anonymous website visitors. They have a very limited set of rights, and the public user is the account used for logged-out website requests.

The special user with id 1, OdooBot, is the technical superuser identity, and the administrator account (id 2 in a standard database) is a normal user who happens to have the Settings group. The "superuser" mode (sudo() or env.su) bypasses security checks in code; you will see why it needs care in Field Security and sudo.

Groups

A group is a record of res.groups. It has a name, a category, users, and a list of implied groups.

XML
<record id="group_library_user" model="res.groups">
  <field name="name">User</field>
  <field name="category_id" ref="module_category_library"/>
</record>

<record id="group_library_manager" model="res.groups">
  <field name="name">Manager</field>
  <field name="category_id" ref="module_category_library"/>
  <field name="implied_ids" eval="[(4, ref('group_library_user'))]"/>
</record>

Because Manager implies User, anyone made a Manager automatically gets the User group too. The settings screen shows groups of one category as a dropdown, for example Library: User / Manager, which is why the category matters. In recent versions a category is called a privilege, but the idea is identical.

flowchart LR
    M["Library / Manager"] -->|implies| U["Library / User"]
    U -->|implies| B["base.group_user<br/>Internal User"]
    A["Settings / Administrator"] -->|implies| B

Implied groups form a chain. Granting the top group grants everything below it.

Standard groups you will meet constantly:

XML ID Meaning
base.group_user Internal user, the base of all backend access
base.group_portal Portal customers
base.group_public Anonymous website visitors
base.group_system Settings administrator (technical access)
base.group_erp_manager Access rights administrator
base.group_no_one Technical features, active in developer mode

Where groups are used

  • On menu items: <menuitem ... groups="library.group_library_manager"/>.
  • On any view element: <field name="cost" groups="library.group_library_manager"/>; the element is removed from the arch for other users.
  • On Python fields: cost = fields.Float(groups="library.group_library_manager").
  • In model access rows (ir.model.access.csv) and record rules.
  • In code: self.env.user.has_group("library.group_library_manager").

A resolver for implied groups

This stand-in stores groups with their implied groups and computes the full set a user ends up with, like Odoo does when it writes the "all groups" cache.

Python Resolve implied groups

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

This second stand-in shows the effect: the same menu tree is filtered depending on the groups.

Python Filter a menu by groups

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice that Library itself, which has no required group, would only show when at least one child is visible in Odoo; our stand-in keeps it simple.

Good practice

  • Create at most two or three groups per app (User, Manager, sometimes Officer). More groups mean a harder test matrix.
  • Make higher groups imply lower ones so you only need to assign one.
  • Never give end users the Settings group just so they can see something; add a proper group instead.
  • Test with a non-admin account. Many bugs only show up when the admin bypass (base.group_system is not a magic bypass, but admins are often also members of everything) is absent.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does implied_ids on a group do?

    If Manager implies User, assigning Manager also grants User.
  2. 2. Which group represents anonymous website visitors?

    base.group_public is for logged-out visitors, while base.group_portal is for logged-in customers and partners.
  3. 3. How do you restrict a single field on a form to a group?

    groups="module.group" removes the field for people outside the group.
  4. 4. What is the purpose of a group category in the settings screen?

    The groups of a category are shown together, for example Library: User or Manager, so an administrator picks one level.

Summary

  • Users are res.users; groups are res.groups; groups are the base of all permissions.
  • Implied groups chain levels: assigning Manager also assigns User.
  • Groups gate menus, view elements, fields, model access and record rules.
  • Internal, portal and public users have very different default rights.
  • Keep group sets small, make higher groups imply lower ones, and test as a non-admin.

Next: Access Rights with ir.model.access