From b53acf4350950abe96eeaac6da00dfdccfd2748d Mon Sep 17 00:00:00 2001 From: Andreas Wabro Date: Mon, 11 Jun 2018 13:29:46 +0200 Subject: [PATCH] Adds addon "ir_rule_website" --- .../ir_rule_website/README.rst | 55 +++++++++++ .../ir_rule_website/__init__.py | 2 + .../ir_rule_website/__manifest__.py | 36 +++++++ .../ir_rule_website/doc/changelog.rst | 4 + .../ir_rule_website/doc/index.rst | 30 ++++++ .../ir_rule_website/models/__init__.py | 2 + .../ir_rule_website/models/ir_rule.py | 19 ++++ .../static/description/icon.png | Bin 0 -> 3035 bytes .../static/description/index.html | 89 ++++++++++++++++++ .../ir_rule_website/tests/__init__.py | 2 + .../tests/test_compute_domain.py | 23 +++++ 11 files changed, 262 insertions(+) create mode 100644 ext/3rd-party-addons/ir_rule_website/README.rst create mode 100644 ext/3rd-party-addons/ir_rule_website/__init__.py create mode 100644 ext/3rd-party-addons/ir_rule_website/__manifest__.py create mode 100644 ext/3rd-party-addons/ir_rule_website/doc/changelog.rst create mode 100644 ext/3rd-party-addons/ir_rule_website/doc/index.rst create mode 100644 ext/3rd-party-addons/ir_rule_website/models/__init__.py create mode 100644 ext/3rd-party-addons/ir_rule_website/models/ir_rule.py create mode 100644 ext/3rd-party-addons/ir_rule_website/static/description/icon.png create mode 100644 ext/3rd-party-addons/ir_rule_website/static/description/index.html create mode 100644 ext/3rd-party-addons/ir_rule_website/tests/__init__.py create mode 100644 ext/3rd-party-addons/ir_rule_website/tests/test_compute_domain.py 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 0000000000000000000000000000000000000000..b43a0a135f903a4c0c401f03a8690fbbd021a2ab GIT binary patch literal 3035 zcmV<13ncW3P))ueQQHJ1Rg98mIup&<-zh`c?djM9xM-*2g`%y!SWDzusm2EEDx3k%Y)@1 z@L+kcJXjvA!P)%o{8@9>FT5*fw0hgsc`>kZ>zPoCrz~G;M%wh{vnQ0~t0Ouo+OX8y zhTV}O`(vk%|Nd`EGA56^<&*^l80F5*XUA9QYYVkB*EZPqpZ?rzUO^Vxb+~r(C!Njh zw}i5oaPj(ulYdrVkm_y^JYHabirzV=a3ZJoddeVC7Mj8U^&=UR$L2rvg9x4TM&^vx zO;v;jzJG82Wbnf}6+8wVE5S%IWD7gUEn$YASMDF6$6=M+|Hj`3EiBYgw06FdPjKB| z2QpgS_8#0atkeE0re=tX!6o6Ru)f@qJV@mfO|o| z&b)>Khn-s=lVbTW8&@8GY~Ke!`*!SM`{L;J7-GzQ2c6>w>e?Dx`H1b2#dBx=w8&-z#6`SnAFTDe4K2wj zi~*^0S1#QDi-NKDXWIy>V)cgL2fL>fes9s*CA?nly7a}dhPI~Gk(udJ=ggS(M6oZ) z_i@FJmXl3zwD~R~jH5gLm8i;s)X~oR(f|El-t1|S`fPb&BMMqjws_J*Qz~EGf*G1R z+&d*#K7H+(m$sB|WIxhS?WfN;G!e&@C8Vxgy;6TT1dfqe=_ti&eQ4^jRi)S+Ea+w( z2Z=!tWSC*q`uCEDC1+2}vC8vUGz@8MNY@^JEP$!Z)B|MAHezX^4wC8s8ygEx_i)W8R?N1mLEz7(mF zWeapieyI8Yc1kxkc2;aI-}&bDLp28gr~2HUIz0XIh*87tOuRVDM2hJlhe)t+*i4mm zFf1t=9TtsP^4ilcu}?^Wh;aG)s`lux7=P*R7gc1xjMInJDWE z8yw)R)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#q%3RW~D1fBmPVFgO$5k8C&X`s$PHZrUt*b@bznW0T!)oTDO1%7p8)UZ3V zhiCbmY>p_)6d&Q*F%YC=ph@bX7Tu6N2Be&F@G)+&A>|tc|JNaAq!J!hEJ-CctQeC@ zU|6vym8h`dLMkC)#fwzp!HOfP1cMb{Qa;!IODJp0O1V2T +
+
+

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)