Skip to content

Commit c6fb7fe

Browse files
davidsvantessonlunny
authored andcommitted
Fix API for edit and delete release attachment (#8285)
* 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 eb11ca6 commit c6fb7fe

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
@@ -9,6 +9,7 @@ import (
99

1010
"code.gitea.io/gitea/models"
1111
"code.gitea.io/gitea/modules/context"
12+
"code.gitea.io/gitea/modules/log"
1213
"code.gitea.io/gitea/modules/setting"
1314
api "code.gitea.io/gitea/modules/structs"
1415
"code.gitea.io/gitea/modules/upload"
@@ -55,6 +56,7 @@ func GetReleaseAttachment(ctx *context.APIContext) {
5556
return
5657
}
5758
if attach.ReleaseID != releaseID {
59+
log.Info("User requested attachment is not in release, release_id %v, attachment_id: %v", releaseID, attachID)
5860
ctx.NotFound()
5961
return
6062
}
@@ -242,13 +244,14 @@ func EditReleaseAttachment(ctx *context.APIContext, form api.EditAttachmentOptio
242244

243245
// Check if release exists an load release
244246
releaseID := ctx.ParamsInt64(":id")
245-
attachID := ctx.ParamsInt64(":attachment")
247+
attachID := ctx.ParamsInt64(":asset")
246248
attach, err := models.GetAttachmentByID(attachID)
247249
if err != nil {
248250
ctx.Error(500, "GetAttachmentByID", err)
249251
return
250252
}
251253
if attach.ReleaseID != releaseID {
254+
log.Info("User requested attachment is not in release, release_id %v, attachment_id: %v", releaseID, attachID)
252255
ctx.NotFound()
253256
return
254257
}
@@ -299,13 +302,14 @@ func DeleteReleaseAttachment(ctx *context.APIContext) {
299302

300303
// Check if release exists an load release
301304
releaseID := ctx.ParamsInt64(":id")
302-
attachID := ctx.ParamsInt64(":attachment")
305+
attachID := ctx.ParamsInt64(":asset")
303306
attach, err := models.GetAttachmentByID(attachID)
304307
if err != nil {
305308
ctx.Error(500, "GetAttachmentByID", err)
306309
return
307310
}
308311
if attach.ReleaseID != releaseID {
312+
log.Info("User requested attachment is not in release, release_id %v, attachment_id: %v", releaseID, attachID)
309313
ctx.NotFound()
310314
return
311315
}

0 commit comments

Comments
 (0)