diff --git a/remote_report_to_printer/__manifest__.py b/remote_report_to_printer/__manifest__.py index b348426..199b330 100644 --- a/remote_report_to_printer/__manifest__.py +++ b/remote_report_to_printer/__manifest__.py @@ -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', diff --git a/remote_report_to_printer/security/ir.model.access.csv b/remote_report_to_printer/security/ir.model.access.csv index 2729507..00cfc41 100644 --- a/remote_report_to_printer/security/ir.model.access.csv +++ b/remote_report_to_printer/security/ir.model.access.csv @@ -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 diff --git a/remote_report_to_printer/tests/test_remote_printer.py b/remote_report_to_printer/tests/test_remote_printer.py index c38a036..a76a857 100644 --- a/remote_report_to_printer/tests/test_remote_printer.py +++ b/remote_report_to_printer/tests/test_remote_printer.py @@ -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,12 +68,48 @@ class TestRemotePrinter(TransactionCase): }) def test_onchange_printer(self): - remote_printer = self.env['res.remote.printer'].create({ - 'remote_id': self.remote.id, - 'printer_id': self.printer_1.id, - 'printer_tray_id': self.tray_1.id, - }) + 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, + }) self.assertTrue(remote_printer.printer_tray_id) 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, + } + )