예제 #1
0
    def post(self, request, organization):
        deletion_statuses = [
            OrganizationStatus.PENDING_DELETION,
            OrganizationStatus.DELETION_IN_PROGRESS]

        if organization.status not in deletion_statuses:
            messages.add_message(request, messages.ERROR, ERR_MESSAGES[organization.status])
            return self.redirect(reverse('sentry'))

        updated = Organization.objects.filter(
            id=organization.id,
            status__in=deletion_statuses,
        ).update(status=OrganizationStatus.VISIBLE)
        if updated:
            client.put('/organizations/{}/'.format(organization.slug), data={
                'cancelDeletion': True,
            }, request=request)
            messages.add_message(request, messages.SUCCESS, MSG_RESTORE_SUCCESS)
            if organization.status == OrganizationStatus.PENDING_DELETION:
                self.create_audit_entry(
                    request=request,
                    organization=organization,
                    target_object=organization.id,
                    event=AuditLogEntryEvent.ORG_RESTORE,
                    data=organization.get_audit_log_data(),
                )
        return self.redirect(reverse('sentry-organization-home', args=[organization.slug]))
예제 #2
0
    def post(self, request, organization):
        deletion_statuses = [
            OrganizationStatus.PENDING_DELETION,
            OrganizationStatus.DELETION_IN_PROGRESS
        ]

        if organization.status not in deletion_statuses:
            messages.add_message(request, messages.ERROR,
                                 ERR_MESSAGES[organization.status])
            return self.redirect(reverse('sentry'))

        updated = Organization.objects.filter(
            id=organization.id,
            status__in=deletion_statuses,
        ).update(status=OrganizationStatus.VISIBLE)
        if updated:
            client.put(u'/organizations/{}/'.format(organization.slug),
                       data={
                           'cancelDeletion': True,
                       },
                       request=request)
            messages.add_message(request, messages.SUCCESS,
                                 MSG_RESTORE_SUCCESS)
            if organization.status == OrganizationStatus.PENDING_DELETION:
                self.create_audit_entry(
                    request=request,
                    organization=organization,
                    target_object=organization.id,
                    event=AuditLogEntryEvent.ORG_RESTORE,
                    data=organization.get_audit_log_data(),
                )
        return self.redirect(organization.get_url())
예제 #3
0
    def post(self, request, organization):
        deletion_statuses = [
            OrganizationStatus.PENDING_DELETION,
            OrganizationStatus.DELETION_IN_PROGRESS
        ]

        if organization.status not in deletion_statuses:
            messages.add_message(request, messages.ERROR,
                                 ERR_MESSAGES[organization.status])
            return self.redirect(reverse('sentry'))

        updated = Organization.objects.filter(
            id=organization.id,
            status__in=deletion_statuses,
        ).update(status=OrganizationStatus.VISIBLE)
        if updated:
            client.put('/organizations/{}/'.format(organization.slug),
                       data={
                           'cancelDeletion': True,
                       },
                       request=request)
            messages.add_message(request, messages.SUCCESS,
                                 MSG_RESTORE_SUCCESS)
        return self.redirect(
            reverse('sentry-organization-home', args=[organization.slug]))
예제 #4
0
    def issue_state_change(self, group, identity, data):
        event_write_key = ApiKey(
            organization=group.project.organization, scope_list=["event:write"]
        )

        # undoing the enum structure of ACTION_TYPE to
        # get a more sensible analytics_event
        action_types = {
            ACTION_TYPE.RESOLVE: "resolve",
            ACTION_TYPE.IGNORE: "ignore",
            ACTION_TYPE.ASSIGN: "assign",
            ACTION_TYPE.UNRESOLVE: "unresolve",
            ACTION_TYPE.UNASSIGN: "unassign",
        }
        action_data = self.make_action_data(data, identity.user_id)
        status = action_types[data["payload"]["actionType"]]
        analytics_event = "integrations.msteams.%s" % status
        analytics.record(
            analytics_event,
            actor_id=identity.user_id,
            organization_id=group.project.organization.id,
        )

        return client.put(
            path=u"/projects/{}/{}/issues/".format(
                group.project.organization.slug, group.project.slug
            ),
            params={"id": group.id},
            data=action_data,
            user=identity.user,
            auth=event_write_key,
        )
예제 #5
0
    def put(self, request, group):
        """
        Update an Issue
        ```````````````

        Updates an individual issues's attributes.  Only the attributes
        submitted are modified.

        :pparam string issue_id: the ID of the group to retrieve.
        :param string status: the new status for the issue.  Valid values
                              are ``"resolved"``, ``resolvedInNextRelease``,
                              ``"unresolved"``, and ``"ignored"``.
        :param string assignedTo: the actor id (or username) of the user or team that should be
                                  assigned to this issue.
        :param boolean hasSeen: in case this API call is invoked with a user
                                context this allows changing of the flag
                                that indicates if the user has seen the
                                event.
        :param boolean isBookmarked: in case this API call is invoked with a
                                     user context this allows changing of
                                     the bookmark flag.
        :param boolean isSubscribed:
        :param boolean isPublic: sets the issue to public or private.
        :auth: required
        """
        discard = request.data.get("discard")

        # TODO(dcramer): we need to implement assignedTo in the bulk mutation
        # endpoint
        try:
            response = client.put(
                path=u"/projects/{}/{}/issues/".format(
                    group.project.organization.slug, group.project.slug),
                params={"id": group.id},
                data=request.data,
                request=request,
            )
        except client.ApiError as e:
            return Response(e.body, status=e.status_code)

        # if action was discard, there isn't a group to serialize anymore
        if discard:
            return response

        # we need to fetch the object against as the bulk mutation endpoint
        # only returns a delta, and object mutation returns a complete updated
        # entity.
        # TODO(dcramer): we should update the API and have this be an explicit
        # flag (or remove it entirely) so that delta's are the primary response
        # for mutation.
        group = Group.objects.get(id=group.id)

        serialized = serialize(
            group,
            request.user,
            GroupSerializer(environment_func=self._get_environment_func(
                request, group.project.organization_id)),
        )

        return Response(serialized, status=response.status_code)
예제 #6
0
    def put(self, request, group):
        """
        Update an Issue
        ```````````````

        Updates an individual issues's attributes.  Only the attributes
        submitted are modified.

        :pparam string issue_id: the ID of the group to retrieve.
        :param string status: the new status for the issue.  Valid values
                              are ``"resolved"``, ``resolvedInNextRelease``,
                              ``"unresolved"``, and ``"ignored"``.
        :param string assignedTo: the username of the user that should be
                               assigned to this issue.
        :param boolean hasSeen: in case this API call is invoked with a user
                                context this allows changing of the flag
                                that indicates if the user has seen the
                                event.
        :param boolean isBookmarked: in case this API call is invoked with a
                                     user context this allows changing of
                                     the bookmark flag.
        :param boolean isSubscribed:
        :param boolean isPublic: sets the issue to public or private.
        :auth: required
        """
        discard = request.DATA.get('discard')

        # TODO(dcramer): we need to implement assignedTo in the bulk mutation
        # endpoint
        response = client.put(
            path='/projects/{}/{}/issues/'.format(
                group.project.organization.slug,
                group.project.slug,
            ),
            params={
                'id': group.id,
            },
            data=request.DATA,
            request=request,
        )

        # if action was discard, there isn't a group to serialize anymore
        if discard:
            return response

        # we need to fetch the object against as the bulk mutation endpoint
        # only returns a delta, and object mutation returns a complete updated
        # entity.
        # TODO(dcramer): we should update the API and have this be an explicit
        # flag (or remove it entirely) so that delta's are the primary response
        # for mutation.
        group = Group.objects.get(id=group.id)

        return Response(serialize(group, request.user), status=response.status_code)
