Adds addon "ir_rule_website"

develop
Andreas Wabro 2018-06-11 13:29:46 +02:00
parent 54764e4d8b
commit a9be327607
11 changed files with 262 additions and 0 deletions

View File

@ -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 <https://www.it-projects.info/team/yelizariev>`__
* `Ildar Nasyrov <https://www.it-projects.info/team/iledarn>`__
Sponsors
--------
* `IT-Projects LLC <https://it-projects.info>`__
Maintainers
-----------
* `IT-Projects LLC <https://it-projects.info>`__
To get a guaranteed support you are kindly requested to purchase the module at `odoo apps store <https://apps.odoo.com/apps/modules/11.0/ir_rule_website/>`__.
Thank you for understanding!
`IT-Projects Team <https://www.it-projects.info/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: `<doc/index.rst>`_
Changelog: `<doc/changelog.rst>`_
Tested on Odoo 11.0 dc61861f90d15797b19f8ebddfb0c8a66d0afa88

View File

@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import models

View File

@ -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,
}

View File

@ -0,0 +1,4 @@
`1.0.0`
-------
- Init version

View File

@ -0,0 +1,30 @@
=========================================
Multi-website support in Security Rules
=========================================
Installation
============
* `Install <https://odoo-development.readthedocs.io/en/latest/odoo/usage/install-module.html>`__ 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,
::
<?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_id])]</field>
</record>
</odoo>

View File

@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import ir_rule

View File

@ -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)

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@ -0,0 +1,89 @@
<section class="oe_container">
<div class="oe_row oe_spaced">
<div class="oe_span12">
<h2 class="oe_slogan" style="color:#875A7B;">Multi-website support in Security Rules</h2>
<h3 class="oe_slogan">Make website-dependent access to pages, products, etc.</h3>
</div>
</div>
</section>
<section class="oe_container">
<div class="oe_row oe_spaced">
<div class="oe_span12">
<div class="alert alert-info oe_mt32" style="padding:0.3em 0.6em; font-size: 150%;">
<i class="fa fa-hand-o-right"></i><b> Technical module that allows implementing different features. For example: </b>
<ul class="list-unstyled">
<li>
<i class="fa fa-check-square-o text-primary"></i>
Show a blog on specific websites only
</li>
<li>
<i class="fa fa-check-square-o text-primary"></i>
Show an event on specific websites only
</li>
<li>
<i class="fa fa-check-square-o text-primary"></i>
Show a product on specific websites only
</li>
</ul>
</div>
</div>
</div>
</section>
<section class="oe_container">
<div class="oe_row oe_spaced">
<div class="oe_span8">
<h2>Need our service?</h2>
<p class="oe_mt32">Contact us by <a href="mailto:apps@it-projects.info">email</a> or fill out <a href="https://www.it-projects.info/page/website.contactus " target="_blank">request form</a></p>
<ul>
<li><a href="mailto:apps@it-projects.info">apps@it-projects.info <i class="fa fa-envelope-o"></i></a></li>
<li><a href="https://www.it-projects.info/page/website.contactus " target="_blank">https://www.it-projects.info/page/website.contactus <i class="fa fa-list-alt"></i></a></li>
</ul>
</div>
<div class="oe_span4">
<div class="stamp" style="width:200px;">
<div style="margin-top: 15px;
position: relative;
font-family:'Vollkorn', serif;
font-size: 16px;
line-height: 25px;
text-transform: uppercase;
font-weight: bold;
color: #75526b;
border: 3px dashed #75526b;
float: left;
padding: 4px 12px;
-webkit-transform: rotate(-1deg);
-o-transform: rotate(-1deg);
-moz-transform: rotate(-1deg);
-ms-transform: rotate(-1deg);">
Tested on Odoo<br/>11.0 community
</div>
<!--<div style="margin-top: 15px;
position: relative;
font-family:'Vollkorn', serif;
font-size: 16px;
line-height: 25px;
text-transform: uppercase;
font-weight: bold;
color: #75526b;
border: 3px dashed #75526b;
float: left;
padding: 4px 12px;
-webkit-transform: rotate(6deg);
-o-transform: rotate(6deg);
-moz-transform: rotate(6deg);
-ms-transform: rotate(6deg);">
Tested on Odoo<br/>11.0 enterprise
</div>-->
</div>
</div>
</div>
</section>

View File

@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import test_compute_domain

View File

@ -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)