Google App Engine - 了解用户是否是管理员 [英] Google App Engine - find out if a user is an administrator

查看:256
本文介绍了Google App Engine - 了解用户是否是管理员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GAE 中,有没有办法找出用户是管理员?

虽然 is_current_user_admin() 显示当前用户是否是管理员,我想知道是否有办法发现给定的 User 对象是否适用于管理员或者不是(例如假设 User.is_admin()函数)。

感谢您的阅读。



Brian

解决方案

不幸的是, User 模型不包含任何有关用户是否为管理员的信息。



如果你的管理员列表很少变化,那么你可以编写你自己的 is_admin()函数来检查 User.user_id() 值对应于您的某个管理员'账户。例如:

  ADMIN_USER_IDS = ['id1','id2',...]#手动填充列表
def is_admin(user):
返回ADMIN_USER_IDS中的user.user_id()


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

这篇关于Google App Engine - 了解用户是否是管理员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