[IMP] document_page_access_group: Users compatibility

TT48786
This commit is contained in:
Víctor Martínez 2024-07-23 17:32:06 +02:00 committed by Bhavesh Heliconia
parent a6e2e785f8
commit f57f6b6fe2
15 changed files with 179 additions and 66 deletions

View File

@ -7,7 +7,7 @@ Document Page Access Group
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:b17b9a59745b22473114b818626d1a54eb0e7d1c5cbe43c07a3040d4619b0f36 !! source digest: sha256:28e06c90139270717bf9f3fbe04145a72fed721a256eb4d526ee229beaf1cc69
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
@ -40,14 +40,13 @@ Usage
===== =====
To select the users that have access to a given document page you need 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 to open a document, go to the 'Security' tab and you have 3 options:
will have access.
Only users that belong to the 'document_knowledge / Manager' group can - Select a group: Only users with those groups will be able to see the
manage access groups to documents. page.
- Select any user: Only the selected users will be able to see the
If no groups are selected in a document, all users that can access page.
document pages can access this document. - Do not select group or user: All users will be able to see the page.
Bug Tracker Bug Tracker
=========== ===========
@ -73,6 +72,10 @@ Contributors
- Manuel Regidor <manuel.regidor@sygel.es> - Manuel Regidor <manuel.regidor@sygel.es>
- Alberto Martínez <alberto.martinez@sygel.es> - Alberto Martínez <alberto.martinez@sygel.es>
- ``Tecnativa <https://www.tecnativa.com>``\ \_:
- Víctor Martínez
Maintainers Maintainers
----------- -----------

View File

@ -4,7 +4,7 @@
{ {
"name": "Document Page Access Group", "name": "Document Page Access Group",
"summary": "Choose groups to access document pages", "summary": "Choose groups to access document pages",
"version": "17.0.1.0.0", "version": "17.0.2.0.0",
"category": "document_knowledge", "category": "document_knowledge",
"website": "https://github.com/OCA/knowledge", "website": "https://github.com/OCA/knowledge",
"author": "Sygel, Odoo Community Association (OCA)", "author": "Sygel, Odoo Community Association (OCA)",

View File

@ -20,6 +20,7 @@ msgstr ""
#. module: document_page_access_group #. module: document_page_access_group
#: model:ir.model.fields,field_description:document_page_access_group.field_document_page__groups_id #: model:ir.model.fields,field_description:document_page_access_group.field_document_page__groups_id
#: model_terms:ir.ui.view,arch_db:document_page_access_group.document_page_access_group_view_wiki_form
msgid "Groups" msgid "Groups"
msgstr "" msgstr ""
@ -27,3 +28,16 @@ msgstr ""
#: model_terms:ir.ui.view,arch_db:document_page_access_group.document_page_access_group_view_wiki_form #: model_terms:ir.ui.view,arch_db:document_page_access_group.document_page_access_group_view_wiki_form
msgid "Security" msgid "Security"
msgstr "" msgstr ""
#. module: document_page_access_group
#: model:ir.model.fields,field_description:document_page_access_group.field_document_page__user_ids
#: model_terms:ir.ui.view,arch_db:document_page_access_group.document_page_access_group_view_wiki_form
msgid "Users"
msgstr ""
#. module: document_page_access_group
#. odoo-python
#: code:addons/document_page_access_group/models/document_page.py:0
#, python-format
msgid "You cannot set groups and users at the same time."
msgstr ""

View File

@ -6,15 +6,16 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 14.0\n" "Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2023-06-05 13:08+0000\n" "POT-Creation-Date: 2024-07-24 07:09+0000\n"
"PO-Revision-Date: 2024-07-24 09:10+0200\n"
"Last-Translator: luis-ron <luis.ron@sygel.es>\n" "Last-Translator: luis-ron <luis.ron@sygel.es>\n"
"Language-Team: none\n" "Language-Team: none\n"
"Language: es\n" "Language: es\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n" "Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n" "Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.17\n" "X-Generator: Poedit 3.0.1\n"
#. module: document_page_access_group #. module: document_page_access_group
#: model:ir.model,name:document_page_access_group.model_document_page #: model:ir.model,name:document_page_access_group.model_document_page
@ -23,6 +24,7 @@ msgstr "Página de documento"
#. module: document_page_access_group #. module: document_page_access_group
#: model:ir.model.fields,field_description:document_page_access_group.field_document_page__groups_id #: model:ir.model.fields,field_description:document_page_access_group.field_document_page__groups_id
#: model_terms:ir.ui.view,arch_db:document_page_access_group.document_page_access_group_view_wiki_form
msgid "Groups" msgid "Groups"
msgstr "Grupos" msgstr "Grupos"
@ -31,11 +33,15 @@ msgstr "Grupos"
msgid "Security" msgid "Security"
msgstr "Seguridad" msgstr "Seguridad"
#~ msgid "Display Name" #. module: document_page_access_group
#~ msgstr "Nombre mostrado" #: model:ir.model.fields,field_description:document_page_access_group.field_document_page__user_ids
#: model_terms:ir.ui.view,arch_db:document_page_access_group.document_page_access_group_view_wiki_form
msgid "Users"
msgstr "Usuarios"
#~ msgid "ID" #. module: document_page_access_group
#~ msgstr "ID" #. odoo-python
#: code:addons/document_page_access_group/models/document_page.py:0
#~ msgid "Last Modified on" #, python-format
#~ msgstr "Última modificación el" msgid "You cannot set groups and users at the same time."
msgstr "No puedes definir grupos y usuarios al mismo tiempo."

View File

@ -23,6 +23,7 @@ msgstr "Pagina documento"
#. module: document_page_access_group #. module: document_page_access_group
#: model:ir.model.fields,field_description:document_page_access_group.field_document_page__groups_id #: model:ir.model.fields,field_description:document_page_access_group.field_document_page__groups_id
#: model_terms:ir.ui.view,arch_db:document_page_access_group.document_page_access_group_view_wiki_form
msgid "Groups" msgid "Groups"
msgstr "Gruppi" msgstr "Gruppi"
@ -31,6 +32,19 @@ msgstr "Gruppi"
msgid "Security" msgid "Security"
msgstr "Sicurezza" msgstr "Sicurezza"
#. module: document_page_access_group
#: model:ir.model.fields,field_description:document_page_access_group.field_document_page__user_ids
#: model_terms:ir.ui.view,arch_db:document_page_access_group.document_page_access_group_view_wiki_form
msgid "Users"
msgstr ""
#. module: document_page_access_group
#. odoo-python
#: code:addons/document_page_access_group/models/document_page.py:0
#, python-format
msgid "You cannot set groups and users at the same time."
msgstr ""
#~ msgid "Display Name" #~ msgid "Display Name"
#~ msgstr "Nome visualizzato" #~ msgstr "Nome visualizzato"

View File

@ -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]), '&amp;', ('groups_id', '=', False), ('user_ids', '=', False)]</field>
</record>
</odoo>

