-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from ImperialCollegeLondon/feature/depositing_…
…user_as_creator Add logged in user as default creator in submission form
- Loading branch information
Showing
3 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
] |