當前位置: 首頁>>代碼示例>>Python>>正文


Python Role.system方法代碼示例

本文整理匯總了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
開發者ID:CodeForAfrica,項目名稱:aleph,代碼行數:11,代碼來源:util.py

示例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)
開發者ID:CodeForAfrica,項目名稱:aleph,代碼行數:14,代碼來源:__init__.py

示例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'))
開發者ID:stefanw,項目名稱:aleph,代碼行數:36,代碼來源:sessions_api.py

示例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
開發者ID:rlugojr,項目名稱:aleph,代碼行數:23,代碼來源:sessions_api.py

示例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('/')
開發者ID:adamchainz,項目名稱:aleph,代碼行數:15,代碼來源:sessions_api.py

示例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()
開發者ID:01-,項目名稱:aleph,代碼行數:18,代碼來源:test_sources_api.py


注:本文中的aleph.model.Role.system方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。