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

Python permissions.assert_perm函数代码示例

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

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



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

示例1: delete

    def delete(self, request, project_id, key):
        """
        Remove all occurances of the given tag key.

            {method} {path}

        """
        project = Project.objects.get(
            id=project_id,
        )

        tagkey = TagKey.objects.get(
            project=project,
            key=key,
        )

        assert_perm(tagkey, request.user, request.auth)

        updated = TagKey.objects.filter(
            id=tagkey.id,
            status=TagKeyStatus.VISIBLE,
        ).update(status=TagKeyStatus.PENDING_DELETION)
        if updated:
            delete_tag_key.delay(object_id=tagkey.id)

            AuditLogEntry.objects.create(
                organization=project.organization,
                actor=request.user,
                ip_address=request.META['REMOTE_ADDR'],
                target_object=tagkey.id,
                event=AuditLogEntryEvent.TAGKEY_REMOVE,
                data=tagkey.get_audit_log_data(),
            )

        return Response(status=204)
开发者ID:uber,项目名称:sentry,代码行数:35,代码来源:project_tagkey_details.py


示例2: get

    def get(self, request, organization_slug):
        organization = Organization.objects.get_from_cache(
            slug=organization_slug,
        )

        assert_perm(organization, request.user, request.auth)

        team_list = Team.objects.get_for_user(
            organization=organization,
            user=request.user,
        )

        project_list = []
        for team in team_list:
            project_list.extend(Project.objects.get_for_user(
                team=team,
                user=request.user,
            ))
        project_list.sort(key=lambda x: x.name)

        team_map = dict(
            (t.id, c) for (t, c) in zip(team_list, serialize(team_list, request.user)),
        )

        context = []
        for project, pdata in zip(project_list, serialize(project_list, request.user)):
            pdata['team'] = team_map[project.team_id]
            context.append(pdata)

        return Response(context)
开发者ID:BlueMoebius,项目名称:sentry,代码行数:30,代码来源:organization_projects.py


示例3: delete

    def delete(self, request, team_id):
        team = Team.objects.get(id=team_id)

        assert_perm(team, request.user, request.auth, access=OrganizationMemberType.ADMIN)

        if team.project_set.filter(id=settings.SENTRY_PROJECT).exists():
            return Response('{"error": "Cannot remove team containing default project."}',
                            status=status.HTTP_403_FORBIDDEN)

        team.update(status=TeamStatus.PENDING_DELETION)

        # we delay the task for 5 minutes so we can implement an undo
        kwargs = {'object_id': team.id}
        delete_team.apply_async(kwargs=kwargs, countdown=60 * 5)

        AuditLogEntry.objects.create(
            organization=team.organization,
            actor=request.user,
            ip_address=request.META['REMOTE_ADDR'],
            target_object=team.id,
            event=AuditLogEntryEvent.TEAM_REMOVE,
            data=team.get_audit_log_data(),
        )

        return Response(status=204)
开发者ID:PostPCEra,项目名称:sentry,代码行数:25,代码来源:team_details.py


示例4: post

    def post(self, request, group_id):
        group = Group.objects.get(
            id=group_id,
        )

        assert_perm(group, request.user, request.auth)

        now = timezone.now()

        group.resolved_at = now

        happened = Group.objects.filter(
            id=group.id,
        ).exclude(status=STATUS_RESOLVED).update(
            status=STATUS_RESOLVED,
            resolved_at=now,
        )

        if happened:
            create_or_update(
                Activity,
                project=group.project,
                group=group,
                type=Activity.SET_RESOLVED,
                user=request.user,
            )

        return Response()
开发者ID:CrazyLionHeart,项目名称:sentry,代码行数:28,代码来源:group_resolve.py


