-
Notifications
You must be signed in to change notification settings - Fork 87
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
Open
everreau
wants to merge
34
commits into
openlibhums:master
Choose a base branch
from
everreau:2610-orcid-tokens
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
2610 orcid tokens #5110
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
efafcf3
save orcid tokens and expirations
everreau 3d051e7
don't allow users to edit orcids directly in profile
everreau d2b237d
allow authors to request orcid from co-authors
everreau c1d4244
fix tests
everreau 1250329
add tests
everreau 7b90eb1
ruff formatting
everreau aba83d4
fix icon link, capitalize i per alainna
everreau 90c8b1d
update tests
everreau 0fc0f01
use ORCID iD (from Alainna)
everreau be0af16
show orcids in repository admin and allow requests
everreau c68057d
fix test
everreau 641995c
allow different emails for inactive accounts
everreau 1a6767d
add date orcid request was sent
everreau 839d954
fix typos, minor changes
everreau e5e69e3
fix date format
everreau 78e659e
use is_staff
everreau a4a866d
add comments, fix messages
everreau 6a1023c
use url_with_return and require post
everreau e9bb6b4
don't use null=True for charfields, fix tests
everreau d80fbdc
ruff
everreau 725bbbb
typo
everreau 59803ef
use sandbox parameter when appropriate
everreau 52fe5e8
re-arrange orcid field
everreau 11cb04f
add orcid display to more view, add is_valid flag for orcids in froze…
everreau fd251e9
add tests for inactive accounts, re-write account matching logic to b…
everreau 24a1d5d
ruff
everreau f0eb00a
add orcid authenticated flag to crossref metadata
everreau fc889aa
don't allow users to add an orcid that is already attached to another…
everreau a411892
remove unused code
everreau c27a70a
remove unused setting and update request text
everreau 94357ae
use validation to determine which account to login to if there are du…
everreau f362c2b
make sure orcid display matches ENABLE_ORCID setting
everreau 0ca9e28
don't let users register with or add orcids if an account with a vali…
everreau ab71ca6
ruff
everreau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
37 changes: 37 additions & 0 deletions
37
src/core/migrations/0110_account_date_orcid_requested_account_orcid_token_and_more.py
This file contains hidden or 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,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), | ||
| ), | ||
| ] |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| from django.urls.base import clear_script_prefix | ||
| from django.utils import timezone | ||
| from django.core import mail | ||
| from journal.tests.utils import make_test_journal | ||
|
|
||
| from utils.testing import helpers | ||
| from utils import setting_handler, install | ||
|
|
@@ -219,7 +220,7 @@ def test_register_with_orcid_token(self, record_mock): | |
| self.assertContains(response, "Campbell") | ||
| self.assertContains(response, "Kasey") | ||
| self.assertContains(response, "[email protected]") | ||
| self.assertNotContains(response, "Register with ORCiD") | ||
| self.assertNotContains(response, "Register with ORCID") | ||
| self.assertContains(response, "http://sandbox.orcid.org/0000-0000-0000-0000") | ||
| self.assertContains( | ||
| response, | ||
|
|
@@ -252,13 +253,13 @@ def test_register_with_orcid_token(self, record_mock): | |
| def test_registration(self): | ||
| response = self.client.get(reverse("core_register")) | ||
| self.assertEqual(response.status_code, 200) | ||
| self.assertContains(response, "Register with ORCiD") | ||
| self.assertContains(response, "Register with ORCID") | ||
|
|
||
| @override_settings(ENABLE_ORCID=False) | ||
| def test_registration(self): | ||
| response = self.client.get(reverse("core_register")) | ||
| self.assertEqual(response.status_code, 200) | ||
| self.assertNotContains(response, "Register with ORCiD") | ||
| self.assertNotContains(response, "Register with ORCID") | ||
|
|
||
| @override_settings(URL_CONFIG="domain", CAPTCHA_TYPE=None) | ||
| def test_mixed_case_login_different_case(self): | ||
|
|
@@ -582,3 +583,88 @@ def setUp(self): | |
| ) | ||
|
|
||
| clear_script_prefix() | ||
|
|
||
| @override_settings(ENABLE_ORCID=False) | ||
| def test_profile_orcid_disabled(self): | ||
| self.client.force_login(self.admin_user) | ||
| response = self.client.get(reverse("core_edit_profile")) | ||
| self.assertContains( | ||
| response, '<input type="text" name="orcid" maxlength="40" id="id_orcid">' | ||
| ) | ||
|
|
||
| @override_settings(ENABLE_ORCID=True) | ||
| def test_profile_orcid_enabled_no_orcid(self): | ||
everreau marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # Profile should offer to connect orcid | ||
| self.client.force_login(self.admin_user) | ||
| response = self.client.get(reverse("core_edit_profile")) | ||
| self.assertNotContains(response, "ORCID could not be validated.") | ||
| self.assertContains(response, "Connect your ORCID") | ||
|
|
||
| @override_settings( | ||
| ENABLE_ORCID=True, ORCID_URL="https://sandbox.orcid.org/oauth/authorize" | ||
| ) | ||
| def test_profile_orcid_unverified(self): | ||
| self.admin_user.orcid = "0000-0000-0000-0000" | ||
| self.admin_user.save() | ||
| self.client.force_login(self.admin_user) | ||
| response = self.client.get(reverse("core_edit_profile")) | ||
| self.assertContains(response, "ORCID iD could not be validated.") | ||
| self.assertContains(response, "Connect your ORCID") | ||
| self.assertContains(response, "https://sandbox.orcid.org/0000-0000-0000-0000") | ||
everreau marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @patch.object(models.Account, "is_orcid_token_valid") | ||
| @override_settings( | ||
| ENABLE_ORCID=True, ORCID_URL="https://sandbox.orcid.org/oauth/authorize" | ||
| ) | ||
| def test_profile_orcid(self, mock_method): | ||
| # override is_orcid_token valid make if valid | ||
| mock_method.return_value = True | ||
| self.admin_user.orcid = "0000-0000-0000-0000" | ||
| self.admin_user.orcid_token = "0a0aaaaa-0aa0-0000-aa00-a00aa0a00000" | ||
| self.admin_user.save() | ||
| self.client.force_login(self.admin_user) | ||
| response = self.client.get(reverse("core_edit_profile")) | ||
| self.assertContains(response, "https://sandbox.orcid.org/0000-0000-0000-0000") | ||
| self.assertContains(response, "remove_orcid") | ||
| self.assertContains( | ||
| response, | ||
| '<input type="hidden" name="orcid" value="0000-0000-0000-0000" id="id_orcid">', | ||
| ) | ||
| self.assertNotContains(response, "ORCID iD could not be validated.") | ||
|
|
||
| @patch.object(models.Account, "is_orcid_token_valid") | ||
| @override_settings( | ||
| ENABLE_ORCID=True, | ||
| URL_CONFIG="domain", | ||
| ORCID_URL="https://sandbox.orcid.org/oauth/authorize", | ||
| ) | ||
| def test_profile_orcid_not_admin(self, mock_method): | ||
| mock_method.return_value = True | ||
|
|
||
| journal_kwargs = { | ||
| "code": "fetests", | ||
| "domain": "fetests.janeway.systems", | ||
| } | ||
| journal = make_test_journal(**journal_kwargs) | ||
|
|
||
| journal_manager = helpers.create_user( | ||
| "[email protected]", ["journal-manager"], journal=journal | ||
| ) | ||
| journal_manager.is_active = True | ||
| journal_manager.save() | ||
|
|
||
| self.regular_user.orcid = "0000-0000-0000-0000" | ||
| self.regular_user.orcid_token = "0a0aaaaa-0aa0-0000-aa00-a00aa0a00000" | ||
| self.regular_user.save() | ||
|
|
||
| self.client.force_login(journal_manager) | ||
|
|
||
| url = reverse("core_user_edit", kwargs={"user_id": self.regular_user.pk}) | ||
| response = self.client.get(url, SERVER_NAME=journal.domain) | ||
| self.assertContains(response, "https://sandbox.orcid.org/0000-0000-0000-0000") | ||
| self.assertContains( | ||
| response, | ||
| '<input type="hidden" name="orcid" value="0000-0000-0000-0000" id="id_orcid">', | ||
| ) | ||
| self.assertNotContains(response, "ORCID iD could not be validated.") | ||
| self.assertNotContains(response, "remove_orcid") | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.