Checking for permissions in template

Visto 25 veces
Saltar al primer mensaje no leído

bloeper

no leída,
22 jul 2010, 14:24:3722/7/10
a TurboGears
Hi all,

I have one more question i am stuck at...
The documentation is just to happy to explain how to check for
permissions with @require.
But i want to check in the template if someone has a permission, is
this possible?

I hope it is, and I prefer without needing to pass somekind of object
in the controller?

Thanks in advance.

Greetings,

Bloeper

NiL

no leída,
22 jul 2010, 15:42:3722/7/10
a TurboGears
just a pointer

the user is known as identity in the template

see lib/base.py

or maybe list permissions in some helper ?

bloeper

no leída,
23 jul 2010, 3:39:1023/7/10
a TurboGears
Ok but if that's the case, can you just do something like:
identity.has_perm(perm_id); ?
Or do I need some other stuff in there?

bloeper

no leída,
23 jul 2010, 13:51:5823/7/10
a TurboGears
I have found that i can use this in a template:
<p py:if="tg.predicates.has_permission( page.permission )">Has full
control</p>

But the problem is, that it doesn't parse the var page.permission :S
When i do:
<p py:if="tg.predicates.has_permission( 'sec_page' )">Has full
control</p>
I get the Has full control line.
But when i use page.permission (which contains sec_page), it doesn't
work.
Anyone has an idea why this is happening?

bloeper

no leída,
24 jul 2010, 7:23:4824/7/10
a TurboGears
Found the problem, needed to use page.permission.permission_name..
Was a bit of a dumb mistake, but fixed now :)

Michael Pedersen

no leída,
26 jul 2010, 21:42:3626/7/10
a turbo...@googlegroups.com
You have a subtle problem in your code there, and it's easy to miss. Your permissions in your template should always evaluate to true from what you've shown. You need to do the following in your template:

<p py:if="tg.predicates.has_permission( page.permission ).is_met()">Has full control</p>

Without that "is_met()" at the end, all calls will result in True, which is very likely not what you want.

--
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to turbo...@googlegroups.com.
To unsubscribe from this group, send email to turbogears+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/turbogears?hl=en.




--
Michael J. Pedersen
My IM IDs: Jabber/pede...@icelus.tzo.com, ICQ/103345809, AIM/pedermj022171
          Yahoo/pedermj2002, MSN/pederm...@hotmail.com

Christoph Zwerschke

no leída,
27 jul 2010, 4:04:1927/7/10
a turbo...@googlegroups.com
Am 27.07.2010 03:42, schrieb Michael Pedersen:
> You have a subtle problem in your code there, and it's easy to miss.
> Your permissions in your template should always evaluate to true from
> what you've shown. You need to do the following in your template:
>
> <p py:if="tg.predicates.has_permission( page.permission ).is_met()">Has
> full control</p>
>
> Without that "is_met()" at the end, all calls will result in True, which
> is very likely not what you want.

I don't think you need to do that. TurboGears adds a __nonzero__ method
to the Predicate class that is automatically calling is_met() for you.

-- Christoph

Michael Pedersen

no leída,
27 jul 2010, 8:58:1427/7/10
a turbo...@googlegroups.com

It shouldn't be necessary, but I got bit in my own templates when I didn't use it. Better safe than sorry, I say.

On Jul 27, 2010 4:04 AM, "Christoph Zwerschke" <ci...@online.de> wrote:

Am 27.07.2010 03:42, schrieb Michael Pedersen:

> You have a subtle problem in your code there, and it's easy to miss.

> Your permissions in your te...

I don't think you need to do that. TurboGears adds a __nonzero__ method
to the Predicate class that is automatically calling is_met() for you.

-- Christoph


--

You received this message because you are subscribed to the Google Groups "TurboGears" group.

To pos...

bloeper

no leída,
28 jul 2010, 4:02:2828/7/10
a TurboGears
Yeah thanks for the quick writeup...
I have changed it in my template, It did work before..
But maybe on another install (such as my host) it doesn't.. And then
it's a long way search to find the problem.

On Jul 27, 2:58 pm, Michael Pedersen <m.peder...@icelus.org> wrote:
> It shouldn't be necessary, but I got bit in my own templates when I didn't
> use it. Better safe than sorry, I say.
>
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos