Skip to content

Commit

Permalink
allow workshop sessions to be terminated
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Fitzgerald <[email protected]>
  • Loading branch information
joefitzgerald committed Jan 22, 2023
1 parent 059e22f commit b64d9f7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
8 changes: 7 additions & 1 deletion training-portal/src/project/apps/workshops/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
views.catalog_environments,
name="workshops_catalog_environments",
),
path("environment/<slug:name>/", views.environment, name="workshops_environment"),
path("environment/<slug:name>/", views.environment,
name="workshops_environment"),
path(
"environment/<slug:name>/create/",
views.environment_create,
Expand Down Expand Up @@ -47,6 +48,11 @@
views.session_extend,
name="workshops_session_extend",
),
path(
"session/<slug:name>/terminate/",
views.session_terminate,
name="workshops_session_terminate",
),
path(
"session/<slug:name>/event/",
views.session_event,
Expand Down
38 changes: 38 additions & 0 deletions training-portal/src/project/apps/workshops/views/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,44 @@ def session_activate(request, name):
return redirect("workshops_session", name=instance.name)


@protected_resource()
@require_http_methods(["GET"])
def session_terminate(request, name):
"""Triggers termination of a workshop session."""

portal = TrainingPortal.objects.get(name=settings.TRAINING_PORTAL)

# Ensure that the session exists.

instance = portal.allocated_session(name)

if not instance:
raise Http404("Session does not exist")

# Check that session is allocated and in use.

if not instance.is_allocated():
return HttpResponseForbidden("Session is not currently in use")

if not request.user.is_staff and not request.user.groups.filter(name="robots").exists():
if instance.owner != request.user:
return HttpResponseForbidden("Access to session not permitted")

instance.mark_as_stopping()

report_analytics_event(instance, "Session/Stopping")

transaction.on_commit(
lambda: delete_workshop_session(instance).schedule())

details = {}

details["started"] = instance.started
details["expires"] = instance.expires

return JsonResponse(details)


@login_required(login_url="/")
@require_http_methods(["GET"])
@resources_lock
Expand Down

0 comments on commit b64d9f7

Please sign in to comment.