web/admin: select all password stage backends by default

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-08-23 17:54:19 +02:00
parent 1b8750e13b
commit 5face5410f
4 changed files with 21 additions and 7 deletions

View File

@ -25,12 +25,12 @@ class TokenSerializer(ManagedSerializer, ModelSerializer):
user = UserSerializer(required=False) user = UserSerializer(required=False)
def validate(self, data: dict[Any, str]) -> dict[Any, str]: def validate(self, attrs: dict[Any, str]) -> dict[Any, str]:
"""Ensure only API or App password tokens are created.""" """Ensure only API or App password tokens are created."""
data.setdefault("intent", TokenIntents.INTENT_API) attrs.setdefault("intent", TokenIntents.INTENT_API)
if data.get("intent") not in [TokenIntents.INTENT_API, TokenIntents.INTENT_APP_PASSWORD]: if attrs.get("intent") not in [TokenIntents.INTENT_API, TokenIntents.INTENT_APP_PASSWORD]:
raise ValidationError(f"Invalid intent {data.get('intent')}") raise ValidationError(f"Invalid intent {attrs.get('intent')}")
return data return attrs
class Meta: class Meta:

View File

@ -25,6 +25,8 @@ def get_attrs(obj: SerializerModel) -> dict[str, Any]:
"component", "component",
"flow_set", "flow_set",
"promptstage_set", "promptstage_set",
"policybindingmodel_ptr_id",
"export_url",
) )
for to_remove_name in to_remove: for to_remove_name in to_remove:
if to_remove_name in data: if to_remove_name in data:

View File

@ -156,11 +156,20 @@ export class IdentificationStageForm extends ModelForm<IdentificationStage, stri
.sourcesAllList({}) .sourcesAllList({})
.then((sources) => { .then((sources) => {
return sources.results.map((source) => { return sources.results.map((source) => {
const selected = Array.from( let selected = Array.from(
this.instance?.sources || [], this.instance?.sources || [],
).some((su) => { ).some((su) => {
return su == source.pk; return su == source.pk;
}); });
// Creating a new instance, auto-select built-in source
// Only when no other sources exist
if (
!this.instance &&
source.component === "" &&
sources.results.length < 2
) {
selected = true;
}
return html`<option return html`<option
value=${ifDefined(source.pk)} value=${ifDefined(source.pk)}
?selected=${selected} ?selected=${selected}

View File

@ -46,8 +46,11 @@ export class PasswordStageForm extends ModelForm<PasswordStage, string> {
}; };
isBackendSelected(field: BackendsEnum): boolean { isBackendSelected(field: BackendsEnum): boolean {
if (!this.instance) {
return true;
}
return ( return (
(this.instance?.backends || []).filter((isField) => { this.instance.backends.filter((isField) => {
return field === isField; return field === isField;
}).length > 0 }).length > 0
); );