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 Amicable Node-Preprint Divorce [PLAT-555][PLAT-480][PLAT-559][PLAT-561] #8422

Closed
Show file tree
Hide file tree
Changes from 135 commits
Commits
Show all changes
146 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
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
164 changes: 82 additions & 82 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 @@ -34,7 +35,7 @@
from addons.base import signals as file_signals
from addons.base.utils import format_last_known_metadata
from osf.models import (BaseFileNode, TrashedFileNode,
OSFUser, AbstractNode,
OSFUser, AbstractNode, Preprint,
NodeLog, DraftRegistration, MetaSchema,
Guid, FileVersionUserMetadata)
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):
Copy link
Contributor Author

@pattisdr pattisdr Jun 19, 2018

Choose a reason for hiding this comment

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

check_access modified to check if someone can access a file on either a node or a preprint

New: non-contributors prevented from accessing a withdrawn preprint file

"""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 == 'copyto' and node.is_registration):
parent = node.parent_node
while parent:
if parent.can_edit(auth):
if isinstance(node, AbstractNode):
if action == 'copyfrom' or (action == 'copyto' 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 = MetaSchema.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 = MetaSchema.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 MetaSchema.DoesNotExist:
pass
except MetaSchema.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,19 +265,18 @@ 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)

if hasattr(node, 'get_addon'):
provider_settings = node.get_addon(provider_name)
if not provider_settings:
raise HTTPError(httplib.BAD_REQUEST)
try:
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 @@ -288,10 +288,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 @@ -329,14 +329,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):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Modified to create waterbutler-related logs like copying/uploading files for either a node or a preprint. Source/destination can be either a node/preprint, and nodes have addons and preprints do not, so most of this logic relates to that.

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 @@ -348,7 +350,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 @@ -375,14 +377,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 @@ -397,7 +404,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 @@ -410,11 +417,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 @@ -443,18 +445,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 @@ -640,26 +631,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 @@ -720,6 +713,13 @@ 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):
# Cannot currently view preprint files in file view
raise HTTPError(httplib.NOT_FOUND, data={
'message_short': 'File Not Found',
'message_long': 'The requested file could not be found.'
})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Verified with Steve, we are not going to be showing preprint-files in the file-detail view.


return addon_view_file(auth, target, file_node, version)


Expand Down
5 changes: 3 additions & 2 deletions addons/osfstorage/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ def waterbutler_opt_hook(func):
def wrapped(payload, *args, **kwargs):
try:
user = OSFUser.load(payload['user'])

dest_target = Guid.load(payload['destination']['target']).referent
# Waterbutler is sending back ['node'] under the destination payload - WB should change to target
target = payload['destination'].get('target') or payload['destination'].get('node')
Copy link
Contributor Author

@pattisdr pattisdr Jun 19, 2018

Choose a reason for hiding this comment

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

The payload that WB is building has a node key under destination, while files-on-anything is moving to target language, since files don't have to be stored on a node. Until this is changed, this works for both target/node keys.

I believe this is why moving/copying/renaming was not working for files-on-anything.

dest_target = Guid.load(target).referent
source = OsfStorageFileNode.get(payload['source'], kwargs['target'])
dest_parent = OsfStorageFolder.get(payload['destination']['parent'], dest_target)

Expand Down
6 changes: 3 additions & 3 deletions addons/osfstorage/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,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 @@ -425,9 +425,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:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

preprint_file is now stored on the Preprint instead of the Node, and it has been renamed to primary_file.

for child in self.children.all().prefetch_related('target'):
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