forked from forgejo/forgejo
Add delete route for attachments, remove upload buttons from issues/comments
This commit is contained in:
parent
34304e6a0c
commit
3c025b3950
5 changed files with 132 additions and 8 deletions
|
@ -1018,13 +1018,17 @@ func IssuePostAttachment(ctx *middleware.Context, params martini.Params) {
|
|||
issueId, _ := base.StrTo(params["index"]).Int64()
|
||||
|
||||
if issueId == 0 {
|
||||
ctx.Handle(400, "issue.IssuePostAttachment", nil)
|
||||
ctx.JSON(400, map[string]interface{}{
|
||||
"ok": false,
|
||||
"error": "invalid issue id",
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
commentId, err := base.StrTo(params["id"]).Int64()
|
||||
commentId, err := base.StrTo(params["comment"]).Int64()
|
||||
|
||||
if err != nil && len(params["id"]) > 0 {
|
||||
if err != nil && len(params["comment"]) > 0 {
|
||||
ctx.JSON(400, map[string]interface{}{
|
||||
"ok": false,
|
||||
"error": "invalid comment id",
|
||||
|
@ -1132,3 +1136,102 @@ func IssueGetAttachment(ctx *middleware.Context, params martini.Params) {
|
|||
|
||||
ctx.ServeFile(attachment.Path, attachment.Name)
|
||||
}
|
||||
|
||||
func IssueDeleteAttachment(ctx *middleware.Context, params martini.Params) {
|
||||
issueId, _ := base.StrTo(params["index"]).Int64()
|
||||
|
||||
if issueId == 0 {
|
||||
ctx.JSON(400, map[string]interface{}{
|
||||
"ok": false,
|
||||
"error": "invalid issue id",
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
commentId, err := base.StrTo(params["comment"]).Int64()
|
||||
|
||||
if err != nil || commentId < 0 {
|
||||
ctx.JSON(400, map[string]interface{}{
|
||||
"ok": false,
|
||||
"error": "invalid comment id",
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
comment, err := models.GetCommentById(commentId)
|
||||
|
||||
if err != nil {
|
||||
ctx.JSON(400, map[string]interface{}{
|
||||
"ok": false,
|
||||
"error": "invalid issue id",
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if comment.PosterId != ctx.User.Id {
|
||||
ctx.JSON(400, map[string]interface{}{
|
||||
"ok": false,
|
||||
"error": "no permissions",
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
attachmentId, err := base.StrTo(params["id"]).Int64()
|
||||
|
||||
if err != nil {
|
||||
ctx.JSON(400, map[string]interface{}{
|
||||
"ok": false,
|
||||
"error": "invalid attachment id",
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
attachment, err := models.GetAttachmentById(attachmentId)
|
||||
|
||||
if err != nil {
|
||||
ctx.JSON(400, map[string]interface{}{
|
||||
"ok": false,
|
||||
"error": "wrong attachment id",
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if attachment.IssueId != issueId {
|
||||
ctx.JSON(400, map[string]interface{}{
|
||||
"ok": false,
|
||||
"error": "attachment not associated with the given issue",
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if attachment.CommentId != commentId {
|
||||
ctx.JSON(400, map[string]interface{}{
|
||||
"ok": false,
|
||||
"error": "attachment not associated with the given comment",
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
err = models.DeleteAttachment(attachment, true)
|
||||
|
||||
if err != nil {
|
||||
ctx.JSON(500, map[string]interface{}{
|
||||
"ok": false,
|
||||
"error": "could not delete attachment",
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
"ok": true,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue