Skip to content

Commit 16d0f5d

Browse files
[DO NOT LAND] task(preprod): Roll out preprod to early adopters
1 parent dc367b8 commit 16d0f5d

12 files changed

+125
-50
lines changed

src/sentry/preprod/api/endpoints/organization_preprod_artifact_assemble.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from rest_framework.request import Request
1010
from rest_framework.response import Response
1111

12-
from sentry import analytics, features
12+
from sentry import analytics
1313
from sentry.api.api_owners import ApiOwner
1414
from sentry.api.api_publish_status import ApiPublishStatus
1515
from sentry.api.base import region_silo_endpoint
@@ -19,6 +19,7 @@
1919
from sentry.models.orgauthtoken import is_org_auth_token_auth, update_org_auth_token_last_used
2020
from sentry.models.project import Project
2121
from sentry.preprod.analytics import PreprodArtifactApiAssembleEvent
22+
from sentry.preprod.permissions import has_preprod_access
2223
from sentry.preprod.tasks import assemble_preprod_artifact, create_preprod_artifact
2324
from sentry.preprod.url_utils import get_preprod_artifact_url
2425
from sentry.preprod.vcs.status_checks.size.tasks import create_preprod_status_check_task
@@ -116,9 +117,7 @@ def post(self, request: Request, project: Project) -> Response:
116117
)
117118
)
118119

119-
if not settings.IS_DEV and not features.has(
120-
"organizations:preprod-frontend-routes", project.organization, actor=request.user
121-
):
120+
if not settings.IS_DEV and not has_preprod_access(project.organization, request.user):
122121
return Response({"error": "Feature not enabled"}, status=403)
123122

124123
with sentry_sdk.start_span(op="preprod_artifact.assemble"):

src/sentry/preprod/api/endpoints/project_preprod_artifact_delete.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from rest_framework.request import Request
77
from rest_framework.response import Response
88

9-
from sentry import analytics, features
9+
from sentry import analytics
1010
from sentry.api.api_owners import ApiOwner
1111
from sentry.api.api_publish_status import ApiPublishStatus
1212
from sentry.api.base import region_silo_endpoint
@@ -15,6 +15,7 @@
1515
from sentry.preprod.analytics import PreprodArtifactApiDeleteEvent
1616
from sentry.preprod.api.bases.preprod_artifact_endpoint import PreprodArtifactEndpoint
1717
from sentry.preprod.models import PreprodArtifact, PreprodArtifactSizeMetrics
18+
from sentry.preprod.permissions import has_preprod_access
1819

1920
logger = logging.getLogger(__name__)
2021

@@ -35,9 +36,7 @@ def delete(
3536
) -> Response:
3637
"""Delete a preprod artifact and all associated data"""
3738

38-
if not features.has(
39-
"organizations:preprod-frontend-routes", project.organization, actor=request.user
40-
):
39+
if not has_preprod_access(project.organization, request.user):
4140
return Response({"error": "Feature not enabled"}, status=403)
4241

4342
analytics.record(

src/sentry/preprod/api/endpoints/project_preprod_build_details.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from rest_framework.request import Request
66
from rest_framework.response import Response
77

8-
from sentry import analytics, features
8+
from sentry import analytics
99
from sentry.api.api_owners import ApiOwner
1010
from sentry.api.api_publish_status import ApiPublishStatus
1111
from sentry.api.base import region_silo_endpoint
@@ -16,6 +16,7 @@
1616
transform_preprod_artifact_to_build_details,
1717
)
1818
from sentry.preprod.models import PreprodArtifact
19+
from sentry.preprod.permissions import has_preprod_access
1920

2021
logger = logging.getLogger(__name__)
2122

@@ -57,9 +58,7 @@ def get(
5758
)
5859
)
5960

60-
if not features.has(
61-
"organizations:preprod-frontend-routes", project.organization, actor=request.user
62-
):
61+
if not has_preprod_access(project.organization, request.user):
6362
return Response({"error": "Feature not enabled"}, status=403)
6463

