From 5f21c7aa2e821ecaae8d7508b7e29d76ec984080 Mon Sep 17 00:00:00 2001 From: Ihsan Ullah Date: Wed, 21 Aug 2024 20:48:41 +0500 Subject: [PATCH 1/2] server_status and monitor_queues pages secured --- src/apps/pages/views.py | 10 +- src/templates/pages/monitor_queues.html | 82 +++++++------ src/templates/pages/server_status.html | 149 +++++++++++++----------- 3 files changed, 133 insertions(+), 108 deletions(-) diff --git a/src/apps/pages/views.py b/src/apps/pages/views.py index 0f21b8cf2..c0042ed98 100644 --- a/src/apps/pages/views.py +++ b/src/apps/pages/views.py @@ -57,8 +57,8 @@ def get_context_data(self, *args, **kwargs): page = self.request.GET.get('page', 1) submissions_per_page = 50 - # Get all submissions - qs = Submission.objects.all() + # Start with an empty queryset + qs = Submission.objects.none() # Only if user is authenticated if self.request.user.is_authenticated: @@ -67,12 +67,12 @@ def get_context_data(self, *args, **kwargs): # and # submissions running on queue which belongs to this user if not self.request.user.is_superuser: - qs = qs.filter( + qs = Submission.objects.filter( Q(owner=self.request.user) | Q(phase__competition__queue__isnull=False, phase__competition__queue__owner=self.request.user) ) - else: - qs = qs.none() # This returns an empty queryset + else: + qs = Submission.objects.all() # Filter out child submissions i.e. submission has no parent if not show_child_submissions: diff --git a/src/templates/pages/monitor_queues.html b/src/templates/pages/monitor_queues.html index bcbf0c4c5..3da947e0f 100644 --- a/src/templates/pages/monitor_queues.html +++ b/src/templates/pages/monitor_queues.html @@ -5,45 +5,61 @@ {% endblock %} {% block content %} -
-

Monitor queues

-
-
-
- - - -
- RabbitMQ -
- This page allows admins to view connections, queued messages, message rates, channels, - exchanges, and other administrative features relating to RabbitMQ e.g. Creating users, - adding v-hosts, and creating policies. + {% if user.is_authenticated %} + {% if user.is_super_user %} +
+

Monitor queues

+
+
+
+ + + +
+ RabbitMQ +
+ This page allows admins to view connections, queued messages, message rates, channels, + exchanges, and other administrative features relating to RabbitMQ e.g. Creating users, + adding v-hosts, and creating policies. +
+
-
-
-
-
- - - -
- Flower -
- Flower is a powerful web-based Celery monitoring tool designed to keep track of our - tasks. - Admins may view the state of which tasks were run, with what arguments, and many more - features. Here you may also view which queues your celery workers are consuming, and the - state of any tasks in them. At last, there is also a great monitoring page for viewing - the - systemic impact of your workers. +
+
+ + + +
+ Flower +
+ Flower is a powerful web-based Celery monitoring tool designed to keep track of our + tasks. + Admins may view the state of which tasks were run, with what arguments, and many more + features. Here you may also view which queues your celery workers are consuming, and the + state of any tasks in them. At last, there is also a great monitoring page for viewing + the + systemic impact of your workers. +
+
+ {% else %} +
+
+ You do not have access to this page! +
+
+ {% endif %} + {% else %} +
+
+ Log In or + Sign Up to view this page +
-
- + {% endif %} {% endblock %} diff --git a/src/templates/pages/server_status.html b/src/templates/pages/server_status.html index dde0138f1..42b13762b 100644 --- a/src/templates/pages/server_status.html +++ b/src/templates/pages/server_status.html @@ -5,81 +5,90 @@ {% endblock %} {% block content %} -
-

Recent Submissions

- - - - - - - - - {% if show_child_submissions %} - - {% endif %} - - - - - - - - - - {% if not submissions %} - - - + {% if user.is_authenticated %} +
+

Recent Submissions

+ + + + +
CompetitionSubmission PKParent PKSizeSubmitterQueueIngestion HostnameScoring HostnameSubmitted atStatus
No submissions, yet!
+ + + + {% if show_child_submissions %} + {% endif %} - {% for submission in submissions %} - - - - {% if show_child_submissions %} - + + + + + + + + + + {% if not submissions %} + + + {% endif %} - - - - - - - - - {% endfor %} - -
CompetitionSubmission PKParent PK
{{ submission.phase.competition.title }}{{ submission.pk }}{{ submission.parent.pk }}SizeSubmitterQueueIngestion HostnameScoring HostnameSubmitted atStatus
No submissions, yet!
{{ submission.file_size }}{{ submission.owner_display_name }}{{ submission.competition_queue }}{{ submission.ingestion_worker_hostname }}{{ submission.scoring_worker_hostname }}{{ submission.created_when|timesince }} ago{{ submission.status }}
+ {% for submission in submissions %} + + {{ submission.phase.competition.title }} + {{ submission.pk }} + {% if show_child_submissions %} + {{ submission.parent.pk }} + {% endif %} + {{ submission.file_size }} + {{ submission.owner_display_name }} + {{ submission.competition_queue }} + {{ submission.ingestion_worker_hostname }} + {{ submission.scoring_worker_hostname }} + {{ submission.created_when|timesince }} ago + {{ submission.status }} + + {% endfor %} + + - - {% if is_paginated %} -
- {% if submissions.has_previous %} - - First - Previous - - {% endif %} - - - Page {{ submissions.number }} of {{ paginator.num_pages }} - - - - {% if submissions.has_next %} - - Next - Last - - {% endif %} + + {% if is_paginated %} +
+ {% if submissions.has_previous %} + + First + Previous + + {% endif %} + + + Page {{ submissions.number }} of {{ paginator.num_pages }} + + + + {% if submissions.has_next %} + + Next + Last + + {% endif %} +
+ {% endif %} +
+ {% else %} +
+
+ Log In or + Sign Up to view this page +
- {% endif %} -
+ {% endif %}