multiple condition @auth.requires(lambda: auth.has_membership('admin')

194 views
Skip to first unread message

Alex Glaros

unread,
May 16, 2015, 5:51:21 PM5/16/15
to web...@googlegroups.com
Does w2p in general accept a lot of conditionals like this in requires membership clause?

@auth.requires(lambda: auth.has_membership('admin') and (db.auth_membership.user_id == auth.user_id) and (db.auth_membership.group_id == db.auth_group.id) and (db.auth_group.role == 'admin') and (db.auth_group.organizationID == request.get_vars.specificOrganizationID))

No errors raised but the constraint doesn't work.

thanks,

Alex Glaros

Anthony

unread,
May 16, 2015, 6:54:46 PM5/16/15
to web...@googlegroups.com, alexg...@gmail.com
All the items except the first element are simply DAL Query objects, so they all evaluate to True. Perhaps you instead mean to build a DAL query based on a conjunction of conditions and then do a select to see if there is a matching record.

Anthony

Alex Glaros

unread,
May 16, 2015, 7:32:32 PM5/16/15
to web...@googlegroups.com
do you mean just manage it in the controller and not in decorator area?

Anthony

unread,
May 16, 2015, 8:38:24 PM5/16/15
to web...@googlegroups.com, alexg...@gmail.com
No, you can use the decorator, but you have to use it properly.

Alex Glaros

unread,
May 16, 2015, 10:25:37 PM5/16/15
to web...@googlegroups.com, alexg...@gmail.com
ahhh... correct

this below seems to work

does it seem right?

@auth.requires(lambda: auth.has_membership('admin') and not(db(db.auth_membership.user_id == auth.user_id).isempty()))

thanks Anthony

Alex

Anthony

unread,
May 16, 2015, 11:11:19 PM5/16/15
to web...@googlegroups.com, alexg...@gmail.com
Sure, but the second condition seems to merely confirm that the current user has membership in at least one group, which is not only an odd requirement, but also redundant if the first condition is true (i.e., if the user has membership in the 'admin' group).

Anthony

Alex Glaros

unread,
May 17, 2015, 12:52:23 AM5/17/15
to web...@googlegroups.com, alexg...@gmail.com
you're right Anthony, that was just a quick test and not the real requirements

thanks so much for all of the work you put into answering web2py questions.... a major roadblock remover

much appreciated,

Alex
Reply all
Reply to author
Forward
0 new messages