本文整理汇总了Python中flask_security.current_user.has_role方法的典型用法代码示例。如果您正苦于以下问题:Python current_user.has_role方法的具体用法?Python current_user.has_role怎么用?Python current_user.has_role使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_security.current_user
的用法示例。
在下文中一共展示了current_user.has_role方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: revert
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import has_role [as 别名]
def revert(link):
""" the link to make the latest version the one selected.
"""
if wiki_for(link).locked and not current_user.has_role('admin'):
flash('Wiki page locked.')
return current_app.login_manager.unauthorized()
latest = request.args.get('latest', None)
if latest is not None:
oldone = wiki_for(link)
newone = (current_session
.query(Wiki)
.filter(Wiki.link == link)
.filter(Wiki.id == int(latest))
.first())
oldone.latest = 0
newone.latest = 1
current_session.add(newone)
current_session.add(oldone)
current_session.commit()
return redirect(url_for('wiki.index', link=link, id=newone.id))
else:
abort(404)
示例2: is_accessible
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import has_role [as 别名]
def is_accessible(self):
if not current_user.is_active or not current_user.is_authenticated:
return False
if current_user.has_role('admin'):
return True
return False
示例3: can_do_stuff_with_job
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import has_role [as 别名]
def can_do_stuff_with_job(current_user, owner):
return current_user.has_role('admin') or current_user.email == owner.email
示例4: jobs_show
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import has_role [as 别名]
def jobs_show():
filtered_jobs = []
if current_user.has_role('admin'):
filtered_jobs = Job.objects
else:
for job in Job.objects:
if job.owner:
if job.owner.email == current_user.email:
filtered_jobs.append(job)
return flask.render_template("jobs_show.html", jobs=filtered_jobs)
示例5: validate
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import has_role [as 别名]
def validate(self):
if not super(GenerateApiKeyForm, self).validate(): # pragma: no cover
return False
if not current_user.has_role("developer"):
return False
return True
示例6: api_auth_required
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import has_role [as 别名]
def api_auth_required(f):
@wraps(f)
def wrapper(*args, **kwargs):
if request.authorization and request.authorization.type == "basic":
user = user_datastore.find_user(api_key=request.authorization.username)
if user and user.has_role("developer"):
_request_ctx_stack.top.user = user
identity_changed.send(
current_app._get_current_object(), identity=Identity(user.id)
)
return f(*args, **kwargs)
abort(401)
return wrapper
示例7: is_accessible
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import has_role [as 别名]
def is_accessible(self):
return current_user.is_authenticated and current_user.has_role("admin")
示例8: can_create
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import has_role [as 别名]
def can_create(self):
return current_user.has_role("package_admin")
示例9: can_edit
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import has_role [as 别名]
def can_edit(self):
return current_user.has_role("package_admin")
示例10: can_delete
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import has_role [as 别名]
def can_delete(self):
return current_user.has_role("admin")
示例11: can_sign
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import has_role [as 别名]
def can_sign(self):
return current_user.has_role("admin")
示例12: can_unsign
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import has_role [as 别名]
def can_unsign(self):
return current_user.has_role("admin")
# Hooks
示例13: get_query
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import has_role [as 别名]
def get_query(self):
if not current_user.has_role("package_admin"):
return (
super(VersionView, self)
.get_query()
.join(self.model.package)
.join(Package.maintainers)
.filter(User.id == current_user.id)
)
return super(VersionView, self).get_query()
示例14: get_count_query
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import has_role [as 别名]
def get_count_query(self):
if not current_user.has_role("package_admin"):
return (
super(VersionView, self)
.get_count_query()
.join(self.model.package)
.join(Package.maintainers)
.filter(User.id == current_user.id)
)
return super(VersionView, self).get_count_query()
# Actions
示例15: index
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import has_role [as 别名]
def index(self):
if not current_user.is_authenticated:
return redirect(url_for("security.login"))
if not any(map(current_user.has_role, ("developer", "package_admin", "admin"))):
abort(403)
return super(IndexView, self).index()