TG 2.3.6 SubClassing CustomAdminConfig allow_only = predicates.has_permission('admin_menu')

12 views
Skip to first unread message

Paul Kraus

unread,
Sep 2, 2015, 10:23:01 AM9/2/15
to TurboGears
Trying to do some basic customization of the admin controller. I want only people that belong to a group that has the permission "admin_menu" to be able to access the admin menu.


I have done this ...

class CustomAdminConfig(TGAdminConfig):
 allow_only
= predicates.has_permission('admin_menu')

admin
= AdminController(model, DBSession, config_type=CustomAdminConfig)



However i still get the error that the user has to be in the group managers. So looking at the parent classes

CustomAdminConfig --> BootstrapTgAdminConfig --> TGAdminConfig --> AdminConfig

allow_only overrides AdminConfig attribute which by default is set to None.

class AdminConfig(object):
 
 
DefaultControllerConfig = CrudRestControllerConfig
 layout
= BasicAdminLayout

 default_index_template
= None
 allow_only
= None
 include_left_menu
= True



The class docs state that allow_only defaults to predicates.in_group('managers'). I can't find anywhere in the code that actually applies this default so as a side question can you point me to where that happens out of curiosity?

Paul Kraus

unread,
Sep 15, 2015, 10:24:24 AM9/15/15
to TurboGears
Anyone??

Moritz Schlarb

unread,
Sep 15, 2015, 10:40:44 AM9/15/15
to turbo...@googlegroups.com
On 02.09.2015 16:23, Paul Kraus wrote:
> The class docs state that allow_only defaults to
> predicates.in_group('managers'). I can't find anywhere in the code that
> actually applies this default so as a side question can you point me to
> where that happens out of curiosity?

https://github.com/TurboGears/tgext.admin/blob/master/tgext/admin/controller.py#L40

But I think your code should actually work... Maybe Alessandro can shed
some light into this...

--
Moritz Schlarb

Alessandro Molina

unread,
Sep 15, 2015, 3:28:38 PM9/15/15
to TurboGears
Thanks for pointing that out.
I only used the admin for Proof of Concepts so I never tried changing the predicate and never noticed it was broken :(

It was failing as the predicate is bool evaluable, so it was not checking if there was a predicate, but if the predicate itself was passing.
I released a 0.6.6 bugfix release that should solve that issue.



--
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email to turbogears+...@googlegroups.com.
To post to this group, send email to turbo...@googlegroups.com.
Visit this group at http://groups.google.com/group/turbogears.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages