summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authoryp05327 <576951401@qq.com>2023-03-31 23:32:18 +0900
committerGitHub <noreply@github.com>2023-03-31 22:32:18 +0800
commit6e58f8400e911e642957acb6d4b63111d98d3de7 (patch)
tree83cdabff6d2c0a27c3cf0c65b2707993bc31531f /models
parent7df036f1a50270b15c58084bb4f2502b66d562ae (diff)
downloadgitea-6e58f8400e911e642957acb6d4b63111d98d3de7.tar.gz
gitea-6e58f8400e911e642957acb6d4b63111d98d3de7.zip
Fix 500 error if there is a name conflict when edit authentication source (#23832)
Diffstat (limited to 'models')
-rw-r--r--models/auth/source.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/models/auth/source.go b/models/auth/source.go
index bade2fecf0..0a904b7772 100644
--- a/models/auth/source.go
+++ b/models/auth/source.go
@@ -317,7 +317,14 @@ func UpdateSource(source *Source) error {
}
}
- _, err := db.GetEngine(db.DefaultContext).ID(source.ID).AllCols().Update(source)
+ has, err := db.GetEngine(db.DefaultContext).Where("name=? AND id!=?", source.Name, source.ID).Exist(new(Source))
+ if err != nil {
+ return err
+ } else if has {
+ return ErrSourceAlreadyExist{source.Name}
+ }
+
+ _, err = db.GetEngine(db.DefaultContext).ID(source.ID).AllCols().Update(source)
if err != nil {
return err
}