mirror of https://github.com/stashapp/stash.git
Allow updating tag name capitalization (#781)
This commit is contained in:
parent
16ea6abf91
commit
5d9cc09fca
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue