mirror of
https://github.com/OCA/server-backend.git
synced 2025-02-18 09:52:42 +02:00
@@ -23,7 +23,7 @@ User roles
|
||||
:target: https://runbot.odoo-community.org/runbot/253/16.0
|
||||
:alt: Try me on Runbot
|
||||
|
||||
|badge1| |badge2| |badge3| |badge4| |badge5|
|
||||
|badge1| |badge2| |badge3| |badge4| |badge5|
|
||||
|
||||
This module was written to extend the standard functionality regarding users
|
||||
and groups management.
|
||||
@@ -152,7 +152,7 @@ promote its widespread use.
|
||||
|
||||
Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:
|
||||
|
||||
|maintainer-sebalix| |maintainer-jcdrubay| |maintainer-novawish|
|
||||
|maintainer-sebalix| |maintainer-jcdrubay| |maintainer-novawish|
|
||||
|
||||
This module is part of the `OCA/server-backend <https://github.com/OCA/server-backend/tree/16.0/base_user_role>`_ project on GitHub.
|
||||
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
from . import models
|
||||
from . import wizard
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
"views/role.xml",
|
||||
"views/user.xml",
|
||||
"views/group.xml",
|
||||
"wizard/create_from_user.xml",
|
||||
],
|
||||
"installable": True,
|
||||
}
|
||||
|
||||
@@ -22,3 +22,7 @@ Add users (with dates or not):
|
||||
.. figure:: /OCA/server-backend/16.0/base_user_role/static/description/role_users.png
|
||||
:width: 80 %
|
||||
:align: center
|
||||
|
||||
Instead of creating roles from scratch, it is possible to create a role
|
||||
based on the groups of an existing user: select or open the user and choose
|
||||
"Create role from user" in the action menu.
|
||||
|
||||
@@ -6,5 +6,6 @@
|
||||
* Kevin Khao <kevin.khao@akretion.com>
|
||||
* Tatiana Deribina <tatiana.deribina@sprintit.fi> (https://sprintit.fi)
|
||||
* Guillem Casassas <guillem.casassas@forgeflow.com>
|
||||
* Guillaume Pothier <gpothier@caligrafix.cl>
|
||||
|
||||
Do not contact contributors directly about support or help with technical issues.
|
||||
|
||||
@@ -1,3 +1,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
|
||||
|
||||
|
@@ -225,3 +225,23 @@ class TestUserRole(TransactionCase):
|
||||
AccessError, "You are not allowed to access 'User role'"
|
||||
):
|
||||
role.read()
|
||||
|
||||
def test_create_role_from_user(self):
|
||||
# Use a wizard instance to create a new role based on the user.
|
||||
# We use assign_to_user = False, as otherwise this module forcibly
|
||||
# assigns the role's groups to the user, which would make this
|
||||
# test useless.
|
||||
wizard = self.env["wizard.create.role.from.user"].create(
|
||||
{
|
||||
"name": "Role for user (without assign)",
|
||||
"assign_to_user": False,
|
||||
}
|
||||
)
|
||||
result = wizard.with_context(active_ids=[self.user_id.id]).create_from_user()
|
||||
|
||||
# Check that the role has the same groups as the user
|
||||
role_id = result["res_id"]
|
||||
role = self.role_model.browse([role_id])
|
||||
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)
|
||||
|
||||
1
base_user_role/wizard/__init__.py
Normal file
1
base_user_role/wizard/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import create_from_user
|
||||
50
base_user_role/wizard/create_from_user.py
Normal file
50
base_user_role/wizard/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/wizard/create_from_user.xml
Normal file
34
base_user_role/wizard/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>
|
||||
Reference in New Issue
Block a user