From b323ea2ae2818ef59128ccd4fa59fef8a5da44b4 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Tue, 2 Aug 2022 22:22:22 +0100 Subject: [PATCH] Make Drilldown public --- app/urls.py | 2 +- core/lib/opensearch.py | 12 ++++++++++-- core/views/ui/drilldown.py | 18 +++++++++--------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/app/urls.py b/app/urls.py index df142ab..ab848e3 100644 --- a/app/urls.py +++ b/app/urls.py @@ -61,7 +61,7 @@ from core.views.ui.insights import ( ) urlpatterns = [ - path("", Home.as_view(), name="home"), + path("", Drilldown.as_view(), name="home"), path("callback", Callback.as_view(), name="callback"), path("billing/", Billing.as_view(), name="billing"), path("order//", Order.as_view(), name="order"), diff --git a/core/lib/opensearch.py b/core/lib/opensearch.py index 6a079c5..dd3bd5c 100644 --- a/core/lib/opensearch.py +++ b/core/lib/opensearch.py @@ -93,8 +93,12 @@ def filter_blacklisted(user, response): if blacklisted_item in str(content): # Remove the item if item in response["hits"]["hits"]: - if not user.is_superuser: + # Anonymous + if not user: response["hits"]["hits"].remove(item) + else: + if not user.is_superuser: + response["hits"]["hits"].remove(item) # Let the UI know something was redacted response["redacted"] += 1 response["exemption"] = True @@ -136,9 +140,13 @@ def query_results(request, size=None): return False if "query" in request.POST: query = request.POST["query"] + if hasattr(request, "user"): + user = request.user + else: + user = None results = run_main_query( client, - request.user, + user, query, size=size, ) diff --git a/core/views/ui/drilldown.py b/core/views/ui/drilldown.py index b0a953d..f663d35 100644 --- a/core/views/ui/drilldown.py +++ b/core/views/ui/drilldown.py @@ -17,27 +17,27 @@ from core.lib.threshold import ( ) -class Drilldown(LoginRequiredMixin, View): +class Drilldown(View): template_name = "ui/drilldown/drilldown.html" plan_name = "drilldown" def get(self, request): - if not request.user.has_plan(self.plan_name): - return render(request, "denied.html") + #if not request.user.has_plan(self.plan_name): + # return render(request, "denied.html") context = { "sizes": settings.OPENSEARCH_MAIN_SIZES, } return render(request, self.template_name, context) -class DrilldownSearch(LoginRequiredMixin, View): +class DrilldownSearch(View): # parser_classes = [JSONParser] template_name = "ui/drilldown/results.html" plan_name = "drilldown" def post(self, request): - if not request.user.has_plan(self.plan_name): - return HttpResponseForbidden() + #if not request.user.has_plan(self.plan_name): + # return HttpResponseForbidden() context = query_results(request) if not context: @@ -59,14 +59,14 @@ class DrilldownSearch(LoginRequiredMixin, View): return HttpResponse("No results") -class ThresholdInfoModal(LoginRequiredMixin, APIView): +class ThresholdInfoModal(APIView): parser_classes = [FormParser] plan_name = "drilldown" template_name = "modals/drilldown.html" def post(self, request): - if not request.user.has_plan(self.plan_name): - return JsonResponse({"success": False}) + #if not request.user.has_plan(self.plan_name): + # return JsonResponse({"success": False}) if "net" not in request.data: return JsonResponse({"success": False}) if "nick" not in request.data: