Skip to content
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

[ENG-6812] BE Reference PR for Preprints DOI Versioning #10816

Draft
wants to merge 255 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
255 commits
Select commit Hold shift + click to select a range
ef1b78a
move preprints migration to the scripts folder
Ostap-Zherebetskyi Nov 11, 2024
53cbfee
update GuidVersionsThrough migrations
Ostap-Zherebetskyi Nov 11, 2024
45aa883
update migrate_preprints_single in migration
Ostap-Zherebetskyi Nov 11, 2024
577015d
added versioned guid support in resolve_guid
Ostap-Zherebetskyi Nov 12, 2024
ea20dbe
added support for versioned guids
Ostap-Zherebetskyi Nov 12, 2024
dc0f548
added router redirect for versioned guids
Ostap-Zherebetskyi Nov 12, 2024
075fa1b
replace delimiter using variable from VersionedGuidMixin
Ostap-Zherebetskyi Nov 12, 2024
ebacc74
added pogress bar for the migration script
Ostap-Zherebetskyi Nov 12, 2024
bfa6ee0
added versioned guid support for admin urls
Ostap-Zherebetskyi Nov 19, 2024
8f82726
Added create_version feature for preprint
Ostap-Zherebetskyi Nov 19, 2024
da201f1
added version field and preprint_versions link
Ostap-Zherebetskyi Nov 21, 2024
9812c2b
rename ListCreatePreprintVersion to PreprintVersionsList
Ostap-Zherebetskyi Nov 21, 2024
57d2df7
added ConflictError
Ostap-Zherebetskyi Nov 21, 2024
117d2b4
updated load method in VersionedGuidMixin
Ostap-Zherebetskyi Nov 21, 2024
3bf86b0
updated create_version method in Preprint model
Ostap-Zherebetskyi Nov 21, 2024
985610a
added permissions check
Ostap-Zherebetskyi Nov 21, 2024
321db66
added affiliated_institutions support
Ostap-Zherebetskyi Nov 21, 2024
f6974a9
removed breakpoint and added comment
Ostap-Zherebetskyi Nov 21, 2024
7d1499c
updated PreprintCreateVersionSerializer
Ostap-Zherebetskyi Nov 25, 2024
e11ce27
updated PreprintVersionsList inheritance
Ostap-Zherebetskyi Nov 25, 2024
2f61566
added PendingVersionExists error
Ostap-Zherebetskyi Nov 25, 2024
81f4083
added bypass for user.is_affiliated_with_institution
Ostap-Zherebetskyi Nov 25, 2024
acb0fa2
added has_create_version_permission method for Preprint
Ostap-Zherebetskyi Nov 25, 2024
eef1930
updated errors and renamed field
Ostap-Zherebetskyi Nov 26, 2024
7a2c17d
renamed dupliate_from_guid field to create_from_guid
Ostap-Zherebetskyi Nov 26, 2024
6eb89fd
renamed error
Ostap-Zherebetskyi Nov 26, 2024
320823d
update create_version method
Ostap-Zherebetskyi Nov 26, 2024
040d6d7
created method for saving DOI locally bypassing CrossRef
Nov 20, 2024
d6aa917
fixed comments
Nov 21, 2024
d9afea5
Fix preprints submission failure due to notification guid length
cslzchen Nov 22, 2024
adf8c15
updated build_posted_content to include doi_relations
Nov 22, 2024
f1e2d23
reformatted methods
Nov 25, 2024
ee22147
changed logic of relations
Nov 26, 2024
40c872b
using version instead of PK
Nov 26, 2024
ecfcfa3
Remove migration files osf_0023 and osf_0024
cslzchen Nov 28, 2024
effeb79
Tweak GuidVersionsThrough
cslzchen Nov 28, 2024
3fd8954
Redo migration
cslzchen Nov 28, 2024
d3ba3df
update router for versioned guid
Ostap-Zherebetskyi Nov 29, 2024
94f4a60
Fix failed tests after DOI updates
Vlad0n20 Nov 26, 2024
8e88024
Update factories
Vlad0n20 Nov 29, 2024
47a5695
Remove factories for Guid
Vlad0n20 Nov 29, 2024
957265b
unit tests for preprint version API
Ostap-Zherebetskyi Nov 28, 2024
12af1e9
update preprint license
Ostap-Zherebetskyi Nov 29, 2024
3a82e0d
updated get_preprint method in PreprintMixin
Ostap-Zherebetskyi Dec 2, 2024
4f0cf59
added propery is_last_version and created a method to check is prepri…
Nov 28, 2024
19b1992
intial refactor
Nov 29, 2024
3c88b94
implemented last version check
Dec 2, 2024
f667562
optimized version filtering
bodintsov Dec 2, 2024
3d11523
improve logic, naming
bodintsov Dec 3, 2024
face521
added PublishedPreprintManager for the Preprint
Ostap-Zherebetskyi Dec 3, 2024
562dc66
updated get_preprint method
Ostap-Zherebetskyi Dec 3, 2024
fda3ae4
versioned preprint update
Ostap-Zherebetskyi Dec 3, 2024
4a6baae
restore comment
Ostap-Zherebetskyi Dec 3, 2024
903cd65
Merge pull request #10818 from Ostap-Zherebetskyi/fix/GUID_routing
cslzchen Dec 3, 2024
3ad75fb
Merge pull request #10819 from Ostap-Zherebetskyi/feature/preprint_tests
cslzchen Dec 3, 2024
3fb7d62
Merge pull request #10815 from bodintsov/feature/implement_latest_ver…
cslzchen Dec 3, 2024
9b3dbb4
added reject preprint update mixin
Ostap-Zherebetskyi Dec 2, 2024
c797860
updated RejectPreprintEditMixin
Ostap-Zherebetskyi Dec 3, 2024
17ceaf0
updated RejectPreprintEditMixin
Ostap-Zherebetskyi Dec 5, 2024
9a7e0f7
Add tests for GuidVersionsThrough
Vlad0n20 Dec 5, 2024
333d7c1
Update tests for GuidVersionsThrough
Vlad0n20 Dec 5, 2024
998d01d
updated sitemap generator
bodintsov Dec 6, 2024
a12568e
removed current implementation check
bodintsov Dec 6, 2024
684eed0
removed imports
bodintsov Dec 6, 2024
9d9ad2b
rename RejectPreprintEditMixin to PreprintOldVersionsImmutableMixin
Ostap-Zherebetskyi Dec 6, 2024
54dcc5b
added versioned guid support
Ostap-Zherebetskyi Dec 6, 2024
e9a1918
Merge pull request #10820 from Ostap-Zherebetskyi/feature/reject_prep…
cslzchen Dec 6, 2024
608825d
updated ReviewableMixin for the versioned preprints
Ostap-Zherebetskyi Dec 5, 2024
4708caf
versioned preprints refactor
Ostap-Zherebetskyi Dec 6, 2024
e876fb0
Add new checks for version guid tests
Vlad0n20 Dec 9, 2024
b395aaa
versioned preprints refactor
Ostap-Zherebetskyi Dec 9, 2024
4a4605c
removed unused parameter
Ostap-Zherebetskyi Dec 9, 2024
b3fc503
update preprint load method
Ostap-Zherebetskyi Dec 9, 2024
7778524
updated split_guid method
Ostap-Zherebetskyi Dec 9, 2024
4a64cc1
Merge pull request #10828 from Ostap-Zherebetskyi/feature/rejected_pr…
cslzchen Dec 9, 2024
4a7aa35
Merge pull request #10813 from Vlad0n20/fix/ENG-6558
cslzchen Dec 9, 2024
c507291
Merge remote-tracking branch 'upstream/feature/preprints-doi-versioni…
Ostap-Zherebetskyi Dec 10, 2024
fec70d2
refactored code, removed useless
bodintsov Dec 10, 2024
b947839
removed litter
bodintsov Dec 10, 2024
a49ec3c
versioned preprints refactor
Ostap-Zherebetskyi Dec 10, 2024
46a4a2a
versioned preprints refactor
Ostap-Zherebetskyi Dec 10, 2024
6dc0b3c
Merge pull request #10834 from Ostap-Zherebetskyi/fix/refactor_versio…
cslzchen Dec 10, 2024
fc70e02
Merge pull request #10829 from bodintsov/feature/update_sitemap_gener…
cslzchen Dec 10, 2024
a0b891d
Fix most api_2 tests
Vlad0n20 Dec 6, 2024
ba86b08
Fix preprint admin tests. The issue was that in WithdrawalRequestMixi…
Vlad0n20 Dec 5, 2024
e350bd0
Update API for version guid and remove test fixes
Vlad0n20 Dec 10, 2024
a9c5d8d
Remove useless code
Vlad0n20 Dec 10, 2024
c9c85e1
Merge pull request #10830 from Vlad0n20/fix/ENG-6547
cslzchen Dec 10, 2024
d551677
fixed 500 eror on invalid guid
bodintsov Dec 11, 2024
56d2d4e
added tests for versioned DOI and crossref metadata
bodintsov Dec 11, 2024
0888f31
updated PreprintOldVersionsImmutableMixin
Ostap-Zherebetskyi Dec 12, 2024
80267ff
added unique constraint to GuidVersionsThrough
bodintsov Dec 12, 2024
7008790
Fix website tests
Vlad0n20 Dec 12, 2024
fcc61de
Merge pull request #10839 from bodintsov/feature/improve_version_inel…
cslzchen Dec 12, 2024
66aea3f
Merge pull request #10846 from Ostap-Zherebetskyi/fix/update_Preprint…
cslzchen Dec 12, 2024
c06e1eb
Merge pull request #10848 from bodintsov/feature/add_uniqueness_to_gu…
cslzchen Dec 12, 2024
70ca5eb
Simplify resolve guid
cslzchen Dec 12, 2024
9f2b980
Merge pull request #10850 from Vlad0n20/fix/ENG-6700
cslzchen Dec 12, 2024
6f362f5
Fix flake8: remove unused import
cslzchen Dec 13, 2024
c075143
added checks for preprint version, fixed tests
bodintsov Dec 13, 2024
7ac2544
Fix assert error in checkin_files_task for website tests
Vlad0n20 Dec 13, 2024
2396c7e
Merge pull request #10852 from Vlad0n20/fix/ENG-6727
cslzchen Dec 13, 2024
5a842c0
Refactor/Document preprint factory version creation
cslzchen Dec 13, 2024
93997e5
Merge pull request #10840 from bodintsov/feature/crossref_and_doi_tests
cslzchen Dec 14, 2024
5e1778e
Rework version creation for model and factory
cslzchen Dec 14, 2024
d7ad314
Fix preprint version creation in crossref tests
cslzchen Dec 16, 2024
a142a72
Fix imports
cslzchen Dec 16, 2024
1bee842
Merge pull request #10853 from cslzchen/feature/version-creation-rework
cslzchen Dec 16, 2024
2a54599
Fix api_3 test, without elasticsearch and share related
Vlad0n20 Dec 11, 2024
eb1f141
Update id_linked_preprints for versioned guids
Vlad0n20 Dec 13, 2024
2d70249
updated tests for sitemap generator
bodintsov Dec 17, 2024
90e6ce7
updated tests
bodintsov Dec 17, 2024
ef6a82e
Fix cressref tests
Vlad0n20 Dec 17, 2024
cc435b0
Merge pull request #10856 from bodintsov/feature/sitemap_generator_un…
cslzchen Dec 17, 2024
4b8894e
Merge pull request #10844 from Vlad0n20/fix/ENG-6673-api-3-test
cslzchen Dec 17, 2024
2706450
Merge remote-tracking branch 'upstream/develop' into feature/preprint…
cslzchen Dec 18, 2024
a9b1204
added sentry logs
bodintsov Dec 18, 2024
09814fd
Update FilterMixin for versioned guid
Vlad0n20 Dec 18, 2024
fa5059f
Add tests for PreprintFactory
Vlad0n20 Dec 16, 2024
1d02840
add tests for PreprintFactory.create_version method
Vlad0n20 Dec 17, 2024
3b86d10
fixed create versioned preprint
Ostap-Zherebetskyi Dec 18, 2024
e1a2630
Merge pull request #10855 from Vlad0n20/ENG-6701
cslzchen Dec 18, 2024
a71d0cf
Merge pull request #10863 from Ostap-Zherebetskyi/fix/versioned_prepr…
cslzchen Dec 18, 2024
7388f6f
refactored sentry messages
bodintsov Dec 19, 2024
2161f03
Add error handling for version guid in FilterMixin.parse_query_params…
Vlad0n20 Dec 19, 2024
a616115
updated file upload for the versioned preprint
Ostap-Zherebetskyi Dec 19, 2024
c8afa3f
Include only latest preprint version to project`s supplements
bodintsov Dec 19, 2024
c500fa5
fixed flake8 error
bodintsov Dec 20, 2024
f16431b
changed _id to base_guid._id according to SHARE update
Ostap-Zherebetskyi Dec 20, 2024
1264cdf
project supplements latest preprint API
bodintsov Dec 20, 2024
baa72c3
Merge pull request #10861 from bodintsov/feature/add_centry_logs_to_c…
cslzchen Dec 20, 2024
13de01d
Merge pull request #10864 from Ostap-Zherebetskyi/fix/versioned_prepr…
cslzchen Dec 20, 2024
8fddaf8
Merge pull request #10862 from Vlad0n20/fix/ENG-6646
cslzchen Dec 21, 2024
ba18d08
Merge pull request #10865 from bodintsov/feature/show_latest_preprint…
cslzchen Dec 21, 2024
7361352
Merge pull request #10868 from Ostap-Zherebetskyi/fix/SHARE_tests
cslzchen Dec 21, 2024
450e107
latest version of preprint in collections
bodintsov Dec 21, 2024
a1ab30d
Merge pull request #10870 from bodintsov/feature/collections_latests_…
cslzchen Dec 21, 2024
687249a
fixed preprint subjects [ENG-6791]
Ostap-Zherebetskyi Dec 24, 2024
45d7615
fixed tests, fixed issues
bodintsov Dec 24, 2024
5fee1e3
Merge pull request #10872 from Ostap-Zherebetskyi/fix/preprint_subjects
cslzchen Dec 26, 2024
4ad6cf3
Merge pull request #10873 from bodintsov/fix/fix_newly_broken_tests_d…
cslzchen Dec 26, 2024
46745ab
fixed preprint file download
Ostap-Zherebetskyi Dec 30, 2024
c2843f0
updated analytics task
Ostap-Zherebetskyi Dec 30, 2024
f9fc966
updated metrics
Ostap-Zherebetskyi Dec 31, 2024
26a2854
update metrics
Ostap-Zherebetskyi Dec 31, 2024
19b31bc
Merge pull request #10878 from Ostap-Zherebetskyi/feature/preprint_me…
cslzchen Dec 31, 2024
88e2f01
Add new tests for preprint moderation states
Vlad0n20 Dec 20, 2024
e2a3e4b
Add checks for new versions
Vlad0n20 Dec 23, 2024
5aa6ff9
Add new tests withdraw request for version preprints
Vlad0n20 Dec 27, 2024
32b8bba
Refactored preprint tests
cslzchen Dec 31, 2024
39b0f76
Merge pull request #10869 from Vlad0n20/ENG-6693
cslzchen Jan 1, 2025
05b9b2e
added Docstrings
Ostap-Zherebetskyi Dec 27, 2024
b331e48
More docstrings/comments for guid and versioned guid
cslzchen Jan 1, 2025
d7d6b18
Fix order for preprint api urls
cslzchen Jan 1, 2025
9fc83fa
More docstrings/comments
cslzchen Jan 1, 2025
d97e485
More docstrings/comments and code optimization
cslzchen Jan 1, 2025
fe83d4f
Merge pull request #10875 from Ostap-Zherebetskyi/feature/preprint_do…
cslzchen Jan 1, 2025
4f11af9
POC impln for handling orphaned version
cslzchen Dec 31, 2024
8d93f94
De-duplicate and normalize unfinished and unpublished check
cslzchen Dec 31, 2024
c3b8203
Merge unfinished and unpublished queries during version creation
cslzchen Dec 31, 2024
2d44a61
Update docstrings/comments + improve error handling
cslzchen Jan 1, 2025
40862ff
Remove duplicate and unuseful sentry logs
cslzchen Jan 1, 2025
ee7b187
Fix flake8
cslzchen Jan 1, 2025
b398764
Fix typo and add TODO
cslzchen Jan 1, 2025
f04e441
Elaborate more on the corner case where versioned guid doesn't exist
cslzchen Jan 1, 2025
c3f2abc
Improve preprint and version creation
cslzchen Jan 1, 2025
eb5b9c6
Merge pull request #10880 from cslzchen/feature/fix-orphaned-version
cslzchen Jan 2, 2025
b558511
added manage command for versioned preprints
Ostap-Zherebetskyi Jan 2, 2025
1c825c9
fixed flake8 issue
Ostap-Zherebetskyi Jan 2, 2025
cd5aa78
Add dry_run, tweak params, improve logs and handle null guid
cslzchen Jan 2, 2025
7282b68
Rename command name
cslzchen Jan 2, 2025
a3c2031
Remove unnecessary logs
cslzchen Jan 2, 2025
2a5e3a8
Merge pull request #10883 from Ostap-Zherebetskyi/feature/preprint_ma…
cslzchen Jan 2, 2025
495204f
Replace wrong exception handling with None check
cslzchen Jan 3, 2025
8ff49ba
Allow Guid.load() to ignore not found and don't log to sentry
cslzchen Jan 3, 2025
c5a602f
Merge pull request #10885 from cslzchen/feature/selenium-and-sentry-f…
cslzchen Jan 3, 2025
6a580d7
Fix CrossRef DOI check task
cslzchen Jan 3, 2025
24a19bb
Fix import
cslzchen Jan 3, 2025
0a46e0e
Improve/fix logs
cslzchen Jan 3, 2025
45af5db
Merge pull request #10886 from cslzchen/feature/fix-crossref-doi-check
cslzchen Jan 3, 2025
67904fb
Fix PreprintOldVersionsImmutableMixin
cslzchen Jan 3, 2025
8730deb
Fix api version to for subjects in preprint version api tests
cslzchen Jan 4, 2025
ffd65fd
Add and fix preprint version creation api tests
cslzchen Jan 4, 2025
11aca57
Fix flake8
cslzchen Jan 4, 2025
5f75be1
Merge pull request #10888 from cslzchen/feature/fix-preprint-mixin
cslzchen Jan 6, 2025
0c95c7d
Merge remote-tracking branch 'upstream/develop' into feature/preprint…
cslzchen Jan 6, 2025
a2bcee1
- ENG-6645 fix api1 failing tests in test_views.py
sh-andriy Dec 9, 2024
ab70669
- ENG-6645 fixed all failing tests api1
sh-andriy Dec 11, 2024
6591a47
- ENG-6645 fix failing tests api1
sh-andriy Dec 19, 2024
35657e3
- ENG-6645 fix failing tests api1
sh-andriy Dec 19, 2024
febabf3
- ENG-6645 fix test_create_preprint_with_supplementary_node + removed…
sh-andriy Dec 19, 2024
b478634
- ENG-6645 fix test_list + test_filter_actions
sh-andriy Dec 20, 2024
e2a79c2
- ENG-6645 code adjustments
sh-andriy Dec 24, 2024
0f3516b
- ENG-6645 pre-commit fix
sh-andriy Dec 26, 2024
ebdb887
Fix circular import for osf/models/mixins.py file
Vlad0n20 Dec 30, 2024
dc59d6a
Fix some comments to pull request
Vlad0n20 Jan 2, 2025
db2febe
Fix merge conflicts after rebase
Vlad0n20 Jan 2, 2025
bdb865f
Fix tests
Vlad0n20 Jan 3, 2025
593699f
Refactor api filters by id for prerpint
cslzchen Jan 6, 2025
17fdb76
Use Guid.split_guid() in test_create_preprint_with_supplementary_node
cslzchen Jan 6, 2025
33140fd
Revert incorret fix, which should not remove version info to pass
cslzchen Jan 6, 2025
d535d5e
Revoke incorrect fix: should fix `Preprint.save()` instead
cslzchen Jan 6, 2025
e1f2e80
Fix flake8
cslzchen Jan 6, 2025
6d4313b
Merge pull request #10879 from Vlad0n20/fix/ENG-6645
cslzchen Jan 7, 2025
503fbf0
Rework save() and update create() & create_version() for Prerpint
cslzchen Jan 7, 2025
235dca7
Update prerpint factories
cslzchen Jan 7, 2025
7e0d89e
Fix unit tests: must use factories or `.create()` to create preprint
cslzchen Jan 7, 2025
43243ab
Add missing kwargs when using `Preprint.create()` in some tests
cslzchen Jan 7, 2025
0164aec
Refactor _id property to use cached_property and fixed related tests
Ostap-Zherebetskyi Jan 6, 2025
317a5ab
update _id cache
Ostap-Zherebetskyi Jan 7, 2025
fb6b5f6
updated PreprintOldVersionsImmutableMixin checks
Ostap-Zherebetskyi Jan 6, 2025
62f2a98
allow resubmission for POST_MODERATION workflow
Ostap-Zherebetskyi Jan 6, 2025
ed31516
added comment
Ostap-Zherebetskyi Jan 7, 2025
116cba9
Improve PreprintOldVersionsImmutableMixin check
cslzchen Jan 7, 2025
f339355
Fix my preprints page; UserPreprints now returns only latest versions
Vlad0n20 Jan 7, 2025
cb168ca
Renam and improve _CachedTruthyProperty
cslzchen Jan 7, 2025
c6659c9
Use @cached_property as is; make version cached too
cslzchen Jan 7, 2025
c0e3af1
Futher improve preprint save
cslzchen Jan 7, 2025
7b16120
Merge pull request #10892 from cslzchen/feature/rework-prerpint-save
cslzchen Jan 7, 2025
79c911e
Merge remote-tracking branch 'upstream/develop' into feature/preprint…
cslzchen Jan 8, 2025
fdbc72c
fixed test TestPublicItemUsageReporter::test_reporter
Ostap-Zherebetskyi Jan 7, 2025
ff69865
fixed test TestGuidVersionsThrough::test_creation_versioned_guid
Ostap-Zherebetskyi Jan 7, 2025
948ad54
Fixed api3 unit tests
Ostap-Zherebetskyi Jan 8, 2025
f5c8aeb
fixed test_bad_requests according to the reviews update [ENG-6802]
Ostap-Zherebetskyi Jan 8, 2025
aed8dc0
fixed api3 unit tests
Ostap-Zherebetskyi Jan 8, 2025
0a93590
Fix contributor add when creating new versions
cslzchen Jan 8, 2025
00d2af1
Replace try with none check since .load() doesn't raise
cslzchen Jan 9, 2025
418245b
Fix format
cslzchen Jan 9, 2025
c818d8c
Merge pull request #10899 from cslzchen/feature/fix-contributor-add
cslzchen Jan 9, 2025
2f3e993
Merge pull request #10894 from Ostap-Zherebetskyi/fix/api3_unit_tests
cslzchen Jan 9, 2025
f415036
Refactor PreprintOldVersionsImmutableMixin and run_accept method
Ostap-Zherebetskyi Jan 9, 2025
be067dc
Minor format/style improvement
cslzchen Jan 9, 2025
608cce3
Merge pull request #10901 from Ostap-Zherebetskyi/fix/edit_rejected_p…
cslzchen Jan 9, 2025
8cce387
Code clean up
cslzchen Jan 9, 2025
a61659f
Add a TODO comment to fix broken filters
cslzchen Jan 9, 2025
d587741
Fix typo and update comment
cslzchen Jan 9, 2025
989ffd5
Merge pull request #10900 from cslzchen/feature/be-code-clean-up
cslzchen Jan 9, 2025
16574e2
Revert incorrect api filter fix for prerpint
cslzchen Jan 9, 2025
51c728e
Fix preprint edit permission
cslzchen Jan 9, 2025
2a8df88
Fix preprint contributor
cslzchen Jan 9, 2025
1aa3169
Implement preprint-action-list filtering on versioned _id
cslzchen Jan 10, 2025
73dc626
Implement review-action-list filtering on versioned _id
cslzchen Jan 10, 2025
96ca301
Fix tests where pending submit is allowed for post-moderation
cslzchen Jan 10, 2025
bc6ceae
Merge pull request #10906 from cslzchen/feature/fix-perm-and-contrib
cslzchen Jan 10, 2025
a5b4e05
Merge pull request #10905 from cslzchen/feature/fix-api-filters
cslzchen Jan 10, 2025
35d70c8
updated preprint filters
Ostap-Zherebetskyi Jan 10, 2025
4182a15
revert commit 45d7615 changes
Ostap-Zherebetskyi Jan 10, 2025
8bc1b00
Merge pull request #10907 from Ostap-Zherebetskyi/fix/preprint_filters
cslzchen Jan 10, 2025
3feb1d2
Fix ClaimUser view to support versioned preprint
cslzchen Jan 10, 2025
5eb448c
Merge pull request #10909 from cslzchen/feature/fix-claim-user-api
cslzchen Jan 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions addons/base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ def decrypt_and_decode_jwt_payload():


def get_authenticated_resource(resource_id):
resource = AbstractNode.load(resource_id) or Preprint.load(resource_id)
resource, _ = Guid.load_referent(resource_id)

if not resource:
raise HTTPError(http_status.HTTP_404_NOT_FOUND, message='Resource not found.')

Expand Down Expand Up @@ -390,8 +391,7 @@ def get_auth(auth, **kwargs):
waterbutler_data = decrypt_and_decode_jwt_payload()

# Authenticate the resource based on the node_id and handle potential draft nodes
resource = get_authenticated_resource(waterbutler_data['nid'])

resource = get_authenticated_resource(waterbutler_data.get('nid'))
# Authenticate the user using cookie or Oauth if possible
authenticate_user_if_needed(auth, waterbutler_data, resource)

Expand Down Expand Up @@ -529,9 +529,9 @@ def create_waterbutler_log(payload, **kwargs):
auth = payload['auth']
# Don't log download actions
if payload['action'] in DOWNLOAD_ACTIONS:
guid = Guid.load(payload['metadata'].get('nid'))
if guid:
node = guid.referent
guid_id = payload['metadata'].get('nid')

node, _ = Guid.load_referent(guid_id)
return {'status': 'success'}

user = OSFUser.load(auth['id'])
Expand Down Expand Up @@ -890,7 +890,7 @@ def addon_view_or_download_file(auth, path, provider, **kwargs):
extras.pop('_', None) # Clean up our url params a bit
action = extras.get('action', 'view')
guid = kwargs.get('guid')
guid_target = getattr(Guid.load(guid), 'referent', None)
guid_target, _ = Guid.load_referent(guid)
target = guid_target or kwargs.get('node') or kwargs['project']

provider_safe = markupsafe.escape(provider)
Expand Down
8 changes: 5 additions & 3 deletions addons/osfstorage/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def load_guid_as_target(func):

@functools.wraps(func)
def wrapped(*args, **kwargs):
guid = kwargs.get('guid')
target = getattr(Guid.load(guid), 'referent', None)
target, _ = Guid.load_referent(kwargs.get('guid'))

if not target:
raise HTTPError(
http_status.HTTP_404_NOT_FOUND,
Expand Down Expand Up @@ -88,7 +88,9 @@ def wrapped(payload, *args, **kwargs):
user = OSFUser.load(payload['user'])
# Waterbutler is sending back ['node'] under the destination payload - WB should change to target
target = payload['destination'].get('target') or payload['destination'].get('node')
dest_target = Guid.load(target).referent
dest_target, _ = Guid.load_referent(target)
if not dest_target:
raise HTTPError(http_status.HTTP_404_NOT_FOUND)
source = OsfStorageFileNode.get(payload['source'], kwargs['target'])
dest_parent = OsfStorageFolder.get(payload['destination']['parent'], dest_target)

Expand Down
2 changes: 1 addition & 1 deletion addons/osfstorage/listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def checkin_files_task(node_id, user_id):
Guid = apps.get_model('osf.Guid')
OSFUser = apps.get_model('osf.OSFUser')

node = Guid.load(node_id).referent
node, _ = Guid.load_referent(node_id)
assert isinstance(node, (AbstractNode, Preprint))
user = OSFUser.load(user_id)

Expand Down
6 changes: 3 additions & 3 deletions addons/osfstorage/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from framework.celery_tasks import app
from framework.postcommit_tasks.handlers import enqueue_postcommit_task
from framework.sessions import get_session
from osf.models import BaseFileNode, Guid
from osf.models import BaseFileNode, Guid, Preprint

from addons.osfstorage import settings

Expand All @@ -21,7 +21,7 @@ def enqueue_update_analytics(node, file, version_idx, action='download'):

@app.task(max_retries=5, default_retry_delay=60)
def update_analytics_async(node_id, file_id, version_idx, session_key=None, action='download'):
node = Guid.load(node_id).referent
node, _ = Guid.load_referent(node_id)
file = BaseFileNode.load(file_id)
update_analytics(node, file, version_idx, session_key, action)

Expand All @@ -43,7 +43,7 @@ def update_analytics(node, file, version_idx, session_key, action='download'):
node_info = {
'contributors': contributors
}
resource = node.guids.first()
resource = node.get_guid() if isinstance(node, Preprint) else node.guids.first()
cslzchen marked this conversation as resolved.
Show resolved Hide resolved

update_counter(resource, file, version=None, action=action, node_info=node_info, session_key=session_key)
update_counter(resource, file, version_idx, action, node_info=node_info, session_key=session_key)
Expand Down
5 changes: 4 additions & 1 deletion addons/osfstorage/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,12 @@ def osfstorage_get_metadata(file_node, **kwargs):
@decorators.autoload_filenode(must_be='folder')
def osfstorage_get_children(file_node, **kwargs):
from django.contrib.contenttypes.models import ContentType
from osf.models.preprint import Preprint
user_id = request.args.get('user_id')
user_content_type_id = ContentType.objects.get_for_model(OSFUser).id
user_pk = OSFUser.objects.filter(guids___id=user_id, guids___id__isnull=False).values_list('pk', flat=True).first()
guid_id = file_node.target.get_guid().id if isinstance(file_node.target, Preprint) else file_node.target.guids.first().id,

with connection.cursor() as cursor:
# Read the documentation on FileVersion's fields before reading this code
Comment on lines +194 to 197
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There maybe a problem here for preprints because it only use the base guid. Need to double check on staging2 when FE is merged.

cursor.execute("""
Expand Down Expand Up @@ -281,7 +284,7 @@ def osfstorage_get_children(file_node, **kwargs):
AND (NOT F.type IN ('osf.trashedfilenode', 'osf.trashedfile', 'osf.trashedfolder'))
""", [
user_content_type_id,
file_node.target.guids.first().id,
guid_id,
user_pk,
user_pk,
user_id,
Expand Down
30 changes: 15 additions & 15 deletions admin/preprints/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@
re_path(r'^known_spam$', views.PreprintKnownSpamList.as_view(), name='known-spam'),
re_path(r'^known_ham$', views.PreprintKnownHamList.as_view(), name='known-ham'),
re_path(r'^withdrawal_requests$', views.PreprintWithdrawalRequestList.as_view(), name='withdrawal-requests'),
re_path(r'^(?P<guid>[a-z0-9]+)/$', views.PreprintView.as_view(), name='preprint'),
re_path(r'^(?P<guid>[a-z0-9]+)/change_provider/$', views.PreprintProviderChangeView.as_view(), name='preprint-provider'),
re_path(r'^(?P<guid>[a-z0-9]+)/machine_state/$', views.PreprintMachineStateView.as_view(), name='preprint-machine-state'),
re_path(r'^(?P<guid>[a-z0-9]+)/reindex_share_preprint/$', views.PreprintReindexShare.as_view(),
re_path(r'^(?P<guid>[A-Za-z0-9_]+)/$', views.PreprintView.as_view(), name='preprint'),
cslzchen marked this conversation as resolved.
Show resolved Hide resolved
re_path(r'^(?P<guid>[A-Za-z0-9_]+)/change_provider/$', views.PreprintProviderChangeView.as_view(), name='preprint-provider'),
re_path(r'^(?P<guid>[A-Za-z0-9_]+)/machine_state/$', views.PreprintMachineStateView.as_view(), name='preprint-machine-state'),
re_path(r'^(?P<guid>[A-Za-z0-9_]+)/reindex_share_preprint/$', views.PreprintReindexShare.as_view(),
name='reindex-share-preprint'),
re_path(r'^(?P<guid>[a-z0-9]+)/remove_user/(?P<user_id>[a-z0-9]+)/$', views.PreprintRemoveContributorView.as_view(),
re_path(r'^(?P<guid>[A-Za-z0-9_]+)/remove_user/(?P<user_id>[a-z0-9]+)/$', views.PreprintRemoveContributorView.as_view(),
name='remove-user'),
re_path(r'^(?P<guid>[a-z0-9]+)/make_private/$', views.PreprintMakePrivate.as_view(), name='make-private'),
re_path(r'^(?P<guid>[a-z0-9]+)/make_public/$', views.PreprintMakePublic.as_view(), name='make-public'),
re_path(r'^(?P<guid>[a-z0-9]+)/remove/$', views.PreprintDeleteView.as_view(), name='remove'),
re_path(r'^(?P<guid>[a-z0-9]+)/restore/$', views.PreprintDeleteView.as_view(), name='restore'),
re_path(r'^(?P<guid>[a-z0-9]+)/confirm_unflag/$', views.PreprintConfirmUnflagView.as_view(), name='confirm-unflag'),
re_path(r'^(?P<guid>[a-z0-9]+)/confirm_spam/$', views.PreprintConfirmSpamView.as_view(), name='confirm-spam'),
re_path(r'^(?P<guid>[a-z0-9]+)/confirm_ham/$', views.PreprintConfirmHamView.as_view(), name='confirm-ham'),
re_path(r'^(?P<guid>[a-z0-9]+)/reindex_elastic_preprint/$', views.PreprintReindexElastic.as_view(),
re_path(r'^(?P<guid>[A-Za-z0-9_]+)/make_private/$', views.PreprintMakePrivate.as_view(), name='make-private'),
re_path(r'^(?P<guid>[A-Za-z0-9_]+)/make_public/$', views.PreprintMakePublic.as_view(), name='make-public'),
re_path(r'^(?P<guid>[A-Za-z0-9_]+)/remove/$', views.PreprintDeleteView.as_view(), name='remove'),
re_path(r'^(?P<guid>[A-Za-z0-9_]+)/restore/$', views.PreprintDeleteView.as_view(), name='restore'),
re_path(r'^(?P<guid>[A-Za-z0-9_]+)/confirm_unflag/$', views.PreprintConfirmUnflagView.as_view(), name='confirm-unflag'),
re_path(r'^(?P<guid>[A-Za-z0-9_]+)/confirm_spam/$', views.PreprintConfirmSpamView.as_view(), name='confirm-spam'),
re_path(r'^(?P<guid>[A-Za-z0-9_]+)/confirm_ham/$', views.PreprintConfirmHamView.as_view(), name='confirm-ham'),
re_path(r'^(?P<guid>[A-Za-z0-9_]+)/reindex_elastic_preprint/$', views.PreprintReindexElastic.as_view(),
name='reindex-elastic-preprint'),
re_path(r'^(?P<guid>[a-z0-9]+)/approve_withdrawal/$', views.PreprintApproveWithdrawalRequest.as_view(),
re_path(r'^(?P<guid>[A-Za-z0-9_]+)/approve_withdrawal/$', views.PreprintApproveWithdrawalRequest.as_view(),
name='approve-withdrawal'),
re_path(r'^(?P<guid>[a-z0-9]+)/reject_withdrawal/$', views.PreprintRejectWithdrawalRequest.as_view(),
re_path(r'^(?P<guid>[A-Za-z0-9_]+)/reject_withdrawal/$', views.PreprintRejectWithdrawalRequest.as_view(),
name='reject-withdrawal'),
]
5 changes: 3 additions & 2 deletions admin/preprints/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
class PreprintMixin(PermissionRequiredMixin):

def get_object(self):
preprint = Preprint.objects.get(guids___id=self.kwargs['guid'])
preprint = Preprint.load(self.kwargs['guid'])
# Django template does not like attributes with underscores for some reason
preprint.guid = preprint._id
return preprint
Expand Down Expand Up @@ -324,9 +324,10 @@ class WithdrawalRequestMixin(PermissionRequiredMixin):
permission_required = 'osf.change_preprintrequest'

def get_object(self):
target = Preprint.load(self.kwargs['guid'])
return PreprintRequest.objects.filter(
request_type='withdrawal',
target__guids___id=self.kwargs['guid'],
target=target,
).first()

def get_success_url(self):
Expand Down
4 changes: 2 additions & 2 deletions api/actions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from api.actions.permissions import ReviewActionPermission
from api.actions.serializers import NodeRequestActionSerializer, ReviewActionSerializer, PreprintRequestActionSerializer
from api.base.exceptions import Conflict
from api.base.filters import ListFilterMixin
from api.base.filters import ReviewActionFilterMixin
from api.base.views import JSONAPIBaseView
from api.base.parsers import (
JSONAPIMultipleRelationshipsParser,
Expand Down Expand Up @@ -110,7 +110,7 @@ def get_object(self):
return action


class ReviewActionListCreate(JSONAPIBaseView, generics.ListCreateAPIView, ListFilterMixin):
class ReviewActionListCreate(JSONAPIBaseView, generics.ListCreateAPIView, ReviewActionFilterMixin):
"""List of review actions viewable by this user

Actions represent state changes and/or comments on a reviewable object (e.g. a preprint)
Expand Down
86 changes: 80 additions & 6 deletions api/base/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from rest_framework import serializers as ser
from rest_framework.filters import OrderingFilter
from osf.models import Subject, Preprint
from osf.models.base import GuidMixin
from osf.models.base import GuidMixin, Guid
from functools import cmp_to_key

def lowercase(lower):
Expand Down Expand Up @@ -568,24 +568,98 @@ def get_serializer_method(self, field_name):


class PreprintFilterMixin(ListFilterMixin):
"""View mixin that uses ListFilterMixin, adding postprocessing for preprint querying
"""View mixin for many preprint listing views. It inherits from ListFilterMixin and customize postprocessing for
preprint querying by provider, subjects and versioned `_id`.

Subclasses must define `get_default_queryset()`.
Note: Subclasses must define `get_default_queryset()`.
"""

@staticmethod
def postprocess_versioned_guid_id_query_param(operation):
"""Handle query parameters when filtering on `_id` for preprint which are now versioned.

Note: preprint achieves versioning by using versioned guid, and thus no long has guid or guid._id for every
version. Must convert `guid___id__in=` look-up to `pk__in` look-up.
"""
preprint_pk_list = []
for val in operation['value']:
referent, version = Guid.load_referent(val)
if referent is None:
continue
preprint_pk_list.append(referent.id)
# Override the operation to filter `id__in=preprint_pk_list`
operation['source_field_name'] = 'id__in'
operation['value'] = preprint_pk_list
operation['op'] = 'eq'

def postprocess_query_param(self, key, field_name, operation):
if field_name == 'provider':
operation['source_field_name'] = 'provider___id'

if field_name == 'id':
operation['source_field_name'] = 'guids___id'
PreprintFilterMixin.postprocess_versioned_guid_id_query_param(operation)

if field_name == 'subjects':
self.postprocess_subject_query_param(operation)

def preprints_queryset(self, base_queryset, auth_user, allow_contribs=True, public_only=False):
return Preprint.objects.can_view(
def preprints_queryset(self, base_queryset, auth_user, allow_contribs=True, public_only=False, latest_only=False):
preprints = Preprint.objects.can_view(
base_queryset=base_queryset,
user=auth_user,
allow_contribs=allow_contribs,
public_only=public_only,
)
if latest_only:
preprints = preprints.filter(guids__isnull=False)
return preprints


class PreprintActionFilterMixin(ListFilterMixin):
"""View mixin for `PreprintActionList`. It inherits from `ListFilterMixin` and customize postprocessing for
versioned preprint.

Note: Subclasses must define `get_default_queryset()`.
"""

@staticmethod
def postprocess_versioned_guid_target_query_param(operation):
"""When target is a preprint, which must be versioned, the traditional non-versioned `guid___id==target`
look-up no longer works. Must convert to PK look-up `referent__id==pk`.
"""
referent, version = Guid.load_referent(operation['value'])
# A valid preprint must have referent and version
if not referent or not version:
return
# Override the operation to filter `target__id=target.pk`
operation['source_field_name'] = 'target__id'
operation['value'] = referent.id
operation['op'] = 'eq'

def postprocess_query_param(self, key, field_name, operation):
"""Handles a special case when filtering on `target`.
"""
if field_name == 'target':
PreprintActionFilterMixin.postprocess_versioned_guid_target_query_param(operation)
else:
super().postprocess_query_param(key, field_name, operation)

class ReviewActionFilterMixin(ListFilterMixin):
"""View mixin for `ReviewActionListCreate`. It inherits from `ListFilterMixin` and uses `PreprintActionFilterMixin`
to customized postprocessing for handling versioned preprint.

Note: Subclasses must define `get_default_queryset()`.
"""
def postprocess_query_param(self, key, field_name, operation):
"""Handles a special case when filtering on `target` and when `target` is a versioned Preprint.
"""
if field_name == 'target':
referent, version = Guid.load_referent(operation['value'])
if referent:
if version:
PreprintActionFilterMixin.postprocess_versioned_guid_target_query_param(operation)
else:
super().postprocess_query_param(key, field_name, operation)
else:
return
else:
super().postprocess_query_param(key, field_name, operation)
3 changes: 1 addition & 2 deletions api/base/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ def get_paginated_response(self, data):
class PreprintContributorPagination(NodeContributorPagination):

def get_resource(self, kwargs):
resource_id = kwargs.get('preprint_id')
return Preprint.load(resource_id)
return Preprint.load(kwargs.get('preprint_id'))


class DraftRegistrationContributorPagination(NodeContributorPagination):
Expand Down
10 changes: 8 additions & 2 deletions api/base/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from framework.auth import Auth
from framework.auth.cas import CasResponse
from framework.auth.oauth_scopes import ComposedScopes, normalize_scopes
from osf.models.base import GuidMixin
from osf.models.base import GuidMixin, VersionedGuidMixin
from osf.utils.requests import check_select_for_update
from website import settings as website_settings
from website import util as website_util # noqa
Expand Down Expand Up @@ -103,7 +103,13 @@ def get_object_or_error(model_or_qs, query_or_pk=None, request=None, display_nam
raise NotFound

elif isinstance(query_or_pk, str):
# they passed a 5-char guid as a string
# If the class is a subclass of `VersionedGuidMixin`, get obj directly from model using `.load()`. The naming
# for `query_or_pk` no longer matches the actual case. It is neither a query nor a pk, but a guid str.
if issubclass(model_cls, VersionedGuidMixin):
obj = model_cls.load(query_or_pk, select_for_update=select_for_update)
# If the class is a subclass of `GuidMixin` (except for `VersionedGuidMixin`), turn it into a query dictionary.
# The naming for `query_or_pk` no longer matches the actual case either. It is neither a query nor a pk, but a
# 5-char guid str. We should be able to use the `.load()` the same way as in the `VersionedGuidMixin` case.
if issubclass(model_cls, GuidMixin):
# if it's a subclass of GuidMixin we know it's primary_identifier_name
query = {'guids___id': query_or_pk}
Expand Down
4 changes: 2 additions & 2 deletions api/chronos/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
urlpatterns = [
re_path(r'^journals/$', views.ChronosJournalList.as_view(), name=views.ChronosJournalList.view_name),
re_path(r'^journals/(?P<journal_id>[-0-9A-Za-z]+)/$', views.ChronosJournalDetail.as_view(), name=views.ChronosJournalDetail.view_name),
re_path(r'^(?P<preprint_id>\w+)/submissions/$', views.ChronosSubmissionList.as_view(), name=views.ChronosSubmissionList.view_name),
re_path(r'^(?P<preprint_id>\w+)/submissions/(?P<submission_id>[-0-9A-Za-z]+)/$', views.ChronosSubmissionDetail.as_view(), name=views.ChronosSubmissionDetail.view_name),
re_path(r'^(?P<preprint_id>[A-Za-z0-9_]+)/submissions/$', views.ChronosSubmissionList.as_view(), name=views.ChronosSubmissionList.view_name),
re_path(r'^(?P<preprint_id>[A-Za-z0-9_]+)/submissions/(?P<submission_id>[-0-9A-Za-z]+)/$', views.ChronosSubmissionDetail.as_view(), name=views.ChronosSubmissionDetail.view_name),
cslzchen marked this conversation as resolved.
Show resolved Hide resolved
]
5 changes: 3 additions & 2 deletions api/chronos/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ def get_serializer_class(self):

def get_default_queryset(self):
user = get_user_auth(self.request).user
preprint_contributors = Preprint.load(self.kwargs['preprint_id'])._contributors
queryset = ChronosSubmission.objects.filter(preprint__guids___id=self.kwargs['preprint_id'])
preprint = Preprint.load(self.kwargs['preprint_id'])
preprint_contributors = preprint._contributors
cslzchen marked this conversation as resolved.
Show resolved Hide resolved
queryset = ChronosSubmission.objects.filter(preprint=preprint)

# Get the list of stale submissions and queue a task to update them
update_list_id = queryset.filter(
Expand Down
Loading
Loading