Skip to content

Commit

Permalink
Fix for MIME type ordering in renderers.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmichaels-harvard committed Jul 27, 2023
1 parent 1141e0f commit 4bad7c5
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 40 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ snovault
Change Log
----------

9.1.0
=====
* Fix for MIME type ordering in renderers.py (differs between cgap and fourfront).


9.0.0
=====
* Merge/unify ingestion and other code from cgap-portal and fourfront.
Expand Down
48 changes: 16 additions & 32 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dcicsnovault"
version = "9.0.0"
version = "9.0.0.1b1" # TODO: To become 9.1.0
description = "Storage support for 4DN Data Portals."
authors = ["4DN-DCIC Team <[email protected]>"]
license = "MIT"
Expand Down Expand Up @@ -123,7 +123,7 @@ pytest-timeout = ">=1.0.0"
# 5.2 had soe bugs that were probably only in Python 2, but we require 5.2 here just in case.
# Any narrowing beyond that is just to help 'poetry lock' converge faster.
# And we only need .safe_load in testing, so we're moving this to dev dependencies. -kmp 22-Feb-2022
PyYAML = ">=5.1,<5.5"
PyYAML = "5.3.1"
"repoze.debug" = ">=1.0.2"
wheel = ">=0.40.0"

Expand Down
2 changes: 1 addition & 1 deletion scripts/macpoetry-install
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# For some reason on Mac M1 (as of July 2023) pyyaml install via poetry is problematic.
pip install pyyaml==5.4.1
pip install pyyaml==5.3.1

CFLAGS="-I$(brew --prefix zlib)/include" LDFLAGS="-L$(brew --prefix zlib)/lib" poetry install
5 changes: 5 additions & 0 deletions snovault/mime_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Web browsers send an Accept request header for initial (e.g. non-AJAX) page requests
# which should contain 'text/html'
MIME_TYPE_HTML = 'text/html'
MIME_TYPE_JSON = 'application/json'
MIME_TYPE_LD_JSON = 'application/ld+json'
9 changes: 9 additions & 0 deletions snovault/project/renderers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Renderers related functions which may be overriden by an implementing app,
# e.g. Foursight or CGAP portal, using the dcicutils project_utils mechanism.

from ..mime_types import MIME_TYPE_HTML, MIME_TYPE_JSON, MIME_TYPE_LD_JSON


class SnovaultProjectRenderers:
def renderers_mime_types_supported(self):
return [MIME_TYPE_JSON, MIME_TYPE_HTML, MIME_TYPE_LD_JSON]
2 changes: 2 additions & 0 deletions snovault/project_defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from .project.authorization import SnovaultProjectAuthorization
from .project.ingestion import SnovaultProjectIngestion
from .project.loadxl import SnovaultProjectLoadxl
from .project.renderers import SnovaultProjectRenderers


@C4ProjectRegistry.register("dcicsnovault")
Expand All @@ -12,6 +13,7 @@ class SnovaultProject(SnovaultProjectAccessKey,
SnovaultProjectAuthorization,
SnovaultProjectIngestion,
SnovaultProjectLoadxl,
SnovaultProjectRenderers,
C4Project):
NAMES = {"NAME": "snovault", "PYPI_NAME": "dcicsnovault"}
ACCESSION_PREFIX = "SNO"
7 changes: 2 additions & 5 deletions snovault/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from subprocess_middleware.worker import TransformWorker
from urllib.parse import urlencode
from webob.cookies import Cookie
from .mime_types import MIME_TYPE_HTML, MIME_TYPE_JSON, MIME_TYPE_LD_JSON
from .project_app import app_project
from .util import content_type_allowed

Expand Down Expand Up @@ -314,13 +315,9 @@ def canonical_redirect(event):

# Web browsers send an Accept request header for initial (e.g. non-AJAX) page requests
# which should contain 'text/html'
MIME_TYPE_HTML = 'text/html'
MIME_TYPE_JSON = 'application/json'
MIME_TYPE_LD_JSON = 'application/ld+json'

# Note: In cgap-portal, MIME_TYPE_JSON is at the head of this list. In fourfront, MIME_TYPE_HTML is.
# The cgap-portal behavior might be a bug we should look at bringing into alignment. -kmp 29-Jan-2022
MIME_TYPES_SUPPORTED = [MIME_TYPE_JSON, MIME_TYPE_HTML, MIME_TYPE_LD_JSON]
MIME_TYPES_SUPPORTED = app_project().renderers_mime_types_supported()
MIME_TYPE_DEFAULT = MIME_TYPES_SUPPORTED[0]
MIME_TYPE_TRIAGE_MODE = 'modern' # if this doesn't work, fall back to 'legacy'

Expand Down

0 comments on commit 4bad7c5

Please sign in to comment.