mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-13 07:24:48 -06:00
[IMP] document_page_access_group_user_role: Users compatibility
TT48786
This commit is contained in:
parent
68766adea3
commit
c12c8c4bef
@ -42,7 +42,7 @@ Usage
|
||||
#. Go to `Knowledge / Pages` and create or edit one.
|
||||
#. Set in the "Roles" tab the one we have just created.
|
||||
#. Go back to the role, edit it and add any group(s).
|
||||
#. The role groups will have been added in the "Security" tab.
|
||||
#. The role users will have been added in the "Security" tab.
|
||||
|
||||
Bug Tracker
|
||||
===========
|
||||
|
@ -4,7 +4,7 @@
|
||||
"name": "Document Page Access Group User Role",
|
||||
"author": "Tecnativa, Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/knowledge",
|
||||
"version": "16.0.1.0.0",
|
||||
"version": "16.0.1.1.0",
|
||||
"depends": ["document_page_access_group", "base_user_role"],
|
||||
"license": "AGPL-3",
|
||||
"category": "Knowledge",
|
||||
|
@ -0,0 +1,13 @@
|
||||
# Copyright 2024 Tecnativa - Víctor Martínez
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
from openupgradelib import openupgrade
|
||||
|
||||
|
||||
@openupgrade.migrate()
|
||||
def migrate(env, version):
|
||||
"""Pages that had roles should now have the correct users."""
|
||||
pages = env["document.page"].sudo().search([("role_ids", "!=", False)])
|
||||
for page in pages:
|
||||
users = page.mapped("role_ids.users")
|
||||
page.role_ids = False
|
||||
page.user_ids = users
|
@ -7,7 +7,7 @@ from odoo import api, fields, models
|
||||
class DocumentPage(models.Model):
|
||||
_inherit = "document.page"
|
||||
|
||||
groups_id = fields.Many2many(compute="_compute_groups_id", store=True)
|
||||
user_ids = fields.Many2many(compute="_compute_user_ids", store=True, readonly=False)
|
||||
role_ids = fields.Many2many(
|
||||
comodel_name="res.users.role",
|
||||
relation="document_page_user_roles_rel",
|
||||
@ -16,8 +16,8 @@ class DocumentPage(models.Model):
|
||||
string="Roles",
|
||||
)
|
||||
|
||||
@api.depends("role_ids", "role_ids.implied_ids")
|
||||
def _compute_groups_id(self):
|
||||
"""Create a compute to auto-set all the groups of the related roles."""
|
||||
@api.depends("role_ids", "role_ids.users")
|
||||
def _compute_user_ids(self):
|
||||
"""Create a compute to auto-set all the users of the related roles."""
|
||||
for item in self:
|
||||
item.groups_id = item.mapped("role_ids.implied_ids")
|
||||
item.user_ids += item.mapped("role_ids.users")
|
||||
|
@ -2,4 +2,4 @@
|
||||
#. Go to `Knowledge / Pages` and create or edit one.
|
||||
#. Set in the "Roles" tab the one we have just created.
|
||||
#. Go back to the role, edit it and add any group(s).
|
||||
#. The role groups will have been added in the "Security" tab.
|
||||
#. The role users will have been added in the "Security" tab.
|
||||
|
@ -1,4 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
@ -391,7 +390,7 @@ ul.auto-toc {
|
||||
<li>Go to <cite>Knowledge / Pages</cite> and create or edit one.</li>
|
||||
<li>Set in the “Roles” tab the one we have just created.</li>
|
||||
<li>Go back to the role, edit it and add any group(s).</li>
|
||||
<li>The role groups will have been added in the “Security” tab.</li>
|
||||
<li>The role users will have been added in the “Security” tab.</li>
|
||||
</ol>
|
||||
</div>
|
||||
<div class="section" id="bug-tracker">
|
||||
|
@ -1,30 +1,47 @@
|
||||
# Copyright 2024 Tecnativa - Víctor Martínez
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from odoo.tests.common import users
|
||||
|
||||
from odoo.addons.base.tests.common import BaseCommon
|
||||
from odoo.addons.document_page_access_group.tests.common import (
|
||||
TestDocumentPageAccessGroupBase,
|
||||
)
|
||||
|
||||
|
||||
class TestDocumentPageAccessGroupUserRole(BaseCommon):
|
||||
class TestDocumentPageAccessGroupUserRole(TestDocumentPageAccessGroupBase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.page = cls.env["document.page"].create(
|
||||
{"name": "Page 1", "type": "content"}
|
||||
)
|
||||
cls.group_a = cls.env["res.groups"].create({"name": "Test group A"})
|
||||
cls.group_b = cls.env["res.groups"].create({"name": "Test group B"})
|
||||
cls.user_role = cls.env["res.users.role"].create(
|
||||
{"name": "Test role", "implied_ids": [(6, 0, [cls.group_a.id])]}
|
||||
{
|
||||
"name": "Test role",
|
||||
"implied_ids": [(6, 0, [cls.group.id])],
|
||||
"users": [(6, 0, [cls.manager_user.id])],
|
||||
}
|
||||
)
|
||||
cls.role_page = cls.env["document.page"].create(
|
||||
{
|
||||
"name": "Role Page (test role)",
|
||||
"type": "content",
|
||||
"role_ids": [(6, 0, [cls.user_role.id])],
|
||||
}
|
||||
)
|
||||
|
||||
def test_document_page_role(self):
|
||||
self.assertFalse(self.page.groups_id)
|
||||
self.page.role_ids = [(4, self.user_role.id)]
|
||||
self.assertIn(self.group_a, self.page.groups_id)
|
||||
self.assertNotIn(self.group_b, self.page.groups_id)
|
||||
self.user_role.implied_ids = [(4, self.group_b.id)]
|
||||
self.assertIn(self.group_a, self.page.groups_id)
|
||||
self.assertIn(self.group_b, self.page.groups_id)
|
||||
self.page.role_ids = [(6, 0, [])]
|
||||
self.assertNotIn(self.group_a, self.page.groups_id)
|
||||
self.assertNotIn(self.group_b, self.page.groups_id)
|
||||
def test_document_page_role_misc(self):
|
||||
self.assertFalse(self.role_page.groups_id)
|
||||
self.assertTrue(self.role_page.user_ids)
|
||||
|
||||
@users("test-user")
|
||||
def test_document_page_role_access_01(self):
|
||||
pages = self.env["document.page"].search([])
|
||||
self.assertIn(self.public_page, pages)
|
||||
self.assertNotIn(self.knowledge_page, pages)
|
||||
self.assertIn(self.user_page, pages)
|
||||
self.assertNotIn(self.role_page, pages)
|
||||
|
||||
@users("test-manager-user")
|
||||
def test_document_page_role_access_02(self):
|
||||
pages = self.env["document.page"].search([])
|
||||
self.assertIn(self.public_page, pages)
|
||||
self.assertIn(self.knowledge_page, pages)
|
||||
self.assertNotIn(self.user_page, pages)
|
||||
self.assertIn(self.role_page, pages)
|
||||
|
@ -8,24 +8,21 @@
|
||||
ref="document_page_access_group.document_page_access_group_view_wiki_form"
|
||||
/>
|
||||
<field name="arch" type="xml">
|
||||
<page name="security" position="after">
|
||||
<page name="roles" string="Roles" groups="base.group_erp_manager">
|
||||
<field name="role_ids">
|
||||
<group name="users" position="before">
|
||||
<group
|
||||
name="roles"
|
||||
string="Roles"
|
||||
attrs="{'invisible': [('groups_id','!=',[])]}"
|
||||
groups="base.group_erp_manager"
|
||||
>
|
||||
<field name="role_ids" nolabel="1" colspan="2">
|
||||
<tree>
|
||||
<field name="name" />
|
||||
<field name="comment" />
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
<!-- It is necessary to add the field without groups to be able to apply the readonly after. !-->
|
||||
<field name="role_ids" invisible="1" groups="!base.group_erp_manager" />
|
||||
</page>
|
||||
<!-- Set groups as readonly if there is a defined roles to avoid UX confusion. !-->
|
||||
<field name="groups_id" position="attributes">
|
||||
<attribute
|
||||
name="attrs"
|
||||
>{'readonly': [('role_ids', '!=', [])]}</attribute>
|
||||
</field>
|
||||
</group>
|
||||
</group>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
|
Loading…
Reference in New Issue
Block a user