Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google App Engine - find out if a user is an administrator

In GAE, is there a way to find out if a User is an administrator?

While the is_current_user_admin() reveals whether the current user is an administrator, I'd like to know if there's a way to discover if a given User object is for an administrator or not (e.g. a hypothetical User.is_admin() function).

Thank you for reading.

Brian

like image 312
Brian M. Hunt Avatar asked Jun 22 '10 21:06

Brian M. Hunt


3 Answers

Unfortunately, the User model does not contain any information about whether the user is an administrator or not.

If your list of administrators changes infrequently, then you could write your own is_admin() function which checks to see if the User.user_id() value corresponds to one of your administrators' accounts. For example:

ADMIN_USER_IDS = ['id1', 'id2', ...]  # manually populated list
def is_admin(user):
    return user.user_id() in ADMIN_USER_IDS
like image 179
David Underhill Avatar answered Nov 02 '22 09:11

David Underhill


This is possible, but not through the User object, and it seems only in the Java api, not in the python. You need to use the UserService:

UserService userService = UserServiceFactory.getUserService();
boolean adminUser = userService.isUserAdmin();
like image 43
Sam Holder Avatar answered Nov 02 '22 11:11

Sam Holder


That's not possible.

You could create a wrapper class around users.User and keep track of whether or not that user was an administrator, as of the last time he/she logged in. (You cannot determine whether a given user is currently an admin, unless that user is currently the client.)

Using Google App Engine's administrator status is somewhat restricting - for example, what if you want to create a new usergroup with privileges that are higher than normal but not quite as high as admininstrator's? It's best not to conflate privileges in your app with privileges in the Administration Console.

like image 23
Nikhil Avatar answered Nov 02 '22 11:11

Nikhil