Skip to content

Commit

Permalink
Fix upload setting in prod env
Browse files Browse the repository at this point in the history
- Upload site setting did not apply, because the url.py did not reload in prod env
- Now check in API call
  • Loading branch information
derneuere committed Aug 18, 2023
1 parent 947c36e commit 2d4668d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
5 changes: 5 additions & 0 deletions api/views/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from chunked_upload.exceptions import ChunkedUploadError
from chunked_upload.models import ChunkedUpload
from chunked_upload.views import ChunkedUploadCompleteView, ChunkedUploadView
from constance import config as site_config
from django.core.files.base import ContentFile
from django.http import HttpResponseForbidden
from django.shortcuts import get_object_or_404
Expand Down Expand Up @@ -36,6 +37,8 @@ class UploadPhotosChunked(ChunkedUploadView):
model = ChunkedUpload

def check_permissions(self, request):
if not site_config.ALLOW_UPLOAD:
return HttpResponseForbidden()
jwt = request.COOKIES.get("jwt")
if jwt is not None:
try:
Expand Down Expand Up @@ -69,6 +72,8 @@ class UploadPhotosChunkedComplete(ChunkedUploadCompleteView):
model = ChunkedUpload

def check_permissions(self, request):
if not site_config.ALLOW_UPLOAD:
return HttpResponseForbidden()
jwt = request.COOKIES.get("jwt")
if jwt is not None:
try:
Expand Down
10 changes: 2 additions & 8 deletions ownphotos/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
2. Add a URL to urlpatterns: re_path(r'^blog/', include('blog.urls'))
"""

from constance import config as site_config
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
Expand Down Expand Up @@ -216,16 +215,11 @@ def post(self, request, *args, **kwargs):
re_path(r"^api/nextcloud/scanphotos", nextcloud_views.ScanPhotosView.as_view()),
re_path(r"^api/photos/download", views.ZipListPhotosView.as_view()),
re_path(r"^api/timezones", timezone.TimeZoneView.as_view()),
re_path(r"api/upload/complete/", upload.UploadPhotosChunkedComplete.as_view()),
re_path(r"api/upload/", upload.UploadPhotosChunked.as_view()),
]
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

if site_config.ALLOW_UPLOAD:
urlpatterns += [
re_path(r"api/upload/complete/", upload.UploadPhotosChunkedComplete.as_view())
]
urlpatterns += [re_path(r"api/upload/", upload.UploadPhotosChunked.as_view())]


if settings.DEBUG:
from drf_spectacular.views import (
SpectacularAPIView,
Expand Down

0 comments on commit 2d4668d

Please sign in to comment.