def test_schedule_and_cancel(self): org = self.create_organization(name="test") team = self.create_team(organization=org, name="delete") schedule = ScheduledDeletion.schedule(team, days=0) ScheduledDeletion.cancel(team) assert not ScheduledDeletion.objects.filter(id=schedule.id).exists() # No errors if we cancel a delete that wasn't started. assert ScheduledDeletion.cancel(team) is None
def put(self, request: Request, organization) -> Response: """ Update an Organization `````````````````````` Update various attributes and configurable settings for the given organization. :pparam string organization_slug: the slug of the organization the team should be created for. :param string name: an optional new name for the organization. :param string slug: an optional new slug for the organization. Needs to be available and unique. :auth: required """ if request.access.has_scope("org:admin"): serializer_cls = OwnerOrganizationSerializer else: serializer_cls = OrganizationSerializer was_pending_deletion = organization.status in DELETION_STATUSES serializer = serializer_cls( data=request.data, partial=True, context={ "organization": organization, "user": request.user, "request": request }, ) if serializer.is_valid(): organization, changed_data = serializer.save() if was_pending_deletion: self.create_audit_entry( request=request, organization=organization, target_object=organization.id, event=AuditLogEntryEvent.ORG_RESTORE, data=organization.get_audit_log_data(), ) ScheduledDeletion.cancel(organization) elif changed_data: self.create_audit_entry( request=request, organization=organization, target_object=organization.id, event=AuditLogEntryEvent.ORG_EDIT, data=changed_data, ) context = serialize( organization, request.user, org_serializers. DetailedOrganizationSerializerWithProjectsAndTeams(), access=request.access, ) return self.respond(context) return self.respond(serializer.errors, status=status.HTTP_400_BAD_REQUEST)