Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deposit: force no caching in the response headers
Browse files Browse the repository at this point in the history
Co-authored-by: jrcastro2 <[email protected]>

closes CERNDocumentServer/cds-rdm#302
zzacharo committed Jan 21, 2025
1 parent 13967bd commit b32d974
Showing 2 changed files with 25 additions and 3 deletions.
21 changes: 21 additions & 0 deletions invenio_app_rdm/records_ui/views/decorators.py
Original file line number Diff line number Diff line change
@@ -403,3 +403,24 @@ def view(**kwargs):
return view

return decorator


def no_cache_response(f):
"""Add appropriate response headers to force no caching.
This decorator is used to prevent caching of the response in the browser. This is needed
in the deposit form as we initialize the form with the record metadata included in the html page
and we don't want the browser to cache this page so that the user always gets the latest version of the record.
"""

@wraps(f)
def view(*args, **kwargs):
response = make_response(f(*args, **kwargs))

response.cache_control.no_cache = True
response.cache_control.no_store = True
response.cache_control.must_revalidate = True

return response

return view
7 changes: 4 additions & 3 deletions invenio_app_rdm/records_ui/views/deposits.py
Original file line number Diff line number Diff line change
@@ -23,9 +23,7 @@
from invenio_rdm_records.proxies import current_rdm_records
from invenio_rdm_records.records.api import get_files_quota
from invenio_rdm_records.resources.serializers import UIJSONSerializer
from invenio_rdm_records.services.components.pids import (
_get_optional_doi_transitions,
)
from invenio_rdm_records.services.components.pids import _get_optional_doi_transitions
from invenio_rdm_records.services.schemas import RDMRecordSchema
from invenio_rdm_records.services.schemas.utils import dump_empty
from invenio_records_resources.services.errors import PermissionDeniedError
@@ -37,6 +35,7 @@

from ..utils import set_default_value
from .decorators import (
no_cache_response,
pass_draft,
pass_draft_community,
pass_draft_files,
@@ -424,6 +423,7 @@ def new_record():
# Views
#
@login_required
@no_cache_response
@pass_draft_community
def deposit_create(community=None):
"""Create a new deposit."""
@@ -475,6 +475,7 @@ def deposit_create(community=None):
@secret_link_or_login_required()
@pass_draft(expand=True)
@pass_draft_files
@no_cache_response
def deposit_edit(pid_value, draft=None, draft_files=None, files_locked=True):
"""Edit an existing deposit."""
# don't show draft's deposit form if the user can't edit it

0 comments on commit b32d974

Please sign in to comment.