mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 12:24:38 +03:00
Bugfix: Fix empty Aliases Being Created for Studios (#6273)
* Filter out empty alias strings in studio modal create * Reject empty alias strings in backend * Remove invalid ValidateAliases call from UpdatePartial This was calling using the values which are not necessarily the final values. --------- Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
var (
|
||||
ErrNameMissing = errors.New("studio name must not be blank")
|
||||
ErrEmptyAlias = errors.New("studio alias must not be an empty string")
|
||||
ErrStudioOwnAncestor = errors.New("studio cannot be an ancestor of itself")
|
||||
)
|
||||
|
||||
@@ -61,9 +62,12 @@ func EnsureStudioNameUnique(ctx context.Context, id int, name string, qb models.
|
||||
return nil
|
||||
}
|
||||
|
||||
func EnsureAliasesUnique(ctx context.Context, id int, aliases []string, qb models.StudioQueryer) error {
|
||||
func ValidateAliases(ctx context.Context, id int, aliases []string, qb models.StudioQueryer) error {
|
||||
for _, a := range aliases {
|
||||
if err := EnsureStudioNameUnique(ctx, id, a, qb); err != nil {
|
||||
if err := validateName(ctx, id, a, qb); err != nil {
|
||||
if errors.Is(err, ErrNameMissing) {
|
||||
return ErrEmptyAlias
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -77,7 +81,7 @@ func ValidateCreate(ctx context.Context, studio models.Studio, qb models.StudioQ
|
||||
}
|
||||
|
||||
if studio.Aliases.Loaded() && len(studio.Aliases.List()) > 0 {
|
||||
if err := EnsureAliasesUnique(ctx, 0, studio.Aliases.List(), qb); err != nil {
|
||||
if err := ValidateAliases(ctx, 0, studio.Aliases.List(), qb); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -131,7 +135,7 @@ func ValidateModify(ctx context.Context, s models.StudioPartial, qb ValidateModi
|
||||
}
|
||||
|
||||
effectiveAliases := s.Aliases.Apply(existing.Aliases.List())
|
||||
if err := EnsureAliasesUnique(ctx, s.ID, effectiveAliases, qb); err != nil {
|
||||
if err := ValidateAliases(ctx, s.ID, effectiveAliases, qb); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user