示例5: get

    def get(self, request, team_id):
        team = Team.objects.get(id=team_id)

        assert_perm(team, request.user, request.auth)

        projects = Project.objects.get_for_user(
            team=team,
            user=request.user,
        )

        if not projects:
            return Response([])

        data = tsdb.get_range(
            model=tsdb.models.project,
            keys=[p.id for p in projects],
            **self._parse_args(request)
        ).values()

        summarized = []
        for n in range(len(data[0])):
            total = sum(d[n][1] for d in data)
            summarized.append((data[0][n][0], total))

        return Response(summarized)
开发者ID:BlueMoebius,项目名称:sentry,代码行数:25,代码来源:team_stats.py


示例6: put

    def put(self, request, team_id):
        team = Team.objects.get(id=team_id)

        assert_perm(team, request.user, request.auth, access=OrganizationMemberType.ADMIN)

        # TODO(dcramer): this permission logic is duplicated from the
        # transformer
        if request.user.is_superuser or team.owner_id == request.user.id:
            serializer = TeamAdminSerializer(team, data=request.DATA, partial=True)
        else:
            serializer = TeamSerializer(team, data=request.DATA, partial=True)

        if serializer.is_valid():
            team = serializer.save()

            AuditLogEntry.objects.create(
                organization=team.organization,
                actor=request.user,
                ip_address=request.META['REMOTE_ADDR'],
                target_object=team.id,
                event=AuditLogEntryEvent.TEAM_EDIT,
                data=team.get_audit_log_data(),
            )

            return Response(serialize(team, request.user))

        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:BlueMoebius,项目名称:sentry,代码行数:27,代码来源:team_details.py


示例7: post

    def post(self, request, group_id):
        group = Group.objects.get(
            id=group_id,
        )

        assert_perm(group, request.user, request.auth)

        form = NewNoteForm(request.DATA)
        if not form.is_valid():
            return Response('{"error": "form"}', status=status.HTTP_400_BAD_REQUEST)

        if Activity.objects.filter(
            group=group,
            type=Activity.NOTE,
            user=request.user,
            data=form.cleaned_data,
            datetime__gte=timezone.now() - timedelta(hours=1)
        ).exists():
            return Response('{"error": "duplicate"}', status=status.HTTP_400_BAD_REQUEST)

        activity = Activity.objects.create(
            group=group,
            project=group.project,
            type=Activity.NOTE,
            user=extract_lazy_object(request.user),
            data=form.cleaned_data,
        )

        # TODO: move this into the queue
        activity.send_notification()

        return Response(serialize(activity, request.user), status=201)
开发者ID:CrazyLionHeart,项目名称:sentry,代码行数:32,代码来源:group_notes.py


示例8: get

    def get(self, request, project_id):
        """
        List a project's releases

        Retrieve a list of releases for a given project.

            {method} {path}

        """
        project = Project.objects.get(
            id=project_id,
        )

        assert_perm(project, request.user, request.auth)

        queryset = Release.objects.filter(
            project=project,
        ).order_by('-date_added')

        return self.paginate(
            request=request,
            queryset=queryset,
            # TODO(dcramer): we want to sort by date_added
            order_by='-id',
            on_results=lambda x: serialize(x, request.user),
        )
开发者ID:BlueMoebius,项目名称:sentry,代码行数:26,代码来源:project_releases.py


示例9: get

    def get(self, request, team_id):
        """
        Return a list of the trending groups for a given team.

        The resulting query will find groups which have been seen since the
        cutoff date, and then sort those by score, returning the highest scoring
        groups first.
        """
        team = Team.objects.get_from_cache(id=team_id)

        assert_perm(team, request.user, request.auth)

        minutes = int(request.REQUEST.get("minutes", 15))
        limit = min(100, int(request.REQUEST.get("limit", 10)))

        project_list = Project.objects.get_for_user(user=request.user, team=team)

        project_dict = dict((p.id, p) for p in project_list)

        cutoff = timedelta(minutes=minutes)
        cutoff_dt = timezone.now() - cutoff

        group_list = list(
            Group.objects.filter(
                project__in=project_dict.keys(), status=GroupStatus.UNRESOLVED, last_seen__gte=cutoff_dt
            )
            .extra(select={"sort_value": "score"})
            .order_by("-score")[:limit]
        )

        for group in group_list:
            group._project_cache = project_dict.get(group.project_id)

        return Response(serialize(group_list, request.user))
