Skip to content

Commit

Permalink
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
  • Loading branch information
zzacharo committed Jan 21, 2025
1 parent 9da9603 commit 02deb31
Show file tree
Hide file tree
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
Expand Up @@ -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
Expand Up @@ -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
Expand All @@ -37,6 +35,7 @@

from ..utils import set_default_value
from .decorators import (
no_cache_response,
pass_draft,
pass_draft_community,
pass_draft_files,
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 02deb31

Please sign in to comment.