Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] website_menu_permission. Better defaults. Easier maintenance.
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
Showing
12 changed files
with
603 additions
and
176 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 |
---|---|---|
@@ -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. |
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 |
---|---|---|
@@ -1,3 +1,2 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). | ||
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
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 |
---|---|---|
@@ -1,3 +1,2 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). | ||
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 |
---|---|---|
@@ -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() |
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,2 @@ | ||
* Simone Orsi simone.orsi@camptocamp.com | ||
* Ronald Portier ronald@therp.nl |
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 @@ | ||
Show/hide website menu items by user group. |
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,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. |
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
Oops, something went wrong.