开发者ID:BlueMoebius,项目名称:sentry,代码行数:34,代码来源:team_groups_trending.py


示例10: get

    def get(self, request, project_id):
        """
        Retrieve event counts for a project

        **Draft:** This endpoint may change in the future without notice.

        Return a set of points representing a normalized timestamp and the
        number of events seen in the period.

            {method} {path}?since=1421092384.822244&until=1434052399.443363

        Query ranges are limited to Sentry's configured time-series resolutions.

        Parameters:

        - since: a timestamp to set the start of the query
        - until: a timestamp to set the end of the query
        - resolution: an explicit resolution to search for (i.e. 10s)

        **Note:** resolution should not be used unless you're familiar with Sentry
        internals as it's restricted to pre-defined values.
        """
        project = Project.objects.get_from_cache(id=project_id)

        assert_perm(project, request.user, request.auth)

        data = tsdb.get_range(model=tsdb.models.project, keys=[project.id], **self._parse_args(request))[project.id]

        return Response(data)
开发者ID:BlueMoebius,项目名称:sentry,代码行数:29,代码来源:project_stats.py


示例11: get

    def get(self, request, group_id):
        """
        List an aggregate's available samples

        Return a list of sampled events bound to an aggregate.

            {method} {path}

        """
        group = Group.objects.get(
            id=group_id,
        )

        assert_perm(group, request.user, request.auth)

        events = Event.objects.filter(
            group=group
        )

        return self.paginate(
            request=request,
            queryset=events,
            # TODO(dcramer): we want to sort by datetime
            order_by='-id',
            on_results=lambda x: serialize(x, request.user),
        )
开发者ID:BlueMoebius,项目名称:sentry,代码行数:26,代码来源:group_events.py


示例12: delete

    def delete(self, request, project_id):
        """
        Permanently remove the given groups.

        Only queries by 'id' are accepted.

            {method} {path}?id=1&id=2&id=3

        If any ids are out of scope this operation will succeed without any data
        mutation
        """
        project = Project.objects.get_from_cache(
            id=project_id,
        )

        assert_perm(project, request.user, request.auth)

        group_ids = request.GET.getlist('id')
        if group_ids:
            group_list = Group.objects.filter(project=project, id__in=group_ids)
            # filter down group ids to only valid matches
            group_ids = [g.id for g in group_list]
        else:
            # missing any kind of filter
            return Response(status=400)

        if not group_ids:
            return Response(status=204)

        # TODO(dcramer): set status to pending deletion
        for group in group_list:
            delete_group.delay(object_id=group.id)

        return Response(status=204)
开发者ID:brettlangdon,项目名称:sentry,代码行数:34,代码来源:project_group_index.py


示例13: get

    def get(self, request, group_id):
        """
        Retrieve an aggregate

        Return details on an individual aggregate.

            {method} {path}

        """
        group = Group.objects.get(
            id=group_id,
        )

        assert_perm(group, request.user, request.auth)

        data = serialize(group, request.user)

        # TODO: these probably should be another endpoint
        activity = self._get_activity(request, group, num=7)
        seen_by = self._get_seen_by(request, group)

        data.update({
            'activity': serialize(activity, request.user),
            'seenBy': serialize(seen_by, request.user),
        })

        return Response(data)
开发者ID:brettlangdon,项目名称:sentry,代码行数:27,代码来源:group_details.py


