diff --git a/ext/3rd-party-addons/ir_rule_website/README.rst b/ext/3rd-party-addons/ir_rule_website/README.rst new file mode 100644 index 00000000..b55252ef --- /dev/null +++ b/ext/3rd-party-addons/ir_rule_website/README.rst @@ -0,0 +1,55 @@ +========================================= + Multi-website support in Security Rules +========================================= + +Allows to use ``website_id`` (current website) in ``domain_force`` field of Record Rules (``ir.rule``), e.g.: + +* ``[('website_ids', 'in', [website_id])]`` +* ``[('website_id', '=', website_id)]`` + + +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) + +Odoo 12.0+ +========== + +We hope this feature will be built-in since Odoo 12.0 at least: https://github.com/odoo/odoo/pull/22743 + +Credits +======= + +Contributors +------------ +* `Ivan Yelizariev `__ +* `Ildar Nasyrov `__ + +Sponsors +-------- +* `IT-Projects LLC `__ + +Maintainers +----------- +* `IT-Projects LLC `__ + + To get a guaranteed support you are kindly requested to purchase the module at `odoo apps store `__. + + Thank you for understanding! + + `IT-Projects Team `__ + +Further information +=================== + +Demo: http://runbot.it-projects.info/demo/access-addons/11.0 + +HTML Description: https://apps.odoo.com/apps/modules/11.0/ir_rule_website + +Usage instructions: ``_ + +Changelog: ``_ + +Tested on Odoo 11.0 dc61861f90d15797b19f8ebddfb0c8a66d0afa88 diff --git a/ext/3rd-party-addons/ir_rule_website/__init__.py b/ext/3rd-party-addons/ir_rule_website/__init__.py new file mode 100644 index 00000000..a0fdc10f --- /dev/null +++ b/ext/3rd-party-addons/ir_rule_website/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import models diff --git a/ext/3rd-party-addons/ir_rule_website/__manifest__.py b/ext/3rd-party-addons/ir_rule_website/__manifest__.py new file mode 100644 index 00000000..05ec03fb --- /dev/null +++ b/ext/3rd-party-addons/ir_rule_website/__manifest__.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +{ + "name": """Multi-website support in Security Rules""", + "summary": """Provide access depending on current website""", + "category": "Access", + # "live_test_url": "", + "images": [], + "version": "1.0.0", + "application": False, + + "author": "IT-Projects LLC, Ildar Nasyrov", + "support": "apps@it-projects.info", + "website": "https://it-projects.info/team/iledarn", + "license": "LGPL-3", + "price": 20.00, + "currency": "EUR", + + "depends": [ + "base", + ], + "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, +} diff --git a/ext/3rd-party-addons/ir_rule_website/doc/changelog.rst b/ext/3rd-party-addons/ir_rule_website/doc/changelog.rst new file mode 100644 index 00000000..9ee2b48b --- /dev/null +++ b/ext/3rd-party-addons/ir_rule_website/doc/changelog.rst @@ -0,0 +1,4 @@ +`1.0.0` +------- + +- Init version diff --git a/ext/3rd-party-addons/ir_rule_website/doc/index.rst b/ext/3rd-party-addons/ir_rule_website/doc/index.rst new file mode 100644 index 00000000..1a61c813 --- /dev/null +++ b/ext/3rd-party-addons/ir_rule_website/doc/index.rst @@ -0,0 +1,30 @@ +========================================= + Multi-website support in Security Rules +========================================= + +Installation +============ + +* `Install `__ this module in a usual way + +Configuration +============= + +This is a core technical module - no configurations are needed + +Usage +===== + +* If you have a model accessible through a website (by means of controller methods) - specify this module into the "depends" section of your manifest file +* Now you can create security rules using `website_id` in `domain_force` fields. For example, + +:: + + + + + Blogs available only for specifed websites + + [('website_ids', 'in', [website_id])] + + diff --git a/ext/3rd-party-addons/ir_rule_website/models/__init__.py b/ext/3rd-party-addons/ir_rule_website/models/__init__.py new file mode 100644 index 00000000..3605b081 --- /dev/null +++ b/ext/3rd-party-addons/ir_rule_website/models/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import ir_rule diff --git a/ext/3rd-party-addons/ir_rule_website/models/ir_rule.py b/ext/3rd-party-addons/ir_rule_website/models/ir_rule.py new file mode 100644 index 00000000..f9626568 --- /dev/null +++ b/ext/3rd-party-addons/ir_rule_website/models/ir_rule.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- + +from odoo import api, models, tools +from odoo.addons.base.ir.ir_rule import IrRule as IrRuleOriginal + + +class IrRule(models.Model): + _inherit = 'ir.rule' + + @api.model + def _eval_context(self): + context = super(IrRule, self)._eval_context() + context['website_id'] = self._context.get('website_id') + return context + + @api.model + @tools.ormcache_context('self._uid', 'model_name', 'mode', keys=["website_id"]) + def _compute_domain(self, model_name, mode="read"): + return IrRuleOriginal._compute_domain.__wrapped__(self, model_name, mode=mode) diff --git a/ext/3rd-party-addons/ir_rule_website/static/description/icon.png b/ext/3rd-party-addons/ir_rule_website/static/description/icon.png new file mode 100644 index 00000000..b43a0a13 Binary files /dev/null and b/ext/3rd-party-addons/ir_rule_website/static/description/icon.png differ diff --git a/ext/3rd-party-addons/ir_rule_website/static/description/index.html b/ext/3rd-party-addons/ir_rule_website/static/description/index.html new file mode 100644 index 00000000..53e7264f --- /dev/null +++ b/ext/3rd-party-addons/ir_rule_website/static/description/index.html @@ -0,0 +1,89 @@ +
+
+
+

