mirror of
https://github.com/OCA/server-backend.git
synced 2025-02-18 09:52:42 +02:00
[15.0][IMP] base_user_role: action to group groups into a role
This commit is contained in:
committed by
Sébastien Alix
parent
93be01eaef
commit
3b7bbf2856
@@ -1,2 +1,2 @@
|
|||||||
from . import models
|
from . import models
|
||||||
from . import wizard
|
from . import wizards
|
||||||
|
|||||||
@@ -19,7 +19,8 @@
|
|||||||
"views/role.xml",
|
"views/role.xml",
|
||||||
"views/user.xml",
|
"views/user.xml",
|
||||||
"views/group.xml",
|
"views/group.xml",
|
||||||
"wizard/create_from_user.xml",
|
"wizards/create_from_user.xml",
|
||||||
|
"wizards/wizard_groups_into_role.xml",
|
||||||
],
|
],
|
||||||
"installable": True,
|
"installable": True,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,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_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_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
|
||||||
|
|||||||
|
@@ -16,6 +16,7 @@ class TestUserRole(TransactionCase):
|
|||||||
)
|
)
|
||||||
cls.user_model = cls.env["res.users"]
|
cls.user_model = cls.env["res.users"]
|
||||||
cls.role_model = cls.env["res.users.role"]
|
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.company1 = cls.env.ref("base.main_company")
|
||||||
cls.company2 = cls.env["res.company"].create({"name": "company2"})
|
cls.company2 = cls.env["res.company"].create({"name": "company2"})
|
||||||
@@ -254,3 +255,18 @@ class TestUserRole(TransactionCase):
|
|||||||
# disable role
|
# disable role
|
||||||
self.user_id.role_line_ids.unlink()
|
self.user_id.role_line_ids.unlink()
|
||||||
self.assertFalse(self.user_id.show_alert)
|
self.assertFalse(self.user_id.show_alert)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
from . import create_from_user
|
|
||||||
2
base_user_role/wizards/__init__.py
Normal file
2
base_user_role/wizards/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
from . import create_from_user
|
||||||
|
from . import wizard_groups_into_role
|
||||||
37
base_user_role/wizards/wizard_groups_into_role.py
Normal file
37
base_user_role/wizards/wizard_groups_into_role.py
Normal 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",
|
||||||
|
},
|
||||||
|
}
|
||||||
31
base_user_role/wizards/wizard_groups_into_role.xml
Normal file
31
base_user_role/wizards/wizard_groups_into_role.xml
Normal 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>
|
||||||
Reference in New Issue
Block a user