-
Notifications
You must be signed in to change notification settings - Fork 88
2610 orcid tokens #5110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
2610 orcid tokens #5110
Changes from 34 commits
efafcf3
3d051e7
d2b237d
c1d4244
1250329
7b90eb1
aba83d4
90c8b1d
0fc0f01
be0af16
c68057d
641995c
1a6767d
839d954
e5e69e3
78e659e
a4a866d
6a1023c
e9bb6b4
d80fbdc
725bbbb
59803ef
52fe5e8
11cb04f
fd251e9
24a1d5d
f0eb00a
fc889aa
a411892
c27a70a
94357ae
f362c2b
0ca9e28
ab71ca6
1b3250e
1e16dd3
fb775b1
b6df6ff
f8b6dba
3d38823
a3a8ec2
62364f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # Generated by Django 4.2.26 on 2026-02-18 21:39 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("core", "0109_salutation_name_20250707_1420"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name="account", | ||
| name="date_orcid_requested", | ||
| field=models.DateTimeField(blank=True, null=True), | ||
| ), | ||
| migrations.AddField( | ||
| model_name="account", | ||
| name="orcid_token", | ||
| field=models.CharField(blank=True, default="", max_length=40), | ||
| ), | ||
| migrations.AddField( | ||
| model_name="account", | ||
| name="orcid_token_expiration", | ||
| field=models.DateTimeField(blank=True, null=True), | ||
| ), | ||
| migrations.AddField( | ||
| model_name="orcidtoken", | ||
| name="access_token", | ||
| field=models.CharField(blank=True, default="", max_length=40), | ||
| ), | ||
| migrations.AddField( | ||
| model_name="orcidtoken", | ||
| name="access_token_expiration", | ||
| field=models.DateTimeField(blank=True, null=True), | ||
| ), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,6 +71,7 @@ | |
| from utils import logic as utils_logic | ||
| from utils.forms import plain_text_validator | ||
| from production import logic as production_logic | ||
| from utils.orcid import is_token_valid | ||
|
|
||
| fs = JanewayFileSystemStorage() | ||
| logger = get_logger(__name__) | ||
|
|
@@ -485,6 +486,9 @@ class Account(AbstractBaseUser, PermissionsMixin): | |
| orcid = models.CharField( | ||
| max_length=40, null=True, blank=True, verbose_name=_("ORCiD") | ||
| ) | ||
| orcid_token = models.CharField(max_length=40, blank=True, default="") | ||
| orcid_token_expiration = models.DateTimeField(null=True, blank=True) | ||
| date_orcid_requested = models.DateTimeField(blank=True, null=True) | ||
everreau marked this conversation as resolved.
Show resolved
Hide resolved
everreau marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| twitter = models.CharField( | ||
| max_length=300, null=True, blank=True, verbose_name=_("Twitter Handle") | ||
| ) | ||
|
|
@@ -884,6 +888,10 @@ def snapshot_as_author(self, article, force_update=True): | |
| "order": article.next_frozen_author_order(), | ||
| } | ||
|
|
||
| if self.orcid: | ||
| frozen_dict["frozen_orcid"] = self.orcid | ||
| frozen_dict["is_frozen_orcid_valid"] = self.is_orcid_token_valid() | ||
|
|
||
| frozen_author, created = submission_models.FrozenAuthor.objects.get_or_create( | ||
| author=self, | ||
| article=article, | ||
|
|
@@ -948,6 +956,12 @@ def hypothesis_username(self): | |
| )[:30] | ||
| return username.lower() | ||
|
|
||
| def get_orcid_url(self): | ||
| return f"{settings.ORCID_URL.replace('oauth/authorize', '')}{self.orcid}" | ||
|
||
|
|
||
| def is_orcid_token_valid(self): | ||
| return is_token_valid(self.orcid, self.orcid_token) | ||
|
|
||
|
|
||
| def generate_expiry_date(): | ||
| return timezone.now() + timedelta(days=1) | ||
|
|
@@ -959,9 +973,11 @@ class OrcidToken(models.Model): | |
| expiry = models.DateTimeField( | ||
| default=generate_expiry_date, verbose_name=_("Expires on") | ||
| ) | ||
| access_token = models.CharField(max_length=40, blank=True, default="") | ||
| access_token_expiration = models.DateTimeField(null=True, blank=True) | ||
|
|
||
| def __str__(self): | ||
| return "ORCiD Token [{0}] - {1}".format(self.orcid, self.token) | ||
| return "ORCID iD Token [{0}] - {1}".format(self.orcid, self.token) | ||
|
|
||
|
|
||
| class PasswordResetToken(models.Model): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you considered making the link straight to the verification step? I think this might be clearer for users who do not remember what the profile page looks like. If they are taken to the profile page, they have to scroll down to the social media and accounts section and notice the button to connect their ORCID, but if they are taken straight to the redirect cycle, they'll be prompted at each step what to do.
We have a helper function in this file that might be useful: