|
|
@@ -15,18 +15,20 @@
|
|
|
# See the License for the specific language governing permissions and
|
|
|
# limitations under the License.
|
|
|
|
|
|
+from functools import wraps
|
|
|
import json
|
|
|
import logging
|
|
|
import re
|
|
|
|
|
|
from django.http import HttpResponse, Http404
|
|
|
+from django.utils.decorators import available_attrs
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
|
|
from desktop.lib.exceptions_renderable import PopupException
|
|
|
from search.models import Collection
|
|
|
|
|
|
from controller import CollectionManagerController
|
|
|
-from utils import example_schema_xml_with_fields_and_unique_key, fields_from_log,\
|
|
|
+from utils import fields_from_log,\
|
|
|
field_values_from_separated_file, get_type_from_morphline_type,\
|
|
|
get_field_types
|
|
|
|
|
|
@@ -34,6 +36,22 @@ from utils import example_schema_xml_with_fields_and_unique_key, fields_from_log
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
+def admin_only():
|
|
|
+ """
|
|
|
+ Ensure only admins are allowed.
|
|
|
+ """
|
|
|
+ def decorator(view_func):
|
|
|
+ @wraps(view_func, assigned=available_attrs(view_func))
|
|
|
+ def _wrapped_view(request, *args, **kwargs):
|
|
|
+ if request.user.is_superuser:
|
|
|
+ return view_func(request, *args, **kwargs)
|
|
|
+ else:
|
|
|
+ raise PopupException(_("Must be a superuser to access this module."))
|
|
|
+ return _wrapped_view
|
|
|
+ return decorator
|
|
|
+
|
|
|
+
|
|
|
+@admin_only()
|
|
|
def parse_fields(request):
|
|
|
if request.method != 'POST':
|
|
|
raise PopupException(_('POST request required.'))
|
|
|
@@ -87,6 +105,7 @@ def parse_fields(request):
|
|
|
return HttpResponse(json.dumps(result), mimetype="application/json")
|
|
|
|
|
|
|
|
|
+@admin_only()
|
|
|
def collections(request):
|
|
|
searcher = CollectionManagerController(request.user)
|
|
|
solr_collections = searcher.get_collections()
|
|
|
@@ -115,6 +134,7 @@ def collections(request):
|
|
|
return HttpResponse(json.dumps(response), mimetype="application/json")
|
|
|
|
|
|
|
|
|
+@admin_only()
|
|
|
def collections_create(request):
|
|
|
if request.method != 'POST':
|
|
|
raise PopupException(_('POST request required.'))
|
|
|
@@ -164,6 +184,7 @@ def collections_create(request):
|
|
|
return HttpResponse(json.dumps(response), mimetype="application/json")
|
|
|
|
|
|
|
|
|
+@admin_only()
|
|
|
def collections_import(request):
|
|
|
if request.method != 'POST':
|
|
|
raise PopupException(_('POST request required.'))
|
|
|
@@ -192,6 +213,7 @@ def collections_import(request):
|
|
|
return HttpResponse(json.dumps(response), mimetype="application/json")
|
|
|
|
|
|
|
|
|
+@admin_only()
|
|
|
def collections_remove(request):
|
|
|
if request.method != 'POST':
|
|
|
raise PopupException(_('POST request required.'))
|
|
|
@@ -219,6 +241,7 @@ def collections_remove(request):
|
|
|
return HttpResponse(json.dumps(response), mimetype="application/json")
|
|
|
|
|
|
|
|
|
+@admin_only()
|
|
|
def collections_fields_and_metadata(request, collection_or_core):
|
|
|
if request.method != 'GET':
|
|
|
raise PopupException(_('GET request required.'))
|
|
|
@@ -244,6 +267,7 @@ def collections_fields_and_metadata(request, collection_or_core):
|
|
|
return HttpResponse(json.dumps(response), mimetype="application/json")
|
|
|
|
|
|
|
|
|
+@admin_only()
|
|
|
def collections_update(request, collection_or_core):
|
|
|
if request.method != 'POST':
|
|
|
raise PopupException(_('POST request required.'))
|
|
|
@@ -278,6 +302,7 @@ def collections_update(request, collection_or_core):
|
|
|
return HttpResponse(json.dumps(response), mimetype="application/json")
|
|
|
|
|
|
|
|
|
+@admin_only()
|
|
|
def collections_data(request, collection_or_core):
|
|
|
if request.method != 'POST':
|
|
|
raise PopupException(_('POST request required.'))
|