[IMP] web_disable_export_group: Differenciate between the XLSX export and the standard export

pull/3102/head
Enric Tobella 2021-10-26 17:06:13 +02:00 committed by Carlos Lopez
parent 43f366352a
commit 5fbecee462
18 changed files with 166 additions and 153 deletions

View File

@ -25,11 +25,9 @@ Web Disable Export Group
|badge1| |badge2| |badge3| |badge4| |badge5| |badge1| |badge2| |badge3| |badge4| |badge5|
In the standard Odoo the UI option 'Export' that is present in the 'Action' menu The standard export group prevents both options: 'Direct Export (xlsx)' and 'Export All'.
and the 'Export All' button of any list view is always enabled (for every user).
This module makes the option 'Export' and 'Export All' enabled only for the users This module adds a new group for the 'Direct Export (xlsx)' feature, leaving the standard one for only the 'Export All' feature.
that belong to the Export Data group.
Admin user can always use the export option. Admin user can always use the export option.
@ -41,13 +39,13 @@ Admin user can always use the export option.
Configuration Configuration
============= =============
Enable the group "Export Data group" to the users who are allowed to Enable the group "Direct Export" to the users who are allowed to
make use of the option 'Export'. make use of the option 'Export xlsx'.
Usage Usage
===== =====
Every user without *Export Data* permission won't have the option available. Every user without *Direct Export (xlsx)* permission won't have the option available.
Bug Tracker Bug Tracker
=========== ===========
@ -81,6 +79,7 @@ Contributors
* David Vidal * David Vidal
* João Marques * João Marques
* Alexandre Díaz * Alexandre Díaz
* Víctor Martínez
Maintainers Maintainers
~~~~~~~~~~~ ~~~~~~~~~~~

View File

@ -4,7 +4,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{ {
"name": "Web Disable Export Group", "name": "Web Disable Export Group",
"version": "14.0.1.0.0", "version": "14.0.2.0.0",
"license": "AGPL-3", "license": "AGPL-3",
"author": "Onestein, " "Tecnativa, " "Odoo Community Association (OCA)", "author": "Onestein, " "Tecnativa, " "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/web", "website": "https://github.com/OCA/web",

View File

@ -17,19 +17,33 @@ msgstr ""
"X-Generator: Weblate 3.10\n" "X-Generator: Weblate 3.10\n"
#. module: web_disable_export_group #. module: web_disable_export_group
#. openerp-web #: model:res.groups,name:web_disable_export_group.group_export_xlsx_data
#: code:addons/web_disable_export_group/static/src/js/disable_export_group.js:0 msgid "Direct Export (xlsx)"
#: code:addons/web_disable_export_group/static/src/js/web_disable_export_group_tour.js:0 msgstr ""
#, python-format
msgid "Export"
msgstr "Exportar"
#. module: web_disable_export_group #. module: web_disable_export_group
#: model:res.groups,name:web_disable_export_group.group_export_data #: model:ir.model.fields,field_description:web_disable_export_group.field_ir_http__display_name
msgid "Export Data" msgid "Display Name"
msgstr "Exportar datos" msgstr ""
#. module: web_disable_export_group #. module: web_disable_export_group
#: model:ir.model,name:web_disable_export_group.model_ir_http #: model:ir.model,name:web_disable_export_group.model_ir_http
msgid "HTTP Routing" msgid "HTTP Routing"
msgstr "Ruta HTTP" msgstr "Ruta HTTP"
#. module: web_disable_export_group
#: model:ir.model.fields,field_description:web_disable_export_group.field_ir_http__id
msgid "ID"
msgstr ""
#. module: web_disable_export_group
#: model:ir.model.fields,field_description:web_disable_export_group.field_ir_http____last_update
msgid "Last Modified on"
msgstr ""
#, python-format
#~ msgid "Export"
#~ msgstr "Exportar"
#~ msgid "Export Data"
#~ msgstr "Exportar datos"

View File

@ -18,19 +18,33 @@ msgstr ""
"X-Generator: Weblate 3.9.1\n" "X-Generator: Weblate 3.9.1\n"
#. module: web_disable_export_group #. module: web_disable_export_group
#. openerp-web #: model:res.groups,name:web_disable_export_group.group_export_xlsx_data
#: code:addons/web_disable_export_group/static/src/js/disable_export_group.js:0 msgid "Direct Export (xlsx)"
#: code:addons/web_disable_export_group/static/src/js/web_disable_export_group_tour.js:0 msgstr ""
#, python-format
msgid "Export"
msgstr "Izvoz"
#. module: web_disable_export_group #. module: web_disable_export_group
#: model:res.groups,name:web_disable_export_group.group_export_data #: model:ir.model.fields,field_description:web_disable_export_group.field_ir_http__display_name
msgid "Export Data" msgid "Display Name"
msgstr "Izvoz podataka" msgstr ""
#. module: web_disable_export_group #. module: web_disable_export_group
#: model:ir.model,name:web_disable_export_group.model_ir_http #: model:ir.model,name:web_disable_export_group.model_ir_http
msgid "HTTP Routing" msgid "HTTP Routing"
msgstr "HTTP usmjeravanje" msgstr "HTTP usmjeravanje"
#. module: web_disable_export_group
#: model:ir.model.fields,field_description:web_disable_export_group.field_ir_http__id
msgid "ID"
msgstr ""
#. module: web_disable_export_group
#: model:ir.model.fields,field_description:web_disable_export_group.field_ir_http____last_update
msgid "Last Modified on"
msgstr ""
#, python-format
#~ msgid "Export"
#~ msgstr "Izvoz"
#~ msgid "Export Data"
#~ msgstr "Izvoz podataka"

View File

@ -17,19 +17,33 @@ msgstr ""
"X-Generator: Weblate 3.10\n" "X-Generator: Weblate 3.10\n"
#. module: web_disable_export_group #. module: web_disable_export_group
#. openerp-web #: model:res.groups,name:web_disable_export_group.group_export_xlsx_data
#: code:addons/web_disable_export_group/static/src/js/disable_export_group.js:0 msgid "Direct Export (xlsx)"
#: code:addons/web_disable_export_group/static/src/js/web_disable_export_group_tour.js:0 msgstr ""
#, python-format
msgid "Export"
msgstr "Exportar"
#. module: web_disable_export_group #. module: web_disable_export_group
#: model:res.groups,name:web_disable_export_group.group_export_data #: model:ir.model.fields,field_description:web_disable_export_group.field_ir_http__display_name
msgid "Export Data" msgid "Display Name"
msgstr "Exportar Dados" msgstr ""
#. module: web_disable_export_group #. module: web_disable_export_group
#: model:ir.model,name:web_disable_export_group.model_ir_http #: model:ir.model,name:web_disable_export_group.model_ir_http
msgid "HTTP Routing" msgid "HTTP Routing"
msgstr "Encaminhamento HTTP" msgstr "Encaminhamento HTTP"
#. module: web_disable_export_group
#: model:ir.model.fields,field_description:web_disable_export_group.field_ir_http__id
msgid "ID"
msgstr ""
#. module: web_disable_export_group
#: model:ir.model.fields,field_description:web_disable_export_group.field_ir_http____last_update
msgid "Last Modified on"
msgstr ""
#, python-format
#~ msgid "Export"
#~ msgstr "Exportar"
#~ msgid "Export Data"
#~ msgstr "Exportar Dados"

View File

@ -13,25 +13,16 @@ msgstr ""
"Content-Transfer-Encoding: \n" "Content-Transfer-Encoding: \n"
"Plural-Forms: \n" "Plural-Forms: \n"
#. module: web_disable_export_group
#: model:res.groups,name:web_disable_export_group.group_export_xlsx_data
msgid "Direct Export (xlsx)"
msgstr ""
#. module: web_disable_export_group #. module: web_disable_export_group
#: model:ir.model.fields,field_description:web_disable_export_group.field_ir_http__display_name #: model:ir.model.fields,field_description:web_disable_export_group.field_ir_http__display_name
msgid "Display Name" msgid "Display Name"
msgstr "" msgstr ""
#. module: web_disable_export_group
#. openerp-web
#: code:addons/web_disable_export_group/static/src/js/disable_export_group.js:0
#: code:addons/web_disable_export_group/static/src/js/web_disable_export_group_tour.js:0
#: code:addons/web_disable_export_group/static/src/js/web_disable_export_group_tour.js:0
#, python-format
msgid "Export"
msgstr ""
#. module: web_disable_export_group
#: model:res.groups,name:web_disable_export_group.group_export_data
msgid "Export Data"
msgstr ""
#. module: web_disable_export_group #. module: web_disable_export_group
#: model:ir.model,name:web_disable_export_group.model_ir_http #: model:ir.model,name:web_disable_export_group.model_ir_http
msgid "HTTP Routing" msgid "HTTP Routing"

View File

@ -17,19 +17,33 @@ msgstr ""
"X-Generator: Weblate 3.8\n" "X-Generator: Weblate 3.8\n"
#. module: web_disable_export_group #. module: web_disable_export_group
#. openerp-web #: model:res.groups,name:web_disable_export_group.group_export_xlsx_data
#: code:addons/web_disable_export_group/static/src/js/disable_export_group.js:0 msgid "Direct Export (xlsx)"
#: code:addons/web_disable_export_group/static/src/js/web_disable_export_group_tour.js:0 msgstr ""
#, python-format
msgid "Export"
msgstr "导出"
#. module: web_disable_export_group #. module: web_disable_export_group
#: model:res.groups,name:web_disable_export_group.group_export_data #: model:ir.model.fields,field_description:web_disable_export_group.field_ir_http__display_name
msgid "Export Data" msgid "Display Name"
msgstr "导出数据" msgstr ""
#. module: web_disable_export_group #. module: web_disable_export_group
#: model:ir.model,name:web_disable_export_group.model_ir_http #: model:ir.model,name:web_disable_export_group.model_ir_http
msgid "HTTP Routing" msgid "HTTP Routing"
msgstr "HTTP路由" msgstr "HTTP路由"
#. module: web_disable_export_group
#: model:ir.model.fields,field_description:web_disable_export_group.field_ir_http__id
msgid "ID"
msgstr ""
#. module: web_disable_export_group
#: model:ir.model.fields,field_description:web_disable_export_group.field_ir_http____last_update
msgid "Last Modified on"
msgstr ""
#, python-format
#~ msgid "Export"
#~ msgstr "导出"
#~ msgid "Export Data"
#~ msgstr "导出数据"

View File

@ -0,0 +1,16 @@
from openupgradelib import openupgrade
def add_new_group_from_group(self, env, group, new_group):
groups = env["res.groups"].search([("implied_ids", "=", group.id)])
groups.write({"implied_ids": [(4, new_group.id)]})
group.users.write({"groups_id": [(4, new_group.id)]})
@openupgrade.migrate()
def migrate(env, version):
group = env.ref("web_disable_export_group.group_export_data")
new_group = env.ref("web_disable_export_group.group_export_xlsx_data")
add_new_group_from_group(env, group, new_group)
group = env.ref("base.group_allow_export")
add_new_group_from_group(env, group, new_group)

View File

@ -13,8 +13,8 @@ class Http(models.AbstractModel):
user = request.env.user user = request.env.user
res.update( res.update(
{ {
"group_export_data": user "group_xlsx_export_data": user
and user.has_group("web_disable_export_group.group_export_data"), and user.has_group("web_disable_export_group.group_export_xlsx_data"),
} }
) )
return res return res

View File

@ -1,2 +1,2 @@
Enable the group "Export Data group" to the users who are allowed to Enable the group "Direct Export" to the users who are allowed to
make use of the option 'Export'. make use of the option 'Export xlsx'.

View File

@ -8,3 +8,4 @@
* David Vidal * David Vidal
* João Marques * João Marques
* Alexandre Díaz * Alexandre Díaz
* Víctor Martínez

View File

@ -1,7 +1,5 @@
In the standard Odoo the UI option 'Export' that is present in the 'Action' menu The standard export group prevents both options: 'Direct Export (xlsx)' and 'Export All'.
and the 'Export All' button of any list view is always enabled (for every user).
This module makes the option 'Export' and 'Export All' enabled only for the users This module adds a new group for the 'Direct Export (xlsx)' feature, leaving the standard one for only the 'Export All' feature.
that belong to the Export Data group.
Admin user can always use the export option. Admin user can always use the export option.

View File

@ -1 +1 @@
Every user without *Export Data* permission won't have the option available. Every user without *Direct Export (xlsx)* permission won't have the option available.

View File

@ -2,8 +2,10 @@
<!-- Copyright 2016 Onestein <!-- Copyright 2016 Onestein
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).--> License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).-->
<odoo> <odoo>
<record id="group_export_data" model="res.groups"> <record id="group_export_xlsx_data" model="res.groups">
<field name="name">Export Data</field> <field name="name">Direct Export (xlsx)</field>
<field name="implied_ids" eval="[(4, ref('base.group_allow_export'))]" />
<field name="category_id" ref="base.module_category_hidden" />
<field <field
name="users" name="users"
eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"

