Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TA#66737 [ADD] users_default_groups #156

Open
wants to merge 4 commits into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .docker_files/main/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion .docker_files/odoo.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions users_default_groups/README.rst
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions users_default_groups/__init__.py
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions users_default_groups/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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,
}
4 changes: 4 additions & 0 deletions users_default_groups/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions users_default_groups/models/res_users.py
Original file line number Diff line number Diff line change
@@ -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)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added users_default_groups/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions users_default_groups/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions users_default_groups/tests/test_users_default_groups.py
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
}
)
# 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": "[email protected]",
}
)
# Verify the user doesn't have the group
not self.assertNotIn(self.group, self.user.groups_id)
Loading