Allow updating tag name capitalization (#781)

This commit is contained in:
InfiniteTF 2020-09-02 02:30:37 +02:00 committed by GitHub
parent 16ea6abf91
commit 5d9cc09fca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions

View File

@ -37,7 +37,7 @@ func (r *mutationResolver) TagCreate(ctx context.Context, input models.TagCreate
qb := models.NewTagQueryBuilder()
// ensure name is unique
if err := manager.EnsureTagNameUnique(newTag.Name, tx); err != nil {
if err := manager.EnsureTagNameUnique(newTag, tx); err != nil {
tx.Rollback()
return nil, err
}
@ -102,7 +102,7 @@ func (r *mutationResolver) TagUpdate(ctx context.Context, input models.TagUpdate
}
if existing.Name != updatedTag.Name {
if err := manager.EnsureTagNameUnique(updatedTag.Name, tx); err != nil {
if err := manager.EnsureTagNameUnique(updatedTag, tx); err != nil {
tx.Rollback()
return nil, err
}

View File

@ -7,18 +7,18 @@ import (
"github.com/stashapp/stash/pkg/models"
)
func EnsureTagNameUnique(name string, tx *sqlx.Tx) error {
func EnsureTagNameUnique(tag models.Tag, tx *sqlx.Tx) error {
qb := models.NewTagQueryBuilder()
// ensure name is unique
sameNameTag, err := qb.FindByName(name, tx, true)
sameNameTag, err := qb.FindByName(tag.Name, tx, true)
if err != nil {
_ = tx.Rollback()
return err
}
if sameNameTag != nil {
return fmt.Errorf("Tag with name '%s' already exists", name)
if sameNameTag != nil && tag.ID != sameNameTag.ID {
return fmt.Errorf("Tag with name '%s' already exists", tag.Name)
}
return nil