Fix channel modal validation

Closes #1091
This commit is contained in:
Nassim Jahnke 2023-02-15 16:37:00 +01:00
parent 186fe47ca6
commit 77bfd237ce
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
2 changed files with 15 additions and 5 deletions

View File

@ -10,17 +10,18 @@ import org.springframework.boot.context.properties.bind.DefaultValue;
@ConfigurationProperties(prefix = "hangar.channels")
public record ChannelsConfig(
@Min(1) @DefaultValue("15") int maxNameLen,
@DefaultValue("15") int maxNameLen,
@DefaultValue("1") int minNameLen,
@DefaultValue("^[a-zA-Z0-9]+$") PatternWrapper nameRegex,
@DefaultValue("cyan") Color colorDefault,
@Size(min = 1, max = 15) @DefaultValue("Release") String nameDefault
) {
public boolean isValidChannelName(final String name) {
return name.length() >= 1 && name.length() <= this.maxNameLen() && this.nameRegex().test(name);
return name.length() >= this.minNameLen() && name.length() <= this.maxNameLen() && this.nameRegex().test(name);
}
public Validation channelName() {
return new Validation(this.nameRegex(), this.maxNameLen(), null);
return new Validation(this.nameRegex(), this.maxNameLen(), this.minNameLen());
}
}

View File

@ -7,7 +7,7 @@ import Button from "~/lib/components/design/Button.vue";
import Modal from "~/lib/components/modals/Modal.vue";
import { useBackendData } from "~/store/backendData";
import InputText from "~/lib/components/ui/InputText.vue";
import { isSame, required } from "~/lib/composables/useValidationHelpers";
import { isSame, maxLength, minLength, pattern, required } from "~/lib/composables/useValidationHelpers";
import { validChannelName, validChannelColor } from "~/composables/useHangarValidations";
import InputCheckbox from "~/lib/components/ui/InputCheckbox.vue";
import { ChannelFlag } from "~/types/enums";
@ -90,7 +90,16 @@ reset();
<Modal :title="edit ? i18n.t('channel.modal.titleEdit') : i18n.t('channel.modal.titleNew')" window-classes="w-150">
<template #default="{ on }">
<div v-if="!frozen">
<InputText v-model.trim="name" :label="i18n.t('channel.modal.name')" :rules="[required(), validChannelName()(props.projectId, props.channel?.name)]" />
<InputText
v-model.trim="name"
:label="i18n.t('channel.modal.name')"
:rules="[
required(),
maxLength()(useBackendData.validations.project.channels.max),
pattern()(useBackendData.validations.project.channels.regex),
validChannelName()(props.projectId, props.channel?.name),
]"
/>
<p class="text-lg font-bold mt-3 mb-1">{{ i18n.t("channel.modal.color") }}</p>
<div v-for="(arr, arrIndex) in swatches" :key="arrIndex" class="flex">
<div v-for="(c, n) in arr" :key="n" class="flex-grow-0 flex-shrink-1 pa-2 pr-1 mb-1">