From 33d1d77bf0dde39efe8ac8b80d97d89b4627e227 Mon Sep 17 00:00:00 2001 From: getsentry-bot Date: Thu, 26 Sep 2024 17:51:10 +0000 Subject: [PATCH] Revert "ref(uptime): Drop usage of uptime-api-create-update in be (#78149)" This reverts commit b09c5412dcaef1b4d2120d1b603381f87c8c5212. Co-authored-by: wedamija <6288560+wedamija@users.noreply.github.com> --- .../endpoints/project_uptime_alert_index.py | 5 +++++ .../test_project_uptime_alert_index.py | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/sentry/uptime/endpoints/project_uptime_alert_index.py b/src/sentry/uptime/endpoints/project_uptime_alert_index.py index 978a8822fbb1b5..21b0cd465a5388 100644 --- a/src/sentry/uptime/endpoints/project_uptime_alert_index.py +++ b/src/sentry/uptime/endpoints/project_uptime_alert_index.py @@ -2,6 +2,7 @@ from rest_framework.request import Request from rest_framework.response import Response +from sentry import features from sentry.api.api_owners import ApiOwner from sentry.api.api_publish_status import ApiPublishStatus from sentry.api.base import region_silo_endpoint @@ -45,6 +46,10 @@ def post(self, request: Request, project: Project) -> Response: """ Create a new monitor. """ + if not features.has( + "organizations:uptime-api-create-update", project.organization, actor=request.user + ): + return Response(status=404) validator = UptimeMonitorValidator( data=request.data, context={ diff --git a/tests/sentry/uptime/endpoints/test_project_uptime_alert_index.py b/tests/sentry/uptime/endpoints/test_project_uptime_alert_index.py index d8304c550ba21c..ddb372b6512c21 100644 --- a/tests/sentry/uptime/endpoints/test_project_uptime_alert_index.py +++ b/tests/sentry/uptime/endpoints/test_project_uptime_alert_index.py @@ -2,6 +2,7 @@ from rest_framework.exceptions import ErrorDetail +from sentry.testutils.helpers import with_feature from sentry.uptime.endpoints.validators import MAX_REQUEST_SIZE_BYTES from sentry.uptime.models import ProjectUptimeSubscription, ProjectUptimeSubscriptionMode from sentry.uptime.subscriptions.subscriptions import DEFAULT_SUBSCRIPTION_TIMEOUT_MS @@ -15,6 +16,18 @@ class ProjectUptimeAlertIndexBaseEndpointTest(UptimeAlertBaseEndpointTest): class ProjectUptimeAlertIndexPostEndpointTest(ProjectUptimeAlertIndexBaseEndpointTest): method = "post" + def test_no_feature(self): + self.get_error_response( + self.organization.slug, + self.project.slug, + name="test", + owner=f"user:{self.user.id}", + url="http://sentry.io", + interval_seconds=60, + status_code=404, + ) + + @with_feature("organizations:uptime-api-create-update") def test(self): resp = self.get_success_response( self.organization.slug, @@ -36,6 +49,7 @@ def test(self): assert uptime_subscription.timeout_ms == DEFAULT_SUBSCRIPTION_TIMEOUT_MS assert uptime_subscription.body is None + @with_feature("organizations:uptime-api-create-update") def test_no_owner(self): resp = self.get_success_response( self.organization.slug, @@ -55,6 +69,7 @@ def test_no_owner(self): assert uptime_subscription.interval_seconds == 60 assert uptime_subscription.timeout_ms == DEFAULT_SUBSCRIPTION_TIMEOUT_MS + @with_feature("organizations:uptime-api-create-update") def test_mode_no_superadmin(self): resp = self.get_error_response( self.organization.slug, @@ -70,6 +85,7 @@ def test_mode_no_superadmin(self): "mode": [ErrorDetail(string="Only superusers can modify `mode`", code="invalid")] } + @with_feature("organizations:uptime-api-create-update") def test_mode_superadmin(self): self.login_as(self.user, superuser=True) resp = self.get_success_response( @@ -91,6 +107,7 @@ def test_mode_superadmin(self): assert uptime_subscription.interval_seconds == 60 assert uptime_subscription.timeout_ms == DEFAULT_SUBSCRIPTION_TIMEOUT_MS + @with_feature("organizations:uptime-api-create-update") def test_headers_body_method(self): resp = self.get_success_response( self.organization.slug, @@ -115,6 +132,7 @@ def test_headers_body_method(self): assert uptime_subscription.body == '{"key": "value"}' assert uptime_subscription.headers == [["header", "value"]] + @with_feature("organizations:uptime-api-create-update") def test_headers_body_method_already_exists(self): resp = self.get_success_response( self.organization.slug, @@ -159,6 +177,7 @@ def test_headers_body_method_already_exists(self): newer_uptime_monitor.uptime_subscription_id != new_uptime_monitor.uptime_subscription_id ) + @with_feature("organizations:uptime-api-create-update") def test_headers_invalid_format(self): resp = self.get_error_response( self.organization.slug, @@ -176,6 +195,7 @@ def test_headers_invalid_format(self): "headers": [ErrorDetail(string="Expected array of header tuples.", code="invalid")] } + @with_feature("organizations:uptime-api-create-update") def test_size_too_big(self): resp = self.get_error_response( self.organization.slug, @@ -197,6 +217,7 @@ def test_size_too_big(self): ] } + @with_feature("organizations:uptime-api-create-update") def test_over_limit(self): with mock.patch( "sentry.uptime.subscriptions.subscriptions.MAX_MANUAL_SUBSCRIPTIONS_PER_ORG", new=1