From 4e8c162a104a46f7625b0ad624285ed39568d3a1 Mon Sep 17 00:00:00 2001 From: Sawyer Bergeron Date: Thu, 5 Aug 2021 18:17:37 +0000 Subject: Fixing usability critiques Signed-off-by: Sawyer Bergeron Change-Id: I5cbdef6cee6643beeb7c4af402d16c6b9055969b Signed-off-by: Sawyer Bergeron --- laas_api_documentation.yaml | 29 ++++++++++++++++++++--- src/api/urls.py | 5 ++-- src/api/views.py | 37 +++++++++++++++++------------- src/resource_inventory/resource_manager.py | 7 +++++- 4 files changed, 56 insertions(+), 22 deletions(-) diff --git a/laas_api_documentation.yaml b/laas_api_documentation.yaml index d16497d..ee967b0 100644 --- a/laas_api_documentation.yaml +++ b/laas_api_documentation.yaml @@ -192,16 +192,36 @@ paths: - application/json responses: '200': - description: successfel operation + description: successful operation schema: - $ref: '#/definitions/UserProfile' + type: array + items: + $ref: '#/definitions/UserProfile' '401': description: Unauthorized API key + /labs: + get: + tags: + - Lab + summary: List all labs and some of their info + description: '' + operationId: listLabs + produces: + - application/json + responses: + '200': + description: successful operation + schema: + type: array + items: + $ref: '#/definitions/Lab' + '401': + description: Unauthorized API Key /labs/{labID}/users: get: tags: - Lab - summary: Get all users at a lab + summary: Get all users that are visible to a lab for operational purposes description: '' operationId: labUsers consumes: @@ -216,6 +236,9 @@ paths: responses: '200': description: successful + schema: array + items: + $ref: '#/definitions/UserProfile' '400': description: invalid lab id securityDefinitions: diff --git a/src/api/urls.py b/src/api/urls.py index 1878d9c..52a6fc7 100644 --- a/src/api/urls.py +++ b/src/api/urls.py @@ -52,7 +52,8 @@ from api.views import ( images_for_template, specific_booking, extend_booking, - all_users + all_users, + list_labs ) urlpatterns = [ @@ -82,7 +83,7 @@ urlpatterns = [ path('resource_inventory//images', images_for_template), path('users', all_users), - path('labs', all_labs), + path('labs', list_labs), url(r'^token$', GenerateTokenView.as_view(), name='generate_token'), ] diff --git a/src/api/views.py b/src/api/views.py index 84085b4..1793c79 100644 --- a/src/api/views.py +++ b/src/api/views.py @@ -11,6 +11,7 @@ import json import math import traceback +import sys from datetime import timedelta from django.contrib.auth.decorators import login_required @@ -34,6 +35,7 @@ from notifier.manager import NotificationHandler from analytics.models import ActiveVPNUser from booking.quick_deployer import create_from_API from resource_inventory.models import ResourceTemplate +from django.db.models import Q """ @@ -362,9 +364,13 @@ def make_booking(request): try: booking = create_from_API(request.body, token.user) - except Exception as e: + + except Exception: + finalTrace = '' exc_type, exc_value, exc_traceback = sys.exc_info() - return HttpResponse(str(traceback.format_exception(exc_type, exc_value, exc_traceback)), status=400) + for i in traceback.format_exception(exc_type, exc_value, exc_traceback): + finalTrace += '
' + i.strip() + return HttpResponse(finalTrace, status=400) sbooking = AutomationAPIManager.serialize_booking(booking) return JsonResponse(sbooking, safe=False) @@ -419,7 +425,7 @@ def images_for_template(request, template_id=""): """ User API Views """ -lab_info + def all_users(request): token = auth_and_log(request, 'users') @@ -428,7 +434,7 @@ def all_users(request): return HttpResponse('Unauthorized', status=401) users = [AutomationAPIManager.serialize_userprofile(up) - for up in UserProfile.objects.exclude(user=token.user)] + for up in UserProfile.objects.filter(public_user=True)] return JsonResponse(users, safe=False) @@ -438,21 +444,20 @@ Lab API Views """ -def all_labs(): - lab_list=[] +def list_labs(request): + lab_list = [] for lab in Lab.objects.all(): lab_info = { - 'name':lab.name, - 'username':lab.lab_user.username, - 'status':lab.status, - 'project':lab.project, - 'description':lab.description, - 'location':lab.location, - 'info':lab.lab_info_link, - 'email':lab.contact_email, - 'phone':lab.contact_phone + 'name': lab.name, + 'username': lab.lab_user.username, + 'status': lab.status, + 'project': lab.project, + 'description': lab.description, + 'location': lab.location, + 'info': lab.lab_info_link, + 'email': lab.contact_email, + 'phone': lab.contact_phone } lab_list.append(lab_info) return JsonResponse(lab_list, safe=False) - diff --git a/src/resource_inventory/resource_manager.py b/src/resource_inventory/resource_manager.py index 1935e0c..37bf33c 100644 --- a/src/resource_inventory/resource_manager.py +++ b/src/resource_inventory/resource_manager.py @@ -6,14 +6,16 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import annotations + import re -import typing from typing import Optional from django.db.models import Q from dashboard.exceptions import ResourceAvailabilityException from resource_inventory.models import ( + Resource, ResourceBundle, ResourceTemplate, ResourceConfiguration, @@ -23,6 +25,9 @@ from resource_inventory.models import ( InterfaceConfiguration, ) +from account.models import Lab +from django.contrib.auth.models import User + class ResourceManager: -- cgit 1.2.3-korg