[IMP] web_access_rule_buttons: black, isort, prettier.

This commit is contained in:
dsolanki
2020-12-03 12:42:10 +05:30
parent ccfd3fa1de
commit 5bd44c0cc3
7 changed files with 44 additions and 29 deletions

View File

@@ -0,0 +1 @@
../../../../web_access_rule_buttons

View File

@@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

View File

@@ -4,14 +4,14 @@
{
"name": "Web Access Rules Buttons",
"summary": "Disable Edit button if access rules prevent this action",
"version": "12.0.1.0.0",
"version": "14.0.1.0.0",
"author": "Camptocamp, Onestein, Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Web",
"depends": [
"web",
],
"website": "https://github.com/OCA/web/tree/11.0/web_access_rule_buttons",
"website": "https://github.com/OCA/web",
"data": [
"views/web_access_rule_buttons.xml",
],

View File

@@ -1,25 +1,26 @@
# Copyright 2016 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import models, api, exceptions
from odoo import api, exceptions, models
class Base(models.AbstractModel):
""" The base model, which is implicitly inherited by all models. """
_inherit = 'base'
_inherit = "base"
@api.multi
def check_access_rule_all(self, operations=None):
"""Verifies that the operation given by ``operations`` is allowed for
the user according to ir.rules.
the user according to ir.rules.
If ``operations`` is empty, it returns the result for all actions.
If ``operations`` is empty, it returns the result for all actions.
:param operation: a list of ``read``, ``create``, ``write``, ``unlink``
:return: {operation: access} (access is a boolean)
:param operation: a list of ``read``, ``create``, ``write``, ``unlink``
:return: {operation: access} (access is a boolean)
"""
if not operations or not any(operations):
operations = ['read', 'create', 'write', 'unlink']
operations = ["read", "create", "write", "unlink"]
result = {}
for operation in operations:
if self.is_transient() or not self.ids:

View File

@@ -5,21 +5,22 @@ odoo.define("web_access_rule_buttons.main", function (require) {
"use strict";
var FormController = require("web.FormController");
FormController.include({
_update: function (state) {
return this._super(state).then(this.show_hide_buttons(state));
},
show_hide_buttons : function (state) {
show_hide_buttons: function (state) {
var self = this;
return self._rpc({
model: this.modelName,
method: 'check_access_rule_all',
args: [[state.data.id], ["write"]],
}).then(function (accesses) {
self.show_hide_edit_button(accesses.write);
});
return self
._rpc({
model: this.modelName,
method: "check_access_rule_all",
args: [[state.data.id], ["write"]],
})
.then(function (accesses) {
self.show_hide_edit_button(accesses.write);
});
},
show_hide_edit_button : function (access) {
show_hide_edit_button: function (access) {
if (this.$buttons) {
var button = this.$buttons.find(".o_form_button_edit");
if (button) {
@@ -27,6 +28,5 @@ odoo.define("web_access_rule_buttons.main", function (require) {
}
}
},
});
});

View File

@@ -7,13 +7,13 @@ class TestAccessRuleButtons(TransactionCase):
def setUp(self):
super(TestAccessRuleButtons, self).setUp()
self.curr_obj = self.env['res.currency']
self.curr_record = self.env.ref('base.USD')
self.curr_obj = self.env["res.currency"]
self.curr_record = self.env.ref("base.USD")
def test_check_access_rule_1(self):
res = self.curr_obj.check_access_rule_all(['write'])
self.assertTrue(res['write'])
res = self.curr_obj.check_access_rule_all(["write"])
self.assertTrue(res["write"])
def test_check_access_rule_2(self):
res = self.curr_record.check_access_rule_all(['write'])
self.assertTrue(res['write'])
res = self.curr_record.check_access_rule_all(["write"])
self.assertTrue(res["write"])

View File

@@ -1,8 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<template id="assets_backend" name="web_access_rule_buttons assets" inherit_id="web.assets_backend">
<template
id="assets_backend"
name="web_access_rule_buttons assets"
inherit_id="web.assets_backend"
>
<xpath expr="." position="inside">
<script type="text/javascript" src="/web_access_rule_buttons/static/src/js/form_controller.js"></script>
<script
type="text/javascript"
src="/web_access_rule_buttons/static/src/js/form_controller.js"
/>
</xpath>
</template>
</odoo>