View File

@ -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",
)

View File

@ -1,10 +1,19 @@
# Copyright 2022 Manuel Regidor <manuel.regidor@sygel.es> # 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). # 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): class DocumentPage(models.Model):
_inherit = "document.page" _inherit = "document.page"
groups_id = fields.Many2many(comodel_name="res.groups", string="Groups") 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

View File

@ -1,2 +1,5 @@
- Manuel Regidor \<<manuel.regidor@sygel.es>\> - Manuel Regidor \<<manuel.regidor@sygel.es>\>
- Alberto Martínez \<<alberto.martinez@sygel.es>\> - Alberto Martínez \<<alberto.martinez@sygel.es>\>
* `Tecnativa <https://www.tecnativa.com>`_:
* Víctor Martínez

View File

@ -1,9 +1,5 @@
To select the users that have access to a given document page you need To select the users that have access to a given document page
to open a document, go to the 'Security' tab and select which groups you need to open a document, go to the 'Security' tab and you have 3 options:
will have access. - 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.
Only users that belong to the 'document_knowledge / Manager' group can - Do not select group or user: All users will be able to see the page.
manage access groups to documents.
If no groups are selected in a document, all users that can access
document pages can access this document.

View File

@ -12,7 +12,7 @@
/> />
<field <field
name="domain_force" name="domain_force"
>['|', ('groups_id', '=', False), ('groups_id', 'in', [g.id for g in user.groups_id])]</field> >['|', ('groups_id', 'in', [g.id for g in user.groups_id]), '|', ('user_ids', 'in', [user.id]), '&amp;', ('groups_id', '=', False), ('user_ids', '=', False)]</field>
</record> </record>
<record id="document_page_rule_full_access" model="ir.rule"> <record id="document_page_rule_full_access" model="ir.rule">
<field name="name">Document Page Full Access</field> <field name="name">Document Page Full Access</field>

View File

