sources/oauth: fix error on user enrollment when no enrollment flow is defined
fixes #636 Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
221e4b665c
commit
4e86aa3f59
|
@ -15,9 +15,11 @@ class OAuthSourceForm(forms.ModelForm):
|
||||||
self.fields["authentication_flow"].queryset = Flow.objects.filter(
|
self.fields["authentication_flow"].queryset = Flow.objects.filter(
|
||||||
designation=FlowDesignation.AUTHENTICATION
|
designation=FlowDesignation.AUTHENTICATION
|
||||||
)
|
)
|
||||||
|
self.fields["authentication_flow"].required = True
|
||||||
self.fields["enrollment_flow"].queryset = Flow.objects.filter(
|
self.fields["enrollment_flow"].queryset = Flow.objects.filter(
|
||||||
designation=FlowDesignation.ENROLLMENT
|
designation=FlowDesignation.ENROLLMENT
|
||||||
)
|
)
|
||||||
|
self.fields["enrollment_flow"].required = True
|
||||||
if hasattr(self.Meta, "overrides"):
|
if hasattr(self.Meta, "overrides"):
|
||||||
for overide_field, overide_value in getattr(self.Meta, "overrides").items():
|
for overide_field, overide_value in getattr(self.Meta, "overrides").items():
|
||||||
self.fields[overide_field].initial = overide_value
|
self.fields[overide_field].initial = overide_value
|
||||||
|
|
|
@ -4,6 +4,7 @@ from typing import Any, Optional
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.http import Http404, HttpRequest, HttpResponse
|
from django.http import Http404, HttpRequest, HttpResponse
|
||||||
|
from django.http.response import HttpResponseBadRequest
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
@ -151,6 +152,8 @@ class OAuthCallback(OAuthClientMixin, View):
|
||||||
PLAN_CONTEXT_REDIRECT: final_redirect,
|
PLAN_CONTEXT_REDIRECT: final_redirect,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
if not flow:
|
||||||
|
return HttpResponseBadRequest()
|
||||||
# We run the Flow planner here so we can pass the Pending user in the context
|
# We run the Flow planner here so we can pass the Pending user in the context
|
||||||
planner = FlowPlanner(flow)
|
planner = FlowPlanner(flow)
|
||||||
plan = planner.plan(self.request, kwargs)
|
plan = planner.plan(self.request, kwargs)
|
||||||
|
@ -233,6 +236,9 @@ class OAuthCallback(OAuthClientMixin, View):
|
||||||
PLAN_CONTEXT_SOURCES_OAUTH_ACCESS: access,
|
PLAN_CONTEXT_SOURCES_OAUTH_ACCESS: access,
|
||||||
}
|
}
|
||||||
# We run the Flow planner here so we can pass the Pending user in the context
|
# We run the Flow planner here so we can pass the Pending user in the context
|
||||||
|
if not source.enrollment_flow:
|
||||||
|
LOGGER.warning("source has no enrollment flow", source=source)
|
||||||
|
return HttpResponseBadRequest()
|
||||||
planner = FlowPlanner(source.enrollment_flow)
|
planner = FlowPlanner(source.enrollment_flow)
|
||||||
plan = planner.plan(self.request, context)
|
plan = planner.plan(self.request, context)
|
||||||
plan.append(in_memory_stage(PostUserEnrollmentStage))
|
plan.append(in_memory_stage(PostUserEnrollmentStage))
|
||||||
|
|
Reference in New Issue