Skip to content

Commit

Permalink
[ADD] [no task] website_menu_permission
Browse files Browse the repository at this point in the history
  • Loading branch information
gfcapalbo authored and NL66278 committed Aug 29, 2019
1 parent 6ade15e commit 61c74ce
Show file tree
Hide file tree
Showing 10 changed files with 856 additions and 0 deletions.
51 changes: 51 additions & 0 deletions website_menu_permission/README.rst
@@ -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.
3 changes: 3 additions & 0 deletions website_menu_permission/__init__.py
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

from . import models
21 changes: 21 additions & 0 deletions website_menu_permission/__manifest__.py
@@ -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,
}
3 changes: 3 additions & 0 deletions website_menu_permission/models/__init__.py
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

from . import website_menu
55 changes: 55 additions & 0 deletions website_menu_permission/models/website_menu.py
@@ -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()
15 changes: 15 additions & 0 deletions website_menu_permission/security/record_rules.xml
@@ -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>

0 comments on commit 61c74ce

Please sign in to comment.