From 539297101727fa9acf6d7f2358bd586424c9b726 Mon Sep 17 00:00:00 2001 From: antonio Date: Tue, 10 Jan 2017 11:47:48 +0100 Subject: [PATCH 1/4] [10.0][ADD] Module base_import_csv_optional This module makes importing data from CSV files optional for each user, allowing it only for those users belonging to a specific group. [FIX] Solved flake8 error E305: expected 2 blank lines after class or function definition, found 1 [FIX] Renamed base_import_csv_optional in base_import_security_group [FIX] Solved flake8 error E501: line too long; [FIX] Removed unnecessary monkeypatch and extended Base.load method; [FIX] Bugfixing in Base.load method; [FIX] Code refactoring [IMP] Tests created --- base_import_security_group/README.rst | 67 +++++++ base_import_security_group/__init__.py | 6 + base_import_security_group/__manifest__.py | 26 +++ base_import_security_group/i18n/ca.po | 21 +++ base_import_security_group/i18n/es.po | 21 +++ base_import_security_group/i18n/fr.po | 21 +++ base_import_security_group/i18n/gl.po | 21 +++ base_import_security_group/i18n/it.po | 21 +++ base_import_security_group/i18n/pt.po | 21 +++ base_import_security_group/i18n/sk.po | 21 +++ base_import_security_group/models/__init__.py | 6 + base_import_security_group/models/models.py | 39 ++++ .../base_import_security_group_security.xml | 11 ++ .../static/description/icon.png | Bin 0 -> 2754 bytes .../static/description/icon.svg | 168 ++++++++++++++++++ .../static/src/js/import.js | 30 ++++ base_import_security_group/tests/__init__.py | 5 + .../tests/test_base_import_security_group.py | 49 +++++ .../views/base_import.xml | 10 ++ 19 files changed, 564 insertions(+) create mode 100644 base_import_security_group/README.rst create mode 100644 base_import_security_group/__init__.py create mode 100644 base_import_security_group/__manifest__.py create mode 100644 base_import_security_group/i18n/ca.po create mode 100644 base_import_security_group/i18n/es.po create mode 100644 base_import_security_group/i18n/fr.po create mode 100644 base_import_security_group/i18n/gl.po create mode 100644 base_import_security_group/i18n/it.po create mode 100644 base_import_security_group/i18n/pt.po create mode 100644 base_import_security_group/i18n/sk.po create mode 100644 base_import_security_group/models/__init__.py create mode 100644 base_import_security_group/models/models.py create mode 100644 base_import_security_group/security/base_import_security_group_security.xml create mode 100644 base_import_security_group/static/description/icon.png create mode 100644 base_import_security_group/static/description/icon.svg create mode 100644 base_import_security_group/static/src/js/import.js create mode 100644 base_import_security_group/tests/__init__.py create mode 100644 base_import_security_group/tests/test_base_import_security_group.py create mode 100644 base_import_security_group/views/base_import.xml diff --git a/base_import_security_group/README.rst b/base_import_security_group/README.rst new file mode 100644 index 000000000..5a36d3d55 --- /dev/null +++ b/base_import_security_group/README.rst @@ -0,0 +1,67 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +=============================================== +Group-based permissions for importing CSV files +=============================================== + +This module makes importing data from CSV files optional for each user, +allowing it only for those users belonging to a specific group. +Any other user not belonging to such group will not have the "Import" button +available anywhere. The action will even be blocked internally (to prevent +XMLRPC access, for example). + + +Usage +===== + +To allow a user to import data from CSV files, just follow this steps: + +* Go to *Settings/Users/Users* menu. +* Enter the user you want to allow. +* Within the "Access Rights" tab and "Technical Settings" group, check the + option "Allow importing CSV files". + + +For further information, please visit: + +- https://www.odoo.com/forum/help-1 + + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smash it by providing detailed and welcomed feedback. + +Credits +======= + +Contributors +------------ + +* Alejandro Santana +* Antonio Esposito + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. + +Icon +---- + +Iconic fonts used in module icon are Font Awesome: http://fontawesome.io/ diff --git a/base_import_security_group/__init__.py b/base_import_security_group/__init__.py new file mode 100644 index 000000000..ca88ff9fd --- /dev/null +++ b/base_import_security_group/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# Copyright 2015 Anubía, soluciones en la nube,SL (http://www.anubia.es) +# Copyright 2017 Onestein (http://www.onestein.eu) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/base_import_security_group/__manifest__.py b/base_import_security_group/__manifest__.py new file mode 100644 index 000000000..ad35af7be --- /dev/null +++ b/base_import_security_group/__manifest__.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Copyright 2015 Anubía, soluciones en la nube,SL (http://www.anubia.es) +# Copyright 2017 Onestein (http://www.onestein.eu) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + 'name': 'Optional CSV import', + 'version': '10.0.1.0.0', + 'category': 'Server tools', + 'summary': 'Group-based permissions for importing CSV files', + 'license': 'AGPL-3', + 'author': 'Odoo Community Association (OCA), ' + 'Alejandro Santana , ' + 'Onestein', + 'maintainer': 'Odoo Community Association (OCA)', + 'website': 'http://odoo-community.org', + 'depends': [ + 'web', + 'base_import', + ], + 'data': [ + 'security/base_import_security_group_security.xml', + 'views/base_import.xml', + ], + 'installable': True, +} diff --git a/base_import_security_group/i18n/ca.po b/base_import_security_group/i18n/ca.po new file mode 100644 index 000000000..8264c7643 --- /dev/null +++ b/base_import_security_group/i18n/ca.po @@ -0,0 +1,21 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_import_security_group +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-08-06 18:37+0000\n" +"PO-Revision-Date: 2015-08-06 18:37+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: base_import_security_group +#: model:res.groups,name:base_import_security_group.group_import_csv +msgid "Import CSV files" +msgstr "Importar arxius CSV" diff --git a/base_import_security_group/i18n/es.po b/base_import_security_group/i18n/es.po new file mode 100644 index 000000000..45980b00a --- /dev/null +++ b/base_import_security_group/i18n/es.po @@ -0,0 +1,21 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_import_security_group +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-08-06 18:37+0000\n" +"PO-Revision-Date: 2015-08-06 18:37+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: base_import_security_group +#: model:res.groups,name:base_import_security_group.group_import_csv +msgid "Import CSV files" +msgstr "Importar archivos CSV" diff --git a/base_import_security_group/i18n/fr.po b/base_import_security_group/i18n/fr.po new file mode 100644 index 000000000..4ef9d1dd4 --- /dev/null +++ b/base_import_security_group/i18n/fr.po @@ -0,0 +1,21 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_import_security_group +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-08-06 18:37+0000\n" +"PO-Revision-Date: 2015-08-06 18:37+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: base_import_security_group +#: model:res.groups,name:base_import_security_group.group_import_csv +msgid "Import CSV files" +msgstr "Importation de fichiers CSV" diff --git a/base_import_security_group/i18n/gl.po b/base_import_security_group/i18n/gl.po new file mode 100644 index 000000000..1c2b3de0c --- /dev/null +++ b/base_import_security_group/i18n/gl.po @@ -0,0 +1,21 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_import_security_group +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-08-06 18:37+0000\n" +"PO-Revision-Date: 2015-08-06 18:37+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: base_import_security_group +#: model:res.groups,name:base_import_security_group.group_import_csv +msgid "Import CSV files" +msgstr "Importar arquivos CSV" diff --git a/base_import_security_group/i18n/it.po b/base_import_security_group/i18n/it.po new file mode 100644 index 000000000..5f3546161 --- /dev/null +++ b/base_import_security_group/i18n/it.po @@ -0,0 +1,21 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_import_security_group +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-08-06 18:37+0000\n" +"PO-Revision-Date: 2015-08-06 18:37+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: base_import_security_group +#: model:res.groups,name:base_import_security_group.group_import_csv +msgid "Import CSV files" +msgstr "Importazione di file CSV" diff --git a/base_import_security_group/i18n/pt.po b/base_import_security_group/i18n/pt.po new file mode 100644 index 000000000..1c2b3de0c --- /dev/null +++ b/base_import_security_group/i18n/pt.po @@ -0,0 +1,21 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_import_security_group +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-08-06 18:37+0000\n" +"PO-Revision-Date: 2015-08-06 18:37+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: base_import_security_group +#: model:res.groups,name:base_import_security_group.group_import_csv +msgid "Import CSV files" +msgstr "Importar arquivos CSV" diff --git a/base_import_security_group/i18n/sk.po b/base_import_security_group/i18n/sk.po new file mode 100644 index 000000000..8d1a57577 --- /dev/null +++ b/base_import_security_group/i18n/sk.po @@ -0,0 +1,21 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_import_security_group +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-08-06 18:37+0000\n" +"PO-Revision-Date: 2015-08-06 18:37+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: base_import_security_group +#: model:res.groups,name:base_import_security_group.group_import_csv +msgid "Import CSV files" +msgstr "Importovať súbory CSV" diff --git a/base_import_security_group/models/__init__.py b/base_import_security_group/models/__init__.py new file mode 100644 index 000000000..ca88ff9fd --- /dev/null +++ b/base_import_security_group/models/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# Copyright 2015 Anubía, soluciones en la nube,SL (http://www.anubia.es) +# Copyright 2017 Onestein (http://www.onestein.eu) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/base_import_security_group/models/models.py b/base_import_security_group/models/models.py new file mode 100644 index 000000000..bfef76e80 --- /dev/null +++ b/base_import_security_group/models/models.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# Copyright 2015 Anubía, soluciones en la nube,SL (http://www.anubia.es) +# Copyright 2017 Onestein (http://www.onestein.eu) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import logging + +from odoo import api, models + +_logger = logging.getLogger(__name__) + + +class Base(models.AbstractModel): + _inherit = 'base' + + @api.model + def load(self, fields, data): + '''Overriding this method we only allow its execution + if current user belongs to the group allowed for CSV data import. + An exception is raised otherwise, and also log the import attempt. + ''' + current_user = self.env.user + allowed_group = 'base_import_security_group.group_import_csv' + allowed_group_id = self.env.ref( + allowed_group, + raise_if_not_found=False + ) + if not allowed_group_id or current_user.has_group(allowed_group): + res = super(Base, self).load(fields=fields, data=data) + else: + msg = ('User (ID: %s) is not allowed to import data ' + 'in model %s.') % (self.env.uid, self._name) + _logger.info(msg) + messages = [] + info = {} + messages.append( + dict(info, type='error', message=msg, moreinfo=None)) + res = {'ids': None, 'messages': messages} + return res diff --git a/base_import_security_group/security/base_import_security_group_security.xml b/base_import_security_group/security/base_import_security_group_security.xml new file mode 100644 index 000000000..0445f0ead --- /dev/null +++ b/base_import_security_group/security/base_import_security_group_security.xml @@ -0,0 +1,11 @@ + + + + + + Import CSV files + + + + + diff --git a/base_import_security_group/static/description/icon.png b/base_import_security_group/static/description/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..4386c93592d01d75d59ee52a558636fda0bfdbb1 GIT binary patch literal 2754 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 literal 0 HcmV?d00001 diff --git a/base_import_security_group/static/description/icon.svg b/base_import_security_group/static/description/icon.svg new file mode 100644 index 000000000..18e65d7a7 --- /dev/null +++ b/base_import_security_group/static/description/icon.svg @@ -0,0 +1,168 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/base_import_security_group/static/src/js/import.js b/base_import_security_group/static/src/js/import.js new file mode 100644 index 000000000..12f043fb8 --- /dev/null +++ b/base_import_security_group/static/src/js/import.js @@ -0,0 +1,30 @@ +odoo.define('web.ListImport', function (require) { + "use strict"; + var core = require('web.core'); + var ListView = require('web.ListView'); + var Model = require('web.Model'); + + ListView.prototype.defaults.import_enabled = false; + ListView.include(/** @lends instance.web.ListView# */{ + + load_list: function (data, grouped) { + + var self = this; + var Users = new Model('res.users'); + + var result = this._super.apply(this, arguments); + Users.call('has_group', ['base_import_security_group.group_import_csv']) + .then(function (result) { + var import_enabled = result; + self.options.import_enabled = import_enabled; + + if (import_enabled === false) { + if (self.$buttons) { + self.$buttons.find('.o_button_import').remove(); + } + } + }); + return result; + } + }); +}); diff --git a/base_import_security_group/tests/__init__.py b/base_import_security_group/tests/__init__.py new file mode 100644 index 000000000..f065a1581 --- /dev/null +++ b/base_import_security_group/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Onestein (http://www.onestein.eu) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import test_base_import_security_group diff --git a/base_import_security_group/tests/test_base_import_security_group.py b/base_import_security_group/tests/test_base_import_security_group.py new file mode 100644 index 000000000..0c32867ba --- /dev/null +++ b/base_import_security_group/tests/test_base_import_security_group.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Onestein (http://www.onestein.eu) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + + +from odoo.tests import common + + +class TestImportSecurityGroup(common.TransactionCase): + def setUp(self): + super(TestImportSecurityGroup, self).setUp() + self.Access = self.env['ir.model.access'] + self.user_test = self.env.ref('base.user_demo') + + def test_01_load(self): + + fields = ( + 'id', + 'name', + 'perm_read', + 'perm_write', + 'perm_create', + 'perm_unlink', + ) + + data = [ + ('access_res_users_test', 'res.users test', '1', '0', '0', '0',), + ('access_res_users_test2', 'res.users test2', '1', '1', '1', '1'), + ] + + res = self.Access.load(fields, data) + + self.assertEqual(res['ids'], False) + self.assertEqual(len(res['messages']), 2) + self.assertEqual( + res['messages'][0]['message'], + "Missing required value for the field 'Object' (model_id)") + self.assertEqual( + res['messages'][1]['message'], + "Missing required value for the field 'Object' (model_id)") + + res2 = self.Access.sudo(self.user_test).load(fields, data) + + self.assertEqual(res2['ids'], None) + self.assertEqual(len(res2['messages']), 1) + self.assertEqual( + res2['messages'][0]['message'], + 'User (ID: %s) is not allowed to import data in ' + 'model ir.model.access.' % self.user_test.id) diff --git a/base_import_security_group/views/base_import.xml b/base_import_security_group/views/base_import.xml new file mode 100644 index 000000000..73aedfe32 --- /dev/null +++ b/base_import_security_group/views/base_import.xml @@ -0,0 +1,10 @@ + + + + + + From ccf655625f52bf02ccd0e7474dcc21674931bed0 Mon Sep 17 00:00:00 2001 From: Stefan Rijnhart Date: Fri, 17 Mar 2017 20:24:12 +0100 Subject: [PATCH 2/4] [ADD] js tests --- .../tests/test_base_import_security_group.py | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/base_import_security_group/tests/test_base_import_security_group.py b/base_import_security_group/tests/test_base_import_security_group.py index 0c32867ba..b2c48e2df 100644 --- a/base_import_security_group/tests/test_base_import_security_group.py +++ b/base_import_security_group/tests/test_base_import_security_group.py @@ -6,14 +6,34 @@ from odoo.tests import common -class TestImportSecurityGroup(common.TransactionCase): +class TestImportSecurityGroup(common.HttpCase): def setUp(self): super(TestImportSecurityGroup, self).setUp() self.Access = self.env['ir.model.access'] self.user_test = self.env.ref('base.user_demo') - def test_01_load(self): + def has_button_import(self, falsify=False, user=None): + """ + Verify that the button is either visible or invisible. + After the adjacent button is loaded, allow for a second for + the asynchronous call to finish and update the visibility """ + code = """ + window.setTimeout(function () { + if (%s$('.o_button_import').length) { + console.log('ok'); + } else { + console.log('error'); + }; + }, 1000); + """ % ('!' if falsify else '') + action = self.env.ref('base.action_partner_category_form') + link = '/web#action=%s' % action.id + self.phantom_js( + link, code, "$('button.o_list_button_add').length", + login=user.login) + def test_01_load(self): + """ Admin user can import data, but the demo user cannot """ fields = ( 'id', 'name', @@ -28,6 +48,7 @@ class TestImportSecurityGroup(common.TransactionCase): ('access_res_users_test2', 'res.users test2', '1', '1', '1', '1'), ] + self.has_button_import(user=self.env.user) res = self.Access.load(fields, data) self.assertEqual(res['ids'], False) @@ -39,6 +60,7 @@ class TestImportSecurityGroup(common.TransactionCase): res['messages'][1]['message'], "Missing required value for the field 'Object' (model_id)") + self.has_button_import(falsify=True, user=self.user_test) res2 = self.Access.sudo(self.user_test).load(fields, data) self.assertEqual(res2['ids'], None) From 357cc315555d006b01c6743831b56257e9b39a71 Mon Sep 17 00:00:00 2001 From: antonio Date: Mon, 20 Mar 2017 15:58:58 +0100 Subject: [PATCH 3/4] [FIX] Fixed Phantom JS tests [FIX] Updated travis postgresql version [FIX] Updated phantom_js version in travis [FIX] Configured travis to run tests for this module in isolation mode [FIX] Configured travis to run tests for this module in isolation mode [FIX] Added group to demo_user for test purposes [FIX] Changed waiting condition on Phantom JS test [FIX] Removed Travis configuration for isolated test environment [FIX] Changed waiting condition in phantom_js test [FIX] Changed target action in phantom_js test [FIX] Changed target action in phantom_js test --- .travis.yml | 10 +++++++++- .../tests/test_base_import_security_group.py | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index d93895204..f117abe8a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,8 @@ python: - "2.7" addons: - postgresql: "9.2" # minimal postgresql version for the daterange method + postgresql: "9.3" # minimal postgresql version for the base_import_security_group module + # more info: https://github.com/OCA/maintainer-quality-tools/issues/432 apt: packages: - expect-dev # provides unbuffer utility @@ -29,6 +30,13 @@ env: virtualenv: system_site_packages: true +before_install: + - "export PATH=$PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64/bin:$PATH" + - "if [ $(phantomjs --version) != '2.1.1' ]; then rm -rf $PWD/travis_phantomjs; mkdir -p $PWD/travis_phantomjs; fi" + - "if [ $(phantomjs --version) != '2.1.1' ]; then wget https://assets.membergetmember.co/software/phantomjs-2.1.1-linux-x86_64.tar.bz2 -O $PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2; fi" + - "if [ $(phantomjs --version) != '2.1.1' ]; then tar -xvf $PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2 -C $PWD/travis_phantomjs; fi" + - "phantomjs --version" + install: - git clone https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools - export PATH=${HOME}/maintainer-quality-tools/travis:${PATH} diff --git a/base_import_security_group/tests/test_base_import_security_group.py b/base_import_security_group/tests/test_base_import_security_group.py index b2c48e2df..985fe9325 100644 --- a/base_import_security_group/tests/test_base_import_security_group.py +++ b/base_import_security_group/tests/test_base_import_security_group.py @@ -26,8 +26,8 @@ class TestImportSecurityGroup(common.HttpCase): }; }, 1000); """ % ('!' if falsify else '') - action = self.env.ref('base.action_partner_category_form') - link = '/web#action=%s' % action.id + action = self.env.ref('base.action_partner_category_form').id + link = '/web#action=%s' % action self.phantom_js( link, code, "$('button.o_list_button_add').length", login=user.login) From 560941cd9436d3f1399b6660c33b47064ad52645 Mon Sep 17 00:00:00 2001 From: antonio Date: Wed, 26 Jul 2017 11:13:23 +0200 Subject: [PATCH 4/4] [FIX] Updated module informations --- base_import_security_group/README.rst | 17 ++++++----------- .../base_import_security_group_security.xml | 2 +- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/base_import_security_group/README.rst b/base_import_security_group/README.rst index 5a36d3d55..febbf1fbb 100644 --- a/base_import_security_group/README.rst +++ b/base_import_security_group/README.rst @@ -1,33 +1,26 @@ .. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg - :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :target: http://www.gnu.org/licenses/agpl :alt: License: AGPL-3 =============================================== Group-based permissions for importing CSV files =============================================== -This module makes importing data from CSV files optional for each user, +This module makes importing data from CSV and Excel files optional for each user, allowing it only for those users belonging to a specific group. Any other user not belonging to such group will not have the "Import" button available anywhere. The action will even be blocked internally (to prevent XMLRPC access, for example). - Usage ===== -To allow a user to import data from CSV files, just follow this steps: +To allow a user to import data from CSV and Excel files, just follow this steps: * Go to *Settings/Users/Users* menu. * Enter the user you want to allow. * Within the "Access Rights" tab and "Technical Settings" group, check the - option "Allow importing CSV files". - - -For further information, please visit: - -- https://www.odoo.com/forum/help-1 - + option "Allow importing CSV/Excel files". Bug Tracker =========== @@ -46,6 +39,8 @@ Contributors * Alejandro Santana * Antonio Esposito +Do not contact contributors directly about support or help with technical issues. + Maintainer ---------- diff --git a/base_import_security_group/security/base_import_security_group_security.xml b/base_import_security_group/security/base_import_security_group_security.xml index 0445f0ead..d8d8c6b34 100644 --- a/base_import_security_group/security/base_import_security_group_security.xml +++ b/base_import_security_group/security/base_import_security_group_security.xml @@ -3,7 +3,7 @@ - Import CSV files + Import CSV/Excel files