-
-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] document_page_access_group: Users compatibility
TT48786
- Loading branch information
1 parent
5c4ad10
commit 389e6d5
Showing
14 changed files
with
164 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
document_page_access_group/migrations/17.0.1.1.0/noupdate_changes.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version='1.0' encoding='utf-8' ?> | ||
<odoo> | ||
<record id="document_page_rule" model="ir.rule"> | ||
<field | ||
name="domain_force" | ||
>['|', ('groups_id', 'in', [g.id for g in user.groups_id]), '|', ('user_ids', 'in', [user.id]), '&', ('groups_id', '=', False), ('user_ids', '=', False)]</field> | ||
</record> | ||
</odoo> |
12 changes: 12 additions & 0 deletions
12
document_page_access_group/migrations/17.0.1.1.0/post-migration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# 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): | ||
openupgrade.load_data( | ||
env.cr, | ||
"document_page_access_group", | ||
"migrations/17.0.1.1.0/noupdate_changes.xml", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
# Copyright 2022 Manuel Regidor <manuel.regidor@sygel.es> | ||
# Copyright 2024 Tecnativa - Víctor Martínez | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
from odoo import _, api, fields, models | ||
from odoo.exceptions import UserError | ||
|
||
|
||
class DocumentPage(models.Model): | ||
_inherit = "document.page" | ||
|
||
groups_id = fields.Many2many(comodel_name="res.groups", string="Groups") | ||
user_ids = fields.Many2many(comodel_name="res.users", string="Users") | ||
|
||
@api.constrains("groups_id", "user_ids") | ||
def check_document_page_groups_users(self): | ||
for _item in self.filtered(lambda x: x.groups_id and x.user_ids): | ||
raise UserError(_("You cannot set groups and users at the same time.")) | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
- Manuel Regidor \<<manuel.regidor@sygel.es>\> | ||
- Alberto Martínez \<<alberto.martinez@sygel.es>\> | ||
* `Tecnativa <https://www.tecnativa.com>`_: | ||
|
||
* Víctor Martínez |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,5 @@ | ||
To select the users that have access to a given document page you need | ||
to open a document, go to the 'Security' tab and select which groups | ||
will have access. | ||
|
||
Only users that belong to the 'document_knowledge / Manager' group can | ||
manage access groups to documents. | ||
|
||
If no groups are selected in a document, all users that can access | ||
document pages can access this document. | ||
To select the users that have access to a given document page | ||
you need to open a document, go to the 'Security' tab and you have 3 options: | ||
- Select a group: Only users with those groups will be able to see the page. | ||
- Select any user: Only the selected users will be able to see the page. | ||
- Do not select group or user: All users will be able to see the page. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
from odoo.tests import new_test_user | ||
|
||
from odoo.addons.base.tests.common import BaseCommon | ||
|
||
|
||
class TestDocumentPageAccessGroupBase(BaseCommon): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.group = cls.env["res.groups"].create({"name": "Test group"}) | ||
cls.user = new_test_user( | ||
cls.env, login="test-user", groups="document_knowledge.group_document_user" | ||
) | ||
cls.manager_user = new_test_user( | ||
cls.env, | ||
login="test-manager-user", | ||
groups="document_knowledge.group_document_user", | ||
) | ||
cls.manager_user.write({"groups_id": [(4, cls.group.id)]}) | ||
cls.public_page = cls.env["document.page"].create( | ||
{"name": "Public Page", "type": "content"} | ||
) | ||
cls.knowledge_page = cls.env["document.page"].create( | ||
{ | ||
"name": "Knowledge Page", | ||
"type": "content", | ||
"groups_id": [(6, 0, [cls.group.id])], | ||
} | ||
) | ||
cls.user_page = cls.env["document.page"].create( | ||
{ | ||
"name": "User Page (basic user)", | ||
"type": "content", | ||
"user_ids": [(6, 0, [cls.user.id])], | ||
} | ||
) |
42 changes: 19 additions & 23 deletions
42
document_page_access_group/tests/test_document_page_access_group.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,25 @@ | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
from odoo.exceptions import UserError | ||
from odoo.tests import common | ||
from odoo.tests.common import users | ||
|
||
from .common import TestDocumentPageAccessGroupBase | ||
|
||
class TestDocumentPageAccessGroup(common.TransactionCase): | ||
def setUp(self): | ||
super().setUp() | ||
self.document_user_group = self.browse_ref( | ||
"document_knowledge.group_document_user" | ||
).id | ||
self.test_group = self.browse_ref("base.group_erp_manager").id | ||
self.user_id = self.env["res.users"].create( | ||
{ | ||
"name": "user", | ||
"login": "user_login", | ||
"email": "user_email", | ||
"groups_id": [(4, self.document_user_group)], | ||
} | ||
) | ||
self.page = self.env["document.page"].create( | ||
{"name": "Page 1", "type": "content"} | ||
) | ||
|
||
def test_page_access(self): | ||
self.assertIsNone(self.page.with_user(self.user_id).check_access_rule("read")) | ||
self.page.write({"groups_id": [(4, self.test_group)]}) | ||
class TestDocumentPageAccessGroup(TestDocumentPageAccessGroupBase): | ||
def test_page_access_constrains(self): | ||
with self.assertRaises(UserError): | ||
self.page.with_user(self.user_id).check_access_rule("read") | ||
self.knowledge_page.write({"user_ids": [(6, 0, [self.user.id])]}) | ||
|
||
@users("test-user") | ||
def test_page_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) | ||
|
||
@users("test-manager-user") | ||
def test_page_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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters