当前位置: 首页>>代码示例>>Python>>正文


Python Credentials.get方法代码示例

本文整理汇总了Python中allura.lib.security.Credentials.get方法的典型用法代码示例。如果您正苦于以下问题:Python Credentials.get方法的具体用法?Python Credentials.get怎么用?Python Credentials.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在allura.lib.security.Credentials的用法示例。


在下文中一共展示了Credentials.get方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_make_app_admin_only

# 需要导入模块: from allura.lib.security import Credentials [as 别名]
# 或者: from allura.lib.security.Credentials import get [as 别名]
def test_make_app_admin_only():
    h.set_context('test', 'wiki', neighborhood='Projects')
    anon = M.User.anonymous()
    dev = M.User.query.get(username='test-user')
    admin = M.User.query.get(username='test-admin')
    c.project.add_user(dev, ['Developer'])
    ThreadLocalORMSession.flush_all()
    Credentials.get().clear()
    assert has_access(c.app, 'read', user=anon)()
    assert has_access(c.app, 'read', user=dev)()
    assert has_access(c.app, 'read', user=admin)()
    assert not has_access(c.app, 'create', user=anon)()
    assert has_access(c.app, 'create', user=dev)()
    assert has_access(c.app, 'create', user=admin)()
    assert c.app.is_visible_to(anon)
    assert c.app.is_visible_to(dev)
    assert c.app.is_visible_to(admin)
    h.make_app_admin_only(c.app)
    ThreadLocalORMSession.flush_all()
    Credentials.get().clear()
    assert not has_access(c.app, 'read', user=anon)()
    assert not has_access(c.app, 'read', user=dev)()
    assert has_access(c.app, 'read', user=admin)()
    assert not has_access(c.app, 'create', user=anon)()
    assert not has_access(c.app, 'create', user=dev)()
    assert has_access(c.app, 'create', user=admin)()
    assert not c.app.is_visible_to(anon)
    assert not c.app.is_visible_to(dev)
    assert c.app.is_visible_to(admin)
开发者ID:abhinavthomas,项目名称:allura,代码行数:31,代码来源:test_helpers.py

示例2: test_deny_access_for_single_user

# 需要导入模块: from allura.lib.security import Credentials [as 别名]
# 或者: from allura.lib.security.Credentials import get [as 别名]
 def test_deny_access_for_single_user(self):
     wiki = c.project.app_instance('wiki')
     user = M.User.by_username('test-user')
     assert has_access(wiki, 'read', user)()
     wiki.acl.append(M.ACE.deny(M.ProjectRole.by_user(user, upsert=True)._id, 'read', 'Spammer'))
     Credentials.get().clear()
     assert not has_access(wiki, 'read', user)()
开发者ID:jekatgithub,项目名称:incubator-allura,代码行数:9,代码来源:test_security.py

示例3: zarkov_event

# 需要导入模块: from allura.lib.security import Credentials [as 别名]
# 或者: from allura.lib.security.Credentials import get [as 别名]
    def zarkov_event(self, event_type, user=None, neighborhood=None, project=None, app=None, extra=None):
        context = dict(user=None, neighborhood=None, project=None, tool=None, mount_point=None, is_project_member=False)

        if not config.get("zarkov.host"):
            return

        user = user or getattr(c, "user", None)
        project = project or getattr(c, "project", None)
        app = app or getattr(c, "app", None)
        if user:
            context["user"] = user.username
        if project:
            context.update(project=project.shortname, neighborhood=project.neighborhood.url_prefix.strip("/"))
            if user:
                cred = Credentials.get()
                if cred is not None:
                    for pr in cred.user_roles(user._id, project._id).reaching_roles:
                        if pr.get("name") and pr.get("name")[0] != "*":
                            context["is_project_member"] = True
        if app:
            context.update(tool=app.config.tool_name, mount_point=app.config.options.mount_point)

        try:
            if self._zarkov is None:
                self._zarkov = ZarkovClient(config.get("zarkov.host", "tcp://127.0.0.1:6543"))
            self._zarkov.event(event_type, context, extra)
        except Exception, ex:
            self._zarkov = None
            log.error("Error sending zarkov event(%r): %r", ex, dict(type=event_type, context=context, extra=extra))
开发者ID:apache,项目名称:incubator-allura,代码行数:31,代码来源:app_globals.py

示例4: prepare_context

