Skip to content

Commit

Permalink
[IMP] website_menu_permission. Better defaults. Easier maintenance.
Browse files Browse the repository at this point in the history
1. Prevent just installing this module of making most menu's unavailable for logged in users;
2. Make menu's directly configurable from website settings, as not all menu's are linked to a page;
3. Use group_ids field in new website.menu form to edit groups.

With this commit, just installing this module will not change anything in existing permissions.

TODO: update tests and README.rst.
  • Loading branch information
NL66278 committed Sep 30, 2019
1 parent 61c74ce commit e4404f3
Show file tree
Hide file tree
Showing 12 changed files with 603 additions and 176 deletions.
74 changes: 53 additions & 21 deletions website_menu_permission/README.rst
@@ -1,51 +1,83 @@
.. 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
=======================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fwebsite-lightgray.png?logo=github
:target: https://github.com/OCA/website/tree/11.0/website_menu_permission
:alt: OCA/website
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/website-11-0/website-11-0-website_menu_permission
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/186/11.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

Show/hide website menu items by user group.

TODO
**Table of contents**

.. contents::
:local:

Usage
=====

To use this module, you need to:

TODO

#. Go to Website ==> Configuration ==> Website menu's.
#. Edit the menu that you want to limit to certain groups, and add
the names of the groups that should have access.

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.
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 <https://github.com/OCA/website/issues/new?body=module:%20website_menu_permission%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Camptocamp

Contributors
------------
~~~~~~~~~~~~

- Simone Orsi simone.orsi@camptocamp.com
* Simone Orsi simone.orsi@camptocamp.com
* Ronald Portier ronald@therp.nl

Maintainer
----------
Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. 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.

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.
This module is part of the `OCA/website <https://github.com/OCA/website/tree/11.0/website_menu_permission>`_ project on GitHub.

To contribute to this module, please visit https://odoo-community.org.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 1 addition & 2 deletions website_menu_permission/__init__.py
@@ -1,3 +1,2 @@
# -*- coding: utf-8 -*-

# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
from . import models
6 changes: 2 additions & 4 deletions website_menu_permission/__manifest__.py
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Simone Orsi
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl)

# Copyright 2017 Simone Orsi.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
{
'name': 'Website Menu Permission',
'version': '11.0.1.0.0',
Expand Down
3 changes: 1 addition & 2 deletions website_menu_permission/models/__init__.py
@@ -1,3 +1,2 @@
# -*- coding: utf-8 -*-

# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
from . import website_menu
48 changes: 2 additions & 46 deletions website_menu_permission/models/website_menu.py
@@ -1,55 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Simone Orsi
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
# Copyright 2017 Simone Orsi.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
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()
2 changes: 2 additions & 0 deletions website_menu_permission/readme/CONTRIBUTORS.rst
@@ -0,0 +1,2 @@
* Simone Orsi simone.orsi@camptocamp.com
* Ronald Portier ronald@therp.nl
1 change: 1 addition & 0 deletions website_menu_permission/readme/DESCRIPTION.rst
@@ -0,0 +1 @@
Show/hide website menu items by user group.
5 changes: 5 additions & 0 deletions website_menu_permission/readme/USAGE.rst
@@ -0,0 +1,5 @@
To use this module, you need to:

#. Go to Website ==> Configuration ==> Website menu's.
#. Edit the menu that you want to limit to certain groups, and add
the names of the groups that should have access.
3 changes: 1 addition & 2 deletions website_menu_permission/security/record_rules.xml
Expand Up @@ -4,12 +4,11 @@
<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="domain_force">['|',('group_ids','in', user.groups_id.ids), ('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 e4404f3

Please sign in to comment.