• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python access.from_user函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sentry.auth.access.from_user函数的典型用法代码示例。如果您正苦于以下问题:Python from_user函数的具体用法?Python from_user怎么用?Python from_user使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: tag_value_details

def tag_value_details(request, organization, project, key, value_id):
    tag_key = TagKey.objects.get(
        project=project, key=key)
    tag_value = TagValue.objects.get(
        project=project, key=key, id=value_id)

    event_list = Group.objects.filter(
        grouptag__project=project,
        grouptag__key=key,
        grouptag__value=tag_value.value,
    ).order_by('-score')

    return render_to_response('sentry/explore/tag_value_details.html', {
        'SECTION': 'explore',
        'project': project,
        'team': project.team,
        'organization': organization,
        'tag_key': tag_key,
        'tag_value': tag_value,
        'event_list': event_list,
        'ACCESS': access.from_user(
            user=request.user,
            organization=organization,
        ).to_django_context(),
    }, request)
开发者ID:DZTPY,项目名称:sentry,代码行数:25,代码来源:explore.py


示例2: get_view_response

    def get_view_response(self, request, group):
        from sentry.models import Event

        self.selected = request.path == self.get_url(group)

        if not self.selected:
            return

        response = self.view(request, group)

        if not response:
            return

        if isinstance(response, HttpResponseRedirect):
            return response

        if not isinstance(response, Response):
            raise NotImplementedError('Use self.render() when returning responses.')

        event = group.get_latest_event() or Event()
        event.group = group

        request.access = access.from_user(request.user, group.organization)

        return response.respond(request, {
            'plugin': self,
            'project': group.project,
            'group': group,
            'event': event,
            'can_admin_event': request.access.has_scope('event:write'),
            'can_remove_event': request.access.has_scope('event:delete'),
        })
开发者ID:GpadillaQ,项目名称:sentry,代码行数:32,代码来源:v1.py


示例3: tag_list

def tag_list(request, organization, project):
    tag_key_qs = sorted(TagKey.objects.filter(
        project=project
    ), key=lambda x: x.get_label())

    tag_value_qs = TagValue.objects.filter(
        project=project).order_by('-times_seen')

    # O(N) db access
    tag_list = []
    for tag_key in tag_key_qs:
        # prevent some excess queries by binding project
        tag_key.project = project
        tag_values = tag_value_qs.filter(key=tag_key.key)[:5]
        for tag_value in tag_values:
            tag_value.project = project
        tag_list.append((tag_key, tag_values))

    return render_to_response('sentry/explore/tag_list.html', {
        'SECTION': 'explore',
        'project': project,
        'team': project.team,
        'organization': organization,
        'tag_list': tag_list,
        'ACCESS': access.from_user(
            user=request.user,
            organization=organization,
        ).to_django_context(),
    }, request)
开发者ID:DZTPY,项目名称:sentry,代码行数:29,代码来源:explore.py


示例4: get

    def get(self, request, organization):
        """
        Retrieve an organization

        Return details on an individual organization including various details
        such as membership access, features, and teams.

            {method} {path}

        """
        team_list = list(Team.objects.filter(
            organization=organization,
            status=TeamStatus.VISIBLE,
        ))

        feature_list = []
        if features.has('organizations:sso', organization, actor=request.user):
            feature_list.append('sso')

        if getattr(organization.flags, 'allow_joinleave'):
            feature_list.append('open-membership')

        context = serialize(organization, request.user)
        context['access'] = access.from_user(request.user, organization).scopes
        context['features'] = feature_list
        context['teams'] = serialize(
            team_list, request.user, TeamWithProjectsSerializer())
        return Response(context)
开发者ID:nagyistoce,项目名称:sentry,代码行数:28,代码来源:organization_details.py


示例5: tag_value_list

def tag_value_list(request, organization, project, key):
    tag_key = TagKey.objects.select_related('project').get(
        project=project, key=key)
    tag_values_qs = TagValue.objects.filter(
        project=project, key=key).select_related('project')

    sort = request.GET.get('sort')
    if sort not in SORT_OPTIONS:
        sort = DEFAULT_SORT_OPTION

    if sort == 'recent':
        tag_values_qs = tag_values_qs.order_by('-last_seen')
    elif sort == 'newest':
        tag_values_qs = tag_values_qs.order_by('-first_seen')
    elif sort == 'events':
        tag_values_qs = tag_values_qs.order_by('-times_seen')

    return render_to_response('sentry/explore/tag_value_list.html', {
        'SECTION': 'explore',
        'project': project,
        'team': project.team,
        'organization': organization,
        'SORT_OPTIONS': SORT_OPTIONS,
        'sort_label': SORT_OPTIONS[sort],
        'tag_key': tag_key,
        'tag_values': tag_values_qs,
        'ACCESS': access.from_user(
            user=request.user,
            organization=project.organization,
        ).to_django_context(),
    }, request)
开发者ID:DZTPY,项目名称:sentry,代码行数:31,代码来源:explore.py


示例6: test_member_no_teams_open_membership

    def test_member_no_teams_open_membership(self):
        user = self.create_user()
        organization = self.create_organization(
            owner=self.user,
            flags=Organization.flags.allow_joinleave,
        )
        member = self.create_member(
            organization=organization,
            user=user,
            role='member',
            teams=(),
        )
        team = self.create_team(organization=organization)
        project = self.create_project(organization=organization, teams=[team])

        result = access.from_user(user, organization)
        assert result.sso_is_valid
        assert not result.requires_sso
        assert result.scopes == member.get_scopes()
        assert result.has_team_access(team)
        assert result.has_team_scope(team, 'project:read')
        assert result.has_project_access(project)
        assert result.has_projects_access([project])
        assert result.has_project_scope(project, 'project:read')
        assert not result.has_project_membership(project)
开发者ID:yaoqi,项目名称:sentry,代码行数:25,代码来源:test_access.py


示例7: serialize

    def serialize(self, obj, attrs, user):
        from sentry import features
        from sentry.app import env
        from sentry.api.serializers.models.team import TeamWithProjectsSerializer

        team_list = list(Team.objects.filter(organization=obj, status=TeamStatus.VISIBLE))

        feature_list = []
        if features.has("organizations:events", obj, actor=user):
            feature_list.append("events")
        if features.has("organizations:sso", obj, actor=user):
            feature_list.append("sso")

        if getattr(obj.flags, "allow_joinleave"):
            feature_list.append("open-membership")

        context = super(DetailedOrganizationSerializer, self).serialize(obj, attrs, user)
        context["quota"] = {
            "maxRate": quotas.get_organization_quota(obj),
            "projectLimit": int(
                OrganizationOption.objects.get_value(organization=obj, key="sentry:project-rate-limit", default=100)
            ),
        }
        context["teams"] = serialize(team_list, user, TeamWithProjectsSerializer())
        if env.request:
            context["access"] = access.from_request(env.request, obj).scopes
        else:
            context["access"] = access.from_user(user, obj).scopes
        context["features"] = feature_list
        context["pendingAccessRequests"] = OrganizationAccessRequest.objects.filter(team__organization=obj).count()
        return context
开发者ID:simudream,项目名称:sentry,代码行数:31,代码来源:organization.py


示例8: serialize

    def serialize(self, obj, attrs, user):
        from sentry import features
        from sentry.api.serializers.models.team import TeamWithProjectsSerializer

        team_list = list(Team.objects.filter(
            organization=obj,
            status=TeamStatus.VISIBLE,
        ))

        feature_list = []
        if features.has('organizations:sso', obj, actor=user):
            feature_list.append('sso')

        if getattr(obj.flags, 'allow_joinleave'):
            feature_list.append('open-membership')

        context = super(DetailedOrganizationSerializer, self).serialize(
            obj, attrs, user)
        context['teams'] = serialize(
            team_list, user, TeamWithProjectsSerializer())
        context['access'] = access.from_user(user, obj).scopes
        context['features'] = feature_list
        context['pendingAccessRequests'] = OrganizationAccessRequest.objects.filter(
            team__organization=obj,
        ).count()
        return context
开发者ID:noah-lee,项目名称:sentry,代码行数:26,代码来源:organization.py


示例9: test_anonymous_user

    def test_anonymous_user(self):
        user = self.create_user()
        anon_user = AnonymousUser()
        organization = self.create_organization(owner=user)
        result = access.from_user(anon_user, organization)

        assert not result.is_active
开发者ID:duanshuaimin,项目名称:sentry,代码行数:7,代码来源:test_access.py


示例10: get_default_context