@ -8,10 +8,11 @@
/* /*
:Author: David Goodger (goodger@python.org) :Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ :Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain. :Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils. Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet. customize this style sheet.
@ -274,7 +275,7 @@ pre.literal-block, pre.doctest-block, pre.math, pre.code {
margin-left: 2em ; margin-left: 2em ;
margin-right: 2em } margin-right: 2em }
pre.code .ln { color: grey; } /* line numbers */ pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee } pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 } pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@ -300,7 +301,7 @@ span.option {
span.pre { span.pre {
white-space: pre } white-space: pre }
span.problematic { span.problematic, pre.problematic {
color: red } color: red }
span.section-subtitle { span.section-subtitle {
@ -366,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:b17b9a59745b22473114b818626d1a54eb0e7d1c5cbe43c07a3040d4619b0f36 !! source digest: sha256:28e06c90139270717bf9f3fbe04145a72fed721a256eb4d526ee229beaf1cc69
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/knowledge/tree/17.0/document_page_access_group"><img alt="OCA/knowledge" src="https://img.shields.io/badge/github-OCA%2Fknowledge-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/knowledge-17-0/knowledge-17-0-document_page_access_group"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/knowledge&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p> <p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/knowledge/tree/17.0/document_page_access_group"><img alt="OCA/knowledge" src="https://img.shields.io/badge/github-OCA%2Fknowledge-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/knowledge-17-0/knowledge-17-0-document_page_access_group"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/knowledge&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows to select which users groups have access to the <p>This module allows to select which users groups have access to the
@ -387,12 +388,14 @@ document pages.</p>
<div class="section" id="usage"> <div class="section" id="usage">
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1> <h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<p>To select the users that have access to a given document page you need <p>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 to open a document, go to the Security tab and you have 3 options:</p>
will have access.</p> <ul class="simple">
<p>Only users that belong to the document_knowledge / Manager group can <li>Select a group: Only users with those groups will be able to see the
manage access groups to documents.</p> page.</li>
<p>If no groups are selected in a document, all users that can access <li>Select any user: Only the selected users will be able to see the
document pages can access this document.</p> page.</li>
<li>Do not select group or user: All users will be able to see the page.</li>
</ul>
</div> </div>
<div class="section" id="bug-tracker"> <div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1> <h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
@ -415,12 +418,18 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
<ul class="simple"> <ul class="simple">
<li>Manuel Regidor &lt;<a class="reference external" href="mailto:manuel.regidor&#64;sygel.es">manuel.regidor&#64;sygel.es</a>&gt;</li> <li>Manuel Regidor &lt;<a class="reference external" href="mailto:manuel.regidor&#64;sygel.es">manuel.regidor&#64;sygel.es</a>&gt;</li>
<li>Alberto Martínez &lt;<a class="reference external" href="mailto:alberto.martinez&#64;sygel.es">alberto.martinez&#64;sygel.es</a>&gt;</li> <li>Alberto Martínez &lt;<a class="reference external" href="mailto:alberto.martinez&#64;sygel.es">alberto.martinez&#64;sygel.es</a>&gt;</li>
<li><tt class="docutils literal">Tecnativa <span class="pre">&lt;https://www.tecnativa.com&gt;</span></tt>_:<ul>
<li>Víctor Martínez</li>
</ul>
</li>
</ul> </ul>
</div> </div>
<div class="section" id="maintainers"> <div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2> <h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p> <p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a> <a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose <p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use.</p> promote its widespread use.</p>

View File

@ -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])],
}
)

View File

@ -1,29 +1,25 @@
# 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.exceptions import UserError from odoo.exceptions import UserError
from odoo.tests import common from odoo.tests.common import users
from .common import TestDocumentPageAccessGroupBase
class TestDocumentPageAccessGroup(common.TransactionCase): class TestDocumentPageAccessGroup(TestDocumentPageAccessGroupBase):
def setUp(self): def test_page_access_constrains(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)]})
with self.assertRaises(UserError): 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)

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2022 Manuel Regidor <manuel.regidor@sygel.es> <!-- 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). --> License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo> <odoo>
<record id="document_page_access_group_view_wiki_form" model="ir.ui.view"> <record id="document_page_access_group_view_wiki_form" model="ir.ui.view">
@ -13,7 +14,12 @@
string="Security" string="Security"
groups="document_page.group_document_manager" groups="document_page.group_document_manager"
> >
<field name="groups_id" /> <group name="groups" string="Groups" invisible="user_ids">
<field name="groups_id" nolabel="1" colspan="2" />
</group>
<group name="users" string="Users" invisible="groups_id">
<field name="user_ids" widget="many2many_tags" />
</group>
</page> </page>
</xpath> </xpath>
</field> </field>