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:
		| @ -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"] | ||||||
|  |  | ||||||
|  | |||||||
| @ -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 | ||||||
|  | |||||||
| @ -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,16 +47,26 @@ 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 stages.results.map((stage) => { | ||||||
|  |                                             return stage.flowSet?.map((flow) => { | ||||||
|  |                                                 if (seenFlowSlugs.includes(flow.slug)) { | ||||||
|  |                                                     return html``; | ||||||
|  |                                                 } | ||||||
|  |                                                 seenFlowSlugs.push(flow.slug); | ||||||
|                                                 return html`<option |                                                 return html`<option | ||||||
|                                                     value=${flow.slug} |                                                     value=${flow.slug} | ||||||
|                                                     ?selected=${flow.slug === this.selectedFlow} |                                                     ?selected=${flow.slug === this.selectedFlow} | ||||||
| @ -64,6 +74,7 @@ export class InvitationListLink extends LitElement { | |||||||
|                                                     ${flow.slug} |                                                     ${flow.slug} | ||||||
|                                                 </option>`; |                                                 </option>`; | ||||||
|                                             }); |                                             }); | ||||||
|  |                                         }); | ||||||
|                                     }), |                                     }), | ||||||
|                                 html`<option>${t`Loading...`}</option>`, |                                 html`<option>${t`Loading...`}</option>`, | ||||||
|                             )} |                             )} | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Jens Langhammer
					Jens Langhammer