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