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

Jkmarx/remove unused igv stuff #2844

Merged
merged 17 commits into from Jul 9, 2018
Merged

Conversation

jkmarx
Copy link
Member

@jkmarx jkmarx commented Jul 5, 2018

Feel free to test using swagger.

@hackdna Unsure the status of the remove link, but this api should be able to support it.

@scottx611x Unit test will come in the next pull request, if this works for Ilya. If it doesn't, then we'll just remove the Node V2 API.

@jkmarx jkmarx added this to the Release 1.6.5 milestone Jul 5, 2018
@jkmarx jkmarx requested review from scottx611x and hackdna July 6, 2018 15:50
@codecov
Copy link

codecov bot commented Jul 6, 2018

Codecov Report

Merging #2844 into develop will decrease coverage by 0.77%.
The diff coverage is 36.36%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2844      +/-   ##
===========================================
- Coverage    58.77%   57.99%   -0.78%     
===========================================
  Files          431      431              
  Lines        27054    26643     -411     
  Branches      1261     1261              
===========================================
- Hits         15901    15452     -449     
- Misses       11153    11191      +38
Impacted Files Coverage Δ
refinery/data_set_manager/test_views.py 100% <ø> (ø) ⬆️
refinery/core/urls.py 100% <ø> (ø) ⬆️
...js/file-browser/ctrls/data-file-edit-modal-ctrl.js 60.71% <0%> (-28.76%) ⬇️
...ource/js/file-browser/services/nodes-v2-service.js 100% <100%> (ø)
...e/js/file-browser/ctrls/data-file-dropdown-ctrl.js 78.94% <100%> (+9.71%) ⬆️
refinery/core/views.py 40.41% <22.72%> (-1.93%) ⬇️
refinery/core/serializers.py 78.04% <45.45%> (-6.47%) ⬇️
refinery/data_set_manager/models.py 83.59% <0%> (-0.89%) ⬇️
refinery/core/models.py 74.59% <0%> (-0.71%) ⬇️
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0c25f5b...09c74d3. Read the comment docs.


try:
FileStoreItem.objects\
.get(uuid=old_file_uuid).delete_datafile()
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we would want to delete the datafile on every patch, correct? I would think that would only be necessary if the old file_uuid differed from the new one

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, correct. I'll fix that.

Copy link
Member Author

Choose a reason for hiding this comment

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

FYI, this api is only supporting what we need which right now is removing file_uuid. It does not support adding or changing.

@@ -693,13 +696,79 @@ def graph(self, request, *args, **kwargs):
)


class NodeViewSet(viewsets.ModelViewSet):
Copy link
Member

Choose a reason for hiding this comment

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

What was the need for the ModelViewSet to APIView change?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

I was more so curious about the underlying need to switch from one to the other

fields = ['uuid', 'file_uuid']

def validate_file_uuid(self, file_uuid):
if file_uuid != 'None':
Copy link
Member

Choose a reason for hiding this comment

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

Are we setting Node.file_uuid to the string 'None' by default? That seems off to me.
Maybe you're looking for: if file_uuid is not None:?

@jkmarx jkmarx self-assigned this Jul 6, 2018
* Add service for removing file.

* Add method to view.

* Seperate the add and remove features.

* Add file name.

* Add remove for owners only.

* Fix download for nonowners.
@jkmarx jkmarx merged commit 2f968bf into develop Jul 9, 2018
@jkmarx jkmarx deleted the jkmarx/remove-unused-igv-stuff branch July 9, 2018 14:37
Copy link
Member

@hackdna hackdna left a comment

Choose a reason for hiding this comment

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

It'd be great to add unit tests to this PR before it is merged to make sure Node API access controls are working correctly.

'ready_for_igv_detail_view',
'file_uuid'
]
fields = ['uuid', 'file_uuid']
Copy link
Member

Choose a reason for hiding this comment

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

('uuid, 'file_uuid')

example

required: false
...
"""
http_method_names = ['get', 'patch']
Copy link
Member

Choose a reason for hiding this comment

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

The recommended approach to restrict API methods is to inherit from GenericViewSet and add appropriate mixins.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not a viewset.

http_method_names = ['get', 'patch']

def update_file_store(self, old_uuid, new_uuid):
if new_uuid is None:
Copy link
Member

Choose a reason for hiding this comment

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

This check should not be needed since validate_file_uuid() in serializer already handles validation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Even though the api is only supporting file_uuid deletion, this is needed to avoid future issues when the file_uuid is not changed and other fields are.

"""
http_method_names = ['get', 'patch']

def update_file_store(self, old_uuid, new_uuid):
Copy link
Member

Choose a reason for hiding this comment

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

This method contains very simple logic and is used only once, so does not need to be factored out.

def update_file_store(self, old_uuid, new_uuid):
if new_uuid is None:
try:
FileStoreItem.objects.get(uuid=old_uuid).delete_datafile()
Copy link
Member

Choose a reason for hiding this comment

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

Try block should be as simple as possible, so delete_datafile() should be moved out.

public_group = ExtendedGroup.objects.public_group()

if request.user.has_perm('core.read_dataset', data_set) or \
'read_dataset' in get_perms(public_group, data_set):
Copy link
Member

Choose a reason for hiding this comment

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

DRF docs recommend using a custom permission class

serializer = NodeSerializer(node)
return Response(serializer.data)

return Response(node, status=status.HTTP_401_UNAUTHORIZED)
Copy link
Member

Choose a reason for hiding this comment

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

Returning a Node instance contradicts HTTP 401 status code.

if data_set_owner == request.user:
serializer = NodeSerializer(node, data=request.data, partial=True)
if serializer.is_valid():
serializer.save()
Copy link
Member

Choose a reason for hiding this comment

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

This should probably be the last action contingent on success of data file deletion and Solr index updates.

lookup_field = 'uuid'
http_method_names = ['get']
# permission_classes = (IsAuthenticated,)
class NodeViewSet(APIView):
Copy link
Member

Choose a reason for hiding this comment

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

Missing authentication_classes and permission_classes attributes.

old_file_uuid = node.file_uuid
data_set_owner = node.study.get_dataset().get_owner()

if data_set_owner == request.user:
Copy link
Member

Choose a reason for hiding this comment

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

DRF docs recommend using a custom permission class

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.

None yet

3 participants