Opened 6 years ago

Closed 6 years ago

#18991 closed New feature (fixed)

Allow the use of 'app_name.perm_name' in perms in templates

Reported by: Anssi Kääriäinen Owned by: nobody
Component: Template system Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Now that we have smart if tag, it seems natural to look up permissions by

{% if 'someapp.someperm' in perms %}
  Permission found!
{% endif %}

In addition to feeling more natural to me, this has two additional benefits:

  • If is possible to look up permissions containing characters which aren't allowed by template variable resoultion: if perms.someapp.some-perm doesn't work for example.
  • The exact same syntax is likely to work in other template engines, too (think Jinja2).

I have implemented this in

I hope to push this into 1.5.

Change History (3)

comment:1 Changed 6 years ago by Anssi Kääriäinen

I forgot to mention that the above branch contains the fix for #18979, too. So, that is the !EQLimiterObject stuff in the patch...

comment:2 Changed 6 years ago by Anssi Kääriäinen

A pull created:

BTW, there is another benefit of the alternate syntax: permission lookups using variables.

There isn't support for perm_obj in perms, only the string syntax is supported. Using Permission objects directly would be a natural extensions to this feature...

comment:3 Changed 6 years ago by Anssi Kääriäinen <akaariai@…>

Resolution: fixed
Status: newclosed

In d5a4f209c3889a76a23a19f3212ab2d7b5c62e1c:

Fixed #18991 -- Allowed permission lookup by "if in"

When looking permissions from PermWrapper it is now possible to use
{% if "someapp.someperm" in perms %} instead of
{% if perms.someapp.someperm %}.

Note: See TracTickets for help on using tickets.
Back to Top