Loading src/hls/views.py +28 −1 Changes for src/hls/views.py: 28 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -8,7 +8,27 @@ import os from pathlib import Path def file_passthru(request: HttpRequest, path: str) -> HttpResponseBase: def file_passthru_noauth(request: HttpRequest, path: str) -> HttpResponseBase: try: file_hash = path[6:70] resource_instance = Resource.objects.get( file__hash=file_hash, ) tested_path = os.path.realpath(Path(settings.HLS_DIR, path)) if not tested_path.startswith(settings.HLS_DIR): raise PermissionDenied() if not Path(tested_path).exists(): raise Http404() return RangedFileResponse( request, open(tested_path, "rb"), content_type=resource_instance.file.file_type.mime, ) except Resource.DoesNotExist: raise Http404() def file_passthru_auth(request: HttpRequest, path: str) -> HttpResponseBase: if not request.user.is_anonymous: file_hash = path[6:70] for project_instance in Project.objects.filter( Loading @@ -31,3 +51,10 @@ def file_passthru(request: HttpRequest, path: str) -> HttpResponseBase: content_type=resource_instance.file.file_type.mime, ) raise PermissionDenied() def file_passthru(request: HttpRequest, path: str) -> HttpResponseBase: if settings.HLS_URLS_NEED_AUTH: return file_passthru_auth(request, path) else: return file_passthru_noauth(request, path) src/iiif/views.py +5 −1 Changes for src/iiif/views.py: 5 added lines, 1 removed line. Original line number Diff line number Diff line from django.http import StreamingHttpResponse, HttpResponse, HttpRequest from revproxy.views import ProxyView from django.conf import settings from django.shortcuts import redirect from revproxy.response import get_django_response from typing import Union def get_request_headers(self): Loading Loading @@ -51,7 +53,9 @@ class IIIFProxyView(ProxyView): upstream = settings.JAMA_IIIF_UPSTREAM_URL add_x_forwarded = True def dispatch(self, request, path): def dispatch( self, request: HttpRequest, path ) -> Union[StreamingHttpResponse, HttpResponse]: # print(f"### Upstream in setting: {settings.JAMA_IIIF_UPSTREAM_URL}") # print(f"### Upstream in class: {self.upstream}") # print(request.path) Loading src/jama/settings.py +4 −1 Changes for src/jama/settings.py: 4 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -77,10 +77,13 @@ JAMA_IIIF_UPSCALING_PREFIX = ( IIIF_DIR = os.getenv("JAMA_IIIF_DIR") or str(Path(VAR_DIR, "iiif").resolve()) os.makedirs(IIIF_DIR, exist_ok=True) IIIF_PATH_SEPARATOR = os.getenv("JAMA_IIIF_PATH_SEPARATOR") or os.path.sep IIIF_URLS_NEED_AUTH = ( False if os.getenv("JAMA_IIIF_URLS_NEED_AUTH", "0") == "0" else True ) HLS_DIR = os.getenv("JAMA_HLS_DIR") or str(Path(VAR_DIR, "hls").resolve()) os.makedirs(HLS_DIR, exist_ok=True) HLS_URLS_NEED_AUTH = False if os.getenv("JAMA_HLS_URLS_NEED_AUTH", "0") == "0" else True ARK_SERVER = os.getenv("JAMA_ARK_SERVER", "") ARK_APP_ID = os.getenv("JAMA_ARK_APP_ID", "") Loading src/resources/acl.py +21 −6 Changes for src/resources/acl.py: 21 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -249,21 +249,36 @@ class UserAccess: return self._permissions def can_crud(self, object_or_class, crud_access) -> bool: return has_crud_access(self.permissions, object_or_class, crud_access) return ( has_crud_access(self.permissions, object_or_class, crud_access) and self.user.is_active ) def can_create(self, object_or_class) -> bool: return has_crud_access(self.permissions, object_or_class, CRUD_CREATE) return ( has_crud_access(self.permissions, object_or_class, CRUD_CREATE) and self.user.is_active ) def can_read(self, object_or_class) -> bool: if self.user.is_superuser: # superuser gets a pass if self.user.is_superuser and self.user.is_active: # superuser gets a pass return True return has_crud_access(self.permissions, object_or_class, CRUD_READ) return ( has_crud_access(self.permissions, object_or_class, CRUD_READ) and self.user.is_active ) def can_update(self, object_or_class) -> bool: return has_crud_access(self.permissions, object_or_class, CRUD_UPDATE) return ( has_crud_access(self.permissions, object_or_class, CRUD_UPDATE) and self.user.is_active ) def can_delete(self, object_or_class) -> bool: return has_crud_access(self.permissions, object_or_class, CRUD_DELETE) return ( has_crud_access(self.permissions, object_or_class, CRUD_DELETE) and self.user.is_active ) def check_create(self, object_or_class): """ Loading src/rpc/serializers.py −9 Changes for src/rpc/serializers.py: 0 added lines, 9 removed lines. Original line number Diff line number Diff line Loading @@ -202,15 +202,6 @@ def file( settings.JAMA_IIIF_ENDPOINT, iiif_path, settings.JAMA_IIIF_UPSCALING_PREFIX ) if include_metas: # This will NOT use the prefetched data and will generate a HUGE # number of queries with large sets of resources (see Herbier Corbières): # # for prop in file_instance.metadataresourcevalue_set.filter( # metadata__expose=True # ).order_by("-metadata__set", "metadata__rank", "id"): # props.append(metadata_resource_value(prop, cache=cache)) # # Slightly different result but much less for prop in file_instance.metadataresourcevalue_set.all(): if prop.metadata.expose and prop.metadata.title.lower().strip() not in [ "sourcefile", Loading Loading
src/hls/views.py +28 −1 Changes for src/hls/views.py: 28 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -8,7 +8,27 @@ import os from pathlib import Path def file_passthru(request: HttpRequest, path: str) -> HttpResponseBase: def file_passthru_noauth(request: HttpRequest, path: str) -> HttpResponseBase: try: file_hash = path[6:70] resource_instance = Resource.objects.get( file__hash=file_hash, ) tested_path = os.path.realpath(Path(settings.HLS_DIR, path)) if not tested_path.startswith(settings.HLS_DIR): raise PermissionDenied() if not Path(tested_path).exists(): raise Http404() return RangedFileResponse( request, open(tested_path, "rb"), content_type=resource_instance.file.file_type.mime, ) except Resource.DoesNotExist: raise Http404() def file_passthru_auth(request: HttpRequest, path: str) -> HttpResponseBase: if not request.user.is_anonymous: file_hash = path[6:70] for project_instance in Project.objects.filter( Loading @@ -31,3 +51,10 @@ def file_passthru(request: HttpRequest, path: str) -> HttpResponseBase: content_type=resource_instance.file.file_type.mime, ) raise PermissionDenied() def file_passthru(request: HttpRequest, path: str) -> HttpResponseBase: if settings.HLS_URLS_NEED_AUTH: return file_passthru_auth(request, path) else: return file_passthru_noauth(request, path)
src/iiif/views.py +5 −1 Changes for src/iiif/views.py: 5 added lines, 1 removed line. Original line number Diff line number Diff line from django.http import StreamingHttpResponse, HttpResponse, HttpRequest from revproxy.views import ProxyView from django.conf import settings from django.shortcuts import redirect from revproxy.response import get_django_response from typing import Union def get_request_headers(self): Loading Loading @@ -51,7 +53,9 @@ class IIIFProxyView(ProxyView): upstream = settings.JAMA_IIIF_UPSTREAM_URL add_x_forwarded = True def dispatch(self, request, path): def dispatch( self, request: HttpRequest, path ) -> Union[StreamingHttpResponse, HttpResponse]: # print(f"### Upstream in setting: {settings.JAMA_IIIF_UPSTREAM_URL}") # print(f"### Upstream in class: {self.upstream}") # print(request.path) Loading
src/jama/settings.py +4 −1 Changes for src/jama/settings.py: 4 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -77,10 +77,13 @@ JAMA_IIIF_UPSCALING_PREFIX = ( IIIF_DIR = os.getenv("JAMA_IIIF_DIR") or str(Path(VAR_DIR, "iiif").resolve()) os.makedirs(IIIF_DIR, exist_ok=True) IIIF_PATH_SEPARATOR = os.getenv("JAMA_IIIF_PATH_SEPARATOR") or os.path.sep IIIF_URLS_NEED_AUTH = ( False if os.getenv("JAMA_IIIF_URLS_NEED_AUTH", "0") == "0" else True ) HLS_DIR = os.getenv("JAMA_HLS_DIR") or str(Path(VAR_DIR, "hls").resolve()) os.makedirs(HLS_DIR, exist_ok=True) HLS_URLS_NEED_AUTH = False if os.getenv("JAMA_HLS_URLS_NEED_AUTH", "0") == "0" else True ARK_SERVER = os.getenv("JAMA_ARK_SERVER", "") ARK_APP_ID = os.getenv("JAMA_ARK_APP_ID", "") Loading
src/resources/acl.py +21 −6 Changes for src/resources/acl.py: 21 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -249,21 +249,36 @@ class UserAccess: return self._permissions def can_crud(self, object_or_class, crud_access) -> bool: return has_crud_access(self.permissions, object_or_class, crud_access) return ( has_crud_access(self.permissions, object_or_class, crud_access) and self.user.is_active ) def can_create(self, object_or_class) -> bool: return has_crud_access(self.permissions, object_or_class, CRUD_CREATE) return ( has_crud_access(self.permissions, object_or_class, CRUD_CREATE) and self.user.is_active ) def can_read(self, object_or_class) -> bool: if self.user.is_superuser: # superuser gets a pass if self.user.is_superuser and self.user.is_active: # superuser gets a pass return True return has_crud_access(self.permissions, object_or_class, CRUD_READ) return ( has_crud_access(self.permissions, object_or_class, CRUD_READ) and self.user.is_active ) def can_update(self, object_or_class) -> bool: return has_crud_access(self.permissions, object_or_class, CRUD_UPDATE) return ( has_crud_access(self.permissions, object_or_class, CRUD_UPDATE) and self.user.is_active ) def can_delete(self, object_or_class) -> bool: return has_crud_access(self.permissions, object_or_class, CRUD_DELETE) return ( has_crud_access(self.permissions, object_or_class, CRUD_DELETE) and self.user.is_active ) def check_create(self, object_or_class): """ Loading
src/rpc/serializers.py −9 Changes for src/rpc/serializers.py: 0 added lines, 9 removed lines. Original line number Diff line number Diff line Loading @@ -202,15 +202,6 @@ def file( settings.JAMA_IIIF_ENDPOINT, iiif_path, settings.JAMA_IIIF_UPSCALING_PREFIX ) if include_metas: # This will NOT use the prefetched data and will generate a HUGE # number of queries with large sets of resources (see Herbier Corbières): # # for prop in file_instance.metadataresourcevalue_set.filter( # metadata__expose=True # ).order_by("-metadata__set", "metadata__rank", "id"): # props.append(metadata_resource_value(prop, cache=cache)) # # Slightly different result but much less for prop in file_instance.metadataresourcevalue_set.all(): if prop.metadata.expose and prop.metadata.title.lower().strip() not in [ "sourcefile", Loading