Skip to content

Commit

Permalink
deposit: record login required on deposit edit
Browse files Browse the repository at this point in the history
  • Loading branch information
anikachurilova authored and kpsherva committed May 31, 2024
1 parent df7fd15 commit b6c8326
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
24 changes: 23 additions & 1 deletion invenio_app_rdm/records_ui/views/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

from functools import wraps

from flask import g, make_response, redirect, request, url_for
from flask import g, make_response, redirect, request, session, url_for
from flask_login import login_required
from invenio_communities.communities.resources.serializer import (
UICommunityJSONSerializer,
)
Expand Down Expand Up @@ -381,3 +382,24 @@ def view(*args, **kwargs):
return response

return view


def secret_link_or_login_required():
"""Skip login redirection check for requests with secret links.
If access has been granted via a secret link, then permissions are checked
in the dedicated view.
"""

def decorator(f):
@wraps(f)
def view(**kwargs):
secret_link_token_arg = "token"
session_token = session.get(secret_link_token_arg, None)
if session_token is None:
login_required(f)
return f(**kwargs)

return view

return decorator
9 changes: 7 additions & 2 deletions invenio_app_rdm/records_ui/views/deposits.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@
from sqlalchemy.orm import load_only

from ..utils import set_default_value
from .decorators import pass_draft, pass_draft_community, pass_draft_files
from .decorators import (
pass_draft,
pass_draft_community,
pass_draft_files,
secret_link_or_login_required,
)
from .filters import get_scheme_label


Expand Down Expand Up @@ -409,7 +414,7 @@ def deposit_create(community=None):
)


@login_required
@secret_link_or_login_required()
@pass_draft(expand=True)
@pass_draft_files
def deposit_edit(pid_value, draft=None, draft_files=None, files_locked=True):
Expand Down

0 comments on commit b6c8326

Please sign in to comment.