Skip to content

Commit 7156e2a

Browse files
davidsvantessonlunny
authored andcommitted
Fix API for edit and delete release attachment (#8290)
* Add logging for when user requested attachment doesn't belong to the specified release. * Fix API to use correct variable for release asset (attachment)
1 parent e51d91a commit 7156e2a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

routers/api/v1/repo/release_attachment.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"code.gitea.io/gitea/models"
1313
"code.gitea.io/gitea/modules/context"
14+
"code.gitea.io/gitea/modules/log"
1415
"code.gitea.io/gitea/modules/setting"
1516

1617
api "code.gitea.io/gitea/modules/structs"
@@ -57,6 +58,7 @@ func GetReleaseAttachment(ctx *context.APIContext) {
5758
return
5859
}
5960
if attach.ReleaseID != releaseID {
61+
log.Info("User requested attachment is not in release, release_id %v, attachment_id: %v", releaseID, attachID)
6062
ctx.NotFound()
6163
return
6264
}
@@ -256,13 +258,14 @@ func EditReleaseAttachment(ctx *context.APIContext, form api.EditAttachmentOptio
256258

257259
// Check if release exists an load release
258260
releaseID := ctx.ParamsInt64(":id")
259-
attachID := ctx.ParamsInt64(":attachment")
261+
attachID := ctx.ParamsInt64(":asset")
260262
attach, err := models.GetAttachmentByID(attachID)
261263
if err != nil {
262264
ctx.Error(500, "GetAttachmentByID", err)
263265
return
264266
}
265267
if attach.ReleaseID != releaseID {
268+
log.Info("User requested attachment is not in release, release_id %v, attachment_id: %v", releaseID, attachID)
266269
ctx.NotFound()
267270
return
268271
}
@@ -313,13 +316,14 @@ func DeleteReleaseAttachment(ctx *context.APIContext) {
313316

314317
// Check if release exists an load release
315318
releaseID := ctx.ParamsInt64(":id")
316-
attachID := ctx.ParamsInt64(":attachment")
319+
attachID := ctx.ParamsInt64(":asset")
317320
attach, err := models.GetAttachmentByID(attachID)
318321
if err != nil {
319322
ctx.Error(500, "GetAttachmentByID", err)
320323
return
321324
}
322325
if attach.ReleaseID != releaseID {
326+
log.Info("User requested attachment is not in release, release_id %v, attachment_id: %v", releaseID, attachID)
323327
ctx.NotFound()
324328
return
325329
}

0 commit comments

Comments
 (0)