1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

allow edit issue and comment

This commit is contained in:
Unknwon
2015-08-20 04:31:28 +08:00
parent f114f78743
commit 371572cf5f
11 changed files with 243 additions and 53 deletions

View File

@@ -258,7 +258,27 @@ func IsErrIssueNotExist(err error) bool {
}
func (err ErrIssueNotExist) Error() string {
return fmt.Sprintf("issue does not exist [id: %d, repo_id: %d, index: %4]", err.ID, err.RepoID, err.Index)
return fmt.Sprintf("issue does not exist [id: %d, repo_id: %d, index: %d]", err.ID, err.RepoID, err.Index)
}
// _________ __
// \_ ___ \ ____ _____ _____ ____ _____/ |_
// / \ \/ / _ \ / \ / \_/ __ \ / \ __\
// \ \___( <_> ) Y Y \ Y Y \ ___/| | \ |
// \______ /\____/|__|_| /__|_| /\___ >___| /__|
// \/ \/ \/ \/ \/
type ErrCommentNotExist struct {
ID int64
}
func IsErrCommentNotExist(err error) bool {
_, ok := err.(ErrCommentNotExist)
return ok
}
func (err ErrCommentNotExist) Error() string {
return fmt.Sprintf("comment does not exist [id: %d]", err.ID)
}
// .____ ___. .__

View File

@@ -1363,6 +1363,14 @@ func (c *Comment) AfterSet(colName string, _ xorm.Cell) {
}
}
func (c *Comment) AfterDelete() {
_, err := DeleteAttachmentsByComment(c.ID, true)
if err != nil {
log.Info("Could not delete files for comment %d on issue #%d: %s", c.ID, c.IssueID, err)
}
}
// HashTag returns unique hash tag for comment.
func (c *Comment) HashTag() string {
return "issuecomment-" + com.ToStr(c.ID)
@@ -1473,11 +1481,16 @@ func CreateIssueComment(doer *User, repo *Repository, issue *Issue, content stri
return CreateComment(doer, repo, issue, 0, 0, COMMENT_TYPE_COMMENT, content, attachments)
}
// GetCommentById returns the comment with the given id
func GetCommentById(id int64) (*Comment, error) {
// GetCommentByID returns the comment by given ID.
func GetCommentByID(id int64) (*Comment, error) {
c := new(Comment)
_, err := x.Id(id).Get(c)
return c, err
has, err := x.Id(id).Get(c)
if err != nil {
return nil, err
} else if !has {
return nil, ErrCommentNotExist{id}
}
return c, nil
}
// GetCommentsByIssueID returns all comments of issue by given ID.
@@ -1486,12 +1499,10 @@ func GetCommentsByIssueID(issueID int64) ([]*Comment, error) {
return comments, x.Where("issue_id=?", issueID).Asc("created").Find(&comments)
}
func (c *Comment) AfterDelete() {
_, err := DeleteAttachmentsByComment(c.ID, true)
if err != nil {
log.Info("Could not delete files for comment %d on issue #%d: %s", c.ID, c.IssueID, err)
}
// UpdateComment updates information of comment.
func UpdateComment(c *Comment) error {
_, err := x.Id(c.ID).AllCols().Update(c)
return err
}
// Attachment represent a attachment of issue/comment/release.