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

[Need QA Prep] Feature/The Node-Preprint Divorce [PLAT-555][PLAT-480][PLAT-559][PLAT-561][PLAT-1168] #8640

Closed
Closed
Show file tree
Hide file tree
Changes from 191 commits
Commits
Show all changes
238 commits
Select commit Hold shift + click to select a range
eec5f53
Copy over all necessary behavior to preprint
Mar 12, 2018
b9af62b
Add PreprintContributor model
Mar 12, 2018
4887176
Add missing imports
Mar 12, 2018
6fa68dd
Update references from Contributor to PreprintContributor
Mar 12, 2018
a3c8ab6
Comment out logs for now, fix naming in methods (node->preprint)
Mar 12, 2018
61cffe0
Comment out more logs for now
Mar 12, 2018
e710244
Build migration template
Mar 12, 2018
2b936ca
Write initial versions of migrations
Mar 12, 2018
3765e3d
Copy over relevant contributor tests from node tests
Mar 12, 2018
2a07f1f
Update tests to reference preprints instead of nodes
Mar 12, 2018
49ea52f
Optimize preprint updates
Mar 13, 2018
d8bda8f
Fix tests, add missing imports, fix nonexistent variable references
Mar 15, 2018
54ac459
Update tests
Mar 19, 2018
592d480
finish most change and add migrations
chennan47 Mar 20, 2018
d7abc9b
permission change
chennan47 Mar 20, 2018
8acd0e8
Update preprint model to pass more tests
Mar 20, 2018
64b6590
Merge branch 'feature/node-preprint-divorce-models' into feature/node…
cameronblandford Mar 20, 2018
4d9434f
Merge pull request #3 from chennan47/feature/node-preprint
cameronblandford Mar 20, 2018
21ad0dd
Revert "Merge pull request #3 from chennan47/feature/node-preprint"
Mar 20, 2018
5a44492
fix test
chennan47 Mar 22, 2018
29b1ed2
merge
chennan47 Mar 23, 2018
5e8b821
Update data migration
Mar 26, 2018
44e0b7c
Change node refs to preprint refs in model methods
Mar 26, 2018
e3d926c
update the script
chennan47 Mar 26, 2018
86f3622
wip
chennan47 Mar 26, 2018
b3544bc
a bit refine
chennan47 Mar 27, 2018
e1df58a
improve permission class
chennan47 Mar 27, 2018
5e052f1
change
chennan47 Mar 27, 2018
64502e9
finish refactor code
chennan47 Mar 27, 2018
69c64c1
fix flake 8
chennan47 Mar 27, 2018
9260275
fix migrations
chennan47 Mar 27, 2018
bdf8597
merge
chennan47 Mar 27, 2018
961378c
merge migration
chennan47 Mar 27, 2018
f274c4e
fix null value for description
chennan47 Mar 27, 2018
3af2b2f
fix flake 8
chennan47 Mar 27, 2018
2cdd3f9
remove the save
chennan47 Mar 28, 2018
750f64e
fix set up
chennan47 Mar 28, 2018
dad2424
try save again
chennan47 Mar 28, 2018
f7efea8
move when the contributor is created
chennan47 Mar 28, 2018
62cc3c5
remove debug
chennan47 Mar 28, 2018
c7aac6d
merge
chennan47 Mar 28, 2018
7ba9757
some code fix
chennan47 Mar 28, 2018
2514170
fix for migration script and change the naming for admin preprint per…
chennan47 Apr 3, 2018
5fc9320
finish fix for other than migration script
chennan47 Apr 3, 2018
75ec7c0
merge
chennan47 Apr 3, 2018
5e991c9
small merge fix
chennan47 Apr 3, 2018
a7df58a
update the migration script
chennan47 Apr 18, 2018
a2acafc
fix the migration script for permission group
chennan47 Apr 18, 2018
c1c9139
reponse to code review
chennan47 Apr 24, 2018
cce8387
Start migration cleanup.
pattisdr May 1, 2018
41f1992
Modify PreprintContributor model so read, write, and admin are no lon…
pattisdr May 2, 2018
5bc0715
Modeling changes for NodePreprint divorce.
pattisdr May 2, 2018
f7fbd07
Rename PreprintService model to Preprint model, add migrations for Pr…
pattisdr May 2, 2018
03e494d
Add a data migration for adding the users from the old preprintservic…
pattisdr May 3, 2018
359bea7
Add an add_preprint_log method in the LoggableMixin and add logging t…
pattisdr May 3, 2018
683bebe
Add spam checks on preprint title and description and update elastic …
pattisdr May 3, 2018
5dd0fcc
Add partial index on node and provider where node is not null.
pattisdr May 3, 2018
7d6500d
Add population of new preprint fields to node-preprint divorce data m…
pattisdr May 3, 2018
9d08390
Add newest preprint fields to data migration and add reverse migratio…
pattisdr May 3, 2018
a7564b2
Start efforts on migrating preprint date modified off of node, and up…
pattisdr May 4, 2018
299c6a6
Merge branch 'review/erin/upload_to_anything' into feature/node-preprint
pattisdr May 5, 2018
0011ae1
Merge files on anything work, shuffle around migrations.
pattisdr May 6, 2018
cf523c9
Restore UploadMixin from @erinspace commit 0074c6036f7b8043a9c91f1eb8…
pattisdr May 7, 2018
477c4e0
Modifications to get file uploading to a preprint semi working.
pattisdr May 8, 2018
4d745fa
Add tests for preprint properties.
pattisdr May 8, 2018
0153f4a
Add some preprint model tests, correct issues on preprint model where…
pattisdr May 10, 2018
5d376e2
Add spam tests for preprint and improve spam methods on Preprint model.
pattisdr May 11, 2018
335482a
Move more node model tests over to preprints.
pattisdr May 11, 2018
73a12d7
Modify existing preprint tests tests/test_preprints.py to reflect tha…
pattisdr May 14, 2018
bc42ab1
Update elastic search after saving title, description, preprint_file,…
pattisdr May 14, 2018
30b1cd7
Add _is_preprint_orphan and _has_abandoned_preprint fields to the Pre…
pattisdr May 14, 2018
21af518
Remove newly added preprint signals and use existing contributor_adde…
pattisdr May 15, 2018
aefdc8b
Modify is_preprint_primary methods on OstStorageFile to be looking fo…
pattisdr May 15, 2018
782cd09
Check to see if file target has is_deleted, archiving, or deleted att…
pattisdr May 15, 2018
2596109
Modify has_permission to see if user is in a specific group instead o…
pattisdr May 15, 2018
1f52890
Revert has_permission on the model to use has_perm instead of checkin…
pattisdr May 15, 2018
786efab
Revert temporary changes to test_module.
pattisdr May 15, 2018
a631f84
Consolidate preprint model tests in osf_tests/test_preprint.py
pattisdr May 15, 2018
9a4f380
API changes for Node-Preprint Divorce - making a preprint distinct fr…
pattisdr May 15, 2018
487cc06
Allow creating/updating preprints via APIv2 without requiring a node.
pattisdr May 17, 2018
2cb6eb1
Modify APIv2 preprint tests regarding separating preprint from node a…
pattisdr May 18, 2018
1c9bca8
Node-preprint divorce tests changes - reflecting that important infor…
pattisdr May 21, 2018
8de7274
Change serialization of preprints in admin app.
pattisdr May 21, 2018
10f8ee9
Add tests for osfstorage hooks for moving preprints files.
pattisdr May 22, 2018
b4dd2ba
Allow notificationsubscription to store preprint.
pattisdr May 22, 2018
1d5e556
When looking at addon_view_or_download_file, only fetch addon if it i…
pattisdr May 22, 2018
7f3625c
Add a Preprint > Files API v2 relationship and make osfstorage files …
pattisdr May 23, 2018
559f330
Fix old error where permissions were not being checked on IdentifierD…
pattisdr May 24, 2018
74d1f43
Remove _has_abandoned_preprint and _is_preprint_orphan fields from pr…
pattisdr May 25, 2018
b26a418
Optimizations and changes from code review
erinspace May 24, 2018
707338a
Verifying API Permissions.
pattisdr May 25, 2018
81df85a
Add PreprintCitationDetail and PreprintCitationStyleDetail GET permis…
pattisdr May 25, 2018
dfd860f
Add permission tests for accessing a primary file in the preprint.
pattisdr May 25, 2018
7404167
Restrict preprint files list endpoint so only primary file is returne…
pattisdr May 25, 2018
0a0133a
Add more tests for filtering nodes for preprints - preprints must be …
pattisdr May 29, 2018
6084402
Add PreprintProvidersList endpoint that displays osfstorage provider …
pattisdr May 29, 2018
f9130da
Move attaching node to preprint to update method instead of create me…
pattisdr May 29, 2018
0b20771
Improve preprint filtering on nodes to use the same logic as api/base…
pattisdr May 29, 2018
3abb6d2
Deprecate prepriint field on node and node_is_public on preprint.
pattisdr May 29, 2018
8e2f286
Add preprint-specific scopes to preprint views now that node and prep…
pattisdr May 30, 2018
2401b34
Merge erinspace/upload_to_anything.
pattisdr May 30, 2018
55e4aa6
Move setting supplemental project to preprint model.
pattisdr May 31, 2018
3b19ded
Expand write user preprint permissions and prevent filtering on depre…
pattisdr May 31, 2018
a80eb24
Update preprint write permissions so they can now edit many aspects o…
pattisdr Jun 1, 2018
a271afb
Update default region on a preprint to be the user settings region of…
pattisdr Jun 1, 2018
c249c46
Make preprints elasticsearch changes.
pattisdr Jun 1, 2018
5c0ad7a
Add some osfstorage tests for preprints.
pattisdr Jun 1, 2018
9ce1407
Hide comment links on file if file is a preprint file.
pattisdr Jun 1, 2018
8fe6b06
Modify create_waterbutler_log to work for preprints as well.
pattisdr Jun 2, 2018
ef37d25
Merge erinspace/uploads_to_anything.
pattisdr Jun 3, 2018
6d057f2
Update preprint_node_divorce data migration to add new fields we need…
pattisdr Jun 3, 2018
9800776
Fix items mixed in erinspace/upload_to_anything merge with node_prepr…
pattisdr Jun 3, 2018
b588d06
Attempt to not override preprint auto_now field.
pattisdr Jun 4, 2018
a07612a
Node-Preprint data migration fixes.
pattisdr Jun 4, 2018
4a05388
DRY node-preprint divorce code.
pattisdr Jun 5, 2018
df7ce38
Consolidate contributor methods on the node and preprint models into …
pattisdr Jun 6, 2018
7fed2aa
Non-Ember Frontend Changes for Node/Preprint Divorce
pattisdr Jun 7, 2018
ef620d7
Remove preprint-related model fields off of the Node.
pattisdr Jun 8, 2018
99c8e17
Merge branch 'files-on-anything' into feature/node-preprint and add m…
pattisdr Jun 8, 2018
5b9de71
Preprints Elastic Search updates.
pattisdr Jun 11, 2018
e8334b9
Handle case where a node doesn't have a preprint file when migrating …
pattisdr Jun 12, 2018
9c75c2e
Optimize node-preprint divorce in SQL.
pattisdr Jun 13, 2018
751e409
Small CR changes for node-preprint divorce.
pattisdr Jun 18, 2018
187544d
Modify waterbutler v2 MoveFileMetadataView and CopyFileMetadataView t…
pattisdr Jun 18, 2018
bf2a65b
Modify waterbulter_opt_hook, as there is a discrepancy between what w…
pattisdr Jun 19, 2018
3da67e3
Self-review tweaks to node-preprint divorce.
pattisdr Jun 19, 2018
be1730b
Merge feature/files-on-anything. Rearrange migrations, update spam c…
pattisdr Jun 20, 2018
868e523
Reverse order of nested fields. Wrap ShowIfVersion around HideIfWith…
pattisdr Jun 20, 2018
8dbcdf3
Remove retracted from verified_publishable definition.
pattisdr Jun 20, 2018
f273714
Modify project page preprint banner to more closely match collections…
pattisdr Jun 20, 2018
c5ae763
Add preprints withdrawn filters to preprint queries.
pattisdr Jun 21, 2018
21a666f
Prevent non-contributors from accessing preprint files on withdrawn p…
pattisdr Jun 22, 2018
6fb747b
- Code review cleanup.
pattisdr Jun 26, 2018
ff4d533
Node-preprint divorce code review cleanup.
pattisdr Jun 27, 2018
ad917a3
Move more class-checking logic off of methods on addons/base/views to…
pattisdr Jun 28, 2018
981b0af
- Add bulk updating files for elastic search migration
pattisdr Jun 29, 2018
0c872a8
More NPD CR changes:
pattisdr Jul 2, 2018
05f0403
Merge branch 'feature/files-on-anything' of https://github.com/Center…
pattisdr Jul 4, 2018
8601f2c
Merge branch 'feature/files-on-anything' of https://github.com/Center…
pattisdr Jul 5, 2018
77b5d51
Mock different mail call.
pattisdr Jul 5, 2018
44b3346
Change mocking on preprint tests; osf_admin_change_status_identifier …
pattisdr Jul 5, 2018
80eb0ba
Revert `update_or_enqueue_on_preprint_updated` to call postcommit tasks.
pattisdr Jul 5, 2018
7082dad
Return date_published as issued date for preprints, otherwise omit th…
pattisdr Jul 13, 2018
1fce58c
Merge branch 'feature/files-on-anything' of https://github.com/Center…
pattisdr Jul 13, 2018
d84be3c
Remove unneeded merge migration (pulled files-on-anything just added)…
pattisdr Jul 16, 2018
446ec83
Remove constraint of one preprint per provider per node.
pattisdr Jul 27, 2018
4453504
Merge branch 'develop' of https://github.com/CenterForOpenScience/osf…
pattisdr Aug 17, 2018
0d7f237
Merge branch 'develop' of https://github.com/CenterForOpenScience/osf…
pattisdr Aug 18, 2018
5c5598d
Merge branch 'develop' of https://github.com/CenterForOpenScience/osf…
pattisdr Sep 6, 2018
b97a5d7
Merge branch 'develop' of https://github.com/CenterForOpenScience/osf…
pattisdr Sep 6, 2018
3f790cd
Make fetch_from_waterbutler more generic so it will work with preprints.
pattisdr Sep 13, 2018
69af1b9
Merge branch 'develop' of https://github.com/CenterForOpenScience/osf…
pattisdr Sep 17, 2018
8b113a7
Add osfstorage region property to preprint model and fix `get_auth` m…
pattisdr Sep 17, 2018
73205ef
Remove bad tests added in merge.
pattisdr Sep 17, 2018
5d90f5c
Modify test to expect new response.
pattisdr Sep 17, 2018
9e227ed
Merge branch 'develop' into feature/node-preprint
sloria Sep 18, 2018
4e538a5
Increase title validator to allow 512 characters.
pattisdr Sep 22, 2018
0ef54f2
Merge branch 'feature/node-preprint' of https://github.com/pattisdr/o…
pattisdr Sep 22, 2018
de0e684
Create primary_file guid when it is set on the preprint. Currently n…
pattisdr Sep 23, 2018
44a5b95
Adjust tests regarding maximum node title length being increased to 5…
pattisdr Sep 23, 2018
0c48998
Merge branch 'develop' of https://github.com/CenterForOpenScience/osf…
pattisdr Sep 24, 2018
60d0877
Shift migrations.
pattisdr Sep 24, 2018
45aa40d
Add PreprintNodeRelationship endpoint so the node can be unset from t…
pattisdr Sep 24, 2018
3cb6e1d
Expose node relationship self link on preprints serializer.
pattisdr Sep 25, 2018
b164de8
Merge branch 'develop' of https://github.com/CenterForOpenScience/osf…
pattisdr Sep 26, 2018
a520e94
Move migrations forward.
pattisdr Sep 26, 2018
ee9bb30
Allow unsetting the original_publication_date, for when the date was …
pattisdr Sep 30, 2018
90eb793
Add more backend preprint node divorce tweaks:
pattisdr Oct 1, 2018
d71655e
Modify _kwargs_to_nodes so preprints can be loaded.
pattisdr Oct 2, 2018
7d26297
Minor bug fixing:
pattisdr Oct 2, 2018
b7d8e77
Merge branch 'develop' of https://github.com/CenterForOpenScience/osf…
pattisdr Oct 2, 2018
2609f89
Fix node regions -> preprint regions not being properly migrated.
pattisdr Oct 3, 2018
bd0fd1a
Get_resource for context data errors are not bubbling, and causing 50…
pattisdr Oct 3, 2018
94477f9
Merge branch 'develop' of https://github.com/CenterForOpenScience/osf…
pattisdr Oct 3, 2018
cd772b2
Call get_resource instead of get_node so view can be shared with prep…
pattisdr Oct 4, 2018
8427dad
Allow adding an unregistered contributor with a guid/fullname combo.
pattisdr Oct 4, 2018
f7d0dbe
Modify preprint divorce migration to only migrate over node spam if p…
pattisdr Oct 5, 2018
f4517f3
Remove abandoned preprints from MyProjects page.
pattisdr Oct 5, 2018
6e4c695
Fix Celery=True issues.
pattisdr Oct 5, 2018
51f5d41
Merge branch 'develop' of https://github.com/CenterForOpenScience/osf…
pattisdr Oct 5, 2018
3556297
surface error message so that it does not simply say 500
adlius Oct 5, 2018
bf594e7
Fix tests.
pattisdr Oct 5, 2018
7fa345e
Don't check if doi exists before calling update_or_enqueue_on_resourc…
pattisdr Oct 10, 2018
b9134bc
Merge branch 'develop' of https://github.com/CenterForOpenScience/osf…
pattisdr Oct 11, 2018
1d8b541
Rollback check for self.get_identifier_value('doi') before calling u…
pattisdr Oct 11, 2018
46ea8b8
change email template
adlius Oct 11, 2018
eff8f52
Merge branch 'feature/node-preprint' into feature/claim-user
adlius Oct 11, 2018
b7548f7
Merge pull request #14 from adlius/feature/node-preprint
pattisdr Oct 11, 2018
5759acc
Tweaks to legacy divorce delete and private warnings.
pattisdr Oct 11, 2018
04fc03c
Merge branch 'feature/node-preprint' of https://github.com/pattisdr/o…
pattisdr Oct 11, 2018
32862b5
Merge branch 'develop' of https://github.com/CenterForOpenScience/osf…
pattisdr Oct 11, 2018
e249fa8
Add merge migration.
pattisdr Oct 11, 2018
dee92d8
Update temporary elastic search migration script to use async=False t…
pattisdr Oct 12, 2018
84ec46f
Remove logging and call setup_django(). Dry run not necessary.
pattisdr Oct 12, 2018
8fdd859
Improve is_preprint_orphan property so preprints with deleted primary…
pattisdr Oct 15, 2018
700528b
Merge branch 'develop' of https://github.com/CenterForOpenScience/osf…
pattisdr Oct 15, 2018
7c2f462
Add another merge migration.
pattisdr Oct 15, 2018
070d858
Merge pull request #13 from adlius/feature/claim-user
pattisdr Oct 16, 2018
b4e071e
Adding test for @adlius claim-user feature, testing that HTTPError is…
pattisdr Oct 16, 2018
289fc36
Merge branch 'develop' of https://github.com/CenterForOpenScience/osf…
pattisdr Oct 16, 2018
4c465a8
Merge branch 'develop' into feature/node-preprint
sloria Oct 23, 2018
5c89ca4
Add merge migration
sloria Oct 23, 2018
f364f4f
Fix recording impact metrics
sloria Oct 23, 2018
5efc337
Remove node references from reviews emails.
caseyrollins Oct 23, 2018
2402d9f
Merge pull request #15 from caseyrollins/feature/fix-reviews-emails
pattisdr Oct 23, 2018
fd812d9
Change Open Science Framework to OSF Preprints similar to frontend ht…
pattisdr Oct 23, 2018
7b6b9f2
Remove preprints in initial states from preprint lists.
pattisdr Oct 23, 2018
f4ecdb8
Load guid instead of AbstractNode so digest will work for both a node…
pattisdr Oct 26, 2018
88f02fb
Exclude preprints from queryset from account/register in the admin app.
pattisdr Oct 29, 2018
4cfed9f
Exclude preprints from admin app > user groups selection.
pattisdr Oct 29, 2018
ba60e48
Merge branch 'develop' into feature/node-preprint
sloria Nov 6, 2018
a699674
Fix passing async_update; fix flake8 errors; fix tests
sloria Nov 6, 2018
d463aca
Allow moving preprints into collections.
pattisdr Nov 8, 2018
b01cb77
When double-clicking on a preprint in the dashboard, don't attempt to…
pattisdr Nov 8, 2018
974c52a
Add data migration so preprints can be added to existing collections.
pattisdr Nov 8, 2018
8729e75
Update PageCounter entries in preprint migration.
caseyrollins Nov 7, 2018
adf5796
Merge pull request #17 from caseyrollins/feature/node-preprint
pattisdr Nov 8, 2018
89df1bf
Prevent preprint django groups (even though they are hidden), from be…
pattisdr Nov 13, 2018
e75a73f
Merge branch 'develop' of https://github.com/CenterForOpenScience/osf…
pattisdr Nov 13, 2018
849436f
Add a merge migration.
pattisdr Nov 13, 2018
59c2fea
Consolidate CollectionPreprintsMixin with CollectionMixin and general…
pattisdr Nov 14, 2018
e1e350c
Merge pull request #18 from pattisdr/feature/PLAT-1190preprints-colle…
pattisdr Nov 14, 2018
384a871
Merge branch 'develop' of https://github.com/CenterForOpenScience/osf…
pattisdr Nov 14, 2018
cfdc9f9
Shuffle migrations.
pattisdr Nov 14, 2018
2fcf15b
Add CollectionMixin to CollectionList view.
caseyrollins Nov 16, 2018
fa3716b
Merge pull request #21 from caseyrollins/fix/preprint-collections
pattisdr Nov 16, 2018
dd2a7a1
Only show preprint's status to contributors. PLAT-1225
pattisdr Nov 19, 2018
ab77d75
Merge branch 'develop' of https://github.com/CenterForOpenScience/osf…
pattisdr Nov 19, 2018
2436dbe
Add merge migration.
pattisdr Nov 19, 2018
f3c6980
Adjust preprint banner tests to reflect that noncontribs don't see pr…
pattisdr Nov 20, 2018
80996ef
Fix for digest emails
sloria Nov 20, 2018
108859b
Merge branch 'develop' into feature/node-preprint
sloria Nov 28, 2018
0827696
Allow implicit admins to see status of attached preprint on project p…
pattisdr Nov 29, 2018
44d9a4d
Bugfix - only show warning message for making supplemental project pr…
pattisdr Nov 29, 2018
732dcbf
Bugfix for `is_preprint_primary` property.
pattisdr Nov 29, 2018
6d44523
Bugfix both project contributors and implicit admins should be able t…
pattisdr Nov 29, 2018
15e3b3e
Allow registered users to claim a user on a preprint.
pattisdr Dec 2, 2018
e1852c4
Use the Collection.collected_types through table to bulk add preprint…
pattisdr Dec 4, 2018
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
165 changes: 82 additions & 83 deletions addons/base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import furl
import jwe
import jwt

from django.db import transaction
from django.contrib.contenttypes.models import ContentType

Expand All @@ -35,7 +36,7 @@
from addons.base.utils import format_last_known_metadata, get_mfr_url
from osf import features
from osf.models import (BaseFileNode, TrashedFileNode,
OSFUser, AbstractNode,
OSFUser, AbstractNode, Preprint,
NodeLog, DraftRegistration, RegistrationSchema,
Guid, FileVersionUserMetadata, FileVersion)
from website.profile.utils import get_profile_image_url
Expand Down Expand Up @@ -147,7 +148,6 @@ def get_addon_user_config(**kwargs):
'movefrom': 'write',
}


def check_access(node, auth, action, cas_resp):
"""Verify that user can perform requested action on resource. Raise appropriate
error code if action cannot proceed.
Expand All @@ -158,21 +158,22 @@ def check_access(node, auth, action, cas_resp):

if cas_resp:
if permission == 'read':
if node.is_public:
if node.can_view_files(auth=None):
return True
required_scope = oauth_scopes.CoreScopes.NODE_FILE_READ
required_scope = node.file_read_scope
else:
required_scope = oauth_scopes.CoreScopes.NODE_FILE_WRITE
required_scope = node.file_write_scope

if not cas_resp.authenticated \
or required_scope not in oauth_scopes.normalize_scopes(cas_resp.attributes['accessTokenScope']):
raise HTTPError(httplib.FORBIDDEN)

if permission == 'read':
if node.can_view(auth):
if node.can_view_files(auth):
return True
# The user may have admin privileges on a parent node, in which
# case they should have read permissions
if node.is_registration and node.registered_from.can_view(auth):
if getattr(node, 'is_registration', False) and node.registered_from.can_view(auth):
return True
if permission == 'write' and node.can_edit(auth):
return True
Expand All @@ -188,33 +189,33 @@ def check_access(node, auth, action, cas_resp):
# `node.is_registration` == True. However, we have no way of telling if
# `copyfrom` actions are originating from a node being registered.
# TODO This is raise UNAUTHORIZED for registrations that have not been archived yet
if action == 'copyfrom' or (action == 'upload' and node.is_registration):
parent = node.parent_node
while parent:
if parent.can_edit(auth):
if isinstance(node, AbstractNode):
if action == 'copyfrom' or (action == 'upload' and node.is_registration):
parent = node.parent_node
while parent:
if parent.can_edit(auth):
return True
parent = parent.parent_node

# Users with the prereg admin permission should be allowed to download files
# from prereg challenge draft registrations.
try:
prereg_schema = RegistrationSchema.objects.get(name='Prereg Challenge', schema_version=2)
allowed_nodes = [node] + node.parents
prereg_draft_registration = DraftRegistration.objects.filter(
branched_from__in=allowed_nodes,
registration_schema=prereg_schema
)
if action == 'download' and \
auth.user is not None and \
prereg_draft_registration.count() > 0 and \
auth.user.has_perm('osf.administer_prereg'):
return True
parent = parent.parent_node

# Users with the prereg admin permission should be allowed to download files
# from prereg challenge draft registrations.
try:
prereg_schema = RegistrationSchema.objects.get(name='Prereg Challenge', schema_version=2)
allowed_nodes = [node] + node.parents
prereg_draft_registration = DraftRegistration.objects.filter(
branched_from__in=allowed_nodes,
registration_schema=prereg_schema
)
if action == 'download' and \
auth.user is not None and \
prereg_draft_registration.count() > 0 and \
auth.user.has_perm('osf.administer_prereg'):
return True
except RegistrationSchema.DoesNotExist:
pass
except RegistrationSchema.DoesNotExist:
pass

raise HTTPError(httplib.FORBIDDEN if auth.user else httplib.UNAUTHORIZED)


def make_auth(user):
if user is not None:
return {
Expand Down Expand Up @@ -264,15 +265,16 @@ def get_auth(auth, **kwargs):
except KeyError:
raise HTTPError(httplib.BAD_REQUEST)

node = AbstractNode.load(node_id)
node = AbstractNode.load(node_id) or Preprint.load(node_id)
if not node:
raise HTTPError(httplib.NOT_FOUND)

check_access(node, auth, action, cas_resp)

provider_settings = node.get_addon(provider_name)
if not provider_settings:
raise HTTPError(httplib.BAD_REQUEST)
provider_settings = None
if hasattr(node, 'get_addon'):
provider_settings = node.get_addon(provider_name)
if not provider_settings:
raise HTTPError(httplib.BAD_REQUEST)

try:
path = data.get('path')
Expand Down Expand Up @@ -303,13 +305,13 @@ def get_auth(auth, **kwargs):
region = fileversion.region
credentials = region.waterbutler_credentials
waterbutler_settings = fileversion.serialize_waterbutler_settings(
node_id=provider_settings.owner._id,
root_id=provider_settings.root_node._id,
node_id=provider_settings.owner._id if provider_settings else node._id,
root_id=provider_settings.root_node._id if provider_settings else node.root_folder._id,
)
# If they haven't been set by version region, use the NodeSettings region
if not (credentials and waterbutler_settings):
credentials = provider_settings.serialize_waterbutler_credentials()
waterbutler_settings = provider_settings.serialize_waterbutler_settings()
credentials = node.serialize_waterbutler_credentials(provider_name)
waterbutler_settings = node.serialize_waterbutler_settings(provider_name)
except exceptions.AddonError:
log_exception()
raise HTTPError(httplib.BAD_REQUEST)
Expand All @@ -321,10 +323,10 @@ def get_auth(auth, **kwargs):
'credentials': credentials,
'settings': waterbutler_settings,
'callback_url': node.api_url_for(
('create_waterbutler_log' if not node.is_registration else 'registration_callbacks'),
('create_waterbutler_log' if not getattr(node, 'is_registration', False) else 'registration_callbacks'),
_absolute=True,
_internal=True
),
)
}
}, settings.WATERBUTLER_JWT_SECRET, algorithm=settings.WATERBUTLER_JWT_ALGORITHM), WATERBUTLER_JWE_KEY)}

Expand Down Expand Up @@ -362,14 +364,16 @@ def mark_file_version_as_seen(user, path, version):

@must_be_signed
@no_auto_transaction
@must_be_valid_project(quickfiles_valid=True)
@must_be_valid_project(quickfiles_valid=True, preprints_valid=True)
def create_waterbutler_log(payload, **kwargs):
with transaction.atomic():
try:
auth = payload['auth']
# Don't log download actions, but do update analytics
if payload['action'] in DOWNLOAD_ACTIONS:
node = AbstractNode.load(payload['metadata']['nid'])
guid = Guid.load(payload['metadata'].get('nid'))
if guid:
node = guid.referent
return {'status': 'success'}

user = OSFUser.load(auth['id'])
Expand All @@ -381,7 +385,7 @@ def create_waterbutler_log(payload, **kwargs):
raise HTTPError(httplib.BAD_REQUEST)

auth = Auth(user=user)
node = kwargs['node'] or kwargs['project']
node = kwargs.get('node') or kwargs.get('project') or Preprint.load(kwargs.get('nid')) or Preprint.load(kwargs.get('pid'))

if action in (NodeLog.FILE_MOVED, NodeLog.FILE_COPIED):

Expand All @@ -408,14 +412,19 @@ def create_waterbutler_log(payload, **kwargs):
action = LOG_ACTION_MAP['rename']

destination_node = node # For clarity
source_node = AbstractNode.load(payload['source']['nid'])
source_node = AbstractNode.load(src['nid']) or Preprint.load(src['nid'])

source = source_node.get_addon(payload['source']['provider'])
destination = node.get_addon(payload['destination']['provider'])
# We return provider fullname so we need to load node settings, if applicable
source = None
if hasattr(source_node, 'get_addon'):
source = source_node.get_addon(payload['source']['provider'])
destination = None
if hasattr(node, 'get_addon'):
destination = node.get_addon(payload['destination']['provider'])

payload['source'].update({
'materialized': payload['source']['materialized'].lstrip('/'),
'addon': source.config.full_name,
'addon': source.config.full_name if source else 'osfstorage',
'url': source_node.web_url_for(
'addon_view_or_download_file',
path=payload['source']['path'].lstrip('/'),
Expand All @@ -430,7 +439,7 @@ def create_waterbutler_log(payload, **kwargs):

payload['destination'].update({
'materialized': payload['destination']['materialized'].lstrip('/'),
'addon': destination.config.full_name,
'addon': destination.config.full_name if destination else 'osfstorage',
'url': destination_node.web_url_for(
'addon_view_or_download_file',
path=payload['destination']['path'].lstrip('/'),
Expand All @@ -443,11 +452,6 @@ def create_waterbutler_log(payload, **kwargs):
}
})

payload.update({
'node': destination_node._id,
'project': destination_node.parent_id,
})

if not payload.get('errors'):
destination_node.add_log(
action=action,
Expand Down Expand Up @@ -475,18 +479,7 @@ def create_waterbutler_log(payload, **kwargs):
return {'status': 'success'}

else:
try:
metadata = payload['metadata']
node_addon = node.get_addon(payload['provider'])
except KeyError:
raise HTTPError(httplib.BAD_REQUEST)

if node_addon is None:
raise HTTPError(httplib.BAD_REQUEST)

metadata['path'] = metadata['path'].lstrip('/')

node_addon.create_waterbutler_log(auth, action, metadata)
node.create_waterbutler_log(auth, action, payload)

with transaction.atomic():
file_signals.file_updated.send(target=node, user=user, event_type=action, payload=payload)
Expand Down Expand Up @@ -673,26 +666,28 @@ def addon_view_or_download_file(auth, path, provider, **kwargs):
if not path:
raise HTTPError(httplib.BAD_REQUEST)

node_addon = target.get_addon(provider)
if hasattr(target, 'get_addon'):

if not isinstance(node_addon, BaseStorageAddon):
object_text = markupsafe.escape(getattr(target, 'project_or_component', 'this object'))
raise HTTPError(httplib.BAD_REQUEST, data={
'message_short': 'Bad Request',
'message_long': 'The {} add-on containing {} is no longer connected to {}.'.format(provider_safe, path_safe, object_text)
})
node_addon = target.get_addon(provider)

if not node_addon.has_auth:
raise HTTPError(httplib.UNAUTHORIZED, data={
'message_short': 'Unauthorized',
'message_long': 'The {} add-on containing {} is no longer authorized.'.format(provider_safe, path_safe)
})
if not isinstance(node_addon, BaseStorageAddon):
object_text = markupsafe.escape(getattr(target, 'project_or_component', 'this object'))
raise HTTPError(httplib.BAD_REQUEST, data={
'message_short': 'Bad Request',
'message_long': 'The {} add-on containing {} is no longer connected to {}.'.format(provider_safe, path_safe, object_text)
})

if not node_addon.complete:
raise HTTPError(httplib.BAD_REQUEST, data={
'message_short': 'Bad Request',
'message_long': 'The {} add-on containing {} is no longer configured.'.format(provider_safe, path_safe)
})
if not node_addon.has_auth:
raise HTTPError(httplib.UNAUTHORIZED, data={
'message_short': 'Unauthorized',
'message_long': 'The {} add-on containing {} is no longer authorized.'.format(provider_safe, path_safe)
})

if not node_addon.complete:
raise HTTPError(httplib.BAD_REQUEST, data={
'message_short': 'Bad Request',
'message_long': 'The {} add-on containing {} is no longer configured.'.format(provider_safe, path_safe)
})

savepoint_id = transaction.savepoint()
file_node = BaseFileNode.resolve_class(provider, BaseFileNode.FILE).get_or_create(target, path)
Expand Down Expand Up @@ -753,6 +748,10 @@ def addon_view_or_download_file(auth, path, provider, **kwargs):
if len(request.path.strip('/').split('/')) > 1:
guid = file_node.get_guid(create=True)
return redirect(furl.furl('/{}/'.format(guid._id)).set(args=extras).url)
if isinstance(target, Preprint):
# Redirecting preprint file guids to the preprint detail page
return redirect('/{}/'.format(target._id))

return addon_view_file(auth, target, file_node, version)


Expand Down
6 changes: 3 additions & 3 deletions addons/osfstorage/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def _check_delete_allowed(self):

@property
def is_preprint_primary(self):
return getattr(self.target, 'preprint_file', None) == self and not getattr(self.target, '_has_abandoned_preprint', None)
return getattr(self.target, 'primary_file', None) == self

def delete(self, user=None, parent=None, **kwargs):
self._path = self.path
Expand Down Expand Up @@ -431,9 +431,9 @@ def is_checked_out(self):

@property
def is_preprint_primary(self):
if hasattr(self.target, 'preprint_file') and self.target.preprint_file:
if hasattr(self.target, 'primary_file') and self.target.primary_file:
for child in self.children.all():
if getattr(child.target, 'preprint_file', None):
if getattr(child.target, 'primary_file', None):
if child.is_preprint_primary:
return True
return False
Expand Down
Loading