mirror of
https://github.com/go-gitea/gitea
synced 2024-12-22 12:34:11 +01:00
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
11
cmd/web.go
11
cmd/web.go
|
@ -238,9 +238,14 @@ func runWeb(*cli.Context) {
|
||||||
r.Post("/:index/label", repo.UpdateIssueLabel)
|
r.Post("/:index/label", repo.UpdateIssueLabel)
|
||||||
r.Post("/:index/milestone", repo.UpdateIssueMilestone)
|
r.Post("/:index/milestone", repo.UpdateIssueMilestone)
|
||||||
r.Post("/:index/assignee", repo.UpdateAssignee)
|
r.Post("/:index/assignee", repo.UpdateAssignee)
|
||||||
r.Post("/:index/attachment", repo.IssuePostAttachment)
|
|
||||||
r.Post("/:index/attachment/:id", repo.IssuePostAttachment)
|
m.Group("/:index/attachment", func(r martini.Router) {
|
||||||
r.Get("/:index/attachment/:id", repo.IssueGetAttachment)
|
r.Get("/:id", repo.IssueGetAttachment)
|
||||||
|
r.Post("/", repo.IssuePostAttachment)
|
||||||
|
r.Post("/:comment", repo.IssuePostAttachment)
|
||||||
|
r.Delete("/:comment/:id", repo.IssueDeleteAttachment)
|
||||||
|
})
|
||||||
|
|
||||||
r.Post("/labels/new", bindIgnErr(auth.CreateLabelForm{}), repo.NewLabel)
|
r.Post("/labels/new", bindIgnErr(auth.CreateLabelForm{}), repo.NewLabel)
|
||||||
r.Post("/labels/edit", bindIgnErr(auth.CreateLabelForm{}), repo.UpdateLabel)
|
r.Post("/labels/edit", bindIgnErr(auth.CreateLabelForm{}), repo.UpdateLabel)
|
||||||
r.Post("/labels/delete", repo.DeleteLabel)
|
r.Post("/labels/delete", repo.DeleteLabel)
|
||||||
|
|
|
@ -868,6 +868,14 @@ func CreateComment(userId, repoId, issueId, commitId, line int64, cmtType int, c
|
||||||
return comment, sess.Commit()
|
return comment, sess.Commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetCommentById returns the comment with the given id
|
||||||
|
func GetCommentById(commentId int64) (*Comment, error) {
|
||||||
|
c := &Comment{Id: commentId}
|
||||||
|
_, err := x.Get(c)
|
||||||
|
|
||||||
|
return c, err
|
||||||
|
}
|
||||||
|
|
||||||
// GetIssueComments returns list of comment by given issue id.
|
// GetIssueComments returns list of comment by given issue id.
|
||||||
func GetIssueComments(issueId int64) ([]Comment, error) {
|
func GetIssueComments(issueId int64) ([]Comment, error) {
|
||||||
comments := make([]Comment, 0, 10)
|
comments := make([]Comment, 0, 10)
|
||||||
|
@ -936,14 +944,14 @@ func GetAttachmentById(id int64) (*Attachment, error) {
|
||||||
|
|
||||||
func GetAttachmentsForIssue(issueId int64) ([]*Attachment, error) {
|
func GetAttachmentsForIssue(issueId int64) ([]*Attachment, error) {
|
||||||
attachments := make([]*Attachment, 0, 10)
|
attachments := make([]*Attachment, 0, 10)
|
||||||
err := x.Where("issue_id = ?", issueId).Where("comment_id = 0").Find(&attachments)
|
err := x.Where("issue_id = ?", issueId).And("comment_id = 0").Find(&attachments)
|
||||||
return attachments, err
|
return attachments, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAttachmentsByIssue returns a list of attachments for the given issue
|
// GetAttachmentsByIssue returns a list of attachments for the given issue
|
||||||
func GetAttachmentsByIssue(issueId int64) ([]*Attachment, error) {
|
func GetAttachmentsByIssue(issueId int64) ([]*Attachment, error) {
|
||||||
attachments := make([]*Attachment, 0, 10)
|
attachments := make([]*Attachment, 0, 10)
|
||||||
err := x.Where("issue_id = ?", issueId).Where("comment_id > 0").Find(&attachments)
|
err := x.Where("issue_id = ?", issueId).And("comment_id > 0").Find(&attachments)
|
||||||
return attachments, err
|
return attachments, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1018,13 +1018,17 @@ func IssuePostAttachment(ctx *middleware.Context, params martini.Params) {
|
||||||
issueId, _ := base.StrTo(params["index"]).Int64()
|
issueId, _ := base.StrTo(params["index"]).Int64()
|
||||||
|
|
||||||
if issueId == 0 {
|
if issueId == 0 {
|
||||||
ctx.Handle(400, "issue.IssuePostAttachment", nil)
|
ctx.JSON(400, map[string]interface{}{
|
||||||
|
"ok": false,
|
||||||
|
"error": "invalid issue id",
|
||||||
|
})
|
||||||
|
|
||||||
return
|
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{}{
|
ctx.JSON(400, map[string]interface{}{
|
||||||
"ok": false,
|
"ok": false,
|
||||||
"error": "invalid comment id",
|
"error": "invalid comment id",
|
||||||
|
@ -1132,3 +1136,102 @@ func IssueGetAttachment(ctx *middleware.Context, params martini.Params) {
|
||||||
|
|
||||||
ctx.ServeFile(attachment.Path, attachment.Name)
|
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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -101,13 +101,17 @@
|
||||||
<div class="tab-pane issue-preview-content" id="issue-preview">loading...</div>
|
<div class="tab-pane issue-preview-content" id="issue-preview">loading...</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<!--
|
||||||
<div>
|
<div>
|
||||||
<div id="attached"></div>
|
<div id="attached"></div>
|
||||||
</div>
|
</div>
|
||||||
|
-->
|
||||||
<div class="text-right panel-body">
|
<div class="text-right panel-body">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
<!--
|
||||||
<input type="hidden" name="attachments" value="" />
|
<input type="hidden" name="attachments" value="" />
|
||||||
<button data-accept="{{AllowedTypes}}" data-comment-id="0" class="btn-default btn attachment-add" id="attachments-button">Add Attachments...</button>
|
<button data-accept="{{AllowedTypes}}" data-comment-id="0" class="btn-default btn attachment-add" id="attachments-button">Add Attachments...</button>
|
||||||
|
-->
|
||||||
|
|
||||||
<input type="hidden" value="id" name="repo-id"/>
|
<input type="hidden" value="id" name="repo-id"/>
|
||||||
<button class="btn-success btn">Create new issue</button>
|
<button class="btn-success btn">Create new issue</button>
|
||||||
|
|
|
@ -113,13 +113,17 @@
|
||||||
<div class="tab-pane issue-preview-content" id="issue-preview">Loading...</div>
|
<div class="tab-pane issue-preview-content" id="issue-preview">Loading...</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<!--
|
||||||
<div>
|
<div>
|
||||||
<div id="attached"></div>
|
<div id="attached"></div>
|
||||||
</div>
|
</div>
|
||||||
|
-->
|
||||||
<div class="text-right">
|
<div class="text-right">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
<!--
|
||||||
<input type="hidden" name="attachments" value="" />
|
<input type="hidden" name="attachments" value="" />
|
||||||
<button data-accept="{{AllowedTypes}}" class="btn-default btn attachment-add" id="attachments-button">Add Attachments...</button>
|
<button data-accept="{{AllowedTypes}}" class="btn-default btn attachment-add" id="attachments-button">Add Attachments...</button>
|
||||||
|
-->
|
||||||
|
|
||||||
{{if .IsIssueOwner}}{{if .Issue.IsClosed}}
|
{{if .IsIssueOwner}}{{if .Issue.IsClosed}}
|
||||||
<input type="submit" class="btn-default btn issue-open" id="issue-open-btn" data-origin="Reopen" data-text="Reopen & Comment" name="change_status" value="Reopen"/>{{else}}
|
<input type="submit" class="btn-default btn issue-open" id="issue-open-btn" data-origin="Reopen" data-text="Reopen & Comment" name="change_status" value="Reopen"/>{{else}}
|
||||||
|
|
Loading…
Reference in a new issue