6564
if head_artifact.state == PreprodArtifact.ArtifactState.FAILED:

src/sentry/preprod/api/endpoints/project_preprod_list_builds.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from rest_framework.request import Request
88
from rest_framework.response import Response
99

10-
from sentry import analytics, features
10+
from sentry import analytics
1111
from sentry.api.api_owners import ApiOwner
1212
from sentry.api.api_publish_status import ApiPublishStatus
1313
from sentry.api.base import region_silo_endpoint
@@ -20,6 +20,7 @@
2020
)
2121
from sentry.preprod.api.validators import PreprodListBuildsValidator
2222
from sentry.preprod.models import PreprodArtifact
23+
from sentry.preprod.permissions import has_preprod_access
2324
from sentry.preprod.utils import parse_release_version
2425

2526
logger = logging.getLogger(__name__)
@@ -63,9 +64,7 @@ def get(self, request: Request, project: Project) -> Response:
6364
)
6465
)
6566

66-
if not features.has(
67-
"organizations:preprod-frontend-routes", project.organization, actor=request.user
68-
):
67+
if not has_preprod_access(project.organization, request.user):
6968
return Response({"error": "Feature not enabled"}, status=403)
7069

7170
validator = PreprodListBuildsValidator(data=request.GET)

src/sentry/preprod/api/endpoints/size_analysis/project_preprod_size_analysis_compare.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from rest_framework.request import Request
88
from rest_framework.response import Response
99

10-
from sentry import analytics, features
10+
from sentry import analytics
1111
from sentry.api.api_owners import ApiOwner
1212
from sentry.api.api_publish_status import ApiPublishStatus
1313
from sentry.api.base import region_silo_endpoint
@@ -33,6 +33,7 @@
3333
PreprodArtifactSizeComparison,
3434
PreprodArtifactSizeMetrics,
3535
)
36+
from sentry.preprod.permissions import has_preprod_access
3637
from sentry.preprod.size_analysis.tasks import manual_size_analysis_comparison
3738
from sentry.preprod.size_analysis.utils import build_size_metrics_map, can_compare_size_metrics
3839

@@ -82,9 +83,7 @@ def get(
8283
)
8384
)
8485

85-
if not features.has(
86-
"organizations:preprod-frontend-routes", project.organization, actor=request.user
87-
):
86+
if not has_preprod_access(project.organization, request.user):
8887
return Response({"error": "Feature not enabled"}, status=403)
8988

9089
logger.info(
@@ -268,9 +267,7 @@ def post(
268267
)
269268
)
270269

271-
if not features.has(
272-
"organizations:preprod-frontend-routes", project.organization, actor=request.user
273-
):
270+
if not has_preprod_access(project.organization, request.user):
274271
return Response({"error": "Feature not enabled"}, status=403)
275272

276273
logger.info(

src/sentry/preprod/api/endpoints/size_analysis/project_preprod_size_analysis_compare_download.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from rest_framework.request import Request
77
from rest_framework.response import Response
88

9-
from sentry import analytics, features
9+
from sentry import analytics
1010
from sentry.api.api_owners import ApiOwner
1111
from sentry.api.api_publish_status import ApiPublishStatus
1212
from sentry.api.base import region_silo_endpoint
@@ -15,6 +15,7 @@
1515
from sentry.models.project import Project
1616
from sentry.preprod.analytics import PreprodArtifactApiSizeAnalysisCompareDownloadEvent
1717
from sentry.preprod.models import PreprodArtifactSizeComparison
18+
from sentry.preprod.permissions import has_preprod_access
1819

1920
logger = logging.getLogger(__name__)
2021

@@ -54,9 +55,7 @@ def get(
5455
)
5556
)
5657

57-
if not features.has(
58-
"organizations:preprod-frontend-routes", project.organization, actor=request.user
59-
):
58+
if not has_preprod_access(project.organization, request.user):
6059
return Response({"error": "Feature not enabled"}, status=403)
6160