# 需要导入模块: from allura.lib.security import Credentials [as 别名]
# 或者: from allura.lib.security.Credentials import get [as 别名]
    def prepare_context(self, context):
        response = super(ProjectList, self).prepare_context(context)
        cred = Credentials.get()
        projects = response['projects']
        cred.load_user_roles(c.user._id, *[p._id for p in projects])
        cred.load_project_roles(*[p._id for p in projects])
        if response['sitemaps'] is None:
            response['sitemaps'] = M.Project.menus(projects)
        if response['icon_urls'] is None:
            response['icon_urls'] = M.Project.icon_urls(projects)
        if response['accolades_index'] is None:
            response['accolades_index'] = M.Project.accolades_index(projects)

        if type(response['columns']) == unicode:
            response['columns'] = int(response['columns'])

        true_list = ['true', 't', '1', 'yes', 'y']
        if type(response['show_proj_icon']) == unicode:
            if response['show_proj_icon'].lower() in true_list:
                response['show_proj_icon'] = True
            else:
                response['show_proj_icon'] = False
        if type(response['show_download_button']) == unicode:
            if response['show_download_button'].lower() in true_list:
                response['show_download_button'] = True
            else:
                response['show_download_button'] = False
        if type(response['show_awards_banner']) == unicode:
            if response['show_awards_banner'].lower() in true_list:
                response['show_awards_banner'] = True
            else:
                response['show_awards_banner'] = False

        return response
开发者ID:Bitergia,项目名称:allura,代码行数:36,代码来源:project_list.py

示例5: test_private_ticket

# 需要导入模块: from allura.lib.security import Credentials [as 别名]
# 或者: from allura.lib.security.Credentials import get [as 别名]
    def test_private_ticket(self):
        from pylons import c
        from allura.model import ProjectRole, User
        from allura.model import ACE, ALL_PERMISSIONS, DENY_ALL
        from allura.lib.security import Credentials, has_access
        from allura.websetup import bootstrap

        admin = c.user
        creator = bootstrap.create_user('Not a Project Admin')
        developer = bootstrap.create_user('Project Developer')
        observer = bootstrap.create_user('Random Non-Project User')
        anon = User(_id=None, username='*anonymous',
                    display_name='Anonymous')
        t = Ticket(summary='my ticket', ticket_num=3, reported_by_id=creator._id)

        assert creator == t.reported_by
        role_admin = ProjectRole.by_name('Admin')._id
        role_developer = ProjectRole.by_name('Developer')._id
        role_creator = t.reported_by.project_role()._id
        developer.project_role().roles.append(role_developer)
        cred = Credentials.get().clear()

        t.private = True
        assert t.acl == [ACE.allow(role_developer, ALL_PERMISSIONS),
                         ACE.allow(role_creator, ALL_PERMISSIONS),
                         DENY_ALL]
        assert has_access(t, 'read', user=admin)()
        assert has_access(t, 'create', user=admin)()
        assert has_access(t, 'update', user=admin)()
        assert has_access(t, 'read', user=creator)()
        assert has_access(t, 'create', user=creator)()
        assert has_access(t, 'update', user=creator)()
        assert has_access(t, 'read', user=developer)()
        assert has_access(t, 'create', user=developer)()
        assert has_access(t, 'update', user=developer)()
        assert not has_access(t, 'read', user=observer)()
        assert not has_access(t, 'create', user=observer)()
        assert not has_access(t, 'update', user=observer)()
        assert not has_access(t, 'read', user=anon)()
        assert not has_access(t, 'create', user=anon)()
        assert not has_access(t, 'update', user=anon)()

        t.private = False
        assert t.acl == []
        assert has_access(t, 'read', user=admin)()
        assert has_access(t, 'create', user=admin)()
        assert has_access(t, 'update', user=admin)()
        assert has_access(t, 'read', user=developer)()
        assert has_access(t, 'create', user=developer)()
        assert has_access(t, 'update', user=developer)()
        assert has_access(t, 'read', user=creator)()
        assert has_access(t, 'unmoderated_post', user=creator)()
        assert not has_access(t, 'create', user=creator)()
        assert not has_access(t, 'update', user=creator)()
        assert has_access(t, 'read', user=observer)()
        assert has_access(t, 'read', user=anon)()
开发者ID:Bitergia,项目名称:allura,代码行数:58,代码来源:test_ticket_model.py

示例6: new_projects

