diff --git a/base_import_csv_optional/README.rst b/base_import_csv_optional/README.rst new file mode 100644 index 000000000..15847ef1f --- /dev/null +++ b/base_import_csv_optional/README.rst @@ -0,0 +1,65 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :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 smashing it by providing a detailed and welcomed feedback +`here `_. + + +Credits +======= + +Contributors +------------ + +* Alejandro Santana + +Maintainer +---------- + +.. image:: http://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: http://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 http://odoo-community.org. + +Icon +---- + +Iconic fonts used in module icon are Font Awesome: http://fontawesome.io/ diff --git a/base_import_csv_optional/__init__.py b/base_import_csv_optional/__init__.py new file mode 100644 index 000000000..5b9194b2a --- /dev/null +++ b/base_import_csv_optional/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# License and authorship info in: +# __openerp__.py file at the root folder of this module. + +from . import models diff --git a/base_import_csv_optional/__openerp__.py b/base_import_csv_optional/__openerp__.py new file mode 100644 index 000000000..5c6b7f925 --- /dev/null +++ b/base_import_csv_optional/__openerp__.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Odoo, Open Source Management Solution +# +# Copyright (c) All rights reserved: +# (c) 2015 Anubía, soluciones en la nube,SL (http://www.anubia.es) +# Alejandro Santana +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see http://www.gnu.org/licenses +# +############################################################################## +{ + 'name': 'Optional CSV import', + 'version': '1.0', + 'category': 'Server tools', + 'summary': 'Group-based permissions for importing CSV files', + 'license': 'AGPL-3', + 'author': 'Odoo Community Association (OCA), ' + 'Alejandro Santana ', + 'maintainer': 'Odoo Community Association (OCA)', + 'website': 'http://odoo-community.org', + 'depends': [ + 'base_import' + ], + 'data': [ + 'security/base_import_csv_optional_security.xml', + 'views/base_import.xml', + ], + 'js': [ + 'static/src/js/import.js', + ], + 'installable': True, + 'application': False, + 'auto_install': False, +} diff --git a/base_import_csv_optional/i18n/base_import_csv_optional.pot b/base_import_csv_optional/i18n/base_import_csv_optional.pot new file mode 100644 index 000000000..e766cb91a --- /dev/null +++ b/base_import_csv_optional/i18n/base_import_csv_optional.pot @@ -0,0 +1,21 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_import_csv_optional +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.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_csv_optional +#: model:res.groups,name:base_import_csv_optional.group_import_csv +msgid "Import CSV files" +msgstr "" diff --git a/base_import_csv_optional/i18n/ca.po b/base_import_csv_optional/i18n/ca.po new file mode 100644 index 000000000..87b5e5042 --- /dev/null +++ b/base_import_csv_optional/i18n/ca.po @@ -0,0 +1,21 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_import_csv_optional +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.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_csv_optional +#: model:res.groups,name:base_import_csv_optional.group_import_csv +msgid "Import CSV files" +msgstr "Importar arxius CSV" diff --git a/base_import_csv_optional/i18n/es.po b/base_import_csv_optional/i18n/es.po new file mode 100644 index 000000000..9c4f0f1a8 --- /dev/null +++ b/base_import_csv_optional/i18n/es.po @@ -0,0 +1,21 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_import_csv_optional +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.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_csv_optional +#: model:res.groups,name:base_import_csv_optional.group_import_csv +msgid "Import CSV files" +msgstr "Importar archivos CSV" diff --git a/base_import_csv_optional/i18n/fr.po b/base_import_csv_optional/i18n/fr.po new file mode 100644 index 000000000..1a5477f3c --- /dev/null +++ b/base_import_csv_optional/i18n/fr.po @@ -0,0 +1,21 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_import_csv_optional +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.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_csv_optional +#: model:res.groups,name:base_import_csv_optional.group_import_csv +msgid "Import CSV files" +msgstr "Importation de fichiers CSV" diff --git a/base_import_csv_optional/i18n/gl.po b/base_import_csv_optional/i18n/gl.po new file mode 100644 index 000000000..b07cbb63a --- /dev/null +++ b/base_import_csv_optional/i18n/gl.po @@ -0,0 +1,21 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_import_csv_optional +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.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_csv_optional +#: model:res.groups,name:base_import_csv_optional.group_import_csv +msgid "Import CSV files" +msgstr "Importar arquivos CSV" diff --git a/base_import_csv_optional/i18n/it.po b/base_import_csv_optional/i18n/it.po new file mode 100644 index 000000000..c533b9344 --- /dev/null +++ b/base_import_csv_optional/i18n/it.po @@ -0,0 +1,21 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_import_csv_optional +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.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_csv_optional +#: model:res.groups,name:base_import_csv_optional.group_import_csv +msgid "Import CSV files" +msgstr "Importazione di file CSV" diff --git a/base_import_csv_optional/i18n/pt.po b/base_import_csv_optional/i18n/pt.po new file mode 100644 index 000000000..b07cbb63a --- /dev/null +++ b/base_import_csv_optional/i18n/pt.po @@ -0,0 +1,21 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_import_csv_optional +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.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_csv_optional +#: model:res.groups,name:base_import_csv_optional.group_import_csv +msgid "Import CSV files" +msgstr "Importar arquivos CSV" diff --git a/base_import_csv_optional/i18n/sk.po b/base_import_csv_optional/i18n/sk.po new file mode 100644 index 000000000..f7fced06f --- /dev/null +++ b/base_import_csv_optional/i18n/sk.po @@ -0,0 +1,21 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_import_csv_optional +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.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_csv_optional +#: model:res.groups,name:base_import_csv_optional.group_import_csv +msgid "Import CSV files" +msgstr "Importovať súbory CSV" diff --git a/base_import_csv_optional/models/__init__.py b/base_import_csv_optional/models/__init__.py new file mode 100644 index 000000000..5b9194b2a --- /dev/null +++ b/base_import_csv_optional/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# License and authorship info in: +# __openerp__.py file at the root folder of this module. + +from . import models diff --git a/base_import_csv_optional/models/models.py b/base_import_csv_optional/models/models.py new file mode 100644 index 000000000..9bfeaf683 --- /dev/null +++ b/base_import_csv_optional/models/models.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +# License and authorship info in: +# __openerp__.py file at the root folder of this module. + +from openerp import api +from openerp.models import BaseModel +import logging + +_logger = logging.getLogger(__name__) +base_load = BaseModel.load + + +@api.model +def load_import_optional(self, fields=None, data=None): + '''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. + ''' + res = {} + current_user = self.env['res.users'].browse(self.env.uid) + allowed_group = 'base_import_csv_optional.group_import_csv' + if current_user and current_user.has_group(allowed_group): + res = base_load(self, fields=fields, data=data) + else: + msg = ('User (ID: %s) is not allowed to import data ' + 'in model %s.') % (self.env.uid, self._name) + _logger.error(msg) + messages = [] + info = {} + messages.append(dict(info, type='error', message=msg, moreinfo=None)) + res = {'ids': None, 'messages': messages} + return res + +# Monkey patch function +# Because BaseModel _name = None +BaseModel.load = load_import_optional diff --git a/base_import_csv_optional/security/base_import_csv_optional_security.xml b/base_import_csv_optional/security/base_import_csv_optional_security.xml new file mode 100644 index 000000000..8700681b4 --- /dev/null +++ b/base_import_csv_optional/security/base_import_csv_optional_security.xml @@ -0,0 +1,13 @@ + + + + + + + Import CSV files + + + + + + diff --git a/base_import_csv_optional/static/description/icon.png b/base_import_csv_optional/static/description/icon.png new file mode 100644 index 000000000..4386c9359 Binary files /dev/null and b/base_import_csv_optional/static/description/icon.png differ diff --git a/base_import_csv_optional/static/description/icon.svg b/base_import_csv_optional/static/description/icon.svg new file mode 100644 index 000000000..18e65d7a7 --- /dev/null +++ b/base_import_csv_optional/static/description/icon.svg @@ -0,0 +1,168 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/base_import_csv_optional/static/src/js/import.js b/base_import_csv_optional/static/src/js/import.js new file mode 100644 index 000000000..82dcc08a3 --- /dev/null +++ b/base_import_csv_optional/static/src/js/import.js @@ -0,0 +1,59 @@ +// License, author and contributors information in: +// __openerp__.py file at the root folder of this module. + +openerp.base_import_csv_optional = function (instance) { + var QWeb = instance.web.qweb; + var _t = instance.web._t; + var _lt = instance.web._lt; + + instance.web.ListView.prototype.defaults.import_enabled = false; + base_import_csv_optional = instance.web.ListView.include({ + load_list: function () { + var self = this; + var Users = new openerp.web.Model('res.users'); + + self._super.apply(self, arguments); + + Users.call('has_group', ['base_import_csv_optional.group_import_csv']) + .then(function (result) { + var import_enabled = result; + self.options.import_enabled = import_enabled; + + if (import_enabled) { + if (self.$buttons) { + self.$buttons.remove(); + } + self.$buttons = $(QWeb.render("ListView.buttons", {'widget': self})); + if (self.options.$buttons) { + self.$buttons.appendTo(self.options.$buttons); + } else { + self.$el.find('.oe_list_buttons').replaceWith(self.$buttons); + } + self.$buttons.find('.oe_list_add') + .click(self.proxy('do_add_record')) + .prop('disabled', self.grouped); + + self.$buttons.on('click', '.oe_list_button_import', function () { + self.do_action({ + type: 'ir.actions.client', + tag: 'import', + params: { + model: self.dataset.model, + // self.dataset.get_context() could be a compound? + // not sure. action's context should be evaluated + // so safer bet. Odd that timezone & al in it + // though + context: self.getParent().action.context + } + }, { + on_reverse_breadcrumb: function () { + self.reload(); + } + }); + return false; + }); + } + }); + } + }); +}; diff --git a/base_import_csv_optional/views/base_import.xml b/base_import_csv_optional/views/base_import.xml new file mode 100644 index 000000000..1deb6c341 --- /dev/null +++ b/base_import_csv_optional/views/base_import.xml @@ -0,0 +1,13 @@ + + + + + + + + +