aboutsummaryrefslogtreecommitdiffstats
path: root/src/workflow/views.py
diff options
context:
space:
mode:
authorJustin Choquette <jchoquette@iol.unh.edu>2023-09-27 17:03:38 -0400
committerJustin Choquette <jchoquette@iol.unh.edu>2023-10-19 18:10:17 -0400
commitaff53e072502d63d8002d9c83213ce7f9d12c352 (patch)
tree3a30adca1fe7c958ddc092dbf7b9fa24259dd923 /src/workflow/views.py
parent1947d40115c7b13f8617ea92078a6f910d6bc799 (diff)
user subsystem clean up
Change-Id: Ia59bb7c1e4412693f55cdcaf9607bcb4158850ae Signed-off-by: Justin Choquette <jchoquette@iol.unh.edu>
Diffstat (limited to 'src/workflow/views.py')
-rw-r--r--src/workflow/views.py85
1 files changed, 42 insertions, 43 deletions
diff --git a/src/workflow/views.py b/src/workflow/views.py
index c634b38..a85ac09 100644
--- a/src/workflow/views.py
+++ b/src/workflow/views.py
@@ -11,60 +11,59 @@ import json
from django.shortcuts import render, redirect
from laas_dashboard.settings import TEMPLATE_OVERRIDE
from django.http import HttpResponse
-from django.http.response import JsonResponse
+from liblaas.views import user_get_user
from workflow.forms import BookingMetaForm
-from api.views import liblaas_request, make_booking
-from api.utils import get_booking_prereqs_validator
from account.models import UserProfile
-def no_workflow(request):
- return render(request, 'workflow/no_workflow.html', {'title': "Not Found"}, status=404)
-
-
def login(request):
return render(request, "dashboard/login.html", {'title': 'Authentication Required'})
def design_a_pod_view(request):
- if request.method == "GET":
- if not request.user.is_authenticated:
- return login(request)
- prereq_validator = get_booking_prereqs_validator(UserProfile.objects.get(user=request.user))
- if (prereq_validator["action"] == "no user"):
- return redirect("dashboard:index")
- template = "workflow/design_a_pod.html"
- context = {
- "dashboard": str(TEMPLATE_OVERRIDE)
- }
- return render(request, template, context)
-
- if request.method == "POST":
- print("forwarding request to liblaas...")
- return liblaas_request(request)
+ if request.method != "GET":
+ return HttpResponse(status=405)
+
+ if not request.user.is_authenticated:
+ return login(request)
+
+ profile = UserProfile.objects.get(user=request.user)
+
+ if (not profile or profile.ipa_username == None):
+ return redirect("dashboard:index")
+
+ template = "workflow/design_a_pod.html"
+ context = {
+ "dashboard": str(TEMPLATE_OVERRIDE)
+ }
+ return render(request, template, context)
- return HttpResponse(status=405)
def book_a_pod_view(request):
- if request.method == "GET":
- if not request.user.is_authenticated:
- return login(request)
- prereq_validator = get_booking_prereqs_validator(UserProfile.objects.get(user=request.user))
- if (prereq_validator["action"] == "no user"):
- return redirect("dashboard:index")
- template = "workflow/book_a_pod.html"
- context = {
- "dashboard": str(TEMPLATE_OVERRIDE),
- "form": BookingMetaForm(initial={}, user_initial=[], owner=request.user),
- "prereq_validator": prereq_validator
- }
- return render(request, template, context)
+ if request.method != "GET":
+ return HttpResponse(status=405)
+
+ if not request.user.is_authenticated:
+ return login(request)
+
+ profile = UserProfile.objects.get(user=request.user)
+
+ if (not profile or profile.ipa_username == None):
+ return redirect("dashboard:index")
+
+ vpn_user = user_get_user(profile.ipa_username)
- if request.method == "POST":
- print("forwarding request to liblaas...")
- return liblaas_request(request)
+ # These booleans need to be represented as strings, due to the way jinja interprets them
+ prereqs = {
+ "company": "true" if ("ou" in vpn_user and vpn_user["ou"] != "") else "false",
+ "keys": "true" if ("ipasshpubkey" in vpn_user) and (len(vpn_user["ipasshpubkey"]) > 0) else "false"
+ }
+
+ template = "workflow/book_a_pod.html"
+ context = {
+ "dashboard": str(TEMPLATE_OVERRIDE),
+ "form": BookingMetaForm(initial={}, user_initial=[], owner=request.user),
+ "prereqs": prereqs
+ }
+ return render(request, template, context)
- # Using PUT to signal that we do not want to talk to liblaas
- if request.method == "PUT":
- return make_booking(request)
- return HttpResponse(status=405)