예제 #7
0
    def put(self, request, group):
        """
        Update an Issue
        ```````````````

        Updates an individual issues's attributes.  Only the attributes
        submitted are modified.

        :pparam string issue_id: the ID of the group to retrieve.
        :param string status: the new status for the issue.  Valid values
                              are ``"resolved"``, ``resolvedInNextRelease``,
                              ``"unresolved"``, and ``"ignored"``.
        :param string assignedTo: the username of the user that should be
                               assigned to this issue.
        :param boolean hasSeen: in case this API call is invoked with a user
                                context this allows changing of the flag
                                that indicates if the user has seen the
                                event.
        :param boolean isBookmarked: in case this API call is invoked with a
                                     user context this allows changing of
                                     the bookmark flag.
        :param boolean isSubscribed:
        :auth: required
        """
        discard = request.DATA.get('discard')

        # TODO(dcramer): we need to implement assignedTo in the bulk mutation
        # endpoint
        response = client.put(
            path='/projects/{}/{}/issues/'.format(
                group.project.organization.slug,
                group.project.slug,
            ),
            params={
                'id': group.id,
            },
            data=request.DATA,
            request=request,
        )

        # if action was discard, there isn't a group to serialize anymore
        if discard:
            return response

        # we need to fetch the object against as the bulk mutation endpoint
        # only returns a delta, and object mutation returns a complete updated
        # entity.
        # TODO(dcramer): we should update the API and have this be an explicit
        # flag (or remove it entirely) so that delta's are the primary response
        # for mutation.
        group = Group.objects.get(id=group.id)

        return Response(serialize(group, request.user),
                        status=response.status_code)
예제 #8
0
    def update_group(self, group, identity, data):
        event_write_key = ApiKey(organization=group.project.organization,
                                 scope_list=["event:write"])

        return client.put(
            path=u"/projects/{}/{}/issues/".format(
                group.project.organization.slug, group.project.slug),
            params={"id": group.id},
            data=data,
            user=identity.user,
            auth=event_write_key,
        )
예제 #9
0
    def update_group(self, group: Group, identity: Identity, data: Mapping[str, str]) -> Response:
        event_write_key = ApiKey(
            organization=group.project.organization, scope_list=["event:write"]
        )

        return client.put(
            path=f"/projects/{group.project.organization.slug}/{group.project.slug}/issues/",
            params={"id": group.id},
            data=data,
            user=identity.user,
            auth=event_write_key,
        )
예제 #10
0
    def update_group(self, group, identity, data):
        event_write_key = ApiKey(
            organization=group.project.organization,
            scope_list=['event:write'],
        )

        return client.put(
            path=u'/projects/{}/{}/issues/'.format(
                group.project.organization.slug,
                group.project.slug,
            ),
            params={'id': group.id},
            data=data,
            user=identity.user,
            auth=event_write_key,
        )
예제 #11
0
    def put(self, request, group):
        """
        Update an Issue
        ```````````````

        Updates an individual issue's attributes. Only the attributes submitted
        are modified.

        :pparam string issue_id: the ID of the group to retrieve.
        :param string status: the new status for the issue.  Valid values
                              are ``"resolved"``, ``resolvedInNextRelease``,
                              ``"unresolved"``, and ``"ignored"``.
        :param string assignedTo: the user or team that should be assigned to
                                  this issue. Can be of the form ``"<user_id>"``,
                                  ``"user:<user_id>"``, ``"<username>"``,
                                  ``"<user_primary_email>"``, or ``"team:<team_id>"``.
        :param boolean hasSeen: in case this API call is invoked with a user
                                context this allows changing of the flag
                                that indicates if the user has seen the
                                event.
        :param boolean isBookmarked: in case this API call is invoked with a
                                     user context this allows changing of
                                     the bookmark flag.
        :param boolean isSubscribed:
        :param boolean isPublic: sets the issue to public or private.
        :auth: required
        """
        try:
            discard = request.data.get("discard")

            # TODO(dcramer): we need to implement assignedTo in the bulk mutation
            # endpoint
            response = client.put(
                path=
                f"/projects/{group.project.organization.slug}/{group.project.slug}/issues/",
                params={"id": group.id},
                data=request.data,
                request=request,
            )

            # if action was discard, there isn't a group to serialize anymore
            if discard:
                return response

            # we need to fetch the object against as the bulk mutation endpoint
            # only returns a delta, and object mutation returns a complete updated
            # entity.
            # TODO(dcramer): we should update the API and have this be an explicit
            # flag (or remove it entirely) so that delta's are the primary response
            # for mutation.
            group = Group.objects.get(id=group.id)

            serialized = serialize(
                group,
                request.user,
                GroupSerializer(environment_func=self._get_environment_func(
                    request, group.project.organization_id)),
            )
            return Response(serialized, status=response.status_code)
        except client.ApiError as e:
            logging.error(
                "group_details:put client.ApiError",
                exc_info=True,
            )
            metrics.incr(
                "workflowslo.http_response",
                sample_rate=1.0,
                tags={
                    "status": e.status_code,
                    "detail": "group_details:put:client.ApiError"
                },
            )
            return Response(e.body, status=e.status_code)
        except Exception:
            metrics.incr(
                "group.update.http_response",
                sample_rate=1.0,
                tags={
                    "status": 500,
                    "detail": "group_details:put:Exception"
                },
            )
            raise
예제 #12
0
    def put(self, request, group):
        """
        Update an Issue
        ```````````````

        Updates an individual issues's attributes.  Only the attributes
        submitted are modified.

        :pparam string issue_id: the ID of the group to retrieve.
        :param string status: the new status for the groups.  Valid values
                              are ``"resolved"``, ``"unresolved"`` and
                              ``"ignored"``.
        :param string assignedTo: the username of the user that should be
                               assigned to this issue.
        :param boolean hasSeen: in case this API call is invoked with a user
                                context this allows changing of the flag
                                that indicates if the user has seen the
                                event.
        :param boolean isBookmarked: in case this API call is invoked with a
                                     user context this allows changing of
                                     the bookmark flag.
        :param boolean isSubscribed:
        :auth: required
        """
        # TODO(dcramer): we need to implement assignedTo in the bulk mutation
        # endpoint
        serializer = GroupSerializer(data=request.DATA, partial=True)
        if not serializer.is_valid():
            return Response(serializer.errors, status=400)

        result = serializer.object
        acting_user = request.user if request.user.is_authenticated() else None

        if result.get('assignedTo') and not group.project.member_set.filter(user=result['assignedTo']).exists():
            return Response({'detail': 'Cannot assign to non-team member'}, status=400)

        if 'assignedTo' in result:
            if result['assignedTo']:
                GroupAssignee.objects.assign(group, result['assignedTo'],
                                             acting_user)

                if 'isSubscribed' not in result or result['assignedTo'] != request.user:
                    GroupSubscription.objects.subscribe(
                        group=group,
                        user=result['assignedTo'],
                        reason=GroupSubscriptionReason.assigned,
                    )
            else:
                GroupAssignee.objects.deassign(group, acting_user)

        response = client.put(
            path='/projects/{}/{}/issues/'.format(
                group.project.organization.slug,
                group.project.slug,
            ),
            params={
                'id': group.id,
            },
            data=request.DATA,
            request=request,
        )

        # we need to fetch the object against as the bulk mutation endpoint
        # only returns a delta, and object mutation returns a complete updated
        # entity.
        # TODO(dcramer): we should update the API and have this be an explicit
        # flag (or remove it entirely) so that delta's are the primary response
        # for mutation.
        group = Group.objects.get(id=group.id)

        return Response(serialize(group, request.user),
                        status=response.status_code)