web/admin: only show flows with an invitation stage configured instead of all enrollment flows

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>

#1720
This commit is contained in:
Jens Langhammer 2021-11-04 20:52:11 +01:00
parent b14b9cb0dd
commit 738e4d5c74
3 changed files with 44 additions and 16 deletions

View file

@ -1,4 +1,6 @@
"""Invitation Stage API Views""" """Invitation Stage API Views"""
from django_filters.filters import BooleanFilter
from django_filters.filterset import FilterSet
from rest_framework.fields import JSONField from rest_framework.fields import JSONField
from rest_framework.serializers import ModelSerializer from rest_framework.serializers import ModelSerializer
from rest_framework.viewsets import ModelViewSet from rest_framework.viewsets import ModelViewSet
@ -21,12 +23,23 @@ class InvitationStageSerializer(StageSerializer):
] ]
class InvitationStageFilter(FilterSet):
"""invitation filter"""
no_flows = BooleanFilter("flow", "isnull")
class Meta:
model = InvitationStage
fields = ["name", "no_flows", "continue_flow_without_invitation", "stage_uuid"]
class InvitationStageViewSet(UsedByMixin, ModelViewSet): class InvitationStageViewSet(UsedByMixin, ModelViewSet):
"""InvitationStage Viewset""" """InvitationStage Viewset"""
queryset = InvitationStage.objects.all() queryset = InvitationStage.objects.all()
serializer_class = InvitationStageSerializer serializer_class = InvitationStageSerializer
filterset_fields = "__all__" filterset_class = InvitationStageFilter
ordering = ["name"] ordering = ["name"]
@ -53,7 +66,7 @@ class InvitationViewSet(UsedByMixin, ModelViewSet):
queryset = Invitation.objects.all() queryset = Invitation.objects.all()
serializer_class = InvitationSerializer serializer_class = InvitationSerializer
order = ["-expires"] ordering = ["-expires"]
search_fields = ["created_by__username", "expires"] search_fields = ["created_by__username", "expires"]
filterset_fields = ["created_by__username", "expires"] filterset_fields = ["created_by__username", "expires"]

View file

@ -17143,6 +17143,10 @@ paths:
name: name name: name
schema: schema:
type: string type: string
- in: query
name: no_flows
schema:
type: boolean
- name: ordering - name: ordering
required: false required: false
in: query in: query

View file

@ -11,7 +11,7 @@ import PFFormControl from "@patternfly/patternfly/components/FormControl/form-co
import PFFlex from "@patternfly/patternfly/layouts/Flex/flex.css"; import PFFlex from "@patternfly/patternfly/layouts/Flex/flex.css";
import PFBase from "@patternfly/patternfly/patternfly-base.css"; import PFBase from "@patternfly/patternfly/patternfly-base.css";
import { FlowsApi, FlowsInstancesListDesignationEnum } from "@goauthentik/api"; import { StagesApi } from "@goauthentik/api";
import { DEFAULT_CONFIG } from "../../../api/Config"; import { DEFAULT_CONFIG } from "../../../api/Config";
@ -47,22 +47,33 @@ export class InvitationListLink extends LitElement {
}} }}
> >
${until( ${until(
new FlowsApi(DEFAULT_CONFIG) new StagesApi(DEFAULT_CONFIG)
.flowsInstancesList({ .stagesInvitationStagesList({
ordering: "pk", ordering: "pk",
designation: FlowsInstancesListDesignationEnum.Enrollment, noFlows: false,
}) })
.then((flows) => { .then((stages) => {
if (!this.selectedFlow && flows.results.length > 0) { if (
this.selectedFlow = flows.results[0].slug; !this.selectedFlow &&
stages.results.length > 0 &&
stages.results[0].flowSet
) {
this.selectedFlow = stages.results[0].flowSet[0].slug;
} }
return flows.results.map((flow) => { const seenFlowSlugs: string[] = [];
return html`<option return stages.results.map((stage) => {
value=${flow.slug} return stage.flowSet?.map((flow) => {
?selected=${flow.slug === this.selectedFlow} if (seenFlowSlugs.includes(flow.slug)) {
> return html``;
${flow.slug} }
</option>`; seenFlowSlugs.push(flow.slug);
return html`<option
value=${flow.slug}
?selected=${flow.slug === this.selectedFlow}
>
${flow.slug}
</option>`;
});
}); });
}), }),
html`<option>${t`Loading...`}</option>`, html`<option>${t`Loading...`}</option>`,