Add Insights permission and remove useless APIs

This commit is contained in:
2022-08-26 07:20:30 +01:00
parent 0e7fb8d261
commit c748745426
4 changed files with 25 additions and 30 deletions

View File

@@ -113,6 +113,7 @@ class Perms(models.Model):
("post_irc", "Can post to IRC"),
("post_discord", "Can post to Discord"),
("query_search", "Can search with query strings"),
("use_insights", "Can use the Insights page"),
("index_int", "Can use the internal index"),
("index_meta", "Can use the meta index"),
)

View File

@@ -31,6 +31,16 @@
Subscription management
</a>
</article>
{% include "partials/product-list.html" %}
<div class="box">
<h1 class="subtitle">
This product is currently free. You may cancel any plans above.
</h1>
</div>
<div class="box">
<h1 class="subtitle">
You cannot pay for access to the raw data. It is hashed to preserve privacy.
</h1>
</div>
{# {% include "partials/product-list.html" %} #}
{% endblock %}

View File

@@ -1,6 +1,6 @@
from ast import literal_eval
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
from django.http import HttpResponse, HttpResponseForbidden, JsonResponse
from django.shortcuts import render
from django.views import View
@@ -19,38 +19,32 @@ from core.lib.threshold import (
)
class Insights(LoginRequiredMixin, View):
class Insights(LoginRequiredMixin, PermissionRequiredMixin, View):
template_name = "ui/insights/insights.html"
plan_name = "drilldown"
permission_required = "use_insights"
def get(self, request):
if not request.user.has_plan(self.plan_name):
return render(request, "denied.html")
return render(request, self.template_name)
class InsightsSearch(LoginRequiredMixin, View):
class InsightsSearch(LoginRequiredMixin, PermissionRequiredMixin, View):
# parser_classes = [JSONParser]
template_name = "ui/insights/info.html"
plan_name = "drilldown"
permission_required = "use_insights"
def post(self, request):
if not request.user.has_plan(self.plan_name):
return HttpResponseForbidden()
context = query_single_result(request)
if not context:
return HttpResponseForbidden()
return render(request, self.template_name, context)
class InsightsChannels(LoginRequiredMixin, APIView):
class InsightsChannels(LoginRequiredMixin, PermissionRequiredMixin, APIView):
parser_classes = [FormParser]
template_name = "ui/insights/channels.html"
plan_name = "drilldown"
permission_required = "use_insights"
def post(self, request):
if not request.user.has_plan(self.plan_name):
return HttpResponseForbidden()
if "net" not in request.data:
return HttpResponse("No net")
if "nick" not in request.data:
@@ -65,14 +59,12 @@ class InsightsChannels(LoginRequiredMixin, APIView):
return render(request, self.template_name, context)
class InsightsNicks(LoginRequiredMixin, APIView):
class InsightsNicks(LoginRequiredMixin, PermissionRequiredMixin, APIView):
parser_classes = [FormParser]
template_name = "ui/insights/nicks.html"
plan_name = "drilldown"
permission_required = "use_insights"
def post(self, request):
if not request.user.has_plan(self.plan_name):
return HttpResponseForbidden()
if "net" not in request.data:
return HttpResponse("No net")
if "nick" not in request.data:
@@ -91,14 +83,12 @@ class InsightsNicks(LoginRequiredMixin, APIView):
return render(request, self.template_name, context)
class InsightsMeta(LoginRequiredMixin, APIView):
class InsightsMeta(LoginRequiredMixin, PermissionRequiredMixin, APIView):
parser_classes = [FormParser]
template_name = "ui/insights/meta.html"
plan_name = "drilldown"
permission_required = "use_insights"
def post(self, request):
if not request.user.has_plan(self.plan_name):
return HttpResponseForbidden()
if "net" not in request.data:
return HttpResponse("No net")
if "nicks" not in request.data:
@@ -133,14 +123,12 @@ class InsightsMeta(LoginRequiredMixin, APIView):
return render(request, self.template_name, context)
class InsightsInfoModal(LoginRequiredMixin, APIView):
class InsightsInfoModal(LoginRequiredMixin, PermissionRequiredMixin, APIView):
parser_classes = [FormParser]
plan_name = "drilldown"
template_name = "modals/drilldown.html"
permission_required = "use_insights"
def post(self, request):
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: