本文整理汇总了Python中aleph.model.Role.system方法的典型用法代码示例。如果您正苦于以下问题:Python Role.system方法的具体用法?Python Role.system怎么用?Python Role.system使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aleph.model.Role
的用法示例。
在下文中一共展示了Role.system方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login
# 需要导入模块: from aleph.model import Role [as 别名]
# 或者: from aleph.model.Role import system [as 别名]
def login(self, foreign_id='tester', name=None, email=None,
is_admin=False):
role = self.create_user(foreign_id=foreign_id, name=name, email=email,
is_admin=is_admin)
with self.client.session_transaction() as sess:
sess['roles'] = [Role.system(Role.SYSTEM_GUEST),
Role.system(Role.SYSTEM_USER), role.id]
sess['user'] = role.id
return role
示例2: check_alerts
# 需要导入模块: from aleph.model import Role [as 别名]
# 或者: from aleph.model.Role import system [as 别名]
def check_alerts():
for role_id, in Role.notifiable():
with current_app.test_request_context('/'):
role = Role.by_id(role_id)
request.auth_role = role
request.logged_in = True
# FIXME: can't re-gain access to implicit oauth rules.
# -> https://github.com/pudo/aleph/issues/14
request.auth_roles = [Role.system(Role.SYSTEM_USER),
Role.system(Role.SYSTEM_GUEST),
role.id]
check_role_alerts(role)
示例3: callback
# 需要导入模块: from aleph.model import Role [as 别名]
# 或者: from aleph.model.Role import system [as 别名]
def callback():
resp = oauth_provider.authorized_response()
if resp is None or isinstance(resp, OAuthException):
log.warning("Failed OAuth: %r", resp)
# FIXME: notify the user, somehow.
return redirect(url_for('base_api.ui'))
session['oauth'] = resp
session['roles'] = [Role.system(Role.SYSTEM_USER)]
if 'googleapis.com' in oauth_provider.base_url:
me = oauth_provider.get('userinfo')
user_id = 'google:%s' % me.data.get('id')
role = Role.load_or_create(user_id, Role.USER, me.data.get('name'),
email=me.data.get('email'))
elif 'occrp.org' in oauth_provider.base_url or \
'investigativedashboard.org' in oauth_provider.base_url:
me = oauth_provider.get('api/2/accounts/profile/')
user_id = 'idashboard:user:%s' % me.data.get('id')
role = Role.load_or_create(user_id, Role.USER,
me.data.get('display_name'),
email=me.data.get('email'),
is_admin=me.data.get('is_admin'))
for group in me.data.get('groups', []):
group_id = 'idashboard:%s' % group.get('id')
group_role = Role.load_or_create(group_id, Role.GROUP,
group.get('name'))
session['roles'].append(group_role.id)
else:
raise RuntimeError("Unknown OAuth URL: %r" % oauth_provider.base_url)
session['roles'].append(role.id)
session['user'] = role.id
db.session.commit()
log.info("Logged in: %r", role)
return redirect(url_for('base_api.ui'))
示例4: load_role
# 需要导入模块: from aleph.model import Role [as 别名]
# 或者: from aleph.model.Role import system [as 别名]
def load_role():
request.auth_roles = set([Role.system(Role.SYSTEM_GUEST)])
request.auth_role = None
request.logged_in = False
if session.get('user'):
request.auth_roles.update(session.get('roles', []))
request.auth_role = Role.by_id(session.get('user'))
request.logged_in = True
else:
api_key = request.args.get('api_key')
if api_key is None:
auth_header = request.headers.get('Authorization') or ''
if auth_header.lower().startswith('apikey'):
api_key = auth_header.split(' ', 1).pop()
role = Role.by_api_key(api_key)
if role is None:
return
request.auth_role = role
request.auth_roles.update([Role.system(Role.SYSTEM_USER), role.id])
request.logged_in = True
示例5: callback
# 需要导入模块: from aleph.model import Role [as 别名]
# 或者: from aleph.model.Role import system [as 别名]
def callback():
resp = oauth_provider.authorized_response()
if resp is None or isinstance(resp, OAuthException):
log.warning("Failed OAuth: %r", resp)
# FIXME: notify the user, somehow.
return redirect('/')
session['oauth'] = resp
session['roles'] = [Role.system(Role.SYSTEM_USER)]
signals.handle_oauth_session.send(provider=oauth_provider, session=session)
db.session.commit()
log.info("Logged in: %r", session['user'])
return redirect('/')
示例6: setUp
# 需要导入模块: from aleph.model import Role [as 别名]
# 或者: from aleph.model.Role import system [as 别名]
def setUp(self):
super(SourcesApiTestCase, self).setUp()
self.source = Source()
self.source.foreign_id = "test"
self.source.label = "Test Collection"
self.source.category = "news"
db.session.add(self.source)
db.session.flush()
permission = Permission()
permission.role_id = Role.system(Role.SYSTEM_USER)
permission.read = True
permission.write = True
permission.resource_id = self.source.id
permission.resource_type = Permission.SOURCE
db.session.add(permission)
db.session.commit()