From aff53e072502d63d8002d9c83213ce7f9d12c352 Mon Sep 17 00:00:00 2001 From: Justin Choquette Date: Wed, 27 Sep 2023 17:03:38 -0400 Subject: user subsystem clean up Change-Id: Ia59bb7c1e4412693f55cdcaf9607bcb4158850ae Signed-off-by: Justin Choquette --- src/workflow/views.py | 85 +++++++++++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 43 deletions(-) (limited to 'src/workflow/views.py') 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) -- cgit 1.2.3-korg