diff --git a/src/olympia/files/tests/test_views.py b/src/olympia/files/tests/test_views.py index 78d75a96c3..d54d091ace 100644 --- a/src/olympia/files/tests/test_views.py +++ b/src/olympia/files/tests/test_views.py @@ -121,6 +121,16 @@ class TestFileUploadViewSet(TestCase): ) return response + def test_submissions_disabled(self): + self.create_flag('enable-submissions', note=':-(', everyone=False) + expected = { + 'error': 'Add-on uploads are temporarily unavailable.', + 'reason': ':-(', + } + response = self._create_post() + assert response.status_code == 503 + assert response.json() == expected + def test_not_authenticated(self): self.client.logout_api() response = self.client.get( diff --git a/src/olympia/files/views.py b/src/olympia/files/views.py index 4c17fc51bf..379c0bcef5 100644 --- a/src/olympia/files/views.py +++ b/src/olympia/files/views.py @@ -10,6 +10,7 @@ from rest_framework.viewsets import ReadOnlyModelViewSet import olympia.core.logger from olympia import amo +from olympia.addons.decorators import require_submissions_enabled from olympia.amo.decorators import use_primary_db from olympia.amo.utils import HttpResponseXSendFile from olympia.api.authentication import ( @@ -72,6 +73,7 @@ class FileUploadViewSet(CreateModelMixin, ReadOnlyModelViewSet): def get_queryset(self): return super().get_queryset().filter(user=self.request.user) + @require_submissions_enabled def create(self, request): if 'upload' in request.FILES: filedata = request.FILES['upload']