Browse Source

[IMP] Add export permission

pull/22/head
Sandip Mangukiya 8 years ago
committed by Pedro M. Baeza
parent
commit
f380a9c1eb
  1. 36
      base_export_manager/README.rst
  2. 8
      base_export_manager/__openerp__.py
  3. 6
      base_export_manager/data/ir_exports_data.xml
  4. 1
      base_export_manager/models/__init__.py
  5. 12
      base_export_manager/models/ir_model_access.py
  6. 26
      base_export_manager/models/res_users.py
  7. 63
      base_export_manager/static/src/js/base_export_manager.js
  8. 0
      base_export_manager/views/ir_exports.xml
  9. 15
      base_export_manager/views/ir_model.xml
  10. 28
      base_export_manager/views/ir_model_access.xml
  11. 18
      base_export_manager/views/res_groups.xml

36
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 <rafabn@antiun.com>
* Jairo Llopis <yajo.sk8@gmail.com>
* Dave Lasley <dave@laslabs.com>
* Sandip Mangukiya <smangukiya@ursainfosystems.com>
* Maxime Chambreuil <mchambreuil@ursainfosystems.com>
Maintainer
----------

8
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',

6
base_export_manager/data/ir_exports_data.xml

@ -1,8 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<odoo>
<function model="ir.exports.line" name="_install_base_export_manager"/>
</data>
</openerp>
</odoo>

1
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

12
base_export_manager/models/ir_model_access.py

@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
# Copyright 2016 - Ursa Information Systems <http://ursainfosystems.com>
# 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)

26
base_export_manager/models/res_users.py

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Copyright 2016 - Ursa Information Systems <http://ursainfosystems.com>
# 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

63
base_export_manager/static/src/js/base_export_manager.js

@ -5,7 +5,15 @@
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) {
@ -24,4 +32,59 @@ 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();
}
},
});
});

0
base_export_manager/views/ir_exports_view.xml → base_export_manager/views/ir_exports.xml

15
base_export_manager/views/ir_model.xml

@ -0,0 +1,15 @@
<?xml version="1.0"?>
<odoo>
<record id="ir_model_view_form" model="ir.ui.view">
<field name="name">ir.model.form.base_export_manager</field>
<field name="model">ir.model</field>
<field name="inherit_id" ref="base.view_model_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='access_ids']//tree//field[@name='perm_unlink']" position="after">
<field name="perm_export"/>
</xpath>
</field>
</record>
</odoo>

28
base_export_manager/views/ir_model_access.xml

@ -0,0 +1,28 @@
<?xml version="1.0"?>
<odoo>
<record id="ir_model_access_view_tree"
model="ir.ui.view">
<field name="name">ir.model.access.tree.base_export_manager</field>
<field name="model">ir.model.access</field>
<field name="inherit_id" ref="base.ir_access_view_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='perm_unlink']" position="after">
<field name="perm_export"/>
</xpath>
</field>
</record>
<record id="ir_model_access_view_form"
model="ir.ui.view">
<field name="name">ir.model.access.form.base_export_manager</field>
<field name="model">ir.model.access</field>
<field name="inherit_id" ref="base.ir_access_view_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='perm_unlink']" position="after">
<field name="perm_export"/>
</xpath>
</field>
</record>
</odoo>

18
base_export_manager/views/res_groups.xml

@ -0,0 +1,18 @@
<?xml version="1.0"?>
<odoo>
<record id="res_groups_view_form" model="ir.ui.view">
<field name="name">res.groups.form</field>
<field name="model">res.groups</field>
<field name="inherit_id" ref="base.view_groups_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='model_access']//tree//field[@name='perm_unlink']" position="after">
<field name="perm_export"/>
</xpath>
<xpath expr="//field[@name='model_access']//form//field[@name='perm_unlink']" position="after">
<field name="perm_export"/>
</xpath>
</field>
</record>
</odoo>
Loading…
Cancel
Save