Multi-website support in Security Rules

+

Make website-dependent access to pages, products, etc.

+
+
+
+ +
+
+
+ +
+ Technical module that allows implementing different features. For example: +
    + +
  • + + Show a blog on specific websites only +
  • + +
  • + + Show an event on specific websites only +
  • + +
  • + + Show a product on specific websites only +
  • + +
+
+ +
+
+
+ +
+
+
+

Need our service?

+

Contact us by email or fill out request form

+ +
+
+
+
+ Tested on Odoo
11.0 community +
+ +
+
+
+
diff --git a/ext/3rd-party-addons/ir_rule_website/tests/__init__.py b/ext/3rd-party-addons/ir_rule_website/tests/__init__.py new file mode 100644 index 00000000..e254f1d6 --- /dev/null +++ b/ext/3rd-party-addons/ir_rule_website/tests/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import test_compute_domain diff --git a/ext/3rd-party-addons/ir_rule_website/tests/test_compute_domain.py b/ext/3rd-party-addons/ir_rule_website/tests/test_compute_domain.py new file mode 100644 index 00000000..7a4ae46a --- /dev/null +++ b/ext/3rd-party-addons/ir_rule_website/tests/test_compute_domain.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +from openerp.tests.common import TransactionCase + + +class TestComputeDomain(TransactionCase): + at_install = True + post_install = True + + def setUp(self): + super(TestComputeDomain, self).setUp() + self.demo_user = self.env.ref('base.user_demo') + self.env['ir.rule'].create({'name': 'test ir_rule_website', + 'model_id': self.env.ref('base.model_res_partner').id, + 'domain_force': "[('parent_id', 'in', [website_id])]"}) + + def _cached_compute_domain(self, website_id): + test_domain = ('parent_id', 'in', [website_id]) + domain = self.env['ir.rule'].sudo(user=self.demo_user.id).with_context(website_id=website_id)._compute_domain('res.partner') + self.assertTrue(test_domain in domain) + + def test_cache(self): + self._cached_compute_domain(1) + self._cached_compute_domain(2)