Return 404 from mobile app gateway viewset (#3518)

# What this PR does

Changes how the `MOBILE_APP_GATEWAY_ENABLED` feature flag
enables/disables the mobile app gateway viewset.

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)
This commit is contained in:
Vadim Stepanov 2023-12-06 10:57:07 +00:00 committed by GitHub
parent 0f9c20cf0e
commit 147503eea8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 13 deletions

View file

@ -25,9 +25,9 @@ logger = logging.getLogger(__name__)
class LabelsFeatureFlagViewSet(ViewSet):
def initial(self, request, *args, **kwargs):
super().initial(request, *args, **kwargs)
if not is_labels_feature_enabled(self.request.auth.organization):
raise NotFound
super().initial(request, *args, **kwargs)
class LabelsViewSet(LabelsFeatureFlagViewSet):

View file

@ -23,12 +23,10 @@ MOCK_JWT_PRIVATE_KEY = "asd,mzcxn,vmnzxcv,mnzx,cvmnzaslkdjflaksjdf"
@pytest.fixture(autouse=True)
def setup_urls(settings, reload_urls):
def enable_mobile_app_gateway(settings):
settings.MOBILE_APP_GATEWAY_ENABLED = True
settings.MOBILE_APP_GATEWAY_RSA_PRIVATE_KEY = MOCK_JWT_PRIVATE_KEY
reload_urls("apps.mobile_app.urls")
class MockResponse:
def __init__(self, status_code=status.HTTP_200_OK, data=MOCK_DOWNSTREAM_RESPONSE_DATA):

View file

@ -1,4 +1,3 @@
from django.conf import settings
from django.urls import re_path
from apps.mobile_app.fcm_relay import FCMRelayView
@ -34,11 +33,10 @@ urlpatterns += [
optional_slash_path("fcm_relay", FCMRelayView.as_view(), name="fcm_relay"),
]
if settings.MOBILE_APP_GATEWAY_ENABLED:
urlpatterns += [
re_path(
r"^gateway/(?P<downstream_backend>\w*)/(?P<downstream_path>.*)$",
MobileAppGatewayView.as_view(),
name="gateway",
),
]
urlpatterns += [
re_path(
r"^gateway/(?P<downstream_backend>\w*)/(?P<downstream_path>.*)$",
MobileAppGatewayView.as_view(),
name="gateway",
),
]

View file

@ -99,6 +99,12 @@ class MobileAppGatewayView(APIView):
SupportedDownstreamBackends.INCIDENT,
]
def initial(self, request, *args, **kwargs):
# If the mobile app gateway is not enabled, return a 404
if not settings.MOBILE_APP_GATEWAY_ENABLED:
raise NotFound
super().initial(request, *args, **kwargs)
@classmethod
def _construct_jwt_payload(cls, user: "User") -> typing.Dict[str, typing.Any]:
organization = user.organization