diff --git a/app/server/api.py b/app/server/api.py index 564dc9bd..52fd7eff 100644 --- a/app/server/api.py +++ b/app/server/api.py @@ -32,6 +32,15 @@ class Me(APIView): return Response(serializer.data) +class Features(APIView): + permission_classes = (IsAuthenticated,) + + def get(self, request, *args, **kwargs): + return Response({ + 'cloud_upload': bool(settings.CLOUD_BROWSER_APACHE_LIBCLOUD_PROVIDER), + }) + + class ProjectList(generics.ListCreateAPIView): queryset = Project.objects.all() serializer_class = ProjectPolymorphicSerializer diff --git a/app/server/api_urls.py b/app/server/api_urls.py index 108027fa..ffeeb0c8 100644 --- a/app/server/api_urls.py +++ b/app/server/api_urls.py @@ -1,7 +1,7 @@ from django.urls import path from rest_framework.urlpatterns import format_suffix_patterns -from .api import Me +from .api import Me, Features from .api import ProjectList, ProjectDetail from .api import LabelList, LabelDetail from .api import DocumentList, DocumentDetail @@ -12,6 +12,7 @@ from .api import StatisticsAPI urlpatterns = [ path('me', Me.as_view(), name='me'), + path('features', Features.as_view(), name='features'), path('cloud-upload', CloudUploadAPI.as_view(), name='cloud_uploader'), path('projects', ProjectList.as_view(), name='project_list'), path('projects/', ProjectDetail.as_view(), name='project_detail'), diff --git a/app/server/static/components/mixin.js b/app/server/static/components/mixin.js index a64b1251..1a67a24a 100644 --- a/app/server/static/components/mixin.js +++ b/app/server/static/components/mixin.js @@ -2,7 +2,7 @@ import * as marked from 'marked'; import hljs from 'highlight.js'; import VueJsonPretty from 'vue-json-pretty'; import isEmpty from 'lodash.isempty'; -import HTTP from './http'; +import HTTP, { newHttpClient } from './http'; import Messages from './messages.vue'; const getOffsetFromUrl = (url) => { @@ -227,12 +227,19 @@ export const uploadMixin = { messages: [], format: 'json', isLoading: false, + canUploadFromCloud: false, }), mounted() { hljs.initHighlighting(); }, + created() { + newHttpClient().get('/v1/features').then((response) => { + this.canUploadFromCloud = response.data.cloud_upload; + }); + }, + computed: { projectId() { return window.location.pathname.split('/')[2]; @@ -246,7 +253,7 @@ export const uploadMixin = { return '/cloud-storage' + `?project_id=${this.projectId}` + `&upload_format=${this.format}` - + `&next=${encodeURIComponent(this.postUploadUrl)}` + + `&next=${encodeURIComponent(this.postUploadUrl)}`; }, }, diff --git a/app/server/static/components/upload.pug b/app/server/static/components/upload.pug index 3b082e8f..c9734fc0 100644 --- a/app/server/static/components/upload.pug +++ b/app/server/static/components/upload.pug @@ -42,7 +42,7 @@ div.columns(v-cloak="") span.file-label Select a fileā€¦ span.file-name {{ file.name }} - div.control + div.control(v-if="canUploadFromCloud") a.button( v-bind:href="cloudUploadUrl" v-bind:class="{'is-loading': isLoading}" diff --git a/app/server/tests/test_api.py b/app/server/tests/test_api.py index 428c6faa..6d898edb 100644 --- a/app/server/tests/test_api.py +++ b/app/server/tests/test_api.py @@ -847,6 +847,24 @@ class TestCloudUploader(TestUploader): expected_status=status.HTTP_302_FOUND) +class TestFeatures(APITestCase): + @classmethod + def setUpTestData(cls): + cls.user_name = 'user_name' + cls.user_pass = 'user_pass' + + cls.user = User.objects.create_user(username=cls.user_name, password=cls.user_pass, email='fizz@buzz.com') + + def setUp(self): + self.client.login(username=self.user_name, password=self.user_pass) + + @override_settings(CLOUD_BROWSER_APACHE_LIBCLOUD_PROVIDER=None) + def test_no_cloud_upload(self): + response = self.client.get(reverse('features')) + + self.assertFalse(response.json().get('cloud_upload')) + + class TestParser(APITestCase): def parser_helper(self, filename, parser, include_label=True):