6261
logger.info(

src/sentry/preprod/api/endpoints/size_analysis/project_preprod_size_analysis_download.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
from rest_framework.request import Request
88
from rest_framework.response import Response
99

10-
from sentry import analytics, features
10+
from sentry import analytics
1111
from sentry.api.api_owners import ApiOwner
1212
from sentry.api.api_publish_status import ApiPublishStatus
1313
from sentry.api.base import region_silo_endpoint
1414
from sentry.models.project import Project
1515
from sentry.preprod.analytics import PreprodArtifactApiSizeAnalysisDownloadEvent
1616
from sentry.preprod.api.bases.preprod_artifact_endpoint import PreprodArtifactEndpoint
1717
from sentry.preprod.models import PreprodArtifact, PreprodArtifactSizeMetrics
18+
from sentry.preprod.permissions import has_preprod_access
1819
from sentry.preprod.size_analysis.download import (
1920
SizeAnalysisError,
2021
get_size_analysis_error_response,
@@ -61,9 +62,7 @@ def get(
6162
)
6263
)
6364

64-
if not settings.IS_DEV and not features.has(
65-
"organizations:preprod-frontend-routes", project.organization, actor=request.user
66-
):
65+
if not settings.IS_DEV and not has_preprod_access(project.organization, request.user):
6766
return Response({"error": "Feature not enabled"}, status=403)
6867

6968
try:

src/sentry/preprod/permissions.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
Permission helpers for preprod features.
3+
"""
4+
5+
from __future__ import annotations
6+
7+
from typing import TYPE_CHECKING
8+
9+
from sentry import features
10+
11+
if TYPE_CHECKING:
12+
from sentry.models.organization import Organization
13+
from sentry.users.models.user import RpcUser, User
14+
15+
16+
def has_preprod_access(organization: Organization, user: User | RpcUser | None = None) -> bool:
17+
if organization.flags.early_adopter:
18+
return True
19+
return features.has("organizations:preprod-frontend-routes", organization, actor=user)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import useOrganization from 'sentry/utils/useOrganization';
2+
3+
export function usePreprodAccess(): boolean {
4+
const organization = useOrganization({allowNull: true});
5+
if (!organization) {
6+
return false;
7+
}
8+
return (
9+
organization.isEarlyAdopter ||
10+
organization.features?.includes('preprod-frontend-routes')
11+
);
12+
}

static/app/views/preprod/index.tsx

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
11
import {Outlet} from 'react-router-dom';
22

3-
import Feature from 'sentry/components/acl/feature';
43
import {Alert} from 'sentry/components/core/alert';
54
import * as Layout from 'sentry/components/layouts/thirds';
65
import NoProjectMessage from 'sentry/components/noProjectMessage';
76
import {t} from 'sentry/locale';
87
import useOrganization from 'sentry/utils/useOrganization';
8+
import {usePreprodAccess} from 'sentry/utils/usePreprodAccess';
99

1010
function PreprodContainer() {
1111
const organization = useOrganization();
12+
const hasPreprodAccess = usePreprodAccess();
13+
14+
if (!hasPreprodAccess) {
15+
return (
16+
<Layout.Page withPadding>
17+
<Alert.Container>
18+
<Alert type="warning" showIcon={false}>
19+
{t("You don't have access to this feature")}
20+
</Alert>
21+
</Alert.Container>
22+
</Layout.Page>
23+
);
24+
}
1225

1326
return (
14-
<Feature
15-
features={['organizations:preprod-frontend-routes']}
16-
organization={organization}
17-
renderDisabled={() => (
18-
<Layout.Page withPadding>
19-
<Alert.Container>
20-
<Alert type="warning" showIcon={false}>
21-
{t("You don't have access to this feature")}
22-
</Alert>
23-
</Alert.Container>
24-
</Layout.Page>
25-
)}
26-
>
27-
<NoProjectMessage organization={organization}>
28-
<Outlet />
29-
</NoProjectMessage>
30-
</Feature>
27+
<NoProjectMessage organization={organization}>
28+
<Outlet />
29+
</NoProjectMessage>
3130
);
3231
}
3332

0 commit comments

Comments
 (0)