Skip to content

Commit 25425ad

Browse files
committed
Implement DeleteOauthAuth API and refactor source deletion logic
1 parent c830bc1 commit 25425ad

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

models/auth/source.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,18 @@ func CreateSource(ctx context.Context, source *Source) error {
235235
err = registerableSource.RegisterSource()
236236
if err != nil {
237237
// remove the AuthSource in case of errors while registering configuration
238-
if _, err := db.GetEngine(ctx).ID(source.ID).Delete(new(Source)); err != nil {
238+
if err := DeleteSource(ctx, source.ID); err != nil {
239239
log.Error("CreateSource: Error while wrapOpenIDConnectInitializeError: %v", err)
240240
}
241241
}
242242
return err
243243
}
244244

245+
func DeleteSource(ctx context.Context, id int64) error {
246+
_, err := db.GetEngine(ctx).ID(id).Delete(new(Source))
247+
return err
248+
}
249+
245250
type FindSourcesOptions struct {
246251
db.ListOptions
247252
IsActive optional.Option[bool]

routers/api/v1/admin/auth_oauth.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"net/http"
1010
"net/url"
11+
"strconv"
1112

1213
auth_model "code.gitea.io/gitea/models/auth"
1314
api "code.gitea.io/gitea/modules/structs"
@@ -74,6 +75,20 @@ func EditOauthAuth(ctx *context.APIContext) {
7475

7576
// DeleteOauthAuth api for deleting a authentication method
7677
func DeleteOauthAuth(ctx *context.APIContext) {
78+
oauthIdString := ctx.PathParam("id")
79+
oauthID, oauthIdErr := strconv.Atoi(oauthIdString)
80+
if oauthIdErr != nil {
81+
ctx.APIErrorInternal(oauthIdErr)
82+
}
83+
84+
err := auth_model.DeleteSource(ctx, int64(oauthID))
85+
86+
if err != nil {
87+
ctx.APIErrorInternal(err)
88+
return
89+
}
90+
91+
ctx.Status(http.StatusOK)
7792
}
7893

7994
// // SearchOauthAuth API for getting information of the configured authentication methods according the filter conditions

routers/api/v1/api.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,8 +1650,11 @@ func Routes() *web.Router {
16501650

16511651
m.Group("/admin", func() {
16521652
m.Group("/identity-auth", func() {
1653-
m.Get("", admin.SearchOauthAuth)
1654-
m.Post("/new", admin.CreateOauthAuth)
1653+
m.Group("oauth", func() {
1654+
m.Get("", admin.SearchOauthAuth)
1655+
m.Delete("/{id}", admin.DeleteOauthAuth)
1656+
m.Post("/new", admin.CreateOauthAuth)
1657+
})
16551658
})
16561659

16571660
m.Group("/cron", func() {

0 commit comments

Comments
 (0)