+
+
+ {{ form.orcid.label }}
+
+
+ {% for error in form.orcid.errors %}
+
+
+ {{ error|escape }}
+
+ {% endfor %}
+ {% if form.orcid.value %}
+
+
+
+ {{ form.instance.get_orcid_url }}
+
+
+ {% if form.instance.is_orcid_token_valid %}
+ {% if form.instance == request.user or request.user.is_admin %}
+
+
+ Remove
+
+
+ {% endif %}
+ {% else %}
+
ORCID iD could not be validated.
+ {% endif %}
+ {% endif %}
+ {% if not form.orcid.value or not form.instance.is_orcid_token_valid %}
+ {% if form.instance == request.user %}
+
+ Connect your ORCID iD
+
+ {% else %}
+ {% if form.instance.date_orcid_requested %}
+
Request sent: {{ form.instance.date_orcid_requested|date:"m/d/Y" }}
+ {% endif %}
+
+ Request ORCID iD
+
+ {% endif %}
+ {% endif %}
+ {% if field.help_text %}
+
{{ field.help_text|safe }}
+ {% endif %}
+
diff --git a/src/templates/admin/elements/accounts/user_form.html b/src/templates/admin/elements/accounts/user_form.html
index a0fdfdb389..42774ed9f9 100644
--- a/src/templates/admin/elements/accounts/user_form.html
+++ b/src/templates/admin/elements/accounts/user_form.html
@@ -14,11 +14,18 @@
{% include "admin/elements/forms/field.html" with field=form.twitter %}
{% include "admin/elements/forms/field.html" with field=form.facebook %}
- {% include "admin/elements/forms/field.html" with field=form.orcid %}
{% include "admin/elements/forms/field.html" with field=form.github %}
{% include "admin/elements/forms/field.html" with field=form.linkedin %}
{% include "admin/elements/forms/field.html" with field=form.website %}
+ {% if not settings.ENABLE_ORCID %}
+ {% include "admin/elements/forms/field.html" with field=form.orcid %}
+ {% endif %}
+{% if settings.ENABLE_ORCID %}
+
+ {% include 'admin/elements/accounts/orcid_field.html' with form=form %}
+
+{% endif %}
diff --git a/src/templates/admin/elements/repository/orcid.html b/src/templates/admin/elements/repository/orcid.html
new file mode 100644
index 0000000000..05d736d743
--- /dev/null
+++ b/src/templates/admin/elements/repository/orcid.html
@@ -0,0 +1,10 @@
+{% if author.account.orcid %}
+ {{ author.account.orcid }}
+{% else %}
+ {% if author.account.date_orcid_requested %}
+
Request sent: {{ author.account.date_orcid_requested|date:"m/d/Y" }}
+ {% endif %}
+
+ Request
+
+{% endif %}
diff --git a/src/templates/admin/repository/article.html b/src/templates/admin/repository/article.html
index ce851b814b..49d892fb04 100644
--- a/src/templates/admin/repository/article.html
+++ b/src/templates/admin/repository/article.html
@@ -227,6 +227,7 @@
Authors
{% trans 'Name' %}
{% trans 'Email' %}
+ {% trans 'ORCID' %}
{% trans 'Affiliation' %}
{% trans 'Edit' %}
{% trans 'Delete' %}
@@ -237,6 +238,9 @@ Authors
{{ author.account.full_name }}
{{ author.account.email }}
+
+ {% include "admin/elements/repository/orcid.html" %}
+
{% if author.affiliation %}{{ author.affiliation }}{% else %}
{{ author.account.institution }}{% endif %}
diff --git a/src/templates/admin/repository/submit/authors.html b/src/templates/admin/repository/submit/authors.html
index 6d256c22d9..3465816ce0 100644
--- a/src/templates/admin/repository/submit/authors.html
+++ b/src/templates/admin/repository/submit/authors.html
@@ -75,6 +75,7 @@ {% trans 'Authors' %}
{% trans 'Name' %}
{% trans 'Email' %}
+ {% trans 'ORCID' %}
{% trans 'Affiliation' %}
{% trans 'Delete' %}
@@ -84,6 +85,9 @@
{% trans 'Authors' %}
{{ author.account.full_name }}
{{ author.account.email }}
+
+ {% include "admin/elements/repository/orcid.html" %}
+
{{ author.display_affiliation }}
diff --git a/src/templates/admin/repository/submit/review.html b/src/templates/admin/repository/submit/review.html
index f4dbd2ce29..0f47d44798 100644
--- a/src/templates/admin/repository/submit/review.html
+++ b/src/templates/admin/repository/submit/review.html
@@ -55,12 +55,16 @@ Authors
Email Address
First Name
Last Name
+ ORCID
{% for author in preprint.preprintauthor_set.all %}
{{ author.account.email }}
{{ author.account.first_name }}
{{ author.account.last_name }}
+
+ {% include "admin/elements/repository/orcid.html" %}
+
{% endfor %}
diff --git a/src/utils/install/journal_defaults.json b/src/utils/install/journal_defaults.json
index ff88ba275a..29e464730d 100644
--- a/src/utils/install/journal_defaults.json
+++ b/src/utils/install/journal_defaults.json
@@ -1669,6 +1669,44 @@
"journal-manager"
]
},
+ {
+ "group": {
+ "name": "email"
+ },
+ "setting": {
+ "description": "Email sent when user requests co-authors add ORCID iD.",
+ "is_translatable": true,
+ "name": "orcid_request",
+ "pretty_name": "ORCID iD Request",
+ "type": "rich-text"
+ },
+ "value": {
+ "default": "
Dear {{ user.full_name }} Your co-author has requested your ORCID iD. You can add it by through your profile {{ user_profile_url }}.
"
+ },
+ "editable_by": [
+ "editor",
+ "journal-manager"
+ ]
+ },
+ {
+ "group": {
+ "name": "email"
+ },
+ "setting": {
+ "description": "Email sent to co-authors that do not have accounts to create an account and add ORCID iD.",
+ "is_translatable": true,
+ "name": "orcid_activate_request",
+ "pretty_name": "ORCID iD Create Request",
+ "type": "rich-text"
+ },
+ "value": {
+ "default": "
Dear {{ user.full_name }} Your co-author has requested your ORCID iD. You can add it by through your profile {{ user_profile_url }}.
"
+ },
+ "editable_by": [
+ "editor",
+ "journal-manager"
+ ]
+ },
{
"group": {
"name": "general"
@@ -3607,6 +3645,44 @@
"journal-manager"
]
},
+ {
+ "value": {
+ "default": "ORCID iD Request"
+ },
+ "setting": {
+ "type": "char",
+ "pretty_name": "ORCID iD Request",
+ "is_translatable": true,
+ "description": "Subject for when a submitter requests a co-author's ORCID iD",
+ "name": "subject_orcid_request"
+ },
+ "group": {
+ "name": "email_subject"
+ },
+ "editable_by": [
+ "editor",
+ "journal-manager"
+ ]
+ },
+ {
+ "value": {
+ "default": "ORCID iD Request"
+ },
+ "setting": {
+ "type": "char",
+ "pretty_name": "ORCID iD Request",
+ "is_translatable": true,
+ "description": "Subject for when a submitter requests a co-author's ORCID iD and their account is inactive",
+ "name": "subject_orcid_activate_request"
+ },
+ "group": {
+ "name": "email_subject"
+ },
+ "editable_by": [
+ "editor",
+ "journal-manager"
+ ]
+ },
{
"group": {
"name": "email"
diff --git a/src/utils/orcid.py b/src/utils/orcid.py
index d2d193bd94..63ae02ac28 100755
--- a/src/utils/orcid.py
+++ b/src/utils/orcid.py
@@ -14,6 +14,7 @@
from django.http import QueryDict
import requests
from requests.exceptions import HTTPError
+import datetime
from utils import logic
from utils.logger import get_logger
@@ -48,12 +49,44 @@ def retrieve_tokens(authorization_code, site):
r.raise_for_status()
except HTTPError as e:
logger.error("ORCID request failed: %s" % str(e))
- orcid_id = None
+ # after logging failure continue with an empty response
+ # to avoid additional errors
+ orcid_response = {}
else:
logger.info("OK response from ORCID")
- orcid_id = json.loads(r.text).get("orcid")
+ orcid_response = json.loads(r.text)
- return orcid_id
+ access_token = orcid_response.get("access_token", None)
+ orcid_id = orcid_response.get("orcid", None)
+
+ if "expires_in" in orcid_response:
+ expires = orcid_response.get("expires_in")
+ expiration_date = datetime.datetime.now() + datetime.timedelta(seconds=expires)
+ else:
+ expiration_date = None
+
+ return access_token, expiration_date, orcid_id
+
+
+def is_token_valid(orcid_id, token):
+ api_client = OrcidAPI(
+ settings.ORCID_CLIENT_ID, settings.ORCID_CLIENT_SECRET, sandbox=True
+ )
+ r = api_client._get_public_info(
+ orcid_id, "record", token, None, "application/orcid+json"
+ )
+ return r.status_code == 200
+
+
+def revoke_token(token):
+ url = settings.ORCID_TOKEN_URL.replace("token", "revoke")
+ data = {
+ "client_id": settings.ORCID_CLIENT_ID,
+ "client_secret": settings.ORCID_CLIENT_SECRET,
+ "token": token,
+ }
+ r = requests.post(url, data=data)
+ return r.status_code == 200
def build_redirect_uri(site):
@@ -67,7 +100,9 @@ def build_redirect_uri(site):
def get_orcid_record(orcid):
try:
logger.info("Retrieving ORCID profile for %s", orcid)
- api_client = OrcidAPI(settings.ORCID_CLIENT_ID, settings.ORCID_CLIENT_SECRET)
+ api_client = OrcidAPI(
+ settings.ORCID_CLIENT_ID, settings.ORCID_CLIENT_SECRET, sandbox=True
+ )
search_token = api_client.get_search_token_from_orcid()
return api_client.read_record_public(
orcid,