Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
5 Vastaukset
11499 Näkymät

I need to make CSV import option (for all models) only available to certain security groups in Odoo v8.

How to do that? Any hint?


--- UPDATE ---

So far:

I have created a specific security group and category for CSV import.

A) No security rules

I cannot create security rules over TransientModels (Why? Whyyyy?), therefore I cannot use this over base_import.import model. (Damn! That would have been easy for once!)


B) No xml "groups" allowed for non-visual elements

In addons/base_import/views/base_import.xml there are these lines:

<template id="assets_backend" name="base_import assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<link rel="stylesheet" href="/base_import/static/src/css/import.css"/>
<script type="text/javascript" src="/base_import/static/lib/javascript-state-machine/state-machine.js"></script>
<script type="text/javascript" src="/base_import/static/src/js/import.js"></script>
</xpath>
</template>

But, even I can modify that xpaths and avoid those link and 2 scripts, I cannot make it group-based optional using "groups" attribute, as it is completely ignored (Does "groups" only apply to visual elements like fields, divs, groups and so?)


C) Is it even possible to check groups with t-if? No clue how.

In addons/base_import/static/src/xml/import.xml there are these lines:

    <t t-extend="ListView.buttons">
    <t t-jquery="span.oe_alternative">
        this.attr('t-if', 'widget.options.import_enabled');
    </t>
    <t t-jquery="span.oe_alternative" t-operation="append">
        <a href="#" class="oe_bold oe_list_button_import">Import</a>
    </t>
</t>

But once again, I have no clue how to add a t-if for that "a href" checking if current user belongs to a specific group I have created for csv import.

Documentation says nothing about hot to check it in QWeb views.


D) JS? Really?

Haven't even tried it. Should be easier.

 

Avatar
Hylkää

did you try to override functionlike def do, in base_import module, file models.py, by testing if the user is in your group and if not, do a raise ?

Tekijä

I would like to directly disable any possibility of accesing import by hiding/removing the button. But if everything else fails, I would go there.

Tekijä Paras vastaus

I solved it with javascript. I made a pull request in github with a new module called "import_csv_restrict": https://github.com/OCA/server-tools/pull/154

Avatar
Hylkää

how can i get this module ?

Paras vastaus

the best solution for this is simple, just a configuration trick :

  1. go to Configuration (make sure your admin user have access to Technical settings)

  2. go to user interface / views

  3. search for base_import assets

  4. go to Group page, then add the admin group.     
    then refresh the user then the import button is gone (y)
    PS : i tried this using odoo V8

Avatar
Hylkää

On v10, I get a Validation Error when trying to Save after adding the group.

"Qweb view cannot have 'Groups' define on the record. Use 'groups' attributes inside the view definition"

this solution tested only with odoo 8

Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
5
heinäk. 20
6664
1
maalisk. 15
4877
3
kesäk. 20
3687
1
marrask. 18
9224
11
helmik. 17
63455