示例14: post

    def post(self, request, group_id):
        group = Group.objects.get(id=group_id)

        assert_perm(group, request.user, request.auth)

        serializer = GroupAssigneeSerializer(data=request.DATA)

        if serializer.is_valid():
            user = serializer.object.user
            now = timezone.now()

            assignee, created = GroupAssignee.objects.get_or_create(
                group=group, defaults={"project": group.project, "user": user, "date_added": now}
            )

            if not created:
                affected = (
                    GroupAssignee.objects.filter(group=group).exclude(user=user).update(user=user, date_added=now)
                )
            else:
                affected = True

            if affected:
                create_or_update(
                    Activity, project=group.project, group=group, type=Activity.ASSIGNED, user=request.user
                )

            return Response()

        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:Getsidecar,项目名称:sentry,代码行数:30,代码来源:group_assign.py


示例15: put

    def put(self, request, project_id):
        project = Project.objects.get(id=project_id)

        assert_perm(project, request.user, request.auth, access=MEMBER_ADMIN)

        serializer = ProjectSerializer(project, data=request.DATA, partial=True)

        if serializer.is_valid():
            project = serializer.save()

            options = request.DATA.get('options', {})
            if 'sentry:origins' in options:
                project.update_option('sentry:origins', options['sentry:origins'].split('\n'))
            if 'sentry:resolve_age' in options:
                project.update_option('sentry:resolve_age', int(options['sentry:resolve_age']))

            AuditLogEntry.objects.create(
                organization=project.organization,
                actor=request.user,
                ip_address=request.META['REMOTE_ADDR'],
                target_object=project.id,
                event=AuditLogEntryEvent.PROJECT_EDIT,
                data=project.get_audit_log_data(),
            )

            data = serialize(project, request.user)
            data['options'] = {
                'sentry:origins': '\n'.join(project.get_option('sentry:origins', None) or []),
                'sentry:resolve_age': int(project.get_option('sentry:resolve_age', 0)),
            }
            return Response(data)

        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:PostPCEra,项目名称:sentry,代码行数:33,代码来源:project_details.py


示例16: get

    def get(self, request, team_id):
        team = Team.objects.get_from_cache(id=team_id)

        assert_perm(team, request.user, request.auth)

        data = sorted(AccessGroup.objects.filter(team=team), key=lambda x: x.name)

        return Response(serialize(data, request.user))
开发者ID:BlueMoebius,项目名称:sentry,代码行数:8,代码来源:team_access_group_index.py


示例17: get

    def get(self, request, group_id):
        group = Group.objects.get(id=group_id)

        assert_perm(group, request.user, request.auth)

        event = group.get_latest_event()

        return HttpResponseRedirect(reverse("sentry-api-0-event-details", kwargs={"event_id": event.id}))
开发者ID:BlueMoebius,项目名称:sentry,代码行数:8,代码来源:group_events_latest.py


示例18: get

    def get(self, request, team_id):
        team = Team.objects.get_from_cache(id=team_id)

        assert_perm(team, request.user, request.auth)

        results = list(Project.objects.get_for_user(request.user, team=team))

        return Response(serialize(results, request.user))
开发者ID:CrazyLionHeart,项目名称:sentry,代码行数:8,代码来源:team_project_index.py


示例19: post

    def post(self, request, group_id):
        group = Group.objects.get(
            id=group_id,
        )

        assert_perm(group, request.user, request.auth)

        group.delete()

        return Response()
开发者ID:CrazyLionHeart,项目名称:sentry,代码行数:10,代码来源:group_delete.py


示例20: get

    def get(self, request, group_id):
        group = Group.objects.get(id=group_id)

        assert_perm(group, request.user)

        event = group.get_latest_event()

        return HttpResponseRedirect(reverse('sentry-api-0-event-details', kwargs={
            'event_id': event.id,
        }))
开发者ID:catufunwa,项目名称:sentry,代码行数:10,代码来源:group_events_latest.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python serializers.serialize函数代码示例发布时间:2022-05-27
下一篇:
Python analytics.record函数代码示例发布时间: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