[Django] #30705: Django template permissions not working when used inside the template of an inclusion tag

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[Django] #30705: Django template permissions not working when used inside the template of an inclusion tag

Django
#30705: Django template permissions not working when used inside the template of an
inclusion tag
-------------------------------------+-------------------------------------
               Reporter:  erev0s     |          Owner:  nobody
                   Type:             |         Status:  new
  Uncategorized                      |
              Component:  Template   |        Version:  2.2
  system                             |       Keywords:  permissions,
               Severity:  Normal     |  inclusion tag
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 I have 2 apps in a Django Project i am using to learn django. In the app A
 I have an inclusion tag where I am using a template named
 `templateA.html`. This inclusion tag is being used in the app B, inside
 the template `templateB.html`. The content of `templateA.html` is shown
 properly inside `templateB.html`.

 I noticed though that when I am attempting to check permissions of the
 user using code similar to the following:
 {{{
 {% if perms.appA.can_do_something %}
 show something here
 {% endif %}
 }}}
 then, if I include that code in `templateA.html` it is not working, while
 if I use it in `templateB.html` it is working properly.  I am mentioning
 again that the `templateA.html` is the one used in the inclusion tag I am
 using in the `templateB.html`.

--
Ticket URL: <https://code.djangoproject.com/ticket/30705>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/049.ace1023ee8a2fa8f55cde40a64dcd204%40djangoproject.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30705: Django template permissions not working when used inside the template of an inclusion tag

Django
#30705: Django template permissions not working when used inside the template of an
inclusion tag
-------------------------------------+-------------------------------------
     Reporter:  erev0s               |                    Owner:  nobody
         Type:  Uncategorized        |                   Status:  closed
    Component:  Template system      |                  Version:  2.2
     Severity:  Normal               |               Resolution:  needsinfo
     Keywords:  permissions,         |             Triage Stage:
  inclusion tag                      |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

 * status:  new => closed
 * resolution:   => needsinfo


Comment:

 Hi. I suspect there's not a bug here but, as it stands there not enough
 information to know...

 Could you upload a minimal project that recreates your issue so we can
 have a look? Thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/30705#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/064.d359dc30ea5267503121a50b2abad75e%40djangoproject.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30705: Django template permissions not working when used inside the template of an inclusion tag

Django
In reply to this post by Django
#30705: Django template permissions not working when used inside the template of an
inclusion tag
-------------------------------------+-------------------------------------
     Reporter:  erev0s               |                    Owner:  nobody
         Type:  Uncategorized        |                   Status:  closed
    Component:  Template system      |                  Version:  2.2
     Severity:  Normal               |               Resolution:  needsinfo
     Keywords:  permissions,         |             Triage Stage:
  inclusion tag                      |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by erev0s):

 * Attachment "django-locallibrary-tutorial.tar.gz" added.

 Modifies this project https://github.com/mdn/django-locallibrary-tutorial
 to show the issue mentioned in the ticket

--
Ticket URL: <https://code.djangoproject.com/ticket/30705>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/064.30e02bf55d4878350e113862f6af1edd%40djangoproject.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30705: Django template permissions not working when used inside the template of an inclusion tag

Django
In reply to this post by Django
#30705: Django template permissions not working when used inside the template of an
inclusion tag
-------------------------------------+-------------------------------------
     Reporter:  erev0s               |                    Owner:  nobody
         Type:  Uncategorized        |                   Status:  closed
    Component:  Template system      |                  Version:  2.2
     Severity:  Normal               |               Resolution:  needsinfo
     Keywords:  permissions,         |             Triage Stage:
  inclusion tag                      |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by erev0s):

 I have added as an attachment a modified version of the famous django
 example shown here https://github.com/mdn/django-locallibrary-tutorial
 In the attachment you will find an additional app named
 "check_permissions". Inside the "templatetags" you will find the
 "custom_tag.py" where there is an inclusion tag using the
 "permision_required" decorator.

 The template used for the inclusion tag is located in "catalog/templates
 /link-tag.html" and the custom tag is loaded in the
 "catalog/templates/index.html" which is the main page you find after you
 run the project.

 After you have created an admin user and you setup and run the project you
 will see in the "http://localhost:8000/catalog/" at the bottom that you
 are able to see only the second "<li>" found there.

 [[Image(https://i.imgur.com/6Z6Nq6L.png)]]

 The permission inside the "link-tag.html" is NOT found probably or
 something similar, due to even admin can not access the content.

--
Ticket URL: <https://code.djangoproject.com/ticket/30705#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/064.836298dea80fb62ab8f2257e98a9d15f%40djangoproject.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30705: Django template permissions not working when used inside the template of an inclusion tag

Django
In reply to this post by Django
#30705: Django template permissions not working when used inside the template of an
inclusion tag
-------------------------------------+-------------------------------------
     Reporter:  erev0s               |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Template system      |                  Version:  2.2
     Severity:  Normal               |               Resolution:
     Keywords:  permissions,         |             Triage Stage:
  inclusion tag                      |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz):

 * status:  closed => new
 * resolution:  needsinfo =>
 * type:  Uncategorized => Bug


Comment:

 Reopening as per new provided material.

--
Ticket URL: <https://code.djangoproject.com/ticket/30705#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/064.589ff5dc9b712772a7ae2af7b6e5bdf4%40djangoproject.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30705: Django template permissions not working when used inside the template of an inclusion tag

Django
In reply to this post by Django
#30705: Django template permissions not working when used inside the template of an
inclusion tag
-------------------------------------+-------------------------------------
     Reporter:  erev0s               |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  Template system      |                  Version:  2.2
     Severity:  Normal               |               Resolution:  invalid
     Keywords:  permissions,         |             Triage Stage:
  inclusion tag                      |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

 * status:  new => closed
 * resolution:   => invalid


Comment:

 The block is not rendered because `perms` is not present in the context of
 your inclusion tag, so the conditional correctly evaluates to `False`.

 Take a look at the [https://docs.djangoproject.com/en/2.2/howto/custom-
 template-tags/#inclusion-tags Inclusion tags] docs.
 You'll need to use the `takes_context` kwarg and pass a reference to
 `perms` as per the examples there.

 I recommend investigating [https://django-debug-
 toolbar.readthedocs.io/en/latest/index.html Django Debug Toolbar] to see
 exactly what templates are rendered, with exactly what contexts.

 Please see TicketClosingReasons/UseSupportChannels for appropriate support
 channels.

--
Ticket URL: <https://code.djangoproject.com/ticket/30705#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/064.185e236b23c63ca4a305356b9512866b%40djangoproject.com.