[15.0][IMP] base_user_role: action to group groups into a role

This commit is contained in:
ArnauCForgeFlow
2024-01-26 10:22:47 +01:00
committed by Bert Van Groenendael
parent c4dbfa0037
commit a5abf9eaba
10 changed files with 90 additions and 3 deletions

View File

@@ -1,2 +1,2 @@
from . import models
from . import wizard
from . import wizards

View File

@@ -19,7 +19,8 @@
"views/role.xml",
"views/user.xml",
"views/group.xml",
"wizard/create_from_user.xml",
"wizards/create_from_user.xml",
"wizards/wizard_groups_into_role.xml",
],
"installable": True,
}

View File

@@ -2,3 +2,4 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_res_users_role,access_res_users_role,model_res_users_role,"base.group_erp_manager",1,1,1,1
access_res_users_role_line,access_res_users_role_line,model_res_users_role_line,"base.group_erp_manager",1,1,1,1
access_wizard_create_role_from_user,access_wizard_create_role_from_user,model_wizard_create_role_from_user,"base.group_erp_manager",1,1,1,1
access_wizard_groups_into_role,access_wizard_groups_into_role,model_wizard_groups_into_role,,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_res_users_role access_res_users_role model_res_users_role base.group_erp_manager 1 1 1 1
3 access_res_users_role_line access_res_users_role_line model_res_users_role_line base.group_erp_manager 1 1 1 1
4 access_wizard_create_role_from_user access_wizard_create_role_from_user model_wizard_create_role_from_user base.group_erp_manager 1 1 1 1
5 access_wizard_groups_into_role access_wizard_groups_into_role model_wizard_groups_into_role 1 1 1 1

View File

@@ -16,6 +16,7 @@ class TestUserRole(TransactionCase):
)
cls.user_model = cls.env["res.users"]
cls.role_model = cls.env["res.users.role"]
cls.wiz_model = cls.env["wizard.groups.into.role"]
cls.company1 = cls.env.ref("base.main_company")
cls.company2 = cls.env["res.company"].create({"name": "company2"})
@@ -245,3 +246,18 @@ class TestUserRole(TransactionCase):
user_group_ids = sorted(set(self.user_id.groups_id.ids))
role_group_ids = sorted(set(role.trans_implied_ids.ids))
self.assertEqual(user_group_ids, role_group_ids)
def test_group_groups_into_role(self):
user_group_ids = [group.id for group in self.user_id.groups_id]
# Check that there is not a role with name: Test Role
self.assertFalse(self.role_model.search([("name", "=", "Test Role")]))
# Call create_role function to group groups into a role
wizard = self.wiz_model.with_context(active_ids=user_group_ids).create(
{"name": "Test Role"}
)
wizard.create_role()
# Check that a role with name: Test Role has been created
new_role = self.role_model.search([("name", "=", "Test Role")])
self.assertTrue(new_role)
# Check that the role has the correct groups
self.assertEqual(new_role.implied_ids.ids, user_group_ids)

View File

@@ -1 +0,0 @@
from . import create_from_user

View File

@@ -0,0 +1,2 @@
from . import create_from_user
from . import wizard_groups_into_role

View File

@@ -0,0 +1,37 @@
# Copyright 2021 Sodexis
# License OPL-1 (See LICENSE file for full copyright and licensing details).
from odoo import fields, models
class GroupGroupsIntoRole(models.TransientModel):
"""
This wizard is used to group different groups into a role.
"""
_name = "wizard.groups.into.role"
_description = "Group groups into a role"
name = fields.Char(
required=True,
help="Group groups into a role and specify a name for this role",
)
def create_role(self):
selected_group_ids = self.env.context.get("active_ids", [])
vals = {
"name": self.name,
"implied_ids": selected_group_ids,
}
role = self.env["res.users.role"].create(vals)
return {
"type": "ir.actions.act_window",
"res_model": "res.users.role",
"view_mode": "form",
"res_id": role.id,
"target": "current",
"context": {
"form_view_ref": "base_user_role.view_res_users_role_form",
},
}

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="group_groups_into_role_wiz_view" model="ir.ui.view">
<field name="name">wizard.groups.into.role.wiz.view</field>
<field name="model">wizard.groups.into.role</field>
<field name="arch" type="xml">
<form>
<group>
<field name="name" />
</group>
<footer>
<button
string="Create"
type="object"
class="oe_highlight"
name="create_role"
/>
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
<record id="action_wizard_groups_into_role" model="ir.actions.act_window">
<field name="name">Create Role</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">wizard.groups.into.role</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="binding_model_id" ref="base.model_res_groups" />
</record>
</odoo>