Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qweb t-att-groups errors #5058

Closed
alejandrosantana opened this issue Feb 4, 2015 · 12 comments
Closed

Qweb t-att-groups errors #5058

alejandrosantana opened this issue Feb 4, 2015 · 12 comments

Comments

@alejandrosantana
Copy link

Qweb tag t-att-groups seems to missbehave
Trying to use t-att-$name (as explained in official documentation in https://www.odoo.com/documentation/8.0/reference/qweb.html#attributes ), is ignored in one case, gives error in other (see both cases below, in "Current behaviour").

Impacted versions:

  • 8.0 and above, as it affects qweb view

Prior considerations

  • I am trying, in a custom module and through inheritance, to hide the chat button in the top bar for almost all users except a group of managers defined in this module.
  • Original qweb code is in addons/im_chat/static/src/xml/im_chat.xml, line 86.
<t t-name="im_chat.ImTopButton">
    <li t-att-title='_t("Display Instant Messaging")'>
        <a href="#">
              <i id="oe_topbar_imbutton_icon" class="fa fa-comments-o"/>
        </a>
    </li>
</t>

Steps to reproduce:

  1. In a new module ("my_module"), add these to openerp.py:
    • 'depends': ['im_chat'],
    • 'qweb': ['static/src/xml/im_chat.xml'],
  2. In my my_module/static/src/xml/im_chat.xml I try to inherit the template above (t-name="im_chat.ImTopButton") and moodify its visibility relating it to a security group (let's call it "my_module.chat_manager"), with this code:
<?xml version="1.0" encoding="UTF-8"?>

<templates xml:space="preserve">
<t t-extend="im_chat.ImTopButton">
    <t t-jquery="li" t-operation="replace">
        <li t-att-title='_t("Display Instant Messaging")' t-att-groups="my_module.chat_manager">
            <a href="#">
                <i id="oe_topbar_imbutton_icon" class="fa fa-comments-o"/>
            </a>
        </li>
    </t>
</t>
</templates>

Current behavior:

  • If in t-att-groups I do not specify module name, i.e. t-att-groups="chat_manager" nothing happens, so chat button remains visible for everyone.
    • If in t-att-groups I do specify module name, i.e. t-att-groups="my_module.chat_manager", some errors arise and button is not available for anyone. The errors arisen are popup only (no log, even in debig mode):
    • In Chromium 39.0.2171.65 Ubuntu 14.04 (64-bit):
      Odoo Error del cliente Uncaught Error: QWeb2 - template['im_chat.ImTopButton']: Runtime Error: TypeError: Cannot read property 'group_my_module_manager' of undefined http://localhost:8069/web/js/web.assets_common/05b35c0:1020
      (NOTE: "Error del cliente" means "Client error" in English)
    • In Firefox 35.0.1 the popup error message is different:
      TypeError: dict.my_module is undefined http://localhost:8069/web/static/lib/qweb/qweb2.js line 400 > Function:8

Expected behavior:

  • Chat button in top menu bar only visible for members of group "my_module.chat_manager", invisible for the rest.
@alejandrosantana
Copy link
Author

Is there a way to apply "groups" visibility to qweb xml files?

@alejandrosantana
Copy link
Author

Any insight on this one?

@xmo-odoo
Copy link
Collaborator

t-att-groups is going to evaluate its parameter as a javascript expression (hence the error with my_module.chat_manager, my_module does not exist so it's undefined and accessing an attribute on undefined is an error) then put the result as the groups attribute in the generated HTML.

It is currently possible to do groups-based filtering in qweb-python (using the groups attribute or using a t-if and env.user.has_group), it is not possible to do so in qweb-js (and it's uncertain whether that'll ever be possible as checking the user's groups requires an async call, and qweb rendering is synchronous)

@alejandrosantana
Copy link
Author

So... two things:

  • Can we assume that every ... can be considered as qweb-js? (Or what is the difference between qweb-js and qweb-python?)
  • This way, security policies based on groups are not possible in qweb templates.

@xmo-odoo
Copy link
Collaborator

Can we assume that every ... can be considered as qweb-js? (Or what is the difference between qweb-js and qweb-python?)

I don't understand the question.

This way, security policies based on groups are not possible in qweb templates.

It's not possible in qweb templates used in javascript. It's possible in qweb templates used in python (qweb views if you will).

@alejandrosantana
Copy link
Author

I am trying to understand when happens each case. (Could be added to documentation, for newcomers, as it means quite a diffence in behaviour).

So, the qweb file (or template) will always be the same, but its final behaviour will depend on if its added from javascript, or from a xml view (qweb view, like kanban views).
Is that it?

@xmo-odoo
Copy link
Collaborator

I am trying to understand when happens each case. (Could be added to documentation, for newcomers, as it means quite a diffence in behaviour).

There are some differences outlined in the qweb section of the documentation already, though AFAIK the groups attribute is not documented (even on the Python side).

So, the qweb file (or template) will always be the same, but its final behaviour will depend on if its added from javascript, or from a xml view (qweb view, like kanban views).

Well yeah, there's the basic qweb language/idea, then there are two different implementations which are not completely identical. So the basics are the same, but the details may not be.

@alejandrosantana
Copy link
Author

In documentation (https://www.odoo.com/documentation/8.0/reference/qweb.html#attributes) it is explained with t-att-$name, so you can think that any attribute $name will work (as name='groups', as used in xml views), with no mention of python or js in that particular point.

@xmo-odoo
Copy link
Collaborator

In documentation (https://www.odoo.com/documentation/8.0/reference/qweb.html#attributes) it is explained with t-att-$name, so you can think that any attribute $name will work

And any $name will work, but this feature generates attributes in the output, so t-att-groups will just generate a groups attribute in the output without any further processing. That does work in both qweb-python and qweb-js but it has no relation whatsoever with what you want, the semantics of $name here are (for the most part) irrelevant to the qweb processor.

@alejandrosantana
Copy link
Author

I see, so it is intended mainly for html attributes like title, src, width, and so on, but not for the kind of field control attributes used in XML views.

@xmo-odoo
Copy link
Collaborator

It really is intended only for HTML attributes, and can do nothing else. Which is why there are separate directives/attributes for more meta-control at the qweb level (e.g. t-if)

@alejandrosantana
Copy link
Author

OK, perfect then. I suggest to add that explanation to documentation to avoid ambiguity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants