Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions ir_rule_website/README.rst
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>`_
1 change: 1 addition & 0 deletions ir_rule_website/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
25 changes: 25 additions & 0 deletions ir_rule_website/__manifest__.py
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",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ДИНАР пьяный. Должно быть 2.0.0

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А, это не пьяный. Это в декабре просто было

"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,
}
34 changes: 34 additions & 0 deletions ir_rule_website/doc/changelog.rst
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**
34 changes: 34 additions & 0 deletions ir_rule_website/doc/index.rst
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>
56 changes: 56 additions & 0 deletions ir_rule_website/i18n/de.po
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 ""
59 changes: 59 additions & 0 deletions ir_rule_website/i18n/es_CR.po
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"
47 changes: 47 additions & 0 deletions ir_rule_website/i18n/ir_rule_website.pot
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 ""

Binary file added ir_rule_website/images/ir_rule_website.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions ir_rule_website/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import ir_rule
18 changes: 18 additions & 0 deletions ir_rule_website/models/ir_rule.py
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"]
Binary file added ir_rule_website/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading