0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-07-18 21:42:56 +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()
if err != nil {
// 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)
}
}
return err
}
func DeleteSource(ctx context.Context, id int64) error {
_, err := db.GetEngine(ctx).ID(id).Delete(new(Source))
return err
}
type FindSourcesOptions struct {
db.ListOptions
IsActive optional.Option[bool]

View File

@ -8,6 +8,7 @@ import (
"fmt"
"net/http"
"net/url"
"strconv"
auth_model "code.gitea.io/gitea/models/auth"
api "code.gitea.io/gitea/modules/structs"
@ -74,6 +75,20 @@ func EditOauthAuth(ctx *context.APIContext) {
// DeleteOauthAuth api for deleting a authentication method
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

View File

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