Fix issue content history problems, improve UI (#17404)

* 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
This commit is contained in:
wxiaoguang 2021-10-23 22:47:38 +08:00 committed by GitHub
parent 6c49517cbd
commit 943dc08722
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 8 deletions

View File

@ -804,7 +804,7 @@ func (issue *Issue) ChangeContent(doer *User, content string) (err error) {
return fmt.Errorf("UpdateIssueCols: %v", err) 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 { timeutil.TimeStampNow(), issue.Content, false); err != nil {
return fmt.Errorf("SaveIssueContentHistory: %v", err) return fmt.Errorf("SaveIssueContentHistory: %v", err)
} }
@ -979,7 +979,7 @@ func newIssue(e db.Engine, doer *User, opts NewIssueOptions) (err error) {
return err 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 { timeutil.TimeStampNow(), opts.Issue.Content, true); err != nil {
return err return err
} }

View File

@ -357,6 +357,7 @@ func testInsertIssue(t *testing.T, title, content string, expectIndex int64) *Is
issue := Issue{ issue := Issue{
RepoID: repo.ID, RepoID: repo.ID,
PosterID: user.ID, PosterID: user.ID,
Poster: user,
Title: title, Title: title,
Content: content, Content: content,
} }

View File

@ -88,12 +88,13 @@ func canSoftDeleteContentHistory(ctx *context.Context, issue *models.Issue, comm
if ctx.Repo.IsOwner() { if ctx.Repo.IsOwner() {
canSoftDelete = true canSoftDelete = true
} else if ctx.Repo.CanWrite(models.UnitTypeIssues) { } else if ctx.Repo.CanWrite(models.UnitTypeIssues) {
canSoftDelete = ctx.User.ID == history.PosterID
if comment == nil { 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) canSoftDelete = canSoftDelete && (history.IssueID == issue.ID)
} else { } 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.IssueID == issue.ID)
canSoftDelete = canSoftDelete && (history.CommentID == comment.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 // compare the current history revision with the previous one
dmp := diffmatchpatch.New() 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) diff = dmp.DiffCleanupEfficiency(diff)
// use chroma to render the diff html // use chroma to render the diff html

View File

@ -12,7 +12,7 @@ function showContentHistoryDetail(issueBaseUrl, commentId, historyId, itemTitleH
if ($dialog.length) return; if ($dialog.length) return;
$dialog = $(` $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> <i class="close icon inside"></i>
<div class="header"> <div class="header">
${itemTitleHtml} ${itemTitleHtml}
@ -24,7 +24,7 @@ function showContentHistoryDetail(issueBaseUrl, commentId, historyId, itemTitleH
</div> </div>
</div> </div>
<!-- ".modal .content" style was polluted in "_base.less": "&.modal > .content" --> <!-- ".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 class="ui loader active"></div>
</div> </div>
</div>`); </div>`);