# 需要导入模块: from allura.lib.security import Credentials [as 别名]
# 或者: from allura.lib.security.Credentials import get [as 别名]
 def new_projects(self, **kwargs):
     start_dt = kwargs.pop('start-dt', '')
     end_dt = kwargs.pop('end-dt', '')
     try:
         start_dt = datetime.strptime(start_dt, '%Y/%m/%d %H:%M:%S')
     except ValueError:
         start_dt = datetime.utcnow() + timedelta(days=1)
     try:
         end_dt = datetime.strptime(end_dt, '%Y/%m/%d %H:%M:%S')
     except ValueError:
         end_dt = start_dt - timedelta(days=3) if not end_dt else end_dt
     start = bson.ObjectId.from_datetime(start_dt)
     end = bson.ObjectId.from_datetime(end_dt)
     nb = M.Neighborhood.query.get(name='Users')
     projects = (M.Project.query.find({
         'neighborhood_id': {'$ne': nb._id},
         'deleted': False,
         '_id': {'$lt': start, '$gt': end},
     }).sort('_id', -1)).all()
     # pre-populate roles cache, so we won't query mongo for roles for every project
     # when getting admins with p.admins() in a template
     Credentials.get().load_project_roles(*[p._id for p in projects])
     step = start_dt - end_dt
     params = request.params.copy()
     params['start-dt'] = (start_dt + step).strftime('%Y/%m/%d %H:%M:%S')
     params['end-dt'] = (end_dt + step).strftime('%Y/%m/%d %H:%M:%S')
     newer_url = tg.url(params=params).lstrip('/')
     params['start-dt'] = (start_dt - step).strftime('%Y/%m/%d %H:%M:%S')
     params['end-dt'] = (end_dt - step).strftime('%Y/%m/%d %H:%M:%S')
     older_url = tg.url(params=params).lstrip('/')
     return {
         'projects': projects,
         'newer_url': newer_url,
         'older_url': older_url,
         'window_start': start_dt,
         'window_end': end_dt,
     }
开发者ID:abhinavthomas,项目名称:allura,代码行数:39,代码来源:site_admin.py

示例7: prepare_context

# 需要导入模块: from allura.lib.security import Credentials [as 别名]
# 或者: from allura.lib.security.Credentials import get [as 别名]
    def prepare_context(self, context):
        response = super(ProjectList, self).prepare_context(context)
        cred = Credentials.get()
        projects = response['projects']
        cred.load_user_roles(c.user._id, *[p._id for p in projects])
        cred.load_project_roles(*[p._id for p in projects])

        for opt in ['show_proj_icon', 'show_download_button', 'show_awards_banner']:
            response[opt] = asbool(response[opt])

        if response['icon_urls'] is None and response['show_proj_icon']:
            response['icon_urls'] = M.Project.icon_urls(projects)
        if response['accolades_index'] is None and response['show_awards_banner']:
            response['accolades_index'] = M.Project.accolades_index(projects)

        if type(response['columns']) == unicode:
            response['columns'] = int(response['columns'])

        return response
开发者ID:abhinavthomas,项目名称:allura,代码行数:21,代码来源:project_list.py

示例8: zarkov_event

# 需要导入模块: from allura.lib.security import Credentials [as 别名]
# 或者: from allura.lib.security.Credentials import get [as 别名]
    def zarkov_event(
        self, event_type,
        user=None, neighborhood=None, project=None, app=None,
        extra=None):
        context = dict(
            user=None,
            neighborhood=None, project=None, tool=None,
            mount_point=None,
            is_project_member=False)

        if not zmq:
            return

        user = user or getattr(c, 'user', None)
        project = project or getattr(c, 'project', None)
        app = app or getattr(c, 'app', None)
        if user: context['user'] = user.username
        if project:
            context.update(
                project=project.shortname,
                neighborhood=project.neighborhood.url_prefix.strip('/'))
            if user:
                cred = Credentials.get()
                if cred is not None:
                    for pr in cred.user_roles(user._id, project._id).reaching_roles:
                        if pr.name and pr.name[0] != '*':
                            context['is_project_member'] = True
        if app:
            context.update(
                tool=app.config.tool_name,
                mount_point=app.config.options.mount_point)

        try:
            if self._zarkov is None:
                self._zarkov = ZarkovClient(
                    config.get('zarkov.host', 'tcp://127.0.0.1:6543'))
            self._zarkov.event(event_type, context, extra)
        except Exception, ex:
            self._zarkov = None
            log.error('Error sending zarkov event(%r): %r', ex, dict(
                    type=event_type, context=context, extra=extra))
开发者ID:Bitergia,项目名称:allura,代码行数:43,代码来源:app_globals.py

示例9: credentials

# 需要导入模块: from allura.lib.security import Credentials [as 别名]
# 或者: from allura.lib.security.Credentials import get [as 别名]
 def credentials(self):
     return Credentials.get()
开发者ID:apache,项目名称:incubator-allura,代码行数:4,代码来源:app_globals.py

示例10: test_private_ticket

