[remote_report_to_printer] add permissions to write and

delete to base.group_system
This commit is contained in:
Jordi Ballester Alomar
2018-11-07 11:43:28 +01:00
committed by Olga Marco
parent c96fbca65d
commit 33ab9c18d0
3 changed files with 62 additions and 8 deletions

View File

@@ -3,7 +3,7 @@
{
'name': "Report to printer on remotes",
'version': '11.0.2.1.0',
'version': '11.0.2.1.1',
'category': 'Generic Modules/Base',
'author': "Creu Blanca, Odoo Community Association (OCA)",
'website': 'http://www.agilebg.com',

View File

@@ -1,3 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_remote,access_remote_printer,model_res_remote_printer,base.group_user,1,0,0,0
manage_remote,manage_remote_printer,model_res_remote_printer,base.group_system,1,1,0,0
manage_remote,manage_remote_printer,model_res_remote_printer,base.group_system,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_remote access_remote_printer model_res_remote_printer base.group_user 1 0 0 0
3 manage_remote manage_remote_printer model_res_remote_printer base.group_system 1 1 0 1 0 1

View File

@@ -2,12 +2,20 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests.common import TransactionCase
from odoo.exceptions import ValidationError
from odoo.exceptions import AccessError
class TestRemotePrinter(TransactionCase):
def setUp(self):
super().setUp()
self.system_user_group = self.env.ref('base.group_system')
self.user_group = self.env.ref('base.group_user')
self.printer_manager = self._create_user('printer_manager',
self.system_user_group.id)
self.printer_user = self._create_user('printer_user',
self.user_group.id)
name = 'testing_remote_server'
self.remote = self.env['res.remote'].search([('name', '=', name)])
if not self.remote:
@@ -36,8 +44,18 @@ class TestRemotePrinter(TransactionCase):
'printer_id': self.printer_1.id,
})
def _create_user(self, name, group_ids):
return self.env['res.users'].with_context(
{'no_reset_password': True}).create(
{'name': name,
'password': 'demo',
'login': name,
'email': '@'.join([name, '@test.com']),
'groups_id': [(6, 0, [group_ids])]
})
def test_constrain(self):
self.env['res.remote.printer'].create({
self.env['res.remote.printer'].sudo(self.printer_manager).create({
'remote_id': self.remote.id,
'printer_id': self.printer_1.id,
'is_default': True,
@@ -50,7 +68,8 @@ class TestRemotePrinter(TransactionCase):
})
def test_onchange_printer(self):
remote_printer = self.env['res.remote.printer'].create({
remote_printer = self.env['res.remote.printer'].sudo(
self.printer_manager).create({
'remote_id': self.remote.id,
'printer_id': self.printer_1.id,
'printer_tray_id': self.tray_1.id,
@@ -59,3 +78,38 @@ class TestRemotePrinter(TransactionCase):
remote_printer.printer_id = self.printer_2
remote_printer._onchange_printing_printer_id()
self.assertFalse(remote_printer.printer_tray_id)
def test_permissions_delete_manager(self):
printer = self.env['res.remote.printer'].sudo(
self.printer_manager).create({
'remote_id': self.remote.id,
'printer_id': self.printer_1.id,
'is_default': True,
}
)
printer.sudo(self.printer_manager).unlink()
printer = self.env['res.remote.printer'].search([
('remote_id', '=', self.remote.id),
('printer_id', '=', self.printer_1.id)], limit=1)
self.assertEquals(printer, self.env['res.remote.printer'])
def test_permissions_delete_user(self):
printer = self.env['res.remote.printer'].sudo(
self.printer_manager).create({
'remote_id': self.remote.id,
'printer_id': self.printer_1.id,
'is_default': True,
}
)
with self.assertRaises(AccessError):
printer.sudo(self.printer_user).unlink()
def test_permissions_create_user(self):
with self.assertRaises(AccessError):
self.env['res.remote.printer'].sudo(
self.printer_user).create({
'remote_id': self.remote.id,
'printer_id': self.printer_1.id,
'is_default': True,
}
)