-
Notifications
You must be signed in to change notification settings - Fork 24
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
Changes from all commits
15db617
1f6d9bc
e80358d
eca401a
0355e4d
da9c18a
e42f9cc
0187953
00e4bf8
a89939b
a44ddef
9ee29bb
c7ec459
1bc9818
2c20a34
2910083
09c74d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
from django.core.mail import EmailMessage | ||
from django.core.urlresolvers import reverse | ||
from django.db import transaction | ||
from django.http import (HttpResponse, HttpResponseBadRequest, | ||
from django.http import (Http404, HttpResponse, HttpResponseBadRequest, | ||
HttpResponseForbidden, HttpResponseNotFound, | ||
HttpResponseRedirect, HttpResponseServerError, | ||
JsonResponse) | ||
|
@@ -32,13 +32,16 @@ | |
from requests.exceptions import HTTPError | ||
from rest_framework import authentication, status, viewsets | ||
from rest_framework.decorators import detail_route | ||
from rest_framework.exceptions import APIException | ||
from rest_framework.permissions import IsAuthenticated | ||
from rest_framework.renderers import JSONRenderer | ||
from rest_framework.response import Response | ||
from rest_framework.views import APIView | ||
import xmltodict | ||
|
||
from data_set_manager.models import Node | ||
from data_set_manager.search_indexes import NodeIndex | ||
from file_store.models import FileStoreItem | ||
|
||
from .forms import ProjectForm, UserForm, UserProfileForm, WorkflowForm | ||
from .models import (Analysis, CustomRegistrationProfile, DataSet, Event, | ||
|
@@ -693,13 +696,80 @@ def graph(self, request, *args, **kwargs): | |
) | ||
|
||
|
||
class NodeViewSet(viewsets.ModelViewSet): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What was the need for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
"""API endpoint that allows Nodes to be viewed""" | ||
queryset = Node.objects.all() | ||
serializer_class = NodeSerializer | ||
lookup_field = 'uuid' | ||
http_method_names = ['get'] | ||
# permission_classes = (IsAuthenticated,) | ||
class NodeViewSet(APIView): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing |
||
"""API endpoint that allows Nodes to be viewed". | ||
--- | ||
#YAML | ||
|
||
PATCH: | ||
parameters_strategy: | ||
form: replace | ||
query: merge | ||
|
||
parameters: | ||
- name: uuid | ||
description: User profile uuid used as an identifier | ||
type: string | ||
paramType: path | ||
required: true | ||
- name: file_uuid | ||
description: uuid for file store item | ||
type: string | ||
paramType: form | ||
required: false | ||
... | ||
""" | ||
http_method_names = ['get', 'patch'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The recommended approach to restrict API methods is to inherit from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a viewset. |
||
|
||
def update_file_store(self, old_uuid, new_uuid): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
if new_uuid is None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check should not be needed since There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
try: | ||
FileStoreItem.objects.get(uuid=old_uuid).delete_datafile() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try block should be as simple as possible, so |
||
except (FileStoreItem.DoesNotExist, | ||
FileStoreItem.MultipleObjectsReturned) as e: | ||
logger.error(e) | ||
|
||
def get_object(self, uuid): | ||
try: | ||
return Node.objects.get(uuid=uuid) | ||
except Node.DoesNotExist as e: | ||
logger.error(e) | ||
raise Http404 | ||
except Node.MultipleObjectsReturned as e: | ||
logger.error(e) | ||
raise APIException("Multiple objects returned.") | ||
|
||
def get(self, request, uuid): | ||
node = self.get_object(uuid) | ||
data_set = node.study.get_dataset() | ||
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Returning a Node instance contradicts HTTP 401 status code. |
||
|
||
def patch(self, request, uuid): | ||
node = self.get_object(uuid) | ||
old_file_uuid = node.file_uuid | ||
data_set_owner = node.study.get_dataset().get_owner() | ||
|
||
if data_set_owner == request.user: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DRF docs recommend using a custom permission class |
||
serializer = NodeSerializer(node, data=request.data, partial=True) | ||
if serializer.is_valid(): | ||
serializer.save() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
self.update_file_store(old_file_uuid, node.file_uuid) | ||
NodeIndex().update_object(node, using="data_set_manager") | ||
return Response( | ||
serializer.data, status=status.HTTP_202_ACCEPTED | ||
) | ||
return Response( | ||
serializer.errors, status=status.HTTP_400_BAD_REQUEST | ||
) | ||
|
||
return Response(uuid, status=status.HTTP_401_UNAUTHORIZED) | ||
|
||
|
||
class EventViewSet(viewsets.ModelViewSet): | ||
|
@@ -800,12 +870,10 @@ def get_object(self, uuid): | |
return DataSet.objects.get(uuid=uuid) | ||
except DataSet.DoesNotExist as e: | ||
logger.error(e) | ||
return Response(uuid, status=status.HTTP_404_NOT_FOUND) | ||
raise Http404 | ||
except DataSet.MultipleObjectsReturned as e: | ||
logger.error(e) | ||
return Response( | ||
uuid, status=status.HTTP_500_INTERNAL_SERVER_ERROR | ||
) | ||
raise APIException("Multiple objects returned.") | ||
|
||
def is_user_authorized(self, user, data_set): | ||
if (not user.is_authenticated() or | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
('uuid, 'file_uuid')
example