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
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
|
||||
50
base_user_role/wizards/create_from_user.py
Normal file
50
base_user_role/wizards/create_from_user.py
Normal file
@@ -0,0 +1,50 @@
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class WizardCreateRoleFromUser(models.TransientModel):
|
||||
_name = "wizard.create.role.from.user"
|
||||
_description = "Create role from user wizard"
|
||||
|
||||
name = fields.Char(required=True)
|
||||
assign_to_user = fields.Boolean("Assign to user", default=True)
|
||||
|
||||
def create_from_user(self):
|
||||
self.ensure_one()
|
||||
|
||||
user_ids = self.env.context.get("active_ids", [])
|
||||
assert len(user_ids) == 1
|
||||
|
||||
user_id = user_ids[0]
|
||||
|
||||
role_obj = self.env["res.users.role"]
|
||||
role_line_obj = self.env["res.users.role.line"]
|
||||
user_obj = self.env["res.users"]
|
||||
|
||||
user = user_obj.browse(user_id)
|
||||
|
||||
role = role_obj.create(
|
||||
{
|
||||
"name": self.name,
|
||||
}
|
||||
)
|
||||
|
||||
role.implied_ids = [(6, 0, user.groups_id.ids)]
|
||||
|
||||
if self.assign_to_user:
|
||||
role_line_obj.create(
|
||||
{
|
||||
"role_id": role.id,
|
||||
"user_id": user_id,
|
||||
}
|
||||
)
|
||||
|
||||
return {
|
||||
"context": self.env.context,
|
||||
"name": "Role",
|
||||
"view_type": "form",
|
||||
"view_mode": "form",
|
||||
"res_model": "res.users.role",
|
||||
"res_id": role.id,
|
||||
"target": "current",
|
||||
"type": "ir.actions.act_window",
|
||||
}
|
||||
34
base_user_role/wizards/create_from_user.xml
Normal file
34
base_user_role/wizards/create_from_user.xml
Normal file
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<record id="create_from_user_wizard_action" model="ir.actions.act_window">
|
||||
<field name="name">Create role from user</field>
|
||||
<field name="res_model">wizard.create.role.from.user</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
<field name="binding_model_id" ref="base.model_res_users" />
|
||||
</record>
|
||||
|
||||
<record id="create_from_user_wizard_view" model="ir.ui.view">
|
||||
<field name="name">Create role from user</field>
|
||||
<field name="model">wizard.create.role.from.user</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Create role from user">
|
||||
<group>
|
||||
<field name="name" />
|
||||
<field name="assign_to_user" />
|
||||
</group>
|
||||
|
||||
<footer>
|
||||
<button
|
||||
name="create_from_user"
|
||||
string="Create"
|
||||
type="object"
|
||||
class="oe_highlight"
|
||||
/>
|
||||
or
|
||||
<button string="Close" class="oe_link" special="cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
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