@service.jsondef set_user_group(): """ Changes a user's group (userlevel) Args: first_name,last_name, newgroup in request.args Returns: error message if auth fails Raises: Nothing """ err = None if auth.is_logged_in() and auth.user.userlevel >= 2: # Ok to change it first, last, newgroup = tuple(request.args)[-3:] tbl = db.auth_user qry = ((tbl.first_name == first) & (tbl.last_name == last)) rows = db(qry).select() assert len(rows) <= 1 ## should be impossible to have duplicate names if len(rows) == 0: err = "User '{} {}' not found in database!".format(first, last) else: id = rows[0][tbl.id] newlevel = dict(user=0, tech=1, admin=2)[newgroup.lower()] db(tbl.id == id).update(userlevel=newlevel) else: err = "Changing user groups requires log-in with admin privileges" return dict(msg=err)
try: aid = auth.user.id # raises AttributeError if not logged in. authlevel = db(db.auth_user.id == aid).select()[0].userlevel except AttributeError: authlevel = 0
auth.user.update(userlevel=newlevel)
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/BwEGtzUkJhY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.