Skip to content

Commit

Permalink
adds peak exp changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dxenes1 committed Feb 10, 2023
1 parent cf3f1cb commit d59a692
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 16 deletions.
51 changes: 35 additions & 16 deletions neuvue_project/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,26 @@ def _format_time(x):
def _get_status_count(task_df, status):
return task_df["status"].value_counts().get(status, 0)


# DEV NOTE: Hacky way to restrict dashboard to other group.
class DashboardView(View, LoginRequiredMixin):
def get(self, request, *args, **kwargs):
if not request.user.is_staff:
peak_admin = request.user.groups.filter(name=settings.PEAK_ADMIN).exists()
if not request.user.is_staff and not peak_admin:
return redirect(reverse("index"))

Namespaces = apps.get_model("workspace", "Namespace")

context = {}
context["all_groups"] = sorted([x.name for x in Group.objects.all()])
context["all_groups"].append("See All Users")
context["all_namespaces"] = sorted(
[x.display_name for x in Namespaces.objects.all()]
)
context["all_users"] = sorted([x.username for x in User.objects.all()])
if peak_admin:
context["all_groups"] = [settings.PEAK_COHORT]
context["all_namespaces"] = [settings.PEAK_NAMESPACE]
context["all_users"] = _get_users_from_group(settings.PEAK_COHORT)
else:
context["all_groups"] = sorted([x.name for x in Group.objects.all()])
context["all_groups"].append("See All Users")
context["all_namespaces"] = sorted(
[x.display_name for x in Namespaces.objects.all()]
)
context["all_users"] = sorted([x.username for x in User.objects.all()])

return render(request, "admin_dashboard/dashboard.html", context)

Expand All @@ -78,11 +83,16 @@ def post(self, request, *args, **kwargs):

class DashboardNamespaceView(View, LoginRequiredMixin):
def get(self, request, group=None, namespace=None, *args, **kwargs):
if not request.user.is_staff:
peak_admin = request.user.groups.filter(name=settings.PEAK_ADMIN).exists()
if not request.user.is_staff and not peak_admin:
return redirect(reverse("index"))

if namespace != settings.PEAK_NAMESPACE:
return redirect(reverse("index"))

Namespaces = apps.get_model("workspace", "Namespace")


context = {}
users = _get_users_from_group(group)
table, counts = self._generate_table_and_counts(namespace, users)
Expand Down Expand Up @@ -172,11 +182,17 @@ def _generate_table_and_counts(self, namespace: str, users: List):

class DashboardUserView(View, LoginRequiredMixin):
def get(self, request, username=None, filter=None, *args, **kwargs):
if not request.user.is_staff:
peak_admin = request.user.groups.filter(name=settings.PEAK_ADMIN).exists()
if not request.user.is_staff and not peak_admin:
return redirect(reverse("index"))

if username not in _get_users_from_group(settings.PEAK_COHORT):
return redirect(reverse("index"))
context = {}
table, counts = self._generate_table_and_counts(username)
if peak_admin:
table, counts = self._generate_table_and_counts(username, settings.PEAK_NAMESPACE)
else:
table, counts = self._generate_table_and_counts(username, settings.PEAK_NAMESPACE)

context["username"] = username
context["table"] = table
Expand All @@ -188,14 +204,17 @@ def get(self, request, username=None, filter=None, *args, **kwargs):

return render(request, "admin_dashboard/dashboard-user-view.html", context)

def _generate_table_and_counts(self, user: str):
def _generate_table_and_counts(self, user: str, namespace=None):
table_rows = []
# Counts
tc = tp = to = te = 0
if namespace:
sieve = {"assignee": user,"namespace": namespace}
else:
sieve = {"assignee": user}

user_df = client.get_tasks(
sieve={
"assignee": user,
},
sieve=sieve,
select=[
"opened",
"closed",
Expand Down
5 changes: 5 additions & 0 deletions neuvue_project/neuvue/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,8 @@
mimetypes.add_type("application/javascript", ".js", True)

STATIC_NG_FILES = os.listdir(os.path.join(BASE_DIR, "workspace", "static", "workspace"))

# PEAK EXPERIMENT
PEAK_ADMIN = "AGTExpAdmins"
PEAK_COHORT = "PeakCohort"
PEAK_NAMESPACE = "peakExtension"
10 changes: 10 additions & 0 deletions neuvue_project/workspace/views/tools.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

from django.shortcuts import render, redirect, reverse
from django.contrib.auth.models import Group, User
from django.views.generic.base import View
from django.conf import settings
from neuvue.client import client
Expand All @@ -22,6 +23,12 @@
# Get an instance of a logger
logger = logging.getLogger(__name__)

def _get_users_from_group(group: str):
if group == "See All Users": # case if all users are queried
return []
else: # case if group is provided
users = Group.objects.get(name=group).user_set.all()
return [x.username for x in users]

class InspectTaskView(View):
def get(self, request, task_id=None, *args, **kwargs):
Expand All @@ -36,6 +43,9 @@ def get(self, request, task_id=None, *args, **kwargs):
logging.warning(f"Unauthorized requests from {request.user}.")
return redirect(reverse("index"))

if request.user.username in _get_users_from_group(settings.PEAK_NAMESPACE):
return redirect(reverse("index"))

if task_id is None:
return render(request, "inspect.html", context)

Expand Down

0 comments on commit d59a692

Please sign in to comment.