View File

@ -368,10 +368,8 @@ ul.auto-toc {
!! changes will be overwritten. !! !! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/web/tree/14.0/web_disable_export_group"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/web-14-0/web-14-0-web_disable_export_group"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/162/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p> <p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/web/tree/14.0/web_disable_export_group"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/web-14-0/web-14-0-web_disable_export_group"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/162/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>In the standard Odoo the UI option Export that is present in the Action menu <p>The standard export group prevents both options: Direct Export (xlsx) and Export All.</p>
and the Export All button of any list view is always enabled (for every user).</p> <p>This module adds a new group for the Direct Export (xlsx) feature, leaving the standard one for only the Export All feature.</p>
<p>This module makes the option Export and Export All enabled only for the users
that belong to the Export Data group.</p>
<p>Admin user can always use the export option.</p> <p>Admin user can always use the export option.</p>
<p><strong>Table of contents</strong></p> <p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents"> <div class="contents local topic" id="contents">
@ -389,12 +387,12 @@ that belong to the Export Data group.</p>
</div> </div>
<div class="section" id="configuration"> <div class="section" id="configuration">
<h1><a class="toc-backref" href="#id1">Configuration</a></h1> <h1><a class="toc-backref" href="#id1">Configuration</a></h1>
<p>Enable the group “Export Data group” to the users who are allowed to <p>Enable the group “Direct Export” to the users who are allowed to
make use of the option Export.</p> make use of the option Export xlsx.</p>
</div> </div>
<div class="section" id="usage"> <div class="section" id="usage">
<h1><a class="toc-backref" href="#id2">Usage</a></h1> <h1><a class="toc-backref" href="#id2">Usage</a></h1>
<p>Every user without <em>Export Data</em> permission wont have the option available.</p> <p>Every user without <em>Direct Export (xlsx)</em> permission wont have the option available.</p>
</div> </div>
<div class="section" id="bug-tracker"> <div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id3">Bug Tracker</a></h1> <h1><a class="toc-backref" href="#id3">Bug Tracker</a></h1>
@ -425,6 +423,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<li>David Vidal</li> <li>David Vidal</li>
<li>João Marques</li> <li>João Marques</li>
<li>Alexandre Díaz</li> <li>Alexandre Díaz</li>
<li>Víctor Martínez</li>
</ul> </ul>
</li> </li>
</ul> </ul>

View File

@ -1,33 +1,15 @@
/* Copyright 2016 Onestein /* Copyright 2016 Onestein
Copyright 2018 Tecnativa - David Vidal Copyright 2018 Tecnativa - David Vidal
Copyright 2021 Tecnativa - Alexandre Díaz Copyright 2021 Tecnativa - Alexandre Díaz
Copyright 2022 Tecnativa - Víctor Martínez
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). */ License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). */
odoo.define("web_disable_export_group", function (require) { odoo.define("web_disable_export_group.WebDisableExportGroupController", function (
require
) {
"use strict"; "use strict";
const core = require("web.core");
const Sidebar = require("web.Sidebar");
const session = require("web.session"); const session = require("web.session");
const AbstractController = require("web.AbstractController"); const AbstractController = require("web.AbstractController");
const _t = core._t;
Sidebar.include({
/**
* @override
*/
_addItems: function (sectionCode, items) {
let _items = items;
if (
!session.is_superuser &&
sectionCode === "other" &&
items.length &&
!session.group_export_data
) {
_items = _.reject(_items, {label: _t("Export")});
}
this._super(sectionCode, _items);
},
});
AbstractController.include({ AbstractController.include({
/** /**
@ -37,8 +19,8 @@ odoo.define("web_disable_export_group", function (require) {
if ( if (
!session.is_superuser && !session.is_superuser &&
action && action &&
action.startsWith("export_") && action.startsWith("export_xlsx") &&
!session.group_export_data !session.group_xlsx_export_data
) { ) {
return false; return false;
} }

View File

@ -1,16 +1,14 @@
/* Copyright 2020 Tecnativa - João Marques /* Copyright 2020 Tecnativa - João Marques
Copyright 2022 Tecnativa - Víctor Martínez
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). */ License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). */
odoo.define("web_disable_export_group.tour", function (require) { odoo.define("web_disable_export_group.tour", function (require) {
"use strict"; "use strict";
var core = require("web.core");
var tour = require("web_tour.tour"); var tour = require("web_tour.tour");
var _t = core._t;
tour.register( tour.register(
"export_tour_admin", "export_tour_xlsx_button_ok",
{ {
test: true, test: true,
url: url:
@ -21,25 +19,10 @@ odoo.define("web_disable_export_group.tour", function (require) {
content: "Check if 'Export all' button exists", content: "Check if 'Export all' button exists",
trigger: ".o_list_buttons:has(.o_list_export_xlsx)", trigger: ".o_list_buttons:has(.o_list_export_xlsx)",
}, },
{
content: "Select all records",
trigger: ".custom-control-input:first",
},
{
content: "Open actions",
trigger: ".o_dropdown_toggler_btn",
},
{
content: "Check if Export button exists",
trigger:
'.o_cp_action_menus ul.o_dropdown_menu a:contains("' +
_t("Export") +
'")',
},
] ]
); );
tour.register( tour.register(
"export_tour_demo", "export_tour_xlsx_button_ko",
{ {
test: true, test: true,
url: url:
@ -50,21 +33,6 @@ odoo.define("web_disable_export_group.tour", function (require) {
content: "Check if 'Export all' button exists", content: "Check if 'Export all' button exists",
trigger: ".o_list_buttons:not(:has(.o_list_export_xlsx))", trigger: ".o_list_buttons:not(:has(.o_list_export_xlsx))",
}, },
{
content: "Select all records",
trigger: ".custom-control-input:first",
},
{
content: "Open actions",
trigger: ".o_dropdown_toggler_btn",
},
{
content: "Check if Export button does not exist",
trigger:
'.o_cp_action_menus ul.o_dropdown_menu a:first:not(:contains("' +
_t("Export") +
'"))',
},
] ]
); );
return {}; return {};

View File

@ -1,32 +1,33 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# Copyright 2020 Tecnativa - João Marques # Copyright 2020 Tecnativa - João Marques
# Copyright 2022 Tecnativa - Víctor Martínez
import odoo.tests import odoo.tests
from odoo.tests import new_test_user
@odoo.tests.tagged("post_install", "-at_install") @odoo.tests.tagged("post_install", "-at_install")
class TestTour(odoo.tests.HttpCase): class TestTour(odoo.tests.HttpCase):
def setUp(self): def setUp(self):
super().setUp() super().setUp()
self.env["res.users"].create( new_test_user(
{ self.env,
"name": "user_not_export", login="user_not_export",
"login": "user_not_export", password="user_not_export",
"password": "user_not_export", groups="base.group_user,base.group_system",
"groups_id": [
(
6,
0,
[
self.env.ref("base.group_user").id,
self.env.ref("base.group_system").id,
],
) )
], new_test_user(
} self.env,
login="user_export_xlsx",
password="user_export_xlsx",
groups="base.group_user,base.group_system,%s"
% ("web_disable_export_group.group_export_xlsx_data"),
) )
def test_admin(self): def test_admin(self):
self.start_tour("/web", "export_tour_admin", login="admin") self.start_tour("/web", "export_tour_xlsx_button_ok", login="admin")
def test_user_not_export(self): def test_user_not_export(self):
self.start_tour("/web", "export_tour_demo", login="user_not_export") self.start_tour("/web", "export_tour_xlsx_button_ko", login="user_not_export")
def test_user_export_xlsx(self):
self.start_tour("/web", "export_tour_xlsx_button_ok", login="user_export_xlsx")