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:
parent
c830bc13e4
commit
25425adf29
@ -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]
|
||||
|
@ -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
|
||||
|
@ -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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user