Browse Source

Hide cloud upload button if feature not enabled

pull/213/head
Clemens Wolff 5 years ago
parent
commit
4f21eb6cdd
5 changed files with 39 additions and 4 deletions
  1. 9
      app/server/api.py
  2. 3
      app/server/api_urls.py
  3. 11
      app/server/static/components/mixin.js
  4. 2
      app/server/static/components/upload.pug
  5. 18
      app/server/tests/test_api.py

9
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

3
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/<int:project_id>', ProjectDetail.as_view(), name='project_detail'),

11
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)}`;
},
},

2
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}"

18
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):

Loading…
Cancel
Save