mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-13 15:34:49 -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.
|
#. Go to `Knowledge / Pages` and create or edit one.
|
||||||
#. Set in the "Roles" tab the one we have just created.
|
#. Set in the "Roles" tab the one we have just created.
|
||||||
#. Go back to the role, edit it and add any group(s).
|
#. 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
|
Bug Tracker
|
||||||
===========
|
===========
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
"name": "Document Page Access Group User Role",
|
"name": "Document Page Access Group User Role",
|
||||||
"author": "Tecnativa, Odoo Community Association (OCA)",
|
"author": "Tecnativa, Odoo Community Association (OCA)",
|
||||||
"website": "https://github.com/OCA/knowledge",
|
"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"],
|
"depends": ["document_page_access_group", "base_user_role"],
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"category": "Knowledge",
|
"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):
|
class DocumentPage(models.Model):
|
||||||
_inherit = "document.page"
|
_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(
|
role_ids = fields.Many2many(
|
||||||
comodel_name="res.users.role",
|
comodel_name="res.users.role",
|
||||||
relation="document_page_user_roles_rel",
|
relation="document_page_user_roles_rel",
|
||||||
@ -16,8 +16,8 @@ class DocumentPage(models.Model):
|
|||||||
string="Roles",
|
string="Roles",
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.depends("role_ids", "role_ids.implied_ids")
|
@api.depends("role_ids", "role_ids.users")
|
||||||
def _compute_groups_id(self):
|
def _compute_user_ids(self):
|
||||||
"""Create a compute to auto-set all the groups of the related roles."""
|
"""Create a compute to auto-set all the users of the related roles."""
|
||||||
for item in self:
|
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.
|
#. Go to `Knowledge / Pages` and create or edit one.
|
||||||
#. Set in the "Roles" tab the one we have just created.
|
#. Set in the "Roles" tab the one we have just created.
|
||||||
#. Go back to the role, edit it and add any group(s).
|
#. 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">
|
<!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">
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||||
<head>
|
<head>
|
||||||
@ -391,7 +390,7 @@ ul.auto-toc {
|
|||||||
<li>Go to <cite>Knowledge / Pages</cite> and create or edit one.</li>
|
<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>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>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>
|
</ol>
|
||||||
</div>
|
</div>
|
||||||
<div class="section" id="bug-tracker">
|
<div class="section" id="bug-tracker">
|
||||||
|
@ -1,30 +1,47 @@
|
|||||||
# Copyright 2024 Tecnativa - Víctor Martínez
|
# Copyright 2024 Tecnativa - Víctor Martínez
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# 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
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
super().setUpClass()
|
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(
|
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):
|
def test_document_page_role_misc(self):
|
||||||
self.assertFalse(self.page.groups_id)
|
self.assertFalse(self.role_page.groups_id)
|
||||||
self.page.role_ids = [(4, self.user_role.id)]
|
self.assertTrue(self.role_page.user_ids)
|
||||||
self.assertIn(self.group_a, self.page.groups_id)
|
|
||||||
self.assertNotIn(self.group_b, self.page.groups_id)
|
@users("test-user")
|
||||||
self.user_role.implied_ids = [(4, self.group_b.id)]
|
def test_document_page_role_access_01(self):
|
||||||
self.assertIn(self.group_a, self.page.groups_id)
|
pages = self.env["document.page"].search([])
|
||||||
self.assertIn(self.group_b, self.page.groups_id)
|
self.assertIn(self.public_page, pages)
|
||||||
self.page.role_ids = [(6, 0, [])]
|
self.assertNotIn(self.knowledge_page, pages)
|
||||||
self.assertNotIn(self.group_a, self.page.groups_id)
|
self.assertIn(self.user_page, pages)
|
||||||
self.assertNotIn(self.group_b, self.page.groups_id)
|
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"
|
ref="document_page_access_group.document_page_access_group_view_wiki_form"
|
||||||
/>
|
/>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<page name="security" position="after">
|
<group name="users" position="before">
|
||||||
<page name="roles" string="Roles" groups="base.group_erp_manager">
|
<group
|
||||||
<field name="role_ids">
|
name="roles"
|
||||||
|
string="Roles"
|
||||||
|
attrs="{'invisible': [('groups_id','!=',[])]}"
|
||||||
|
groups="base.group_erp_manager"
|
||||||
|
>
|
||||||
|
<field name="role_ids" nolabel="1" colspan="2">
|
||||||
<tree>
|
<tree>
|
||||||
<field name="name" />
|
<field name="name" />
|
||||||
<field name="comment" />
|
<field name="comment" />
|
||||||
</tree>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
</page>
|
</group>
|
||||||
<!-- It is necessary to add the field without groups to be able to apply the readonly after. !-->
|
</group>
|
||||||
<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>
|
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
</odoo>
|
</odoo>
|
||||||
|
Loading…
Reference in New Issue
Block a user