From d2d3b908c6a873f3ad87f796af548da64f125942 Mon Sep 17 00:00:00 2001 From: Sandip Mangukiya Date: Fri, 5 Aug 2016 11:54:57 -0500 Subject: [PATCH] [IMP] Add export permission --- base_export_manager/README.rst | 36 ++++++++-- base_export_manager/__openerp__.py | 8 ++- base_export_manager/data/ir_exports_data.xml | 8 +-- base_export_manager/models/__init__.py | 1 + base_export_manager/models/ir_model_access.py | 12 ++++ base_export_manager/models/res_users.py | 26 +++++++ .../static/src/js/base_export_manager.js | 67 ++++++++++++++++++- base_export_manager/static/src/xml/base.xml | 8 +-- base_export_manager/views/assets.xml | 20 +++--- .../{ir_exports_view.xml => ir_exports.xml} | 0 base_export_manager/views/ir_model.xml | 15 +++++ base_export_manager/views/ir_model_access.xml | 28 ++++++++ base_export_manager/views/res_groups.xml | 18 +++++ 13 files changed, 217 insertions(+), 30 deletions(-) create mode 100644 base_export_manager/models/ir_model_access.py create mode 100644 base_export_manager/models/res_users.py rename base_export_manager/views/{ir_exports_view.xml => ir_exports.xml} (100%) create mode 100644 base_export_manager/views/ir_model.xml create mode 100644 base_export_manager/views/ir_model_access.xml create mode 100644 base_export_manager/views/res_groups.xml diff --git a/base_export_manager/README.rst b/base_export_manager/README.rst index 79a28887d..07454a9f0 100644 --- a/base_export_manager/README.rst +++ b/base_export_manager/README.rst @@ -2,12 +2,27 @@ :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 -============================ -Manage model export profiles -============================ +=================== +Base Export Manager +=================== -This module allows an admin to manage export profiles (``ir.exports``) that -Odoo stores internally but shows nowhere. +This module extends the export capability: + +1. It allows an admin to manage export profiles (``ir.exports``) that + Odoo stores internally but does not show anywhere. +2. It also adds a new column to access rights to enable/disable export and + override the export method to check if the user is allowed to export. Export + is enabled by default. + +Configuration +============= + +* Activate the developer mode +* Go to Settings > Users > Groups to select a user group +* Edit the group and go to the Access Rights tab +* Uncheck the "Export Access" box on the object of your choice and save + +You can also go to Settings > Technical > Security > Access Rights. Usage ===== @@ -29,8 +44,7 @@ To manage export profiles, you need to: * Choose a name. * Choose a model (table in the database). * Choose the fields to export. - * If you choose a related field, you can choose also up to 3 levels of - subfields. + * If you choose a related field, you can choose also up to 3 levels of subfields. * You can drag & drop to reorder the fields. To use one of those profiles, you need to: @@ -41,6 +55,12 @@ To use one of those profiles, you need to: * Choose your saved export from *Saved exports*. * Press *Export to file*. +Once you have configured groups who cannot export an object: + +* Connect as a user of this group +* Go to the list view of the object you disabled the export +* Select records and open the Action menu. The "Export" is not there. + .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot :target: https://runbot.odoo-community.org/runbot/149/9.0 @@ -70,6 +90,8 @@ Contributors * Rafael Blasco * Jairo Llopis * Dave Lasley +* Sandip Mangukiya +* Maxime Chambreuil Maintainer ---------- diff --git a/base_export_manager/__openerp__.py b/base_export_manager/__openerp__.py index 477f749c5..b5a9be97d 100644 --- a/base_export_manager/__openerp__.py +++ b/base_export_manager/__openerp__.py @@ -5,14 +5,17 @@ { 'name': "Manage model export profiles", 'category': 'Personalization', - 'version': '9.0.1.0.0', + 'version': '9.0.1.1.0', 'depends': [ 'web', ], 'data': [ 'data/ir_exports_data.xml', 'views/assets.xml', - 'views/ir_exports_view.xml', + 'views/ir_exports.xml', + 'views/ir_model.xml', + 'views/ir_model_access.xml', + 'views/res_groups.xml', ], 'qweb': [ "static/src/xml/base.xml", @@ -20,6 +23,7 @@ 'author': 'Antiun IngenierĂ­a S.L., ' 'Tecnativa, ' 'LasLabs, ' + 'Ursa Information Systems, ' 'Odoo Community Association (OCA)', 'website': 'http://www.antiun.com', 'license': 'AGPL-3', diff --git a/base_export_manager/data/ir_exports_data.xml b/base_export_manager/data/ir_exports_data.xml index e4e403f0d..c04761a89 100644 --- a/base_export_manager/data/ir_exports_data.xml +++ b/base_export_manager/data/ir_exports_data.xml @@ -1,8 +1,6 @@ - - + - + - - + diff --git a/base_export_manager/models/__init__.py b/base_export_manager/models/__init__.py index 792a2e8bd..7c2c060ff 100644 --- a/base_export_manager/models/__init__.py +++ b/base_export_manager/models/__init__.py @@ -3,3 +3,4 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import ir_exports, ir_exports_line +from . import ir_model_access, res_users diff --git a/base_export_manager/models/ir_model_access.py b/base_export_manager/models/ir_model_access.py new file mode 100644 index 000000000..24fed7261 --- /dev/null +++ b/base_export_manager/models/ir_model_access.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 - Ursa Information Systems +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + + +from openerp import models, fields + + +class IrModelAccess(models.Model): + _inherit = 'ir.model.access' + + perm_export = fields.Boolean('Export Access', default=True) diff --git a/base_export_manager/models/res_users.py b/base_export_manager/models/res_users.py new file mode 100644 index 000000000..c51534aec --- /dev/null +++ b/base_export_manager/models/res_users.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 - Ursa Information Systems +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + + +from openerp import api, models + + +class ResUsers(models.Model): + _inherit = 'res.users' + + def get_export_models(self): + self.env.cr.execute("SELECT model " + "FROM ir_model " + "WHERE id IN (" + " SELECT distinct(model_id) " + " FROM ir_model_access " + " WHERE perm_export=TRUE AND group_id IN (" + " SELECT gid " + " FROM res_groups_users_rel " + " WHERE uid=%s" + " )" + ")", + (self.env.uid,)) + model_names = [r[0] for r in self.env.cr.fetchall()] + return model_names diff --git a/base_export_manager/static/src/js/base_export_manager.js b/base_export_manager/static/src/js/base_export_manager.js index cf8c52d20..e48fd4f4c 100644 --- a/base_export_manager/static/src/js/base_export_manager.js +++ b/base_export_manager/static/src/js/base_export_manager.js @@ -4,8 +4,16 @@ odoo.define('base_export_manager.base_export_manager', function(require) { 'use strict'; - + + var jQuery = require('$'); var DataExport = require('web.DataExport'); + var core = require('web.core'); + var Model = require('web.DataModel'); + var ListView = require('web.ListView'); + var Sidebar = require('web.Sidebar'); + var _t = core._t; + var Session = require('web.Session'); + DataExport.include({ do_load_export_field: function(field_list) { @@ -23,5 +31,60 @@ odoo.define('base_export_manager.base_export_manager', function(require) { } }, }); - + + + Session.include({ + get_export_models: function() { + if (!this.uid) { + return $.when().resolve(false); + } + var Users = new Model('res.users'); + var export_models = Users.call('get_export_models', []); + return export_models; + }, + }); + + ListView.include({ + view_loading: function(fvg) { + this._super(fvg); + this.is_export_manager(); + }, + is_export_manager: function () { + var self = this; + $.when(Session.get_export_models()).then(function + (export_models) { + self.export_models=export_models; + }); + }, + /** + * Instantiate and render the sidebar. + * Sets this.sidebar + * @param {jQuery} [$node] a jQuery node where the sidebar should be inserted + * $node may be undefined, in which case the ListView inserts the sidebar in + * this.options.$sidebar or in a div of its template + **/ + render_sidebar: function($node) { + var self = this; + self.render_export_enable = jQuery.inArray( this.model, self.export_models ); + if (!this.sidebar && this.options.sidebar) { + this.sidebar = new Sidebar(this, {editable: this.is_action_enabled('edit')}); + if (this.fields_view.toolbar) { + this.sidebar.add_toolbar(this.fields_view.toolbar); + } + this.sidebar.add_items('other', _.compact([ + self.render_export_enable >= 0 && {label: _t("Export"), callback: this.on_sidebar_export}, + this.fields_view.fields.active && {label: _t("Archive"), callback: this.do_archive_selected}, + this.fields_view.fields.active && {label: _t("Unarchive"), callback: this.do_unarchive_selected}, + this.is_action_enabled('delete') && {label: _t('Delete'), callback: this.do_delete_selected} + ])); + + $node = $node || this.options.$sidebar; + this.sidebar.appendTo($node); + + // Hide the sidebar by default (it will be shown as soon as a record is selected) + this.sidebar.do_hide(); + } + }, + }); + }); diff --git a/base_export_manager/static/src/xml/base.xml b/base_export_manager/static/src/xml/base.xml index 744d005ac..b9b51f28a 100644 --- a/base_export_manager/static/src/xml/base.xml +++ b/base_export_manager/static/src/xml/base.xml @@ -1,10 +1,10 @@ - - - () + + + () + - diff --git a/base_export_manager/views/assets.xml b/base_export_manager/views/assets.xml index 49157a606..a334edaee 100644 --- a/base_export_manager/views/assets.xml +++ b/base_export_manager/views/assets.xml @@ -1,15 +1,15 @@ - -