# 需要导入模块: from allura.lib.security import Credentials [as 别名]
# 或者: from allura.lib.security.Credentials import get [as 别名]
    def test_private_ticket(self):
        from allura.model import ProjectRole
        from allura.model import ACE, DENY_ALL
        from allura.lib.security import Credentials, has_access
        from allura.websetup import bootstrap

        admin = c.user
        creator = bootstrap.create_user('Not a Project Admin')
        developer = bootstrap.create_user('Project Developer')
        observer = bootstrap.create_user('Random Non-Project User')
        anon = User(_id=None, username='*anonymous',
                    display_name='Anonymous')
        t = Ticket(summary='my ticket', ticket_num=3,
                   reported_by_id=creator._id)

        assert creator == t.reported_by
        role_admin = ProjectRole.by_name('Admin')._id
        role_developer = ProjectRole.by_name('Developer')._id
        role_creator = ProjectRole.by_user(t.reported_by, upsert=True)._id
        ProjectRole.by_user(
            developer, upsert=True).roles.append(role_developer)
        ThreadLocalORMSession.flush_all()
        cred = Credentials.get().clear()

        t.private = True
        assert_equal(t.acl, [
            ACE.allow(role_developer, 'save_searches'),
            ACE.allow(role_developer, 'read'),
            ACE.allow(role_developer, 'create'),
            ACE.allow(role_developer, 'update'),
            ACE.allow(role_developer, 'unmoderated_post'),
            ACE.allow(role_developer, 'post'),
            ACE.allow(role_developer, 'moderate'),
            ACE.allow(role_developer, 'delete'),
            ACE.allow(role_creator, 'read'),
            ACE.allow(role_creator, 'post'),
            ACE.allow(role_creator, 'create'),
            ACE.allow(role_creator, 'unmoderated_post'),
            DENY_ALL])
        assert has_access(t, 'read', user=admin)()
        assert has_access(t, 'create', user=admin)()
        assert has_access(t, 'update', user=admin)()
        assert has_access(t, 'read', user=creator)()
        assert has_access(t, 'post', user=creator)()
        assert has_access(t, 'unmoderated_post', user=creator)()
        assert has_access(t, 'create', user=creator)()
        assert not has_access(t, 'update', user=creator)()
        assert has_access(t, 'read', user=developer)()
        assert has_access(t, 'create', user=developer)()
        assert has_access(t, 'update', user=developer)()
        assert not has_access(t, 'read', user=observer)()
        assert not has_access(t, 'create', user=observer)()
        assert not has_access(t, 'update', user=observer)()
        assert not has_access(t, 'read', user=anon)()
        assert not has_access(t, 'create', user=anon)()
        assert not has_access(t, 'update', user=anon)()

        t.private = False
        assert t.acl == []
        assert has_access(t, 'read', user=admin)()
        assert has_access(t, 'create', user=admin)()
        assert has_access(t, 'update', user=admin)()
        assert has_access(t, 'read', user=developer)()
        assert has_access(t, 'create', user=developer)()
        assert has_access(t, 'update', user=developer)()
        assert has_access(t, 'read', user=creator)()
        assert has_access(t, 'unmoderated_post', user=creator)()
        assert has_access(t, 'create', user=creator)()
        assert not has_access(t, 'update', user=creator)()
        assert has_access(t, 'read', user=observer)()
        assert has_access(t, 'read', user=anon)()
开发者ID:joequant,项目名称:allura,代码行数:73,代码来源:test_ticket_model.py

示例11: _add_to_group

# 需要导入模块: from allura.lib.security import Credentials [as 别名]
# 或者: from allura.lib.security.Credentials import get [as 别名]
def _add_to_group(user, role):
    M.ProjectRole.by_user(user, upsert=True).roles.append(role._id)
    ThreadLocalODMSession.flush_all()
    Credentials.get().clear()
开发者ID:jekatgithub,项目名称:incubator-allura,代码行数:6,代码来源:test_security.py

示例12: _deny

# 需要导入模块: from allura.lib.security import Credentials [as 别名]
# 或者: from allura.lib.security.Credentials import get [as 别名]
def _deny(obj, role, perm):
    obj.acl.insert(0, M.ACE.deny(role._id, perm))
    ThreadLocalODMSession.flush_all()
    Credentials.get().clear()
开发者ID:jekatgithub,项目名称:incubator-allura,代码行数:6,代码来源:test_security.py

示例13: _add_to_group

# 需要导入模块: from allura.lib.security import Credentials [as 别名]
# 或者: from allura.lib.security.Credentials import get [as 别名]
def _add_to_group(user, role):
    user.project_role().roles.append(role._id)
    ThreadLocalODMSession.flush_all()
    Credentials.get().clear()
开发者ID:johnsca,项目名称:incubator-allura,代码行数:6,代码来源:test_security.py


注:本文中的allura.lib.security.Credentials.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。