diff --git a/app/local_settings.example.py b/app/local_settings.example.py index 62b4f0d..7e69036 100644 --- a/app/local_settings.example.py +++ b/app/local_settings.example.py @@ -53,4 +53,4 @@ THRESHOLD_API_KEY = "name" THRESHOLD_API_TOKEN = "token" THRESHOLD_API_COUNTER = "counter" -DEBUG = True \ No newline at end of file +DEBUG = True diff --git a/app/urls.py b/app/urls.py index db449f7..b28d3a0 100644 --- a/app/urls.py +++ b/app/urls.py @@ -33,6 +33,8 @@ from core.views.dynamic.drilldown import DrilldownSearch, ThresholdInfoModal from core.views.dynamic.insights import ( InsightsChannels, InsightsInfoModal, + InsightsMeta, + InsightsNicks, InsightsSearch, ) @@ -54,13 +56,18 @@ urlpatterns = [ path("admin/", admin.site.urls), path("accounts/", include("django.contrib.auth.urls")), path("accounts/signup/", Signup.as_view(), name="signup"), + ## path("ui/drilldown/", Drilldown.as_view(), name="drilldown"), + path("ui/drilldown/modal/", ThresholdInfoModal.as_view(), name="modal_drilldown"), + path("ui/drilldown/search/", DrilldownSearch.as_view(), name="search_drilldown"), + ## path("ui/insights/", Insights.as_view(), name="insights"), - path("parts/search/drilldown/", DrilldownSearch.as_view(), name="search_drilldown"), - path("parts/search/insights/", InsightsSearch.as_view(), name="search_insights"), - path("parts/channels/insights/", InsightsChannels.as_view(), name="chans_insights"), - path("modal/drilldown/", ThresholdInfoModal.as_view(), name="modal_drilldown"), - path("modal/insights/", InsightsInfoModal.as_view(), name="modal_insights"), + path("ui/insights/search/", InsightsSearch.as_view(), name="search_insights"), + path("ui/insights/channels/", InsightsChannels.as_view(), name="chans_insights"), + path("ui/insights/nicks/", InsightsNicks.as_view(), name="nicks_insights"), + path("ui/insights/meta/", InsightsMeta.as_view(), name="meta_insights"), + path("ui/insights/modal/", InsightsInfoModal.as_view(), name="modal_insights"), + ## path("api/chans/", ThresholdChans.as_view(), name="chans"), path("api/users/", ThresholdUsers.as_view(), name="users"), path("api/online/", ThresholdOnline.as_view(), name="online"), diff --git a/core/lib/nicktrace.py b/core/lib/nicktrace.py new file mode 100644 index 0000000..96f99eb --- /dev/null +++ b/core/lib/nicktrace.py @@ -0,0 +1,15 @@ +from core.lib.opensearch import client, run_main_query + + +def get_nicks(request, net, nick): + """ + Get all related nicknames of the given nickname by tracking nickname changes. + """ + # Get the initial query + query = {} + results = set() + # nicks = query["nicks"] + # for nick in nicks: + # if nick not in results: + # nicks_result = get_nicks(request, net_nick) + # results.add(nick) diff --git a/core/lib/opensearch.py b/core/lib/opensearch.py index 5829e7b..31331de 100644 --- a/core/lib/opensearch.py +++ b/core/lib/opensearch.py @@ -93,7 +93,7 @@ def filter_blacklisted(user, response): response["exemption"] = True -def run_main_query(client, user, query, size=None): +def run_main_query(client, user, query, custom_query=False, size=None): """ Low level helper to run an ES query. Accept a user to pass it to the filter, so we can @@ -101,7 +101,10 @@ def run_main_query(client, user, query, size=None): Accept fields and size, for the fields we want to match and the number of results to return. """ - search_query = construct_query(query, size) + if custom_query: + search_query = query + else: + search_query = construct_query(query, size) try: response = client.search( body=search_query, index=settings.OPENSEARCH_INDEX_MAIN @@ -131,7 +134,7 @@ def query_results(request, size=None): client, request.user, query, - size, + size=size, ) if not results: return False diff --git a/core/templates/ui/insights/channels.html b/core/templates/ui/insights/channels.html index 0bece44..1509ed5 100644 --- a/core/templates/ui/insights/channels.html +++ b/core/templates/ui/insights/channels.html @@ -1,12 +1,9 @@ - - -
-
-
-

- Channels -

- {% for chan in chans %} +
+
+

+ Channels +

+ {% for chan in chans %} @@ -20,9 +17,7 @@ class="button is-small"> {{ chan }} - - {% endfor %} -
+ {% endfor %}
-
+
\ No newline at end of file diff --git a/core/templates/ui/insights/info.html b/core/templates/ui/insights/info.html new file mode 100644 index 0000000..c08b854 --- /dev/null +++ b/core/templates/ui/insights/info.html @@ -0,0 +1,112 @@ +{% load static %} +{% load index %} +
+
+

+ Information +

+
+ {% if item is not None %} +
+ + + + + + + + + + + + + + + + + + + + + + + +
src + {% if item.src == 'irc' %} + + + + IRC + {% elif item.src == 'dis' %} + + + + Discord + {% endif %} +
nick + {% if item.online is True %} + + + + {{ item.nick }} + {% elif item.online is False %} + + + + {{ item.nick }} + {% else %} + + + + {{ item.nick }} + {% endif %} + {% if item.num_chans is not None %} + + {{ item.num_chans }} + + {% endif %} +
host{{ item.host }}
actions + {% if item.src == 'irc' %} + + {% endif %} +
net{{ item.net }}
+
+ {% endif %} +
+
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/core/templates/ui/insights/insights.html b/core/templates/ui/insights/insights.html index ec54203..b6b3140 100644 --- a/core/templates/ui/insights/insights.html +++ b/core/templates/ui/insights/insights.html @@ -38,46 +38,66 @@ .icon { border-bottom: 0px !important;}
- -
-
-
- {% csrf_token %} -
- -
+
+
+
+
+ + {% csrf_token %}
-
- - - - + +
+
+
+ + + + +
+
-
-
-
-
- -
-
- -
- -
-
+
+
+ +
+
+ + +
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
- -
-
{% endblock %} \ No newline at end of file diff --git a/core/templates/ui/insights/meta.html b/core/templates/ui/insights/meta.html new file mode 100644 index 0000000..f3e6534 --- /dev/null +++ b/core/templates/ui/insights/meta.html @@ -0,0 +1,21 @@ +
+
+

+ Meta +

+ + + + + + bbb + + +
+
\ No newline at end of file diff --git a/core/templates/ui/insights/nicks.html b/core/templates/ui/insights/nicks.html new file mode 100644 index 0000000..6d9042c --- /dev/null +++ b/core/templates/ui/insights/nicks.html @@ -0,0 +1,21 @@ +
+
+

+ Nicks +

+ + + + + + aaa + + +
+
\ No newline at end of file diff --git a/core/templates/ui/insights/results.html b/core/templates/ui/insights/results.html deleted file mode 100644 index 896cbf0..0000000 --- a/core/templates/ui/insights/results.html +++ /dev/null @@ -1,94 +0,0 @@ -{% load static %} -{% load index %} - -
-

- Information -

-
-
- {% if item is not None %} -
- - - - - - - - - - - - - - - - - - - - - - - -
src - {% if item.src == 'irc' %} - - - - IRC - {% elif item.src == 'dis' %} - - - - Discord - {% endif %} -
nick - {% if item.online is True %} - - - - {{ item.nick }} - {% elif item.online is False %} - - - - {{ item.nick }} - {% else %} - - - - {{ item.nick }} - {% endif %} - {% if item.num_chans is not None %} - - {{ item.num_chans }} - - {% endif %} -
host{{ item.host }}
actions - {% if item.src == 'irc' %} - - {% endif %} -
net{{ item.net }}
-
- {% endif %} -
-
-
-
-
\ No newline at end of file diff --git a/core/views/dynamic/insights.py b/core/views/dynamic/insights.py index f50c0d9..d539d6d 100644 --- a/core/views/dynamic/insights.py +++ b/core/views/dynamic/insights.py @@ -5,6 +5,7 @@ from django.views import View from rest_framework.parsers import FormParser from rest_framework.views import APIView +from core.lib.nicktrace import get_nicks from core.lib.opensearch import query_single_result from core.lib.threshold import ( annotate_num_chans, @@ -16,7 +17,7 @@ from core.lib.threshold import ( class InsightsSearch(LoginRequiredMixin, View): # parser_classes = [JSONParser] - template_name = "ui/insights/results.html" + template_name = "ui/insights/info.html" plan_name = "drilldown" def post(self, request): @@ -57,6 +58,44 @@ class InsightsChannels(LoginRequiredMixin, APIView): return HttpResponse("No results") +class InsightsNicks(LoginRequiredMixin, APIView): + parser_classes = [FormParser] + template_name = "ui/insights/nicks.html" + plan_name = "drilldown" + + 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: + return HttpResponse("No nick") + net = request.data["net"] + nick = request.data["nick"] + + context = {"net": net, "nick": nick} + return render(request, self.template_name, context) + + +class InsightsMeta(LoginRequiredMixin, APIView): + parser_classes = [FormParser] + template_name = "ui/insights/meta.html" + plan_name = "drilldown" + + 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: + return HttpResponse("No nick") + net = request.data["net"] + nick = request.data["nick"] + + context = {"net": net, "nick": nick} + return render(request, self.template_name, context) + + class InsightsInfoModal(LoginRequiredMixin, APIView): parser_classes = [FormParser] plan_name = "drilldown"