Skip to content

Commit d563a7f

Browse files
authored
Merge pull request #35600 from dimagi/dm/simple-esview
Remove unused Django view functionality from ESView
2 parents e2603b1 + 26d4dcf commit d563a7f

File tree

1 file changed

+4
-68
lines changed

1 file changed

+4
-68
lines changed

corehq/apps/api/es.py

Lines changed: 4 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@
33
import json
44
import logging
55

6-
from django.utils.decorators import classonlymethod, method_decorator
7-
from django.views.generic import View
8-
96
from no_exceptions.exceptions import Http400
107

118
from dimagi.utils.parsing import ISO_DATE_FORMAT
129

1310
from corehq.apps.api.models import ESCase, ESXFormInstance
1411
from corehq.apps.api.util import object_does_not_exist
15-
from corehq.apps.domain.decorators import login_and_domain_required
1612
from corehq.apps.es import filters
1713
from corehq.apps.es.cases import CaseES, case_adapter
1814
from corehq.apps.es.exceptions import ESError
@@ -32,78 +28,18 @@ class DateTimeError(ValueError):
3228
pass
3329

3430

35-
class ESView(View):
36-
"""
37-
Generic CBV for interfacing with the Elasticsearch REST api.
38-
This is necessary because tastypie's built in REST assumptions don't like
39-
ES's POST for querying, which we can set explicitly here.
40-
41-
For security purposes, queries ought to be domain'ed by the requesting user, so a base_query
42-
is encouraged to be added.
43-
44-
Access to the APIs can be done via url endpoints which are attached to the corehq.api.urls
31+
class ESView:
32+
"""Wrapper for an ES adapter that may be used in a web context
4533
46-
or programmatically via the self.run_query() method.
47-
48-
This current iteration of the ESView must require a domain for its usage for security purposes.
34+
Some errors are translated to HTTP errors.
4935
"""
50-
#note - for security purposes, csrf protection is ENABLED
51-
#search POST queries must take the following format:
52-
#query={query_json}
53-
#csrfmiddlewaretoken=token
54-
55-
#in curl, this is:
56-
#curl -b "csrftoken=<csrftoken>;sessionid=<session_id>"
57-
# -H "Content-Type: application/json"
58-
# -XPOST http://server/a/domain/api/v0.1/xform_es/
59-
# -d"[email protected]&csrfmiddlewaretoken=<csrftoken>"
60-
#or, call this programmatically to avoid CSRF issues.
61-
62-
domain = ""
36+
6337
doc_type = None
6438
model = None
6539

66-
http_method_names = ['get', 'post', 'head', ]
67-
6840
def __init__(self, domain):
69-
super(ESView, self).__init__()
7041
self.domain = domain.lower()
7142

72-
def head(self, *args, **kwargs):
73-
raise NotImplementedError("Not implemented")
74-
75-
@method_decorator(login_and_domain_required)
76-
#@method_decorator(csrf_protect)
77-
# todo: csrf_protect temporarily removed and left to implementor's prerogative
78-
# getting ajax'ed csrf token method needs revisit.
79-
def dispatch(self, *args, **kwargs):
80-
req = args[0]
81-
self.pretty = req.GET.get('pretty', False)
82-
if self.pretty:
83-
self.indent = 4
84-
else:
85-
self.indent = None
86-
ret = super(ESView, self).dispatch(*args, **kwargs)
87-
return ret
88-
89-
@classonlymethod
90-
def as_view(cls, **initkwargs):
91-
"""
92-
Django as_view cannot be used since the constructor requires information only present in the request.
93-
"""
94-
raise Exception('as_view not supported for domain-specific ESView')
95-
96-
@classonlymethod
97-
def as_domain_specific_view(cls, **initkwargs):
98-
"""
99-
Creates a simple domain-specific class-based view for passing through ES requests.
100-
"""
101-
def view(request, domain, *args, **kwargs):
102-
self = cls(domain)
103-
return self.dispatch(request, domain, *args, **kwargs)
104-
105-
return view
106-
10743
def get_document(self, doc_id):
10844
try:
10945
doc = self.adapter.get(doc_id)

0 commit comments

Comments
 (0)