def get_default_context(request, existing_context=None, team=None):
    from sentry.plugins import plugins

    context = {
        'EVENTS_PER_PAGE': EVENTS_PER_PAGE,
        'URL_PREFIX': settings.SENTRY_URL_PREFIX,
        'SINGLE_ORGANIZATION': settings.SENTRY_SINGLE_ORGANIZATION,
        'PLUGINS': plugins,
        'ALLOWED_HOSTS': settings.ALLOWED_HOSTS,
        'SENTRY_RAVEN_JS_URL': settings.SENTRY_RAVEN_JS_URL,
    }

    if existing_context:
        if team is None and 'team' in existing_context:
            team = existing_context['team']

        if 'project' in existing_context:
            project = existing_context['project']
        else:
            project = None
    else:
        project = None

    if team:
        organization = team.organization
    elif project:
        organization = project.organization
    else:
        organization = None

    if request:
        context.update({
            'request': request,
        })

        if (not existing_context or 'TEAM_LIST' not in existing_context) and team:
            context['TEAM_LIST'] = Team.objects.get_for_user(
                organization=team.organization,
                user=request.user,
                with_projects=True,
            )

        user = request.user
    else:
        user = AnonymousUser()

    if organization:
        context['selectedOrganization'] = serialize(organization, user)
    if team:
        context['selectedTeam'] = serialize(team, user)
    if project:
        context['selectedProject'] = serialize(project, user)

    if not existing_context or 'ACCESS' not in existing_context:
        context['ACCESS'] = access.from_user(
            user=user,
            organization=organization,
        ).to_django_context()

    return context
开发者ID:carriercomm,项目名称:sentry-1,代码行数:60,代码来源:helpers.py


示例11: group_list

def group_list(request, organization, project):
    query = request.GET.get("query")
    if query and uuid_re.match(query):
        # Forward to event if it exists
        try:
            group_id = EventMapping.objects.filter(project=project, event_id=query).values_list("group", flat=True)[0]
        except IndexError:
            pass
        else:
            return HttpResponseRedirect(
                reverse(
                    "sentry-group",
                    kwargs={
                        "project_id": project.slug,
                        "organization_slug": project.organization.slug,
                        "group_id": group_id,
                    },
                )
            )

    response = _get_group_list(request=request, project=project)
    if isinstance(response, HttpResponse):
        return response

    # XXX: this is duplicate in _get_group_list
    sort_label = SORT_OPTIONS[response["sort"]]

    has_realtime = not request.GET.get("cursor")

    query_dict = request.GET.copy()
    if "cursor" in query_dict:
        del query_dict["cursor"]
    cursorless_query_string = query_dict.urlencode()

    GroupMeta.objects.populate_cache(response["event_list"])

    return render_to_response(
        "sentry/groups/group_list.html",
        {
            "team": project.team,
            "organization": organization,
            "project": project,
            "from_date": response["date_from"],
            "to_date": response["date_to"],
            "date_type": response["date_type"],
            "has_realtime": has_realtime,
            "event_list": response["event_list"],
            "prev_cursor": response["prev_cursor"],
            "next_cursor": response["next_cursor"],
            "today": response["today"],
            "sort": response["sort"],
            "query": query,
            "cursorless_query_string": cursorless_query_string,
            "sort_label": sort_label,
            "SORT_OPTIONS": SORT_OPTIONS,
            "ACCESS": access.from_user(user=request.user, organization=organization).to_django_context(),
        },
        request,
    )
开发者ID:alfonsolzrg,项目名称:sentry,代码行数:59,代码来源:groups.py


示例12: render_with_group_context

def render_with_group_context(group, template, context, request=None,
                              event=None, is_public=False):
    context.update({
        'team': group.project.team,
        'organization': group.project.organization,
        'project': group.project,
        'group': group,
    })

    if request and request.user.is_authenticated():
        context['ACCESS'] = access.from_user(
            user=request.user,
            organization=group.organization,
        ).to_django_context()
    else:
        context['ACCESS'] = access.DEFAULT.to_django_context()

    if event:
        if event.id:
            # TODO(dcramer): we dont want to actually use gt/lt here as it should
            # be inclusive. However, that would need to ensure we have some kind
            # of way to know which event was the previous (an offset), or to add
            # a third sort key (which is not yet indexed)
            base_qs = group.event_set.exclude(id=event.id)
            try:
                next_event = base_qs.filter(
                    datetime__gt=event.datetime,
                ).order_by('datetime')[0:1].get()
            except Event.DoesNotExist:
                next_event = None

            try:
                prev_event = base_qs.filter(
                    datetime__lt=event.datetime,
                ).order_by('-datetime')[0:1].get()
            except Event.DoesNotExist:
                prev_event = None
        else:
            next_event = None
            prev_event = None

        if not is_public:
            extra_data = event.data.get('extra', {})
            if not isinstance(extra_data, dict):
                extra_data = {}

            context.update({
                'tags': event.get_tags(),
                'json_data': extra_data,
            })

        context.update({
            'event': event,
            'version_data': event.data.get('modules', None),
            'next_event': next_event,
            'prev_event': prev_event,
        })

    return render_to_response(template, context, request)
开发者ID:DZTPY,项目名称:sentry,代码行数:59,代码来源:groups.py


示例13: test_anonymous_user

    def test_anonymous_user(self):
        from django.contrib.auth.models import AnonymousUser
        user = self.create_user()
        anon_user = AnonymousUser()
        organization = self.create_organization(owner=user)
        result = access.from_user(anon_user, organization)

        assert not result.is_active
开发者ID:aibar,项目名称:sentry,代码行数:8,代码来源:test_access.py


示例14: group_list

def group_list(request, organization, project):
    query = request.GET.get('query')
    if query and uuid_re.match(query):
        # Forward to event if it exists
        try:
            group_id = EventMapping.objects.filter(
                project=project, event_id=query
            ).values_list('group', flat=True)[0]
        except IndexError:
            pass
        else:
            return HttpResponseRedirect(reverse('sentry-group', kwargs={
                'project_id': project.slug,
                'organization_slug': project.organization.slug,
                'group_id': group_id,
            }))

    response = _get_group_list(
        request=request,
        project=project,
    )
    if isinstance(response, HttpResponse):
        return response

    # XXX: this is duplicate in _get_group_list
    sort_label = SORT_OPTIONS[response['sort']]

    has_realtime = not request.GET.get('cursor')

    query_dict = request.GET.copy()
    if 'cursor' in query_dict:
        del query_dict['cursor']
    cursorless_query_string = query_dict.urlencode()

    GroupMeta.objects.populate_cache(response['event_list'])

    return render_to_response('sentry/groups/group_list.html', {
        'team': project.team,
        'organization': organization,
        'project': project,
        'from_date': response['date_from'],
        'to_date': response['date_to'],
        'date_type': response['date_type'],
        'has_realtime': has_realtime,
        'event_list': response['event_list'],
        'prev_cursor': response['prev_cursor'],
        'next_cursor': response['next_cursor'],
        'today': response['today'],
        'sort': response['sort'],
        'query': query,
        'cursorless_query_string': cursorless_query_string,
        'sort_label': sort_label,
        'SORT_OPTIONS': SORT_OPTIONS,
        'ACCESS': access.from_user(
            user=request.user,
            organization=organization,
        ).to_django_context(),
    }, request)
开发者ID:Qwiz,项目名称:sentry,代码行数:58,代码来源:groups.py


示例15: serialize

    def serialize(self, obj, attrs, user):
        from sentry import features
        from sentry.app import env
        from sentry.api.serializers.models.team import TeamWithProjectsSerializer

        team_list = list(Team.objects.filter(
            organization=obj,
            status=TeamStatus.VISIBLE,
        ))
        for team in team_list:
            team._organization_cache = obj

        onboarding_tasks = list(OrganizationOnboardingTask.objects.filter(
            organization=obj,
        ).select_related('user'))

        feature_list = []
        if features.has('organizations:sso', obj, actor=user):
            feature_list.append('sso')
        if features.has('organizations:callsigns', obj, actor=user):
            feature_list.append('callsigns')
        if features.has('organizations:new-tracebacks', obj, actor=user):
            feature_list.append('new-tracebacks')
        if features.has('organizations:onboarding', obj, actor=user) and \
                not OrganizationOption.objects.filter(organization=obj).exists():
            feature_list.append('onboarding')
        if features.has('organizations:api-keys', obj, actor=user) or \
                ApiKey.objects.filter(organization=obj).exists():
            feature_list.append('api-keys')

        if getattr(obj.flags, 'allow_joinleave'):
            feature_list.append('open-membership')
        if not getattr(obj.flags, 'disable_shared_issues'):
            feature_list.append('shared-issues')

        context = super(DetailedOrganizationSerializer, self).serialize(
            obj, attrs, user)
        context['quota'] = {
            'maxRate': quotas.get_organization_quota(obj),
            'projectLimit': int(OrganizationOption.objects.get_value(
                organization=obj,
                key='sentry:project-rate-limit',
                default=100,
            )),
        }
        context['teams'] = serialize(
            team_list, user, TeamWithProjectsSerializer())
        if env.request:
            context['access'] = access.from_request(env.request, obj).scopes
        else:
            context['access'] = access.from_user(user, obj).scopes
        context['features'] = feature_list
        context['pendingAccessRequests'] = OrganizationAccessRequest.objects.filter(
            team__organization=obj,
        ).count()
        context['onboardingTasks'] = serialize(onboarding_tasks, user, OnboardingTasksSerializer())
        return context
