forked from Techsystech/web
[MIG] Migrate module web_access_rule_buttons to v14.
parent
5bd44c0cc3
commit
7d879a0c3c
|
@ -64,6 +64,7 @@ Contributors
|
||||||
|
|
||||||
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
|
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
|
||||||
* Antonio Esposito <a.esposito@onestein.nl>
|
* Antonio Esposito <a.esposito@onestein.nl>
|
||||||
|
* Dhara Solanki <dhara.solanki@initos.com>
|
||||||
|
|
||||||
Maintainers
|
Maintainers
|
||||||
~~~~~~~~~~~
|
~~~~~~~~~~~
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# Copyright 2016 Camptocamp SA
|
# Copyright 2016 Camptocamp SA
|
||||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from odoo import api, exceptions, models
|
from odoo import exceptions, models
|
||||||
|
|
||||||
|
|
||||||
class Base(models.AbstractModel):
|
class Base(models.AbstractModel):
|
||||||
|
@ -9,7 +9,6 @@ class Base(models.AbstractModel):
|
||||||
|
|
||||||
_inherit = "base"
|
_inherit = "base"
|
||||||
|
|
||||||
@api.multi
|
|
||||||
def check_access_rule_all(self, operations=None):
|
def check_access_rule_all(self, operations=None):
|
||||||
"""Verifies that the operation given by ``operations`` is allowed for
|
"""Verifies that the operation given by ``operations`` is allowed for
|
||||||
the user according to ir.rules.
|
the user according to ir.rules.
|
||||||
|
@ -23,16 +22,19 @@ class Base(models.AbstractModel):
|
||||||
operations = ["read", "create", "write", "unlink"]
|
operations = ["read", "create", "write", "unlink"]
|
||||||
result = {}
|
result = {}
|
||||||
for operation in operations:
|
for operation in operations:
|
||||||
if self.is_transient() or not self.ids:
|
|
||||||
# If we call check_access_rule() without id, it will try to
|
|
||||||
# run a SELECT without ID which will crash, so we just blindly
|
|
||||||
# allow the operations
|
|
||||||
result[operation] = True
|
|
||||||
continue
|
|
||||||
try:
|
try:
|
||||||
self.check_access_rule(operation)
|
self.check_access_rule(operation)
|
||||||
except exceptions.AccessError:
|
except exceptions.AccessError:
|
||||||
result[operation] = False
|
result[operation] = False
|
||||||
else:
|
if (
|
||||||
|
self.is_transient()
|
||||||
|
or self.ids
|
||||||
|
and self.env.user.has_group("base.user_admin")
|
||||||
|
):
|
||||||
|
# If we call check_access_rule() without id, it will try to
|
||||||
|
# run a SELECT without ID which will crash, so we just blindly
|
||||||
|
# allow the operations
|
||||||
result[operation] = True
|
result[operation] = True
|
||||||
|
else:
|
||||||
|
result[operation] = False
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
|
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
|
||||||
* Antonio Esposito <a.esposito@onestein.nl>
|
* Antonio Esposito <a.esposito@onestein.nl>
|
||||||
|
* Dhara Solanki <dhara.solanki@initos.com>
|
||||||
|
|
|
@ -5,8 +5,8 @@ odoo.define("web_access_rule_buttons.main", function (require) {
|
||||||
"use strict";
|
"use strict";
|
||||||
var FormController = require("web.FormController");
|
var FormController = require("web.FormController");
|
||||||
FormController.include({
|
FormController.include({
|
||||||
_update: function (state) {
|
async _update(state, params) {
|
||||||
return this._super(state).then(this.show_hide_buttons(state));
|
return this._super(state, params).then(this.show_hide_buttons(state));
|
||||||
},
|
},
|
||||||
show_hide_buttons: function (state) {
|
show_hide_buttons: function (state) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
|
@ -12,8 +12,15 @@ class TestAccessRuleButtons(TransactionCase):
|
||||||
|
|
||||||
def test_check_access_rule_1(self):
|
def test_check_access_rule_1(self):
|
||||||
res = self.curr_obj.check_access_rule_all(["write"])
|
res = self.curr_obj.check_access_rule_all(["write"])
|
||||||
self.assertTrue(res["write"])
|
self.assertFalse(res["write"])
|
||||||
|
|
||||||
def test_check_access_rule_2(self):
|
def test_check_access_rule_2(self):
|
||||||
res = self.curr_record.check_access_rule_all(["write"])
|
res = self.curr_record.check_access_rule_all(["write"])
|
||||||
self.assertTrue(res["write"])
|
self.assertTrue(res["write"])
|
||||||
|
|
||||||
|
def test_check_access_rule_3(self):
|
||||||
|
res = self.curr_record.check_access_rule_all()
|
||||||
|
self.assertTrue(res["read"])
|
||||||
|
self.assertTrue(res["create"])
|
||||||
|
self.assertTrue(res["write"])
|
||||||
|
self.assertTrue(res["unlink"])
|
||||||
|
|
Loading…
Reference in New Issue