Skip to content

Commit e231fe5

Browse files
Sandip Mangukiyastefan-tecnativa
Sandip Mangukiya
authored andcommittedAug 4, 2023
[IMP] Add export permission
1 parent ba1c047 commit e231fe5

13 files changed

+217
-30
lines changed
 

‎base_export_manager/README.rst

+29-7
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,27 @@
22
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
33
:alt: License: AGPL-3
44

5-
============================
6-
Manage model export profiles
7-
============================
5+
===================
6+
Base Export Manager
7+
===================
88

9-
This module allows an admin to manage export profiles (``ir.exports``) that
10-
Odoo stores internally but shows nowhere.
9+
This module extends the export capability:
10+
11+
1. It allows an admin to manage export profiles (``ir.exports``) that
12+
Odoo stores internally but does not show anywhere.
13+
2. It also adds a new column to access rights to enable/disable export and
14+
override the export method to check if the user is allowed to export. Export
15+
is enabled by default.
16+
17+
Configuration
18+
=============
19+
20+
* Activate the developer mode
21+
* Go to Settings > Users > Groups to select a user group
22+
* Edit the group and go to the Access Rights tab
23+
* Uncheck the "Export Access" box on the object of your choice and save
24+
25+
You can also go to Settings > Technical > Security > Access Rights.
1126

1227
Usage
1328
=====
@@ -29,8 +44,7 @@ To manage export profiles, you need to:
2944
* Choose a name.
3045
* Choose a model (table in the database).
3146
* Choose the fields to export.
32-
* If you choose a related field, you can choose also up to 3 levels of
33-
subfields.
47+
* If you choose a related field, you can choose also up to 3 levels of subfields.
3448
* You can drag & drop to reorder the fields.
3549

3650
To use one of those profiles, you need to:
@@ -41,6 +55,12 @@ To use one of those profiles, you need to:
4155
* Choose your saved export from *Saved exports*.
4256
* Press *Export to file*.
4357

58+
Once you have configured groups who cannot export an object:
59+
60+
* Connect as a user of this group
61+
* Go to the list view of the object you disabled the export
62+
* Select records and open the Action menu. The "Export" is not there.
63+
4464
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
4565
:alt: Try me on Runbot
4666
:target: https://runbot.odoo-community.org/runbot/149/9.0
@@ -70,6 +90,8 @@ Contributors
7090
* Rafael Blasco <rafabn@antiun.com>
7191
* Jairo Llopis <yajo.sk8@gmail.com>
7292
* Dave Lasley <dave@laslabs.com>
93+
* Sandip Mangukiya <smangukiya@ursainfosystems.com>
94+
* Maxime Chambreuil <mchambreuil@ursainfosystems.com>
7395

7496
Maintainer
7597
----------

