0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-07-20 03:58:26 +02:00

Implement DeleteOauthAuth API and refactor source deletion logic

This commit is contained in:
Tim Riedl 2025-04-19 00:36:54 +02:00
parent c830bc13e4
commit 25425adf29
No known key found for this signature in database
GPG Key ID: 172D6410FC4F844E
3 changed files with 26 additions and 3 deletions

View File

@ -235,13 +235,18 @@ func CreateSource(ctx context.Context, source *Source) error {
err = registerableSource.RegisterSource() err = registerableSource.RegisterSource()
if err != nil { if err != nil {
// remove the AuthSource in case of errors while registering configuration // remove the AuthSource in case of errors while registering configuration
if _, err := db.GetEngine(ctx).ID(source.ID).Delete(new(Source)); err != nil { if err := DeleteSource(ctx, source.ID); err != nil {
log.Error("CreateSource: Error while wrapOpenIDConnectInitializeError: %v", err) log.Error("CreateSource: Error while wrapOpenIDConnectInitializeError: %v", err)
} }
} }
return err return err
} }
func DeleteSource(ctx context.Context, id int64) error {
_, err := db.GetEngine(ctx).ID(id).Delete(new(Source))
return err
}
type FindSourcesOptions struct { type FindSourcesOptions struct {
db.ListOptions db.ListOptions
IsActive optional.Option[bool] IsActive optional.Option[bool]

View File

@ -8,6 +8,7 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"net/url" "net/url"
"strconv"
auth_model "code.gitea.io/gitea/models/auth" auth_model "code.gitea.io/gitea/models/auth"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
@ -74,6 +75,20 @@ func EditOauthAuth(ctx *context.APIContext) {
// DeleteOauthAuth api for deleting a authentication method // DeleteOauthAuth api for deleting a authentication method
func DeleteOauthAuth(ctx *context.APIContext) { func DeleteOauthAuth(ctx *context.APIContext) {
oauthIdString := ctx.PathParam("id")
oauthID, oauthIdErr := strconv.Atoi(oauthIdString)
if oauthIdErr != nil {
ctx.APIErrorInternal(oauthIdErr)
}
err := auth_model.DeleteSource(ctx, int64(oauthID))
if err != nil {
ctx.APIErrorInternal(err)
return
}
ctx.Status(http.StatusOK)
} }
// // SearchOauthAuth API for getting information of the configured authentication methods according the filter conditions // // SearchOauthAuth API for getting information of the configured authentication methods according the filter conditions

View File

@ -1650,8 +1650,11 @@ func Routes() *web.Router {
m.Group("/admin", func() { m.Group("/admin", func() {
m.Group("/identity-auth", func() { m.Group("/identity-auth", func() {
m.Get("", admin.SearchOauthAuth) m.Group("oauth", func() {
m.Post("/new", admin.CreateOauthAuth) m.Get("", admin.SearchOauthAuth)
m.Delete("/{id}", admin.DeleteOauthAuth)
m.Post("/new", admin.CreateOauthAuth)
})
}) })
m.Group("/cron", func() { m.Group("/cron", func() {