Skip to content

Commit

Permalink
Merge pull request #90 from ImperialCollegeLondon/feature/depositing_…
Browse files Browse the repository at this point in the history
…user_as_creator

Add logged in user as default creator in submission form
  • Loading branch information
cc-a authored Dec 9, 2024
2 parents 0ee39c6 + 0971f69 commit 0dcece3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ exclude = "test_data/.*\\.py"

[[tool.mypy.overrides]]
module = [
"flask_login.*",
"flask_oauthlib.*",
"invenio_app.*",
"invenio_assets.*",
Expand Down
2 changes: 2 additions & 0 deletions site/ic_data_repo/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from invenio_oauthclient.views.client import auto_redirect_login

from .custom_fields import * # noqa: F401,F403
from .utils import get_user_form_default

# Flask
# =====
Expand Down Expand Up @@ -113,6 +114,7 @@
}
],
"publisher": "Imperial College London",
"creators": lambda: get_user_form_default(),
}

# See:
Expand Down
38 changes: 38 additions & 0 deletions site/ic_data_repo/config/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Utilities for settings."""

from typing import Any, List

from flask_login import current_user


def get_user_form_default() -> List[dict[str, Any]]:
"""Format the current user profile for the submission form.
The default user profile schema has two string properties;
full name and affiliations. More details (identifiers?) would
have to come from the SSO.
https://github.com/inveniosoftware/invenio-accounts/blob/master/invenio_accounts/profiles/schemas.py
"""
affiliations = []

try:
name = current_user.user_profile["full_name"]
given_name = name.split(", ")[1]
family_name = name.split(", ")[0]
except KeyError:
return []

if "affiliations" in current_user.user_profile:
affiliations.append({"name": current_user.user_profile["affiliations"]})

return [
{
"person_or_org": {
"type": "personal",
"name": name,
"given_name": given_name,
"family_name": family_name,
},
"affiliations": affiliations,
},
]

0 comments on commit 0dcece3

Please sign in to comment.