开发者ID:E-LLP,项目名称:sentry,代码行数:57,代码来源:organization.py


示例16: has_object_permission

    def has_object_permission(self, request, view, organization):
        if request.auth:
            if self.is_project_key(request):
                return False
            return request.auth.organization_id == organization.id

        request.access = access.from_user(request.user, organization)
        allowed_scopes = set(self.scope_map[request.method])
        return any(request.access.has_scope(s) for s in allowed_scopes)
开发者ID:ChadKillingsworth,项目名称:sentry,代码行数:9,代码来源:organization.py


示例17: render_with_group_context

def render_with_group_context(group, template, context, request=None, event=None, is_public=False):
    context.update(
        {
            "team": group.project.team,
            "organization": group.project.organization,
            "project": group.project,
            "group": group,
        }
    )

    if request and request.user.is_authenticated():
        context["ACCESS"] = access.from_user(user=request.user, organization=group.organization).to_django_context()
    else:
        context["ACCESS"] = access.DEFAULT.to_django_context()

    if event:
        if event.id:
            # HACK(dcramer): work around lack of unique sorting on datetime
            base_qs = Event.objects.filter(group=event.group_id).exclude(id=event.id)
            try:
                next_event = sorted(
                    base_qs.filter(datetime__gte=event.datetime).order_by("datetime")[0:5],
                    key=lambda x: (x.datetime, x.id),
                )[0]
            except IndexError:
                next_event = None

            try:
                prev_event = sorted(
                    base_qs.filter(datetime__lte=event.datetime).order_by("-datetime")[0:5],
                    key=lambda x: (x.datetime, x.id),
                    reverse=True,
                )[0]
            except IndexError:
                prev_event = None
        else:
            next_event = None
            prev_event = None

        if not is_public:
            extra_data = event.data.get("extra", {})
            if not isinstance(extra_data, dict):
                extra_data = {}

            context.update({"tags": event.get_tags(), "json_data": extra_data})

        context.update(
            {
                "event": event,
                "version_data": event.data.get("modules", None),
                "next_event": next_event,
                "prev_event": prev_event,
            }
        )

    return render_to_response(template, context, request)
开发者ID:alfonsolzrg,项目名称:sentry,代码行数:56,代码来源:groups.py


示例18: test_no_access

    def test_no_access(self):
        organization = self.create_organization()
        team = self.create_team(organization=organization)
        user = self.create_user()

        result = access.from_user(user, organization)
        assert not result.is_active
        assert result.sso_is_valid
        assert not result.scopes
        assert not result.has_team(team)
开发者ID:noah-lee,项目名称:sentry,代码行数:10,代码来源:test_access.py


示例19: test_global_org_member_access

    def test_global_org_member_access(self):
        user = self.create_user()
        organization = self.create_organization(owner=user)
        member = organization.member_set.get(user=user)
        team = self.create_team(organization=organization)

        result = access.from_user(user, organization)
        assert result.is_active
        assert result.sso_is_valid
        assert result.scopes == member.get_scopes()
        assert result.has_team(team)
开发者ID:Batterfii,项目名称:sentry,代码行数:11,代码来源:test_access.py


示例20: test_no_access

    def test_no_access(self):
        organization = self.create_organization()
        team = self.create_team(organization=organization)
        user = self.create_user()

        result = access.from_user(user, organization)
        assert not result.sso_is_valid
        assert not result.requires_sso
        assert not result.scopes
        assert not result.has_team_access(team)
        assert not result.has_team_membership(team)
开发者ID:alexandrul,项目名称:sentry,代码行数:11,代码来源:test_access.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python superuser.is_active_superuser函数代码示例发布时间:2022-05-27
下一篇:
Python access.from_request函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap