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