Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] [no task] website_menu_permission
- Loading branch information
Showing
10 changed files
with
856 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
.. image:: https://img.shields.io/badge/licence-lgpl--3-blue.svg | ||
:target: http://www.gnu.org/licenses/LGPL-3.0-standalone.html | ||
:alt: License: LGPL-3 | ||
|
||
|
||
======================= | ||
Website Menu Permission | ||
======================= | ||
|
||
Show/hide website menu items by user group. | ||
|
||
TODO | ||
|
||
|
||
Usage | ||
===== | ||
|
||
|
||
TODO | ||
|
||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/website/issues>`_. In | ||
case of trouble, please check there if your issue has already been | ||
reported. If you spotted it first, help us smashing it by providing a | ||
detailed and welcomed feedback. | ||
|
||
Credits | ||
======= | ||
|
||
Contributors | ||
------------ | ||
|
||
- Simone Orsi simone.orsi@camptocamp.com | ||
|
||
Maintainer | ||
---------- | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
This module is maintained by the OCA. | ||
|
||
OCA, or the Odoo Community Association, is a nonprofit organization | ||
whose mission is to support the collaborative development of Odoo | ||
features and promote its widespread use. | ||
|
||
To contribute to this module, please visit https://odoo-community.org. |
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,3 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from . import models |
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,21 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Simone Orsi | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl) | ||
|
||
{ | ||
'name': 'Website Menu Permission', | ||
'version': '11.0.1.0.0', | ||
'author': 'Camptocamp,Odoo Community Association (OCA)', | ||
'website': 'https://github.com/OCA/website', | ||
'license': 'LGPL-3', | ||
'category': 'Website', | ||
'summary': 'Allow to show/hide website menu items by user groups.', | ||
'depends': [ | ||
'website', | ||
], | ||
'data': [ | ||
'security/record_rules.xml', | ||
'views/website_views.xml', | ||
], | ||
'installable': 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from . import website_menu |
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,55 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Simone Orsi | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
from odoo import fields, models | ||
|
||
|
||
class WebsiteMenu(models.Model): | ||
_inherit = 'website.menu' | ||
|
||
# TODO: when we'll have an advanced form for editing groups | ||
# we should add an handler to update flags (like `_update_menu_groups`) | ||
group_ids = fields.Many2many( | ||
comodel_name='res.groups', | ||
) | ||
user_logged = fields.Boolean( | ||
string="User Logged-in", | ||
default=True, | ||
help="If checked, " | ||
"this item will be available for logged-in users.", | ||
inverse='_update_menu_groups', | ||
) | ||
user_not_logged = fields.Boolean( | ||
string="User Not Logged-in", | ||
default=True, | ||
help="If checked, " | ||
"this item will be available for not logged-in users.", | ||
inverse='_update_menu_groups', | ||
) | ||
|
||
@property | ||
def menu_group_public(self): | ||
return self.env.ref('base.group_public') | ||
|
||
@property | ||
def menu_group_logged(self): | ||
return self.env.ref('base.group_portal') | ||
|
||
def _get_updated_groups(self): | ||
"""Get update groups recordset for current menu item.""" | ||
groups = self.group_ids | ||
if self.user_logged: | ||
groups |= self.menu_group_logged | ||
else: | ||
groups -= self.menu_group_logged | ||
if self.user_not_logged: | ||
groups |= self.menu_group_public | ||
else: | ||
groups -= self.menu_group_public | ||
return groups | ||
|
||
def _update_menu_groups(self): | ||
if self.env.context.get('ws_menu_skip_group_update'): | ||
return | ||
for item in self: | ||
item.group_ids = item._get_updated_groups() |
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,15 @@ | ||
<?xml version="1.0"?> | ||
<odoo> | ||
|
||
<record id="website_menu_access" model="ir.rule"> | ||
<field name="name">website_menu_permission group access</field> | ||
<field name="model_id" ref="model_website_menu"/> | ||
<field name="domain_force">['|',('group_ids','in', [g.id for g in user.groups_id]), ('group_ids','=',False)]</field> | ||
<field name="perm_read" eval="True"/> | ||
<field name="perm_create" eval="False"/> | ||
<field name="perm_write" eval="False"/> | ||
<field name="perm_unlink" eval="False"/> | ||
</record> | ||
|
||
|
||
</odoo> |
Oops, something went wrong.