‎base_export_manager/__openerp__.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,25 @@
55
{
66
'name': "Manage model export profiles",
77
'category': 'Personalization',
8-
'version': '9.0.1.0.0',
8+
'version': '9.0.1.1.0',
99
'depends': [
1010
'web',
1111
],
1212
'data': [
1313
'data/ir_exports_data.xml',
1414
'views/assets.xml',
15-
'views/ir_exports_view.xml',
15+
'views/ir_exports.xml',
16+
'views/ir_model.xml',
17+
'views/ir_model_access.xml',
18+
'views/res_groups.xml',
1619
],
1720
'qweb': [
1821
"static/src/xml/base.xml",
1922
],
2023
'author': 'Antiun Ingeniería S.L., '
2124
'Tecnativa, '
2225
'LasLabs, '
26+
'Ursa Information Systems, '
2327
'Odoo Community Association (OCA)',
2428
'website': 'http://www.antiun.com',
2529
'license': 'AGPL-3',
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<openerp>
3-
<data>
2+
<odoo>
43

5-
<function model="ir.exports.line" name="_install_base_export_manager"/>
4+
<function model="ir.exports.line" name="_install_base_export_manager"/>
65

7-
</data>
8-
</openerp>
6+
</odoo>

‎base_export_manager/models/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
44

55
from . import ir_exports, ir_exports_line
6+
from . import ir_model_access, res_users
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2016 - Ursa Information Systems <http://ursainfosystems.com>
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
4+
5+
6+
from openerp import models, fields
7+
8+
9+
class IrModelAccess(models.Model):
10+
_inherit = 'ir.model.access'
11+
12+
perm_export = fields.Boolean('Export Access', default=True)
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2016 - Ursa Information Systems <http://ursainfosystems.com>
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
4+
5+
6+
from openerp import api, models
7+
8+
9+
class ResUsers(models.Model):
10+
_inherit = 'res.users'
11+
12+
def get_export_models(self):
13+
self.env.cr.execute("SELECT model "
14+
"FROM ir_model "
15+
"WHERE id IN ("
16+
" SELECT distinct(model_id) "
17+
" FROM ir_model_access "
18+
" WHERE perm_export=TRUE AND group_id IN ("
19+
" SELECT gid "
20+
" FROM res_groups_users_rel "
21+
" WHERE uid=%s"
22+
" )"
23+
")",
24+
(self.env.uid,))
25+
model_names = [r[0] for r in self.env.cr.fetchall()]
26+
return model_names

‎base_export_manager/static/src/js/base_export_manager.js

+65-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@
44

55
odoo.define('base_export_manager.base_export_manager', function(require) {
66
'use strict';
7-
7+
8+
var jQuery = require('$');
89
var DataExport = require('web.DataExport');
10+
var core = require('web.core');
11+
var Model = require('web.DataModel');
12+
var ListView = require('web.ListView');
13+
var Sidebar = require('web.Sidebar');
14+
var _t = core._t;
15+
var Session = require('web.Session');
16+
917

1018
DataExport.include({
1119
do_load_export_field: function(field_list) {
@@ -23,5 +31,60 @@ odoo.define('base_export_manager.base_export_manager', function(require) {
2331
}
2432
},
2533
});
26-
34+
35+
36+
Session.include({
37+
get_export_models: function() {
38+
if (!this.uid) {
39+
return $.when().resolve(false);
40+
}
41+
var Users = new Model('res.users');
42+
var export_models = Users.call('get_export_models', []);
43+
return export_models;
44+
},
45+
});
46+
47+
ListView.include({
48+
view_loading: function(fvg) {
49+
this._super(fvg);
50+
this.is_export_manager();
51+
},
52+
is_export_manager: function () {
53+
var self = this;
54+
$.when(Session.get_export_models()).then(function
55+
(export_models) {
56+
self.export_models=export_models;
57+
});
58+
},
59+
/**
60+
* Instantiate and render the sidebar.
61+
* Sets this.sidebar
62+
* @param {jQuery} [$node] a jQuery node where the sidebar should be inserted
63+
* $node may be undefined, in which case the ListView inserts the sidebar in
64+
* this.options.$sidebar or in a div of its template
65+
**/
66+
render_sidebar: function($node) {
67+
var self = this;
68+
self.render_export_enable = jQuery.inArray( this.model, self.export_models );
69+
if (!this.sidebar && this.options.sidebar) {
70+
this.sidebar = new Sidebar(this, {editable: this.is_action_enabled('edit')});
71+
if (this.fields_view.toolbar) {
72+
this.sidebar.add_toolbar(this.fields_view.toolbar);
73+
}
74+
this.sidebar.add_items('other', _.compact([
75+
self.render_export_enable >= 0 && {label: _t("Export"), callback: this.on_sidebar_export},
76+
this.fields_view.fields.active && {label: _t("Archive"), callback: this.do_archive_selected},
77+
this.fields_view.fields.active && {label: _t("Unarchive"), callback: this.do_unarchive_selected},
78+
this.is_action_enabled('delete') && {label: _t('Delete'), callback: this.do_delete_selected}
79+
]));
80+
81+
$node = $node || this.options.$sidebar;
82+
this.sidebar.appendTo($node);
83+
84+
// Hide the sidebar by default (it will be shown as soon as a record is selected)
85+
this.sidebar.do_hide();
86+
}
87+
},
88+
});
89+
2790
});
+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<templates id="template" xml:space="preserve">
33

4-
<t t-extend="ExportTreeView-Secondary.children">
5-
<t t-jquery="#tree-column a" t-operation="append">
6-
(<t t-esc="field.id"/>)
4+
<t t-extend="ExportTreeView-Secondary.children">
5+
<t t-jquery="#tree-column a" t-operation="append">
6+
(<t t-esc="field.id"/>)
7+
</t>
78
</t>
8-
</t>
99

1010
</templates>

‎base_export_manager/views/assets.xml

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<odoo>
33

4-
<!-- Add Javascript -->
5-
<template id="assets_backend"
6-
inherit_id="web.assets_backend"
7-
name="Add technical name to field items"
8-
priority="20">
9-
<xpath expr="." position="inside">
10-
<script type="text/javascript"
11-
src="/base_export_manager/static/src/js/base_export_manager.js"/>
12-
</xpath>
13-
</template>
4+
<!-- Add Javascript -->
5+
<template id="assets_backend"
6+
inherit_id="web.assets_backend"
7+
name="Add technical name to field items"
8+
priority="20">
9+
<xpath expr="." position="inside">
10+
<script type="text/javascript"
11+
src="/base_export_manager/static/src/js/base_export_manager.js"/>
12+
</xpath>
13+
</template>
1414

1515
</odoo>
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0"?>
2+
<odoo>
3+
4+
<record id="ir_model_view_form" model="ir.ui.view">
5+
<field name="name">ir.model.form.base_export_manager</field>
6+
<field name="model">ir.model</field>
7+
<field name="inherit_id" ref="base.view_model_form"/>
8+
<field name="arch" type="xml">
9+
<xpath expr="//field[@name='access_ids']//tree//field[@name='perm_unlink']" position="after">
10+
<field name="perm_export"/>
11+
</xpath>
12+
</field>
13+
</record>
14+
15+
</odoo>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0"?>
2+
<odoo>
3+
4+
<record id="ir_model_access_view_tree"
5+
model="ir.ui.view">
6+
<field name="name">ir.model.access.tree.base_export_manager</field>
7+
<field name="model">ir.model.access</field>
8+
<field name="inherit_id" ref="base.ir_access_view_tree"/>
9+
<field name="arch" type="xml">
10+
<xpath expr="//field[@name='perm_unlink']" position="after">
11+
<field name="perm_export"/>
12+
</xpath>
13+
</field>
14+
</record>
15+
16+
<record id="ir_model_access_view_form"
17+
model="ir.ui.view">
18+
<field name="name">ir.model.access.form.base_export_manager</field>
19+
<field name="model">ir.model.access</field>
20+
<field name="inherit_id" ref="base.ir_access_view_form"/>
21+
<field name="arch" type="xml">
22+
<xpath expr="//field[@name='perm_unlink']" position="after">
23+
<field name="perm_export"/>
24+
</xpath>
25+
</field>
26+
</record>
27+
28+
</odoo>
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<odoo>
3+
4+
<record id="res_groups_view_form" model="ir.ui.view">
5+
<field name="name">res.groups.form</field>
6+
<field name="model">res.groups</field>
7+
<field name="inherit_id" ref="base.view_groups_form"/>
8+
<field name="arch" type="xml">
9+
<xpath expr="//field[@name='model_access']//tree//field[@name='perm_unlink']" position="after">
10+
<field name="perm_export"/>
11+
</xpath>
12+
<xpath expr="//field[@name='model_access']//form//field[@name='perm_unlink']" position="after">
13+
<field name="perm_export"/>
14+
</xpath>
15+
</field>
16+
</record>
17+
18+
</odoo>

0 commit comments

Comments
 (0)
Please sign in to comment.