Skip to content

Commit 65871ea

Browse files
committed
Make DeletePublicKey return err
1 parent 19fa201 commit 65871ea

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

models/ssh_key.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,7 @@ func deletePublicKeys(e *xorm.Session, keyIDs ...int64) error {
506506
func DeletePublicKey(doer *User, id int64) (err error) {
507507
key, err := GetPublicKeyByID(id)
508508
if err != nil {
509-
if IsErrKeyNotExist(err) {
510-
return nil
511-
}
512-
return fmt.Errorf("GetPublicKeyByID: %v", err)
509+
return err
513510
}
514511

515512
// Check if user has access to delete this key.

routers/api/v1/admin/user.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -258,26 +258,19 @@ func DeleteUserPublicKey(ctx *context.APIContext) {
258258
// responses:
259259
// "204":
260260
// "$ref": "#/responses/empty"
261-
// "404":
262-
// "$ref": "#/responses/notFound"
263261
// "403":
264262
// "$ref": "#/responses/forbidden"
263+
// "404":
264+
// "$ref": "#/responses/notFound"
265265
u := user.GetUserByParams(ctx)
266266
if ctx.Written() {
267267
return
268268
}
269269

270-
if _, err := models.GetPublicKeyByID(ctx.ParamsInt64(":id")); err != nil {
270+
if err := models.DeletePublicKey(u, ctx.ParamsInt64(":id")); err != nil {
271271
if models.IsErrKeyNotExist(err) {
272272
ctx.Status(404)
273-
} else {
274-
ctx.Error(500, "DeleteUserPublicKey", err)
275-
}
276-
return
277-
}
278-
279-
if err := models.DeletePublicKey(u, ctx.ParamsInt64(":id")); err != nil {
280-
if models.IsErrKeyAccessDenied(err) {
273+
} else if models.IsErrKeyAccessDenied(err) {
281274
ctx.Error(403, "", "You do not have access to this key")
282275
} else {
283276
ctx.Error(500, "DeleteUserPublicKey", err)

routers/api/v1/user/key.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,12 @@ func DeletePublicKey(ctx *context.APIContext) {
178178
// "$ref": "#/responses/empty"
179179
// "403":
180180
// "$ref": "#/responses/forbidden"
181+
// "404":
182+
// "$ref": "#/responses/notFound"
181183
if err := models.DeletePublicKey(ctx.User, ctx.ParamsInt64(":id")); err != nil {
182-
if models.IsErrKeyAccessDenied(err) {
184+
if models.IsErrKeyNotExist(err) {
185+
ctx.Status(404)
186+
} else if models.IsErrKeyAccessDenied(err) {
183187
ctx.Error(403, "", "You do not have access to this key")
184188
} else {
185189
ctx.Error(500, "DeletePublicKey", err)

0 commit comments

Comments
 (0)