def get(self, request, organization, version):
        """
        Retrieve an Organization's Release
        ``````````````````````````````````

        Return details on an individual release.

        :pparam string organization_slug: the slug of the organization the
                                          release belongs to.
        :pparam string version: the version identifier of the release.
        :auth: required
        """
        project_id = request.GET.get("project")
        with_health = request.GET.get("health") == "1"
        summary_stats_period = request.GET.get("summaryStatsPeriod") or "14d"
        health_stats_period = request.GET.get("healthStatsPeriod") or (
            "24h" if with_health else "")
        if summary_stats_period not in STATS_PERIODS:
            raise ParseError(detail=get_stats_period_detail(
                "summaryStatsPeriod", STATS_PERIODS))
        if health_stats_period and health_stats_period not in STATS_PERIODS:
            raise ParseError(detail=get_stats_period_detail(
                "healthStatsPeriod", STATS_PERIODS))

        try:
            release = Release.objects.get(organization_id=organization.id,
                                          version=version)
        except Release.DoesNotExist:
            raise ResourceDoesNotExist

        if not self.has_release_permission(request, organization, release):
            raise ResourceDoesNotExist

        if with_health and project_id:
            try:
                project = Project.objects.get_from_cache(id=int(project_id))
            except (ValueError, Project.DoesNotExist):
                raise ParseError(detail="Invalid project")
            release._for_project_id = project.id

        return Response(
            serialize(
                release,
                request.user,
                with_health_data=with_health,
                summary_stats_period=summary_stats_period,
                health_stats_period=health_stats_period,
            ))
Esempio n. 2
0
    def get(self, request, project, version):
        """
        Retrieve a Project's Release
        ````````````````````````````

        Return details on an individual release.

        :pparam string organization_slug: the slug of the organization the
                                          release belongs to.
        :pparam string project_slug: the slug of the project to retrieve the
                                     release of.
        :pparam string version: the version identifier of the release.
        :auth: required
        """
        with_health = request.GET.get("health") == "1"
        summary_stats_period = request.GET.get("summaryStatsPeriod") or "48h"
        health_stats_period = request.GET.get("healthStatsPeriod") or (
            "24h" if with_health else "")
        if summary_stats_period not in SUMMARY_STATS_PERIOD:
            raise ParseError(detail=get_stats_period_detail(
                "summaryStatsPeriod", SUMMARY_STATS_PERIOD))
        if health_stats_period not in HEALTH_STATS_PERIOD:
            raise ParseError(detail=get_stats_period_detail(
                "healthStatsPeriod", HEALTH_STATS_PERIOD))

        try:
            release = Release.objects.get(
                organization_id=project.organization_id,
                projects=project,
                version=version)
        except Release.DoesNotExist:
            raise ResourceDoesNotExist

        if with_health:
            release._for_project_id = project.id

        return Response(
            serialize(
                release,
                request.user,
                project=project,
                with_health_data=with_health,
                summary_stats_period=summary_stats_period,
                health_stats_period=health_stats_period,
            ))
    def get(self, request, organization, version):
        """
        Retrieve an Organization's Release
        ``````````````````````````````````

        Return details on an individual release.

        :pparam string organization_slug: the slug of the organization the
                                          release belongs to.
        :pparam string version: the version identifier of the release.
        :auth: required
        """
        # Dictionary responsible for storing selected project meta data
        current_project_meta = {}
        project_id = request.GET.get("project")
        with_health = request.GET.get("health") == "1"
        summary_stats_period = request.GET.get("summaryStatsPeriod") or "14d"
        health_stats_period = request.GET.get("healthStatsPeriod") or ("24h" if with_health else "")
        sort = request.GET.get("sort") or "date"

        if summary_stats_period not in STATS_PERIODS:
            raise ParseError(detail=get_stats_period_detail("summaryStatsPeriod", STATS_PERIODS))
        if health_stats_period and health_stats_period not in STATS_PERIODS:
            raise ParseError(detail=get_stats_period_detail("healthStatsPeriod", STATS_PERIODS))

        try:
            release = Release.objects.get(organization_id=organization.id, version=version)
        except Release.DoesNotExist:
            raise ResourceDoesNotExist

        if not self.has_release_permission(request, organization, release):
            raise ResourceDoesNotExist

        if with_health and project_id:
            try:
                project = Project.objects.get_from_cache(id=int(project_id))
            except (ValueError, Project.DoesNotExist):
                raise ParseError(detail="Invalid project")
            release._for_project_id = project.id

        if project_id:
            # Add sessions time bound to current project meta data
            environments = set(request.GET.getlist("environment")) or None
            current_project_meta.update(
                {
                    **get_release_sessions_time_bounds(
                        project_id=int(project_id),
                        release=release.version,
                        org_id=organization.id,
                        environments=environments,
                    )
                }
            )

            # Get prev and next release to current release
            try:
                filter_params = self.get_filter_params(request, organization)
                current_project_meta.update(
                    {
                        **self.get_adjacent_releases_to_current_release(
                            org=organization,
                            release=release,
                            filter_params=filter_params,
                            stats_period=summary_stats_period,
                            sort=sort,
                        )
                    }
                )
            except InvalidSortException:
                return Response({"detail": "invalid sort"}, status=400)

        return Response(
            serialize(
                release,
                request.user,
                with_health_data=with_health,
                summary_stats_period=summary_stats_period,
                health_stats_period=health_stats_period,
                current_project_meta=current_project_meta,
            )
        )