From ba36ace7cede520ab05a7a162246a0cf6aeb6cff Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Tue, 18 Jan 2022 22:49:51 +0800 Subject: [PATCH 1/3] Fix PR comments UI --- routers/api/v1/repo/issue_comment.go | 2 +- routers/web/repo/issue.go | 15 +++-- .../repo/issue/view_content/comments.tmpl | 61 ++++++++++++++----- web_src/js/features/repo-diff.js | 2 +- web_src/js/features/repo-issue-content.js | 2 +- web_src/less/_repository.less | 2 + 6 files changed, 58 insertions(+), 26 deletions(-) diff --git a/routers/api/v1/repo/issue_comment.go b/routers/api/v1/repo/issue_comment.go index b929cec3737c4..496ac29947d58 100644 --- a/routers/api/v1/repo/issue_comment.go +++ b/routers/api/v1/repo/issue_comment.go @@ -537,7 +537,7 @@ func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption) if !ctx.IsSigned || (ctx.User.ID != comment.PosterID && !ctx.Repo.IsAdmin()) { ctx.Status(http.StatusForbidden) return - } else if comment.Type != models.CommentTypeComment { + } else if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeReview { ctx.Status(http.StatusNoContent) return } diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index ee94e0e6d888d..5b55d23cf59c7 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -1333,7 +1333,7 @@ func ViewIssue(ctx *context.Context) { return } - if comment.Type == models.CommentTypeComment { + if comment.Type == models.CommentTypeComment || comment.Type == models.CommentTypeReview { if err := comment.LoadAttachments(); err != nil { ctx.ServerError("LoadAttachments", err) return @@ -2194,7 +2194,8 @@ func UpdateCommentContent(ctx *context.Context) { if !ctx.IsSigned || (ctx.User.ID != comment.PosterID && !ctx.Repo.CanWriteIssuesOrPulls(comment.Issue.IsPull)) { ctx.Error(http.StatusForbidden) return - } else if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeCode { + } + if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeReview { ctx.Error(http.StatusNoContent) return } @@ -2212,11 +2213,9 @@ func UpdateCommentContent(ctx *context.Context) { return } - if comment.Type == models.CommentTypeComment { - if err := comment.LoadAttachments(); err != nil { - ctx.ServerError("LoadAttachments", err) - return - } + if err := comment.LoadAttachments(); err != nil { + ctx.ServerError("LoadAttachments", err) + return } // when the update request doesn't intend to update attachments (eg: change checkbox state), ignore attachment updates @@ -2404,7 +2403,7 @@ func ChangeCommentReaction(ctx *context.Context) { ctx.Error(http.StatusForbidden) return - } else if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeCode { + } else if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeCode && comment.Type != models.CommentTypeReview { ctx.Error(http.StatusNoContent) return } diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 3242a5b3e563a..73057248c7e20 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -399,7 +399,7 @@ {{else if eq .Type 22}}
-
+
{{if .OriginalAuthor }} {{else}} @@ -434,23 +434,46 @@
{{if .Content}} -
+
- - {{if .OriginalAuthor }} - - {{svg (MigrationIcon $.Repository.GetOriginalURLHostname)}} - {{ .OriginalAuthor }} - - {{if $.Repository.OriginalURL}} - ({{$.i18n.Tr "repo.migrated_from" ($.Repository.OriginalURL|Escape) ($.Repository.GetOriginalURLHostname|Escape) | Safe }}){{end}} - {{else}} - {{.Poster.GetDisplayName}} - {{end}} +
+ + {{if .OriginalAuthor }} + + {{svg (MigrationIcon $.Repository.GetOriginalURLHostname)}} + {{ .OriginalAuthor }} + + {{if $.Repository.OriginalURL}} + ({{$.i18n.Tr "repo.migrated_from" ($.Repository.OriginalURL|Escape) ($.Repository.GetOriginalURLHostname|Escape) | Safe }}){{end}} + {{else}} + {{.Poster.GetDisplayName}} + {{end}} - {{$.i18n.Tr "repo.issues.review.left_comment" | Safe}} - + {{$.i18n.Tr "repo.issues.review.left_comment" | Safe}} + +
+
+ {{if (.ShowRole.HasRole "Poster")}} +
+ {{$.i18n.Tr "repo.issues.poster"}} +
+ {{end}} + {{if (.ShowRole.HasRole "Writer")}} +
+ {{$.i18n.Tr "repo.issues.collaborator"}} +
+ {{end}} + {{if (.ShowRole.HasRole "Owner")}} +
+ {{$.i18n.Tr "repo.issues.owner"}} +
+ {{end}} + {{if not $.Repository.IsArchived}} + {{template "repo/issue/view_content/add_reaction" Dict "ctx" $ "ActionURL" (Printf "%s/comments/%d/reactions" $.RepoLink .ID)}} + {{template "repo/issue/view_content/context_menu" Dict "ctx" $ "item" . "delete" true "issue" true "diff" false "IsCommentPoster" (and $.IsSigned (eq $.SignedUserID .PosterID))}} + {{end}} +
@@ -460,10 +483,18 @@ {{$.i18n.Tr "repo.issues.no_content"}} {{end}}
+
{{.Content}}
+
{{if .Attachments}} {{template "repo/issue/view_content/attachments" Dict "ctx" $ "Attachments" .Attachments "Content" .RenderedContent}} {{end}}
+ {{$reactions := .Reactions.GroupByType}} + {{if $reactions}} +
+ {{template "repo/issue/view_content/reactions" Dict "ctx" $ "ActionURL" (Printf "%s/comments/%d/reactions" $.RepoLink .ID) "Reactions" $reactions}} +
+ {{end}}
{{end}} diff --git a/web_src/js/features/repo-diff.js b/web_src/js/features/repo-diff.js index 3d937bbdb1fa6..f877af7211cac 100644 --- a/web_src/js/features/repo-diff.js +++ b/web_src/js/features/repo-diff.js @@ -45,7 +45,7 @@ export function initRepoDiffConversationForm() { }); - $('.resolve-conversation').on('click', async function (e) { + $(document).on('click', '.resolve-conversation', async function (e) { e.preventDefault(); const comment_id = $(this).data('comment-id'); const origin = $(this).data('origin'); diff --git a/web_src/js/features/repo-issue-content.js b/web_src/js/features/repo-issue-content.js index 602523f89d374..40e88fb1f3fd8 100644 --- a/web_src/js/features/repo-issue-content.js +++ b/web_src/js/features/repo-issue-content.js @@ -109,7 +109,7 @@ export function initRepoIssueContentHistory() { if (!issueIndex) return; const $itemIssue = $('.repository.issue .timeline-item.comment.first'); // issue(PR) main content - const $comments = $('.repository.issue .comment-list .comment'); // includes: issue(PR) comments, code rerview comments + const $comments = $('.repository.issue .comment-list .comment'); // includes: issue(PR) comments, review comments, code comments if (!$itemIssue.length && !$comments.length) return; const repoLink = $('#repolink').val(); diff --git a/web_src/less/_repository.less b/web_src/less/_repository.less index 5e7fdc4204c7d..75ccc8d25f84b 100644 --- a/web_src/less/_repository.less +++ b/web_src/less/_repository.less @@ -2673,10 +2673,12 @@ a { color: var(--color-text); + text-decoration: none; } a:hover { color: var(--color-primary); + text-decoration: none; } } From 00c60ec66ce9bee8909aeec2a322a58882e5b179 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 19 Jan 2022 00:24:08 +0800 Subject: [PATCH 2/3] fix --- routers/api/v1/repo/issue_comment.go | 3 ++- routers/web/repo/issue.go | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/routers/api/v1/repo/issue_comment.go b/routers/api/v1/repo/issue_comment.go index 496ac29947d58..2931aae62c8e0 100644 --- a/routers/api/v1/repo/issue_comment.go +++ b/routers/api/v1/repo/issue_comment.go @@ -537,7 +537,8 @@ func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption) if !ctx.IsSigned || (ctx.User.ID != comment.PosterID && !ctx.Repo.IsAdmin()) { ctx.Status(http.StatusForbidden) return - } else if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeReview { + } + if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeReview && comment.Type != models.CommentTypeCode { ctx.Status(http.StatusNoContent) return } diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 5b55d23cf59c7..1809dbd94dfbe 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -2195,7 +2195,7 @@ func UpdateCommentContent(ctx *context.Context) { ctx.Error(http.StatusForbidden) return } - if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeReview { + if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeReview && comment.Type != models.CommentTypeCode { ctx.Error(http.StatusNoContent) return } @@ -2403,7 +2403,9 @@ func ChangeCommentReaction(ctx *context.Context) { ctx.Error(http.StatusForbidden) return - } else if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeCode && comment.Type != models.CommentTypeReview { + } + + if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeCode && comment.Type != models.CommentTypeReview { ctx.Error(http.StatusNoContent) return } From b75983b0324bdc3e00cc037a7a2622e58132efbe Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 19 Jan 2022 00:31:02 +0800 Subject: [PATCH 3/3] fix --- models/issue_comment.go | 2 +- routers/api/v1/repo/issue_comment.go | 1 + routers/web/repo/issue.go | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/models/issue_comment.go b/models/issue_comment.go index 99c38bcf59cf2..f4a6b3ce13919 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -519,7 +519,7 @@ func (c *Comment) LoadPoster() error { return c.loadPoster(db.GetEngine(db.DefaultContext)) } -// LoadAttachments loads attachments +// LoadAttachments loads attachments (it never returns error, the error during `GetAttachmentsByCommentIDCtx` is ignored) func (c *Comment) LoadAttachments() error { if len(c.Attachments) > 0 { return nil diff --git a/routers/api/v1/repo/issue_comment.go b/routers/api/v1/repo/issue_comment.go index 2931aae62c8e0..f90028a0ab0e1 100644 --- a/routers/api/v1/repo/issue_comment.go +++ b/routers/api/v1/repo/issue_comment.go @@ -538,6 +538,7 @@ func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption) ctx.Status(http.StatusForbidden) return } + if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeReview && comment.Type != models.CommentTypeCode { ctx.Status(http.StatusNoContent) return diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 1809dbd94dfbe..9dee477537d87 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -2195,6 +2195,7 @@ func UpdateCommentContent(ctx *context.Context) { ctx.Error(http.StatusForbidden) return } + if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeReview && comment.Type != models.CommentTypeCode { ctx.Error(http.StatusNoContent) return