def get(self, request): try: data = request.GET['data'] except KeyError: raise Http404 try: data, project = self.get_validated_data(data, request.user) except InvalidPayload as exc: return Response({'detail': exc.message}, status=400) organizations = Organization.objects.filter( status=OrganizationStatus.ACTIVE, id__in=OrganizationMember.objects.filter( user=request.user, role=roles.get_top_dog().id, ).values_list('organization_id', flat=True), ) return Response({ 'organizations': serialize(list(organizations), request.user, DetailedOrganizationSerializer()), 'project': { 'slug': project.slug, 'id': project.id, } })
def put(self, request, organization): """ 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 }, ) if serializer.is_valid(): organization, changed_data = serializer.save() if was_pending_deletion and organization.status == OrganizationStatus.VISIBLE: self.create_audit_entry( request=request, organization=organization, target_object=organization.id, event=AuditLogEntryEvent.ORG_RESTORE, data=organization.get_audit_log_data(), ) delete_logger.info('object.delete.canceled', extra={ 'object_id': organization.id, 'model': Organization.__name__, }) else: self.create_audit_entry(request=request, organization=organization, target_object=organization.id, event=AuditLogEntryEvent.ORG_EDIT, data=changed_data) return Response( serialize( organization, request.user, DetailedOrganizationSerializer(), )) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def put(self, request, organization): """ 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 """ serializer = OrganizationSerializer(organization, data=request.DATA, partial=True) if serializer.is_valid(): organization = serializer.save() self.create_audit_entry( request=request, organization=organization, target_object=organization.id, event=AuditLogEntryEvent.ORG_EDIT, data=organization.get_audit_log_data(), ) return Response(serialize( organization, request.user, DetailedOrganizationSerializer(), )) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def serialize_detailed_org(context, obj): if 'request' in context: user = context['request'].user else: user = None context = serialize_func( obj, user, DetailedOrganizationSerializer(), ) return mark_safe(json.dumps(context))
def serialize_detailed_org(context, obj): if 'request' in context: user = context['request'].user else: user = None context = serialize_func( obj, user, DetailedOrganizationSerializer(), ) return convert_to_json(context)
def serialize_detailed_org(context, obj): if 'request' in context: user = context['request'].user access = from_user(user, obj) else: user = None access = NoAccess() context = serialize_func(obj, user, DetailedOrganizationSerializer(), access=access) return convert_to_json(context)
def get(self, request, organization): """ Retrieve an Organization ```````````````````````` Return details on an individual organization including various details such as membership access, features, and teams. :pparam string organization_slug: the slug of the organization the team should be created for. :auth: required """ context = serialize( organization, request.user, DetailedOrganizationSerializer(), ) return self.respond(context)
def delete(self, request, organization): """ Delete an Organization `````````````````````` Schedules an organization for deletion. This API endpoint cannot be invoked without a user context for security reasons. This means that at present an organization can only be deleted from the Sentry UI. 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. :pparam string organization_slug: the slug of the organization the team should be created for. :auth: required, user-context-needed """ if not request.user.is_authenticated(): return self.respond({'detail': ERR_NO_USER}, status=401) if organization.is_default: return self.respond({'detail': ERR_DEFAULT_ORG}, status=400) updated = Organization.objects.filter( id=organization.id, status=OrganizationStatus.VISIBLE, ).update(status=OrganizationStatus.PENDING_DELETION) if updated: transaction_id = uuid4().hex countdown = 86400 entry = self.create_audit_entry( request=request, organization=organization, target_object=organization.id, event=AuditLogEntryEvent.ORG_REMOVE, data=organization.get_audit_log_data(), transaction_id=transaction_id, ) organization.send_delete_confirmation(entry, countdown) delete_organization.apply_async( kwargs={ 'object_id': organization.id, 'transaction_id': transaction_id, 'actor_id': request.user.id, }, countdown=countdown, ) delete_logger.info( 'object.delete.queued', extra={ 'object_id': organization.id, 'transaction_id': transaction_id, 'model': Organization.__name__, } ) context = serialize( organization, request.user, DetailedOrganizationSerializer(), ) return self.respond(context, status=202)