diff --git a/.docker_files/main/__manifest__.py b/.docker_files/main/__manifest__.py index e7765bcf..085810f5 100644 --- a/.docker_files/main/__manifest__.py +++ b/.docker_files/main/__manifest__.py @@ -57,6 +57,7 @@ # "profile_hr", "queue_job_auto_requeue", "test_http_request", + "users_default_groups", "utm_archive", "web_email_field_new_tab", "dms_document_url", diff --git a/.docker_files/odoo.conf b/.docker_files/odoo.conf index 3bf385b2..25498c6e 100644 --- a/.docker_files/odoo.conf +++ b/.docker_files/odoo.conf @@ -49,7 +49,7 @@ test_report_directory = False translate_modules = ['all'] unaccent = False without_demo = False -workers = 2 +workers = 0 xmlrpc = True xmlrpc_interface = xmlrpc_port = 8069 diff --git a/Dockerfile b/Dockerfile index 8e3c1f44..30aca298 100644 --- a/Dockerfile +++ b/Dockerfile @@ -57,6 +57,7 @@ COPY profile_hr /mnt/extra-addons/profile_hr COPY private_data_group /mnt/extra-addons/private_data_group COPY queue_job_auto_requeue /mnt/extra-addons/queue_job_auto_requeue COPY test_http_request /mnt/extra-addons/test_http_request +COPY users_default_groups /mnt/extra-addons/users_default_groups COPY utm_archive /mnt/extra-addons/utm_archive COPY web_email_field_new_tab /mnt/extra-addons/web_email_field_new_tab COPY dms_document_url /mnt/extra-addons/dms_document_url diff --git a/users_default_groups/README.rst b/users_default_groups/README.rst new file mode 100644 index 00000000..62900ac6 --- /dev/null +++ b/users_default_groups/README.rst @@ -0,0 +1,27 @@ +Users Default Groups +==================== + +In Odoo Vanilla, when we create a new user, the default groups will be added to +the user even if we have the parameter "Default Access Rights" unchecked. + + +This module fixes this behavior to not set default groups to a new-created user +if the parameter "Default Access Rights" is not checked. + +Usage: +------ + +As a user with the "Administration/Settings" group, I go to the `General Settings` +and verify if the parameter "Default Access Rights" is unchecked. + +.. image:: static/description/default_access_rights_param.png + +Then I go to the `Users & Companies` menu and create a new user. +I can see that there are no groups added by default. + +.. image:: static/description/user_no_default_groups.png + + +Contributors +------------ +* Numigi (tm) and all its contributors (https://bit.ly/numigiens) diff --git a/users_default_groups/__init__.py b/users_default_groups/__init__.py new file mode 100644 index 00000000..5221df8f --- /dev/null +++ b/users_default_groups/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from . import models diff --git a/users_default_groups/__manifest__.py b/users_default_groups/__manifest__.py new file mode 100644 index 00000000..6652a2e5 --- /dev/null +++ b/users_default_groups/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +{ + "name": "Users Default Groups", + "summary": "Fix default groups settings", + "version": "1.0.0", + "category": "Base", + "author": "Numigi", + "license": "AGPL-3", + "depends": ["base_setup"], + "data": [], + "installable": True, + "auto_install": True, +} diff --git a/users_default_groups/models/__init__.py b/users_default_groups/models/__init__.py new file mode 100644 index 00000000..dabe4fe9 --- /dev/null +++ b/users_default_groups/models/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from . import res_users diff --git a/users_default_groups/models/res_users.py b/users_default_groups/models/res_users.py new file mode 100644 index 00000000..babee41e --- /dev/null +++ b/users_default_groups/models/res_users.py @@ -0,0 +1,18 @@ +# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo import fields, models + + +class ResUsers(models.Model): + _inherit = "res.users" + + def _default_groups(self): + default_user_rights = ( + self.env["ir.config_parameter"] + .sudo() + .get_param("base_setup.default_user_rights") + ) + return super()._default_groups() if default_user_rights else [] + + groups_id = fields.Many2many(default=_default_groups) diff --git a/users_default_groups/static/description/default_access_rights_param.png b/users_default_groups/static/description/default_access_rights_param.png new file mode 100644 index 00000000..176c9c43 Binary files /dev/null and b/users_default_groups/static/description/default_access_rights_param.png differ diff --git a/users_default_groups/static/description/icon.png b/users_default_groups/static/description/icon.png new file mode 100644 index 00000000..92a86b10 Binary files /dev/null and b/users_default_groups/static/description/icon.png differ diff --git a/users_default_groups/static/description/user_no_default_groups.png b/users_default_groups/static/description/user_no_default_groups.png new file mode 100644 index 00000000..a6cb610f Binary files /dev/null and b/users_default_groups/static/description/user_no_default_groups.png differ diff --git a/users_default_groups/tests/__init__.py b/users_default_groups/tests/__init__.py new file mode 100644 index 00000000..b5af4fda --- /dev/null +++ b/users_default_groups/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from . import test_users_default_groups diff --git a/users_default_groups/tests/test_users_default_groups.py b/users_default_groups/tests/test_users_default_groups.py new file mode 100644 index 00000000..78d11260 --- /dev/null +++ b/users_default_groups/tests/test_users_default_groups.py @@ -0,0 +1,42 @@ +# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo.tests import common + + +class TestDefaultUserRights(common.SavepointCase): + + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.default_user = cls.env.ref("base.default_user") + cls.group = cls.env.ref("base.group_user") + cls.default_user.write({"groups_id": [(4, cls.group.id)]}) + + def test_default_user_rights_checked(self): + self.env["ir.config_parameter"].set_param( + "base_setup.default_user_rights", True + ) + self.user = self.env["res.users"].create( + { + "name": "Numigi User", + "login": "numigiuser", + "email": "numigiuser@example.com", + } + ) + # Verify the user has the group like the default user + self.assertIn(self.group, self.user.groups_id) + + def test_default_user_rights_unchecked(self): + self.env["ir.config_parameter"].sudo().set_param( + "base_setup.default_user_rights", False + ) + self.user = self.env["res.users"].create( + { + "name": "Numigi User", + "login": "numigiuser", + "email": "numigiuser@example.com", + } + ) + # Verify the user doesn't have the group + not self.assertNotIn(self.group, self.user.groups_id)