Skip to content

Commit 3304703

Browse files
committed
[ADD] 16.0: base_group_erp_user
1 parent 79523b0 commit 3304703

File tree

23 files changed

+868
-0
lines changed

23 files changed

+868
-0
lines changed

base_group_erp_user/README.rst

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
===================
2+
Base Group Erp User
3+
===================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:f5447d6612e26998f20aa899bb8f2d09a3f933d5589af608f26c4b60b1015651
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--backend-lightgray.png?logo=github
20+
:target: https://github.com/OCA/server-backend/tree/16.0/base_group_erp_user
21+
:alt: OCA/server-backend
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/server-backend-16-0/server-backend-16-0-base_group_erp_user
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-backend&target_branch=16.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This modules add a new group "User" in "Administration" category. This
32+
group has basic features to create users and groups but is not allowed
33+
to modify the groups of a user, or the groups of a groups.
34+
35+
This module can also be used with base_group_erp_user role to allow
36+
"Administration Users" to create and edit roles without being able to
37+
modify inherited groups or linked users.
38+
39+
**Table of contents**
40+
41+
.. contents::
42+
:local:
43+
44+
Use Cases / Context
45+
===================
46+
47+
This module has been created in order to allow people creating users and
48+
groups without being able to modify the related security (model access,
49+
model rules, group's users, group's groups, etc). This module can also
50+
be used alongside base_user_group_mgmt to allow administration user to
51+
request the assignation of groups to specific users.
52+
53+
Bug Tracker
54+
===========
55+
56+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-backend/issues>`_.
57+
In case of trouble, please check there if your issue has already been reported.
58+
If you spotted it first, help us to smash it by providing a detailed and welcomed
59+
`feedback <https://github.com/OCA/server-backend/issues/new?body=module:%20base_group_erp_user%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
60+
61+
Do not contact contributors directly about support or help with technical issues.
62+
63+
Credits
64+
=======
65+
66+
Authors
67+
-------
68+
69+
* ACSONE SA/NV
70+
71+
Contributors
72+
------------
73+
74+
- Benjamin Willig [email protected] (https://acsone.eu)
75+
76+
Maintainers
77+
-----------
78+
79+
This module is maintained by the OCA.
80+
81+
.. image:: https://odoo-community.org/logo.png
82+
:alt: Odoo Community Association
83+
:target: https://odoo-community.org
84+
85+
OCA, or the Odoo Community Association, is a nonprofit organization whose
86+
mission is to support the collaborative development of Odoo features and
87+
promote its widespread use.
88+
89+
This module is part of the `OCA/server-backend <https://github.com/OCA/server-backend/tree/16.0/base_group_erp_user>`_ project on GitHub.
90+
91+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

base_group_erp_user/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import mixins
2+
from . import models
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2025 ACSONE SA/NV
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
{
5+
"name": "Base Group Erp User",
6+
"summary": """
7+
This module adds a new group in security management category.
8+
This group allows users to have basic features such as user
9+
or group creation. But they can't change groups associated to
10+
a group or groups associated to a user""",
11+
"version": "16.0.1.0.0",
12+
"license": "AGPL-3",
13+
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
14+
"website": "https://github.com/OCA/server-backend",
15+
"depends": [
16+
"base",
17+
],
18+
"data": [
19+
"security/res_groups.xml",
20+
"security/ir_model_access.xml",
21+
"security/ir_module_category.xml",
22+
"security/ir_rule.xml",
23+
"security/res_users.xml",
24+
"views/menus.xml",
25+
],
26+
"demo": [],
27+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import mixin_erp_user_forbidden_fields
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import logging
2+
3+
from odoo import SUPERUSER_ID, api, models
4+
5+
_logger = logging.getLogger(__name__)
6+
7+
8+
class MixinErpUserForbiddenFields(models.AbstractModel):
9+
_name = "mixin.erp.user.forbidden.fields"
10+
_description = "Mixin ERP User Forbidden Fields"
11+
12+
@api.model_create_multi
13+
def create(self, vals_list):
14+
for vals in vals_list:
15+
self._remove_erp_user_system_forbidden_fields(vals)
16+
return super().create(vals_list)
17+
18+
def write(self, vals):
19+
self._remove_erp_user_system_forbidden_fields(vals)
20+
return super().write(vals)
21+
22+
@api.model
23+
def _get_erp_user_system_forbidden_fields(self):
24+
return []
25+
26+
@api.model
27+
def _is_current_user_only_erp_user(self):
28+
return self.env.user._is_user_only_erp_user()
29+
30+
def _is_user_only_erp_user(self):
31+
self.ensure_one()
32+
if self.id == SUPERUSER_ID:
33+
return False
34+
return self.has_group(
35+
"base_group_erp_user.group_erp_user"
36+
) and not self.has_group("base.group_erp_manager")
37+
38+
@api.model
39+
def _remove_erp_user_system_forbidden_fields(self, values):
40+
if not self._is_current_user_only_erp_user():
41+
return
42+
for fname in self._get_erp_user_system_forbidden_fields():
43+
values.pop(fname, False)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import res_groups
2+
from . import res_users
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright 2025 ACSONE SA/NV
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
import logging
5+
6+
from odoo import api, models
7+
8+
_logger = logging.getLogger(__name__)
9+
10+
11+
class ResGroups(models.Model):
12+
_name = "res.groups"
13+
_inherit = ["res.groups", "mixin.erp.user.forbidden.fields"]
14+
15+
@api.model
16+
def _get_erp_user_system_forbidden_fields(self):
17+
return [
18+
"implied_ids",
19+
"users",
20+
]
21+
22+
@api.model
23+
def _update_user_groups_view(self):
24+
"""
25+
Need to bypass security as ERP user can still update groups names and create new ones.
26+
"""
27+
safe_self = self
28+
if self._is_current_user_only_erp_user():
29+
safe_self = self.sudo()
30+
return super(ResGroups, safe_self)._update_user_groups_view()
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2025 ACSONE SA/NV
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
import logging
5+
6+
from odoo import api, models
7+
8+
_logger = logging.getLogger(__name__)
9+
10+
11+
class ResUsers(models.Model):
12+
_name = "res.users"
13+
_inherit = ["res.users", "mixin.erp.user.forbidden.fields"]
14+
15+
@api.model
16+
def _get_erp_user_system_forbidden_fields(self):
17+
return [
18+
"groups_id",
19+
]
20+
21+
@api.model
22+
def _default_groups(self):
23+
if self._is_current_user_only_erp_user():
24+
return []
25+
return super()._default_groups()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This module has been created in order to allow people creating users and groups without being able to modify the
2+
related security (model access, model rules, group's users, group's groups, etc). This module
3+
can also be used alongside base_user_group_mgmt to allow administration user to request the assignation of groups
4+
to specific users.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Benjamin Willig <[email protected]> (https://acsone.eu)

0 commit comments

Comments
 (0)