Skip to content

Commit

Permalink
[IMP] user_limited_access_settings: add demo section.
Browse files Browse the repository at this point in the history
[ADD] dependency to base_user_role to make compatibility with this module.
  • Loading branch information
legalsylvain committed Dec 16, 2024
1 parent 4466dfc commit d0a5407
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 62 deletions.
27 changes: 0 additions & 27 deletions user_limited_access_settings/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,3 @@ User Limited Access Settings
============================

Create a new Administration group with limited access to create only users and companies

Purpose
=======

This module does this and that...

Explain the use case.

Configuration
=============

To configure this module, you need to:

#. Go to ...

Usage
=====

To use this module, you need to:

#. Go to ...


How to test
===========

...
13 changes: 11 additions & 2 deletions user_limited_access_settings/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,21 @@
"license": "AGPL-3",
"author": "GRAP",
"website": "https://github.com/grap/grap-odoo-incubator",
"depends": ["base_setup", "auth_signup"],
"depends": [
# Odoo
"base_setup",
"auth_signup",
# OCA
"base_user_role",
],
"data": [
"security/res_groups.xml",
"security/ir_rule.xml",
"security/ir.model.access.csv",
"views/menu.xml",
],
"demo": [],
"demo": [
"demo/res_partner.xml",
"demo/res_users.xml",
],
}
15 changes: 15 additions & 0 deletions user_limited_access_settings/demo/res_partner.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2024 Sylvain LE GAL - GRAP
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->

<odoo>

<record id="partner_demo" model="res.partner">
<field name="name">Limited Access</field>
<field name="company_id" ref="base.main_company"/>
<field name="country_id" ref="base.us"/>
<field name="tz">Europe/Brussels</field>
<field name="email">[email protected]</field>
</record>

</odoo>
19 changes: 19 additions & 0 deletions user_limited_access_settings/demo/res_users.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2024 Sylvain LE GAL - GRAP
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->

<odoo>

<record id="user_demo" model="res.users">
<field name="partner_id" ref="partner_demo"/>
<field name="login">limited</field>
<field name="password">limited</field>
<field name="signature" type="html"><span>-- <br/>+Mr Limited Access</span></field>
<field name="company_id" ref="base.main_company"/>
<field name="groups_id" eval="[Command.set([
ref('user_limited_access_settings.group_limited_settings'),
ref('base.group_partner_manager'),
])]"/>
</record>

</odoo>
33 changes: 9 additions & 24 deletions user_limited_access_settings/models/res_users.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
# Copyright 2024 Sylvain LE GAL - GRAP
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, api, models
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


class ResUsers(models.Model):
_inherit = "res.users"

role_line_ids = fields.One2many(
groups="base.group_erp_manager,user_limited_access_settings.group_limited_settings",
)

role_ids = fields.One2many(
groups="base.group_erp_manager,user_limited_access_settings.group_limited_settings",
)

@api.constrains("groups_id")
def _check_escalation(self):
if self.env.user._is_admin():
Expand All @@ -33,26 +41,3 @@ def _check_escalation(self):
),
)
)

# def write(self, vals):
# print("write", self.ids, vals)
# if not self.env.user.has_privilege_escalation:
# group_ids = []
# for k, v in vals.items():
# if k.startswith("in_group_") and v:
# group_ids.append(int(k.split("in_group_")[1]))
# print("group_ids", group_ids)
# for group_id in group_ids:
# if group_id not in self.env.user.groups_id.ids:
# group = self.env["res.groups"].browse(group_id)
# raise ValidationError(
# _(
# "You can set the group '%(group_name)s'"
# " to users, because you are not member of this group.",
# group_name=group.display_name,
# )
# )

# # Peut être utiliser une contrainte ?

# return super().write(vals)
7 changes: 3 additions & 4 deletions user_limited_access_settings/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
This module adds a new basic Administration group named,
"Limited Settings".
This module adds a new basic Administration group named, "Limited Settings".

Members of this group can only create users and companies.
Members of this group can only create users and companies, and see User Roles.

Note:
**Note:**

We prevent right escalation, by preventing user to give access to
groups if he is not member of the group himself.
2 changes: 2 additions & 0 deletions user_limited_access_settings/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ access_change_password_wizard,access.change.password.wizard,base.model_change_pa
access_res_company_group_erp_manager,res_company group_erp_manager,base.model_res_company,group_limited_settings,1,1,1,1
access_res_users_group_erp_manager,res_users group_erp_manager,base.model_res_users,group_limited_settings,1,1,1,1
access_ir_module_category_group_user,ir_module_category group_user,base.model_ir_module_category,group_limited_settings,1,0,0,0
access_res_users_role_limited,access_res_users_role_limited,base_user_role.model_res_users_role,group_limited_settings,1,0,0,0
access_res_users_role_line_limited,access_res_users_role_line_limited,base_user_role.model_res_users_role_line,group_limited_settings,1,1,1,1
6 changes: 1 addition & 5 deletions user_limited_access_settings/tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@ class TestModule(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.demo_user = cls.env.ref("base.user_demo")
cls.demo_user = cls.env.ref("user_limited_access_settings.user_demo")
cls.limited_group = cls.env.ref(
"user_limited_access_settings.group_limited_settings"
)
cls.random_group = cls.env.ref("base.group_private_addresses")
cls.demo_user.groups_id = [
Command.link(cls.limited_group.id),
Command.unlink(cls.random_group.id),
]
cls.user_vals = {
"name": "User 1",
"login": "login1",
Expand Down

0 comments on commit d0a5407

Please sign in to comment.