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

[Migration Required] Feature/NPD Add Preprints to Collections [PLAT-1190] #18

Merged

Conversation

pattisdr
Copy link
Owner

@pattisdr pattisdr commented Nov 8, 2018

Purpose

After NPD, preprints cannot be dragged into Bookmarks or user collections.

Changes

  • Prior to NPD, we weren't actually dragging preprints, but rather, the node the preprint was stored on. Several changes needed to collections endpoints to allow adding preprints to collections.

  • LinkedPreprintsList view collections/<collection_id>/linked_preprints/

  • CollectionLinkedPreprintsRelationship view collections/<collection_id>/relationships/linked_preprints/

  • linked_preprints relationship added to CollectionSerializer

  • Tweaks to MyProjects page so when preprints are dragged to collections or "Remove from collection" is clicked, requests are made to CollectionLinkedPreprintsRelationship to add/remove the preprint

  • Disable requests from being made when you double click on a preprint (projects load children, preprints don't have children)

  • Data migration added to allow preprints to be added to existing collections

screen shot 2018-11-08 at 12 47 40 pm

screen shot 2018-11-08 at 12 48 13 pm

animated gif-source 1

Side effects

⭐️ Not familiar with existing collections - data migration allows preprints to be added to all existing collections, but is this correct? Are there some collections we should not modify?
⭐️ Since dragging "preprints" previously mean dragging the preprint's node, existing collections will have nodes in them that was actually intended to be the preprint. No way to sort out if they actually wanted the project there, or the preprint, but a user can find the preprint and re-add.

Ticket

https://openscience.atlassian.net/browse/PLAT-1190

- AddCollectionLinkedPreprintsRelationship view and CollectionLinkedPreprints view.
- Allow collection to take preprints.
- UI changes on MyProjects page to send requests to new API preprints collections endpoints.
Copy link

@caseyrollins caseyrollins left a comment

Choose a reason for hiding this comment

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

No blockers, just a few minor comments and thoughts. Feel free to address/respond to whatever you like @pattisdr, but I'd be fine merging this as-is. Thank you for fixing this (much larger than expected) issue and for the extensive test coverage! 🐼

@@ -96,7 +96,7 @@ def has_object_permission(self, request, view, obj):
return False
pointer_nodes = []
for pointer in request.data.get('data', []):
node = AbstractNode.load(pointer['id'])
node = AbstractNode.load(pointer['id']) or Preprint.load(pointer['id'])

Choose a reason for hiding this comment

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

Minor: wouldn't be a bad idea to generalize this block of code:

obj = AbstractNode.load(pointer['id']) or Preprint.load(pointer['id'])
if not obj: 
	raise NotFound(detail='Object of type {} with id "{}" was not found'.format(type(obj), pointer['id']))

auth = get_user_auth(self.request)
obj = {
'data': [
pointer for pointer in self.collection_preprints(collection, auth.user)

Choose a reason for hiding this comment

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

Very minor: could be list(self.collection_preprints(...)

@@ -194,7 +206,7 @@ def perform_destroy(self, instance):
instance.delete()


class CollectionDetail(JSONAPIBaseView, generics.RetrieveUpdateDestroyAPIView, CollectionMixin):
class CollectionDetail(JSONAPIBaseView, generics.RetrieveUpdateDestroyAPIView, CollectionMixin, CollectionPreprintsMixin):

Choose a reason for hiding this comment

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

Does CollectionDetail need CollectionPreprintsMixin? I can't see where collection_preprints() is used here or in a CollectionDetail subclass.

Choose a reason for hiding this comment

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

Ah nvm, it's used in the CollectionDetailSerializer

Choose a reason for hiding this comment

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

(not a blocker) What do you think about adding the collection_preprints() to the CollectionMixin instead of creating another mixin? In theory CollectionMixin could also have collection_nodes() and collection_registrations() helpers

Copy link
Owner Author

Choose a reason for hiding this comment

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

good idea 👍

class Meta:
type_ = 'linked_preprints'

def make_instance_obj(self, obj):

Choose a reason for hiding this comment

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

Not a blocker and probably out of scope for this PR, but would be nice if make_instance_obj took a type argument and didn't need to be redefined in each class.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Makes sense but I didn't do that here, because the deleted fields are different on nodes and preprints so I just redefined.

@pattisdr pattisdr changed the title Feature/NPD Add Preprints to Collections [PLAT-1190] [Migration Required] Feature/NPD Add Preprints to Collections [PLAT-1190] Nov 14, 2018
…ize CollectionWriteOrPublicForRelationshipPointers.
@pattisdr pattisdr merged commit e1e350c into feature/node-preprint Nov 14, 2018
pattisdr pushed a commit that referenced this pull request Jun 11, 2019
Merge branch 'develop' into testmon-regression-test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants