mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-13 15:34:49 -06:00
[IMP] document_page_group: black, isort, prettier
This commit is contained in:
parent
7325d0ff51
commit
1b93b10929
@ -2,18 +2,13 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
'name': 'Document Page Group',
|
||||
'summary': """
|
||||
"name": "Document Page Group",
|
||||
"summary": """
|
||||
Define access groups on documents""",
|
||||
'version': '12.0.1.0.0',
|
||||
'license': 'AGPL-3',
|
||||
'author': 'Creu Blanca,Odoo Community Association (OCA)',
|
||||
'website': 'https://github.com/OCA/knowledge',
|
||||
'depends': [
|
||||
'document_page',
|
||||
],
|
||||
'data': [
|
||||
'security/document_page_security.xml',
|
||||
'views/document_page.xml',
|
||||
],
|
||||
"version": "12.0.1.0.0",
|
||||
"license": "AGPL-3",
|
||||
"author": "Creu Blanca,Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/knowledge",
|
||||
"depends": ["document_page",],
|
||||
"data": ["security/document_page_security.xml", "views/document_page.xml",],
|
||||
}
|
||||
|
@ -6,26 +6,26 @@ from odoo import api, fields, models
|
||||
|
||||
class DocumentPage(models.Model):
|
||||
|
||||
_inherit = 'document.page'
|
||||
_inherit = "document.page"
|
||||
|
||||
group_ids = fields.Many2many(
|
||||
'res.groups',
|
||||
"res.groups",
|
||||
store=True,
|
||||
relation='document_page_direct_group',
|
||||
column1='document_page_id',
|
||||
column2='group_id',
|
||||
compute='_compute_group_ids'
|
||||
relation="document_page_direct_group",
|
||||
column1="document_page_id",
|
||||
column2="group_id",
|
||||
compute="_compute_group_ids",
|
||||
)
|
||||
direct_group_ids = fields.Many2many(
|
||||
'res.groups',
|
||||
string='Visible to',
|
||||
help='Set the groups that can view this category and its childs',
|
||||
relation='document_page_group',
|
||||
column1='document_page_id',
|
||||
column2='group_id',
|
||||
"res.groups",
|
||||
string="Visible to",
|
||||
help="Set the groups that can view this category and its childs",
|
||||
relation="document_page_group",
|
||||
column1="document_page_id",
|
||||
column2="group_id",
|
||||
)
|
||||
|
||||
@api.depends('direct_group_ids', 'parent_id', 'parent_id.group_ids')
|
||||
@api.depends("direct_group_ids", "parent_id", "parent_id.group_ids")
|
||||
def _compute_group_ids(self):
|
||||
for record in self:
|
||||
groups = record.direct_group_ids
|
||||
|
@ -1,11 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record model="ir.rule" id="document_page_groups_rule">
|
||||
<field name="name">document_page groups</field>
|
||||
<field name="model_id" ref="model_document_page"/>
|
||||
<field name="global" eval="True"/>
|
||||
<field name="domain_force">['|','&',('type', '=', 'content'),'|','|',('parent_id', '=', False), ('parent_id.group_ids','=',False),('parent_id.group_ids.users','=',user.id), '&', ('type', '=', 'category'), '|', ('group_ids', '=', False), ('group_ids.users', '=', user.id)]</field>
|
||||
<field name="model_id" ref="model_document_page" />
|
||||
<field name="global" eval="True" />
|
||||
<field
|
||||
name="domain_force"
|
||||
>['|','&',('type', '=', 'content'),'|','|',('parent_id', '=', False), ('parent_id.group_ids','=',False),('parent_id.group_ids.users','=',user.id), '&', ('type', '=', 'category'), '|', ('group_ids', '=', False), ('group_ids.users', '=', user.id)]</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
|
@ -5,45 +5,43 @@ from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
class TestDocumentPageGroup(TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestDocumentPageGroup, self).setUp()
|
||||
knowledge_group = self.browse_ref('knowledge.group_document_user').id
|
||||
knowledge_group = self.browse_ref("knowledge.group_document_user").id
|
||||
self.user_id = self.env["res.users"].create(
|
||||
{
|
||||
'name': 'user',
|
||||
'login': 'login',
|
||||
'email': 'email',
|
||||
'groups_id': [(4, knowledge_group)]
|
||||
"name": "user",
|
||||
"login": "login",
|
||||
"email": "email",
|
||||
"groups_id": [(4, knowledge_group)],
|
||||
}
|
||||
)
|
||||
self.group = self.browse_ref('document_page.group_document_manager')
|
||||
self.group = self.browse_ref("document_page.group_document_manager")
|
||||
|
||||
self.categ_1 = self.env['document.page'].create({
|
||||
'name': "Categ 1",
|
||||
'type': 'category'
|
||||
})
|
||||
self.categ_2 = self.env['document.page'].create({
|
||||
'name': "Categ 2",
|
||||
'type': 'category',
|
||||
'parent_id': self.categ_1.id,
|
||||
})
|
||||
self.page = self.env['document.page'].create({
|
||||
'name': "Page 1",
|
||||
'type': 'content',
|
||||
'parent_id': self.categ_1.id,
|
||||
})
|
||||
self.categ_1 = self.env["document.page"].create(
|
||||
{"name": "Categ 1", "type": "category"}
|
||||
)
|
||||
self.categ_2 = self.env["document.page"].create(
|
||||
{"name": "Categ 2", "type": "category", "parent_id": self.categ_1.id,}
|
||||
)
|
||||
self.page = self.env["document.page"].create(
|
||||
{"name": "Page 1", "type": "content", "parent_id": self.categ_1.id,}
|
||||
)
|
||||
|
||||
def test_document_page_group(self):
|
||||
pages = self.env['document.page'].sudo(
|
||||
user=self.user_id.id
|
||||
).search([('type', '=', 'content')])
|
||||
pages = (
|
||||
self.env["document.page"]
|
||||
.sudo(user=self.user_id.id)
|
||||
.search([("type", "=", "content")])
|
||||
)
|
||||
self.assertIn(self.page.id, pages.ids)
|
||||
|
||||
self.categ_1.write({'direct_group_ids': [(4, self.group.id)]})
|
||||
self.categ_1.write({"direct_group_ids": [(4, self.group.id)]})
|
||||
self.assertIn(self.group.id, self.categ_2.group_ids.ids)
|
||||
|
||||
pages = self.env['document.page'].sudo(
|
||||
user=self.user_id.id
|
||||
).search([('type', '=', 'content')])
|
||||
pages = (
|
||||
self.env["document.page"]
|
||||
.sudo(user=self.user_id.id)
|
||||
.search([("type", "=", "content")])
|
||||
)
|
||||
self.assertNotIn(self.page.id, pages.ids)
|
||||
|
@ -1,20 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!-- Copyright 2019 Creu Blanca
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||
|
||||
<odoo>
|
||||
|
||||
<record model="ir.ui.view" id="document_page_form_view">
|
||||
<field name="name">document.page.form (in document_page_group)</field>
|
||||
<field name="model">document.page</field>
|
||||
<field name="inherit_id" ref="document_page.view_category_form"/>
|
||||
<field name="inherit_id" ref="document_page.view_category_form" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="parent_id" position="after">
|
||||
<field name="direct_group_ids" widget="many2many_tags"/>
|
||||
<field name="direct_group_ids" widget="many2many_tags" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
|
||||
</odoo>
|
||||
|
Loading…
Reference in New Issue
Block a user