forked from forgejo/forgejo
Save and view issue/comment content history (#16909)
* issue content history * Use timeutil.TimeStampNow() for content history time instead of issue/comment.UpdatedUnix (which are not updated in time) * i18n for frontend * refactor * clean up * fix refactor * re-format * temp refactor * follow db refactor * rename IssueContentHistory to ContentHistory, remove empty model tags * fix html * use avatar refactor to generate avatar url * add unit test, keep at most 20 history revisions. * re-format * syntax nit * Add issue content history table * Update models/migrations/v197.go Co-authored-by: 6543 <6543@obermui.de> * fix merge Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Lauris BH <lauris@nix.lv>
This commit is contained in:
parent
ff9a8a2231
commit
c5c88f2f18
17 changed files with 766 additions and 8 deletions
|
@ -14,6 +14,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/issues"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/references"
|
||||
|
@ -803,8 +804,13 @@ func (issue *Issue) ChangeContent(doer *User, content string) (err error) {
|
|||
return fmt.Errorf("UpdateIssueCols: %v", err)
|
||||
}
|
||||
|
||||
if err = issue.addCrossReferences(db.GetEngine(ctx), doer, true); err != nil {
|
||||
return err
|
||||
if err = issues.SaveIssueContentHistory(db.GetEngine(ctx), issue.PosterID, issue.ID, 0,
|
||||
timeutil.TimeStampNow(), issue.Content, false); err != nil {
|
||||
return fmt.Errorf("SaveIssueContentHistory: %v", err)
|
||||
}
|
||||
|
||||
if err = issue.addCrossReferences(ctx.Engine(), doer, true); err != nil {
|
||||
return fmt.Errorf("addCrossReferences: %v", err)
|
||||
}
|
||||
|
||||
return committer.Commit()
|
||||
|
@ -972,6 +978,12 @@ func newIssue(e db.Engine, doer *User, opts NewIssueOptions) (err error) {
|
|||
if err = opts.Issue.loadAttributes(e); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = issues.SaveIssueContentHistory(e, opts.Issue.PosterID, opts.Issue.ID, 0,
|
||||
timeutil.TimeStampNow(), opts.Issue.Content, true); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return opts.Issue.addCrossReferences(e, doer, false)
|
||||
}
|
||||
|
||||
|
@ -2132,6 +2144,12 @@ func UpdateReactionsMigrationsByType(gitServiceType structs.GitServiceType, orig
|
|||
func deleteIssuesByRepoID(sess db.Engine, repoID int64) (attachmentPaths []string, err error) {
|
||||
deleteCond := builder.Select("id").From("issue").Where(builder.Eq{"issue.repo_id": repoID})
|
||||
|
||||
// Delete content histories
|
||||
if _, err = sess.In("issue_id", deleteCond).
|
||||
Delete(&issues.ContentHistory{}); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Delete comments and attachments
|
||||
if _, err = sess.In("issue_id", deleteCond).
|
||||
Delete(&Comment{}); err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue