-
Notifications
You must be signed in to change notification settings - Fork 260
[14.0] ir_rule_website #277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
itpp-bot
wants to merge
4
commits into
14.0
Choose a base branch
from
14.0-ir_rule_website
base: 14.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,43 @@ | ||
.. image:: https://itpp.dev/images/infinity-readme.png | ||
:alt: Tested and maintained by IT Projects Labs | ||
:target: https://itpp.dev | ||
|
||
========================== | ||
Multi-Brand Access Rules | ||
========================== | ||
|
||
Allows to use new variables to be used in ``domain_force`` field of Record Rules (``ir.rule``): | ||
|
||
* ``website_ids`` -- equal to ``context["allowed_website_ids"]`` (see module ``web_website``) | ||
* ``websites`` -- browsed ``website_ids`` | ||
|
||
For your information: Odoo provides ``website`` variable, which is equal to current website in frontend and is empty in backend | ||
|
||
Example of usage: | ||
|
||
* Show a blog on specific websites only (TODO: add link to the module) | ||
* Show an event on specific websites only (TODO: add link to the module) | ||
* Show a product on specific websites only (TODO: add link to the module) | ||
|
||
Roadmap | ||
======= | ||
|
||
* This module can be merged to ``web_website`` module | ||
* Website rules don't work for ``/mail/read_followers`` method: https://github.com/itpp-labs/access-addons/issues/232 | ||
|
||
Questions? | ||
========== | ||
|
||
To get an assistance on this module contact us by email :arrow_right: [email protected] | ||
|
||
Contributors | ||
============ | ||
* `Ivan Yelizariev <https://www.it-projects.info/team/yelizariev>`__ | ||
* `Ildar Nasyrov <https://www.it-projects.info/team/iledarn>`__ | ||
|
||
=================== | ||
|
||
Odoo Apps Store: https://apps.odoo.com/apps/modules/13.0/ir_rule_website | ||
|
||
|
||
Tested on `Odoo 14.0 <https://github.com/odoo/odoo/commit/3780fa2af5d5f6cac91e419bcab69a253db280bd>`_ |
This file contains hidden or 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 @@ | ||
from . import models |
This file contains hidden or 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,25 @@ | ||
# Copyright 2020 Ivan Yelizariev | ||
# License MIT (https://opensource.org/licenses/MIT). | ||
{ | ||
"name": """Multi-Brand Access Rules""", | ||
"summary": """Provide access depending on current website""", | ||
"category": "Access", | ||
"images": ["images/ir_rule_website.jpg"], | ||
"version": "14.0.1.0.0", | ||
"application": False, | ||
"author": "IT-Projects LLC, Ildar Nasyrov", | ||
"support": "[email protected]", | ||
"website": "https://twitter.com/OdooFree", | ||
"license": "Other OSI approved licence", # MIT | ||
"depends": ["web_website"], | ||
"external_dependencies": {"python": [], "bin": []}, | ||
"data": [], | ||
"qweb": [], | ||
"demo": [], | ||
"post_load": None, | ||
"pre_init_hook": None, | ||
"post_init_hook": None, | ||
"uninstall_hook": None, | ||
"auto_install": False, | ||
"installable": True, | ||
} |
This file contains hidden or 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,34 @@ | ||
`2.0.0` | ||
------- | ||
|
||
- **Improvement**: simplify code, get rid of ``backend_behavior`` field | ||
|
||
`1.3.2` | ||
------- | ||
|
||
- **Fix**: Models without group binded rules were then wrongly reduced to an 'AND FALSE' condition. After https://github.com/odoo/odoo/commit/023dfaeb6b9499943315358edaa01c8f823ee695 | ||
|
||
`1.3.1` | ||
------- | ||
|
||
- **Fix**: Random wrong result on applying rules in backend | ||
|
||
`1.3.0` | ||
------- | ||
|
||
- **New:** add ``website`` object to a rule evaluation context - to be able to use rules as such ``[('id','=', website.company_id.id)]`` | ||
|
||
`1.2.0` | ||
------- | ||
|
||
- **Add:** Use user's **Current Backend Website** from ``web_website`` module on evaluating website rules in Odoo backend | ||
|
||
`1.1.0` | ||
------- | ||
|
||
- **Add:** New setting in ``ir.rule`` model - to bypass website rules when working from backend | ||
|
||
`1.0.0` | ||
------- | ||
|
||
- **Init version** |
This file contains hidden or 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,34 @@ | ||
========================== | ||
Multi-Brand Access Rules | ||
========================== | ||
|
||
Installation | ||
============ | ||
|
||
* `Install <https://odoo-development.readthedocs.io/en/latest/odoo/usage/install-module.html>`__ this module in a usual way | ||
|
||
Backend Usage | ||
============= | ||
|
||
* As usual open ``[[ Settings ]] >> Technical >> Security >> Record Rules`` to create a new rule or edit existing one | ||
* RESULT: you can use variables ``websites`` and ``website_ids`` in **domain_force** field | ||
|
||
Usage in a module | ||
================= | ||
|
||
If you have a model accessible through a website, you can apply restriction in a following way: | ||
|
||
* Add field ``website_ids`` to your model to specify on which websites the record should be available | ||
* Add this ``ir_rule_website`` into the ``"depends"`` section of your manifest file | ||
* Create a security rule using ``website_ids`` in ``domain_force`` field. For example, | ||
|
||
:: | ||
|
||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<record id="blog_rule_all" model="ir.rule"> | ||
<field name="name">Blogs available only for specifed websites</field> | ||
<field name="model_id" ref="model_blog_blog"/> | ||
<field name="domain_force">[('website_ids', 'in', website_ids)]</field> | ||
</record> | ||
</odoo> |
This file contains hidden or 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,56 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * ir_rule_website | ||
# | ||
# Translators: | ||
# Dawid Runowski <[email protected]>, 2019 | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 10.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2018-04-26 19:17+0000\n" | ||
"PO-Revision-Date: 2018-04-18 13:56+0000\n" | ||
"Last-Translator: Dawid Runowski <[email protected]>, 2019\n" | ||
"Language-Team: German (https://www.transifex.com/it-projects-llc/teams/76080/" | ||
"de/)\n" | ||
"Language: de\n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: nplurals=2; plural=(n != 1);\n" | ||
|
||
#. module: ir_rule_website | ||
#: model:ir.model.fields,field_description:ir_rule_website.field_ir_rule_backend_behaviour | ||
msgid "Backend behaviour" | ||
msgstr "" | ||
|
||
#. module: ir_rule_website | ||
#: selection:ir.rule,backend_behaviour:0 | ||
msgid "Deny access" | ||
msgstr "den Zugang verweiger" | ||
|
||
#. module: ir_rule_website | ||
#: selection:ir.rule,backend_behaviour:0 | ||
msgid "Grant access" | ||
msgstr "den Zugang erlauben" | ||
|
||
#. module: ir_rule_website | ||
#: model:ir.ui.view,arch_db:ir_rule_website.view_rule_form_inherit_ir_rule_website | ||
msgid "Multi-website extension" | ||
msgstr "" | ||
|
||
#. module: ir_rule_website | ||
#: model:ir.model.fields,help:ir_rule_website.field_ir_rule_backend_behaviour | ||
msgid "" | ||
"This is bypass for main rule definition.\n" | ||
" When working from backend there is usually no 'website_id' value in " | ||
"the rule evaluation context\n" | ||
" what leads to SQL syntax error such as 'WHERE website_id IN ()' in " | ||
"rules that using 'website_id'" | ||
msgstr "" | ||
|
||
#. module: ir_rule_website | ||
#: model:ir.model,name:ir_rule_website.model_ir_rule | ||
msgid "ir.rule" | ||
msgstr "" |
This file contains hidden or 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,59 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * ir_rule_website | ||
# | ||
# Translators: | ||
# Randall <[email protected]>, 2018 | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 11.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2018-04-21 00:17+0000\n" | ||
"PO-Revision-Date: 2018-04-21 00:17+0000\n" | ||
"Last-Translator: Randall <[email protected]>, 2018\n" | ||
"Language-Team: Spanish (Costa Rica) (https://www.transifex.com/it-projects-" | ||
"llc/teams/76080/es_CR/)\n" | ||
"Language: es_CR\n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: nplurals=2; plural=(n != 1);\n" | ||
|
||
#. module: ir_rule_website | ||
#: model:ir.model.fields,field_description:ir_rule_website.field_ir_rule__backend_behaviour | ||
msgid "Backend behaviour" | ||
msgstr "" | ||
|
||
#. module: ir_rule_website | ||
#: selection:ir.rule,backend_behaviour:0 | ||
msgid "Deny access" | ||
msgstr "" | ||
|
||
#. module: ir_rule_website | ||
#: selection:ir.rule,backend_behaviour:0 | ||
msgid "Grant access" | ||
msgstr "" | ||
|
||
#. module: ir_rule_website | ||
#: model_terms:ir.ui.view,arch_db:ir_rule_website.view_rule_form_inherit_ir_rule_website | ||
msgid "Multi-website extension" | ||
msgstr "" | ||
|
||
#. module: ir_rule_website | ||
#: model:ir.model,name:ir_rule_website.model_ir_rule | ||
msgid "Record Rule" | ||
msgstr "" | ||
|
||
#. module: ir_rule_website | ||
#: model:ir.model.fields,help:ir_rule_website.field_ir_rule__backend_behaviour | ||
msgid "" | ||
"This is bypass for main rule definition.\n" | ||
" When working from backend there is usually no 'website_id' value in " | ||
"the rule evaluation context\n" | ||
" and rules that using 'website_id' evaluated as False which is not " | ||
"always desirable" | ||
msgstr "" | ||
|
||
#~ msgid "ir.rule" | ||
#~ msgstr "ir.rule" |
This file contains hidden or 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,47 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * ir_rule_website | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 12.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"Last-Translator: <>\n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: \n" | ||
|
||
#. module: ir_rule_website | ||
#: model:ir.model.fields,field_description:ir_rule_website.field_ir_rule__backend_behaviour | ||
msgid "Backend behaviour" | ||
msgstr "" | ||
|
||
#. module: ir_rule_website | ||
#: selection:ir.rule,backend_behaviour:0 | ||
msgid "Deny access" | ||
msgstr "" | ||
|
||
#. module: ir_rule_website | ||
#: selection:ir.rule,backend_behaviour:0 | ||
msgid "Grant access" | ||
msgstr "" | ||
|
||
#. module: ir_rule_website | ||
#: model_terms:ir.ui.view,arch_db:ir_rule_website.view_rule_form_inherit_ir_rule_website | ||
msgid "Multi-website extension" | ||
msgstr "" | ||
|
||
#. module: ir_rule_website | ||
#: model:ir.model,name:ir_rule_website.model_ir_rule | ||
msgid "Record Rule" | ||
msgstr "" | ||
|
||
#. module: ir_rule_website | ||
#: model:ir.model.fields,help:ir_rule_website.field_ir_rule__backend_behaviour | ||
msgid "This is bypass for main rule definition.\n" | ||
" When working from backend there is usually no 'website_id' value in the rule evaluation context\n" | ||
" and rules that using 'website_id' evaluated as False which is not always desirable" | ||
msgstr "" | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 @@ | ||
from . import ir_rule |
This file contains hidden or 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,18 @@ | ||
# Copyright 2020 Ivan Yelizariev | ||
# License MIT (https://opensource.org/licenses/MIT). | ||
from odoo import api, models | ||
|
||
|
||
class IrRule(models.Model): | ||
_inherit = "ir.rule" | ||
|
||
@api.model | ||
def _eval_context(self): | ||
context = super(IrRule, self)._eval_context() | ||
context["website_ids"] = self.env.context.get("allowed_website_ids", []) | ||
context["websites"] = self.env["website"].browse(context["website_ids"]) | ||
return context | ||
|
||
def _compute_domain_keys(self): | ||
""" Return the list of context keys to use for caching ``_compute_domain``. """ | ||
return super(IrRule, self)._compute_domain_keys() + ["allowed_website_ids"] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ДИНАР пьяный. Должно быть 2.0.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А, это не пьяный. Это в декабре просто было