diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/api/models.py | 22 | ||||
-rw-r--r-- | src/api/urls.py | 4 | ||||
-rw-r--r-- | src/api/views.py | 10 |
3 files changed, 35 insertions, 1 deletions
diff --git a/src/api/models.py b/src/api/models.py index df9bbf7..e41a44d 100644 --- a/src/api/models.py +++ b/src/api/models.py @@ -33,7 +33,7 @@ from resource_inventory.models import ( ) from resource_inventory.idf_templater import IDFTemplater from resource_inventory.pdf_templater import PDFTemplater -from account.models import Downtime +from account.models import Downtime, UserProfile from dashboard.utils import AbstractModelQuery @@ -174,6 +174,26 @@ class LabManager(object): for profile in ResourceProfile.objects.filter(labs=self.lab)] return prof + def format_user(self, userprofile): + return { + "id": userprofile.user.id, + "username": userprofile.user.username, + "email": userprofile.email_addr, + "first_name": userprofile.user.first_name, + "last_name": userprofile.user.last_name, + "company": userprofile.company + } + + def get_users(self): + userlist = [self.format_user(profile) for profile in UserProfile.objects.select_related("user").all()] + + return json.dumps({"users": userlist}) + + def get_user(self, user_id): + profile = get_object_or_404(UserProfile, pk=user_id) + + return json.dumps(self.format_user(profile)) + def get_inventory(self): inventory = {} resources = ResourceQuery.filter(lab=self.lab) diff --git a/src/api/urls.py b/src/api/urls.py index 39f07df..0005d34 100644 --- a/src/api/urls.py +++ b/src/api/urls.py @@ -42,6 +42,8 @@ from api.views import ( lab_host, get_pdf, get_idf, + lab_users, + lab_user, GenerateTokenView ) @@ -59,5 +61,7 @@ urlpatterns = [ path('labs/<slug:lab_name>/jobs/new', new_jobs), path('labs/<slug:lab_name>/jobs/current', current_jobs), path('labs/<slug:lab_name>/jobs/done', done_jobs), + path('labs/<slug:lab_name>/users', lab_users), + path('labs/<slug:lab_name>/users/<int:user_id>', lab_user), url(r'^token$', GenerateTokenView.as_view(), name='generate_token'), ] diff --git a/src/api/views.py b/src/api/views.py index bc01562..4e0d058 100644 --- a/src/api/views.py +++ b/src/api/views.py @@ -97,6 +97,16 @@ def lab_status(request, lab_name=""): return JsonResponse(lab_manager.set_status(request.POST), safe=False) return JsonResponse(lab_manager.get_status(), safe=False) +def lab_users(request, lab_name=""): + lab_token = request.META.get('HTTP_AUTH_TOKEN') + lab_manager = LabManagerTracker.get(lab_name, lab_token) + return HttpResponse(lab_manager.get_users(), content_type="text/plain") + +def lab_user(request, lab_name="", user_id=-1): + lab_token = request.META.get('HTTP_AUTH_TOKEN') + lab_manager = LabManagerTracker.get(lab_name, lab_token) + return HttpResponse(lab_manager.get_user(user_id), content_type="text/plain") + @csrf_exempt def update_host_bmc(request, lab_name="", host_id=""): |