Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Update API resources to use Serrano's base resource class #134

Merged
merged 4 commits into from

2 participants

Byron Ruth Don Naegely
Byron Ruth
Owner

No description provided.

Don Naegely naegelyd merged commit 0f80267 into from
Don Naegely naegelyd deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 27, 2014
  1. Byron Ruth
  2. Byron Ruth

    Update NamedSampleResource to bypass Serrano's authentication check

    bruth authored
    This resource must be publicly accessible, so the Serrano-based
    authentication must be ignored.
  3. Byron Ruth
  4. Byron Ruth

    Flake 8 fixes

    bruth authored
This page is out of date. Refresh to see the latest.
4 varify/assessments/resources.py
View
@@ -3,14 +3,14 @@
from django.views.decorators.cache import never_cache
from django.utils import simplejson
from preserialize.serialize import serialize
-from restlib2 import resources
from restlib2.http import codes
+from serrano.resources.base import ThrottledResource
from varify import api
from .models import Assessment
from .forms import AssessmentForm
-class AssessmentResourceBase(resources.Resource):
+class AssessmentResourceBase(ThrottledResource):
model = Assessment
template = api.templates.Assessment
16 varify/conf/global_settings.py
View
@@ -1,11 +1,12 @@
import os
# Import global settings to make it easier to extend settings.
-from django.conf.global_settings import *
+from django.conf.global_settings import * # noqa
# Import the project module to calculate directories relative to the module
# location.
-PROJECT_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../..')
+PROJECT_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)),
+ '../..')
# List all Django apps here. Note that standard Python libraries should not
# be added to this list since Django will not recognize them as apps anyway.
@@ -89,8 +90,8 @@
# to different databases depending on what data is being acted on. For Harvest
# instances that make use of an existing database, it is typically never
# desirable to create all the Harvest application tables in this database, but
-# rather have a separate database for this purpose. That way the "data" database
-# does not need to be changed.
+# rather have a separate database for this purpose. That way the "data"
+# database does not need to be changed.
DATABASE_ROUTERS = {}
@@ -202,7 +203,7 @@
r'^log(in|out)/',
r'^password/reset/',
r'^(static|support|register|verify)/',
- r'^api/samples/(?P<project>.+)/(?P<batch>.+)/(?P<sample>.+)/$',
+ r'^api/',
)
#
@@ -308,7 +309,7 @@
CSRF_COOKIE_NAME = 'varify_csrftoken'
SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
-SESSION_COOKIE_AGE = 60 * 60 # 1 hour
+SESSION_COOKIE_AGE = 60 * 60 # 1 hour
SESSION_COOKIE_NAME = 'varify_sessionid'
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
SESSION_SAVE_EVERY_REQUEST = False
@@ -379,5 +380,8 @@
'METADATA_MIGRATION_APP': 'varify',
}
+SERRANO = {
+ 'AUTH_REQUIRED': True,
+}
VARIFY_SAMPLE_DIRS = ()
6 varify/genes/resources.py
View
@@ -4,12 +4,12 @@
from django.views.decorators.cache import never_cache
from django.core.urlresolvers import reverse
from preserialize.serialize import serialize
-from restlib2 import resources
+from serrano.resources.base import ThrottledResource
from varify import api
from .models import Gene
-class GeneResource(resources.Resource):
+class GeneResource(ThrottledResource):
model = Gene
template = api.templates.Gene
@@ -33,7 +33,7 @@ def get(self, request, pk):
return data
-class GeneSearchResource(resources.Resource):
+class GeneSearchResource(ThrottledResource):
model = Gene
template = api.templates.GeneSearch
6 varify/phenotypes/resources.py
View
@@ -3,13 +3,13 @@
from django.http import Http404
from django.views.decorators.cache import never_cache
from django.core.urlresolvers import reverse
-from restlib2 import resources
+from serrano.resources.base import ThrottledResource
from varify import api
from .models import Phenotype
from preserialize.serialize import serialize
-class PhenotypeResource(resources.Resource):
+class PhenotypeResource(ThrottledResource):
model = Phenotype
template = api.templates.Phenotype
@@ -26,7 +26,7 @@ def get(self, request, pk):
return serialize(phenotype, **self.template)
-class PhenotypeSearchResource(resources.Resource):
+class PhenotypeSearchResource(ThrottledResource):
model = Phenotype
template = api.templates.PhenotypeSearch
17 varify/samples/resources.py
View
@@ -10,6 +10,7 @@
from django.conf import settings
from preserialize.serialize import serialize
from restlib2 import resources
+from serrano.resources.base import ThrottledResource
from varify.variants.resources import VariantResource
from varify import api
from varify.assessments.models import Assessment
@@ -32,7 +33,7 @@ def sample_posthook(instance, data, request):
return data
-class SampleResource(resources.Resource):
+class SampleResource(ThrottledResource):
model = Sample
template = api.templates.Sample
@@ -52,7 +53,7 @@ def get(self, request, pk):
return serialize(sample, posthook=posthook, **self.template)
-class SamplesResource(resources.Resource):
+class SamplesResource(ThrottledResource):
model = Sample
template = api.templates.Sample
@@ -63,12 +64,16 @@ def get(self, request):
return serialize(samples, posthook=posthook, **self.template)
-class NamedSampleResource(resources.Resource):
+class NamedSampleResource(ThrottledResource):
"Resource for looking up a sample by project, batch, and sample name"
model = Sample
template = api.templates.Sample
+ # Bypass authorization check imposed by Serrano's AUTH_REQUIRED setting
+ def __call__(self, *args, **kwargs):
+ return resources.Resource.__call__(self, *args, **kwargs)
+
def is_not_found(self, request, response, project, batch, sample):
try:
instance = self.model.objects.get(project__name=project,
@@ -96,7 +101,7 @@ def get(self, request, project, batch, sample):
return data
-class SampleResultsResource(resources.Resource):
+class SampleResultsResource(ThrottledResource):
"Paginated view of results for a sample."
model = Result
@@ -168,7 +173,7 @@ def get(self, request, pk):
return resp
-class SampleResultResource(resources.Resource):
+class SampleResultResource(ThrottledResource):
model = Result
template = api.templates.SampleResultVariant
@@ -238,7 +243,7 @@ def get(self, request, pk):
return data
-class PhenotypeResource(resources.Resource):
+class PhenotypeResource(ThrottledResource):
def get(self, request, sample_id):
endpoint = settings.PHENOTYPE_ENDPOINT % sample_id
6 varify/variants/resources.py
View
@@ -4,7 +4,7 @@
from django.views.decorators.cache import never_cache
from guardian.shortcuts import get_objects_for_user
from preserialize.serialize import serialize
-from restlib2 import resources
+from serrano.resources.base import ThrottledResource
from varify import api
from varify.samples.models import CohortVariant
from varify.assessments.models import Assessment, Pathogenicity, \
@@ -12,7 +12,7 @@
from .models import Variant
-class VariantResource(resources.Resource):
+class VariantResource(ThrottledResource):
model = Variant
template = api.templates.Variant
@@ -72,7 +72,7 @@ def get(self, request, pk):
return data
-class VariantAssessmentMetricsResource(resources.Resource):
+class VariantAssessmentMetricsResource(ThrottledResource):
model = Variant
def is_not_found(self, request, response, pk):
Something went wrong with that request. Please try again.