Exemplo n.º 1
0
def remove_team(request, team):
    if not can_remove_team(request.user, team):
        return HttpResponseRedirect(reverse('sentry'))

    if request.method == 'POST':
        form = RemoveTeamForm(request.POST)
    else:
        form = RemoveTeamForm()

    if form.is_valid():
        if team.status == TeamStatus.VISIBLE:
            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)

        messages.add_message(
            request, messages.SUCCESS,
            _('Deletion has been queued and will happen automatically.'))

        return HttpResponseRedirect(reverse('sentry'))

    context = csrf(request)
    context.update({
        'page': 'settings',
        'form': form,
        'SUBSECTION': 'settings',
    })

    return render_with_team_context(team, 'sentry/teams/remove.html', context, request)
Exemplo n.º 2
0
    def delete(self, request, team):
        """
        Delete a Team
        `````````````

        Schedules a team for deletion.

        **Note:** Deletion happens asynchronously and therefor is not
        immediate.  However once deletion has begun the state of a project
        changes and will be hidden from most public views.
        """
        logging.getLogger('sentry.deletions').info(
            'Team %s/%s (id=%s) removal requested by user (id=%s)',
            team.organization.slug, team.slug, team.id, request.user.id)

        updated = Team.objects.filter(
            id=team.id,
            status=TeamStatus.VISIBLE,
        ).update(status=TeamStatus.PENDING_DELETION)
        if updated:
            delete_team.apply_async(
                kwargs={'object_id': team.id},
                countdown=3600,
            )

            self.create_audit_entry(
                request=request,
                organization=team.organization,
                target_object=team.id,
                event=AuditLogEntryEvent.TEAM_REMOVE,
                data=team.get_audit_log_data(),
            )

        return Response(status=204)
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    def handle(self, request, organization, team):
        if not can_remove_team(request.user, team):
            return HttpResponseRedirect(reverse('sentry'))

        form = self.get_form(request)

        if form.is_valid():
            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=organization,
                actor=request.user,
                ip_address=request.META['REMOTE_ADDR'],
                target_object=team.id,
                event=AuditLogEntryEvent.TEAM_REMOVE,
                data=team.get_audit_log_data(),
            )

            messages.add_message(
                request, messages.SUCCESS,
                _(u'The team %r was scheduled for deletion.') % (team.name.encode('utf-8'),))

            return HttpResponseRedirect(reverse('sentry'))

        context = {
            'form': form,
        }

        return self.respond('sentry/teams/remove.html', context)
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
def remove_team(request, team):
    if not can_remove_team(request.user, team):
        return HttpResponseRedirect(reverse('sentry'))

    if request.method == 'POST':
        form = RemoveTeamForm(request.POST)
    else:
        form = RemoveTeamForm()

    if form.is_valid():
        if team.status == TeamStatus.VISIBLE:
            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)

        messages.add_message(
            request, messages.SUCCESS,
            _('Deletion has been queued and will happen automatically.'))

        return HttpResponseRedirect(reverse('sentry'))

    context = csrf(request)
    context.update({
        'page': 'settings',
        'form': form,
        'SUBSECTION': 'settings',
    })

    return render_with_team_context(team, 'sentry/teams/remove.html', context, request)
Exemplo n.º 7
0
    def delete(self, request, team):
        """
        Delete a Team
        `````````````

        Schedules a team for deletion.

        **Note:** Deletion happens asynchronously and therefor is not
        immediate.  However once deletion has begun the state of a project
        changes and will be hidden from most public views.
        """
        updated = Team.objects.filter(
            id=team.id,
            status=TeamStatus.VISIBLE,
        ).update(status=TeamStatus.PENDING_DELETION)
        if updated:
            transaction_id = uuid4().hex
            delete_team.apply_async(
                kwargs={
                    'object_id': team.id,
                    'transaction_id': transaction_id,
                },
                countdown=3600,
            )

            self.create_audit_entry(
                request=request,
                organization=team.organization,
                target_object=team.id,
                event=AuditLogEntryEvent.TEAM_REMOVE,
                data=team.get_audit_log_data(),
                transaction_id=transaction_id,
            )

            delete_logger.info(
                'object.delete.queued',
                extra={
                    'object_id': team.id,
                    'transaction_id': transaction_id,
                    'model': type(team).__name__,
                }
            )

        return Response(status=204)
Exemplo n.º 8
0
    def delete(self, request, team):
        """
        Delete a Team
        `````````````

        Schedules a team for deletion.

        **Note:** Deletion happens asynchronously and therefor is not
        immediate.  However once deletion has begun the state of a project
        changes and will be hidden from most public views.
        """
        updated = Team.objects.filter(
            id=team.id,
            status=TeamStatus.VISIBLE,
        ).update(status=TeamStatus.PENDING_DELETION)
        if updated:
            transaction_id = uuid4().hex
            delete_team.apply_async(
                kwargs={
                    'object_id': team.id,
                    'transaction_id': transaction_id,
                },
                countdown=3600,
            )

            self.create_audit_entry(
                request=request,
                organization=team.organization,
                target_object=team.id,
                event=AuditLogEntryEvent.TEAM_REMOVE,
                data=team.get_audit_log_data(),
                transaction_id=transaction_id,
            )

            delete_logger.info(
                'object.delete.queued',
                extra={
                    'object_id': team.id,
                    'transaction_id': transaction_id,
                    'model': type(team).__name__,
                }
            )

        return Response(status=204)
Exemplo n.º 9
0
    def delete(self, request, team_id):
        team = Team.objects.get(id=team_id)

        assert_perm(team, request.user, request.auth, access=MEMBER_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)

        if not (request.user.is_superuser or team.owner_id == request.user.id):
            return Response('{"error": "You do not have permission to remove this team."}', 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)

        return Response(status=204)