]> source.dussan.org Git - gitea.git/commitdiff
Fix issue content history problems, improve UI (#17404)
authorwxiaoguang <wxiaoguang@gmail.com>
Sat, 23 Oct 2021 14:47:38 +0000 (22:47 +0800)
committerGitHub <noreply@github.com>
Sat, 23 Oct 2021 14:47:38 +0000 (22:47 +0800)
* Improve: make diff result better, make the HTML element fit the full height in the content history diff dialog
* Bug fix: when edit the main issue, the poster is wrongly set to the issue poster

models/issue.go
models/issue_test.go
routers/web/repo/issue_content_history.go
web_src/js/features/issue-content-history.js

index 823d82a765a79b9610640771690e192bb334ea97..a27bb1cc7dec9d3e5a5f67d8cade628326a781c2 100644 (file)
@@ -804,7 +804,7 @@ func (issue *Issue) ChangeContent(doer *User, content string) (err error) {
                return fmt.Errorf("UpdateIssueCols: %v", err)
        }
 
-       if err = issues.SaveIssueContentHistory(db.GetEngine(ctx), issue.PosterID, issue.ID, 0,
+       if err = issues.SaveIssueContentHistory(db.GetEngine(ctx), doer.ID, issue.ID, 0,
                timeutil.TimeStampNow(), issue.Content, false); err != nil {
                return fmt.Errorf("SaveIssueContentHistory: %v", err)
        }
@@ -979,7 +979,7 @@ func newIssue(e db.Engine, doer *User, opts NewIssueOptions) (err error) {
                return err
        }
 
-       if err = issues.SaveIssueContentHistory(e, opts.Issue.PosterID, opts.Issue.ID, 0,
+       if err = issues.SaveIssueContentHistory(e, doer.ID, opts.Issue.ID, 0,
                timeutil.TimeStampNow(), opts.Issue.Content, true); err != nil {
                return err
        }
index d726a2434476640ca18d90f8bcd91a5014d959ba..8894d8020176cfbd830c1f269f9796c1b80774c0 100644 (file)
@@ -357,6 +357,7 @@ func testInsertIssue(t *testing.T, title, content string, expectIndex int64) *Is
                issue := Issue{
                        RepoID:   repo.ID,
                        PosterID: user.ID,
+                       Poster:   user,
                        Title:    title,
                        Content:  content,
                }
index c0e958203d5698604e32eecd8856fec47a800442..dc647b8809a128b280797580ddef6a4331d00b3a 100644 (file)
@@ -88,12 +88,13 @@ func canSoftDeleteContentHistory(ctx *context.Context, issue *models.Issue, comm
        if ctx.Repo.IsOwner() {
                canSoftDelete = true
        } else if ctx.Repo.CanWrite(models.UnitTypeIssues) {
-               canSoftDelete = ctx.User.ID == history.PosterID
                if comment == nil {
-                       canSoftDelete = canSoftDelete && (ctx.User.ID == issue.PosterID)
+                       // the issue poster or the history poster can soft-delete
+                       canSoftDelete = ctx.User.ID == issue.PosterID || ctx.User.ID == history.PosterID
                        canSoftDelete = canSoftDelete && (history.IssueID == issue.ID)
                } else {
-                       canSoftDelete = canSoftDelete && (ctx.User.ID == comment.PosterID)
+                       // the comment poster or the history poster can soft-delete
+                       canSoftDelete = ctx.User.ID == comment.PosterID || ctx.User.ID == history.PosterID
                        canSoftDelete = canSoftDelete && (history.IssueID == issue.ID)
                        canSoftDelete = canSoftDelete && (history.CommentID == comment.ID)
                }
@@ -137,7 +138,8 @@ func GetContentHistoryDetail(ctx *context.Context) {
 
        // compare the current history revision with the previous one
        dmp := diffmatchpatch.New()
-       diff := dmp.DiffMain(prevHistoryContentText, history.ContentText, true)
+       // `checklines=false` makes better diff result
+       diff := dmp.DiffMain(prevHistoryContentText, history.ContentText, false)
        diff = dmp.DiffCleanupEfficiency(diff)
 
        // use chroma to render the diff html
index 3b830f50f8661036a8e07b390ec93149b26fdb4a..c71d3789d4bf9b44dce704bbd4e2712783391c3f 100644 (file)
@@ -12,7 +12,7 @@ function showContentHistoryDetail(issueBaseUrl, commentId, historyId, itemTitleH
   if ($dialog.length) return;
 
   $dialog = $(`
-<div class="ui modal content-history-detail-dialog" style="min-height: 50%;">
+<div class="ui modal content-history-detail-dialog">
   <i class="close icon inside"></i>
   <div class="header">
     ${itemTitleHtml}
@@ -24,7 +24,7 @@ function showContentHistoryDetail(issueBaseUrl, commentId, historyId, itemTitleH
     </div>
   </div>
   <!-- ".modal .content" style was polluted in "_base.less": "&.modal > .content"  -->
-  <div class="scrolling content" style="text-align: left;">
+  <div class="scrolling content" style="text-align: left; min-height: 30vh;">
       <div class="ui loader active"></div>
   </div>
 </div>`);