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
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
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();
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With