From 2d43ef239b58c0cf051f8d90907a0d579aa8906b Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Tue, 24 Nov 2020 21:07:06 +0800 Subject: [PATCH 1/4] ui: show 'owner' tag for real owner Signed-off-by: a1012112796 <1012112796@qq.com> --- custom/conf/app.example.ini | 2 + .../doc/advanced/config-cheat-sheet.en-us.md | 1 + .../doc/advanced/config-cheat-sheet.zh-cn.md | 1 + models/issue_comment.go | 1 + models/repo_permission.go | 21 ++++++++++ modules/setting/setting.go | 40 ++++++++++--------- options/locale/locale_en-US.ini | 1 + routers/repo/issue.go | 19 ++++++++- templates/repo/issue/view_content.tmpl | 2 + .../repo/issue/view_content/comments.tmpl | 2 + 10 files changed, 69 insertions(+), 21 deletions(-) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index 1311c5a650036..10fd9daafd414 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -207,6 +207,8 @@ DEFAULT_SHOW_FULL_NAME = false SEARCH_REPO_DESCRIPTION = true ; Whether to enable a Service Worker to cache frontend assets USE_SERVICE_WORKER = true +; show `system administrator` tag on comment header +SHOW_SYS_ADMIN_COMMENT_TAG = true [ui.admin] ; Number of users that are displayed on one page diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index eaf43da29a7ed..6ee8413f8ebbc 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -172,6 +172,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`. - `DEFAULT_SHOW_FULL_NAME`: **false**: Whether the full name of the users should be shown where possible. If the full name isn't set, the username will be used. - `SEARCH_REPO_DESCRIPTION`: **true**: Whether to search within description at repository search on explore page. - `USE_SERVICE_WORKER`: **true**: Whether to enable a Service Worker to cache frontend assets. +- `SHOW_SYS_ADMIN_COMMENT_TAG`: **false**: show `system administrator` tag on comment header ### UI - Admin (`ui.admin`) diff --git a/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md b/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md index 505fdcdf718e5..4e159a8d3f044 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md +++ b/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md @@ -40,6 +40,7 @@ menu: - `ISSUE_PAGING_NUM`: 工单页面每页显示的工单数量。 - `MEMBERS_PAGING_NUM`: **20**: 组织成员页面每页显示的成员数量。 - `FEED_MAX_COMMIT_NUM`: 活动流页面显示的最大提交数量。 +- `SHOW_SYS_ADMIN_COMMENT_TAG`: **false**: 在系统管理员的评论上显示 `系统管理员` 标志 ### UI - Admin (`ui.admin`) diff --git a/models/issue_comment.go b/models/issue_comment.go index 7bcea40b93006..78e1ea614171f 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -111,6 +111,7 @@ const ( CommentTagPoster CommentTagWriter CommentTagOwner + CommentTagSysAdmin ) // Comment represents a comment in commit and issue page. diff --git a/models/repo_permission.go b/models/repo_permission.go index 7768bb6257f6c..138613b2e92e3 100644 --- a/models/repo_permission.go +++ b/models/repo_permission.go @@ -271,6 +271,27 @@ func getUserRepoPermission(e Engine, repo *Repository, user *User) (perm Permiss return } +// IsUserRealRepoAdmin check if this user is real repo admin +func IsUserRealRepoAdmin(repo *Repository, user *User) (bool, error) { + if repo.OwnerID == user.ID { + return true, nil + } + + sess := x.NewSession() + defer sess.Close() + + if err := repo.getOwner(sess); err != nil { + return false, err + } + + accessMode, err := accessLevel(sess, user, repo) + if err != nil { + return false, err + } + + return accessMode >= AccessModeAdmin, nil +} + // IsUserRepoAdmin return true if user has admin right of a repo func IsUserRepoAdmin(repo *Repository, user *User) (bool, error) { return isUserRepoAdmin(x, repo, user) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 708dc282337db..69947817fe487 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -160,25 +160,26 @@ var ( // UI settings UI = struct { - ExplorePagingNum int - IssuePagingNum int - RepoSearchPagingNum int - MembersPagingNum int - FeedMaxCommitNum int - FeedPagingNum int - GraphMaxCommitNum int - CodeCommentLines int - ReactionMaxUserNum int - ThemeColorMetaTag string - MaxDisplayFileSize int64 - ShowUserEmail bool - DefaultShowFullName bool - DefaultTheme string - Themes []string - Reactions []string - ReactionsMap map[string]bool - SearchRepoDescription bool - UseServiceWorker bool + ExplorePagingNum int + IssuePagingNum int + RepoSearchPagingNum int + MembersPagingNum int + FeedMaxCommitNum int + FeedPagingNum int + GraphMaxCommitNum int + CodeCommentLines int + ReactionMaxUserNum int + ThemeColorMetaTag string + MaxDisplayFileSize int64 + ShowUserEmail bool + DefaultShowFullName bool + DefaultTheme string + Themes []string + Reactions []string + ReactionsMap map[string]bool + SearchRepoDescription bool + UseServiceWorker bool + ShowSysAdminCommentTag bool Notification struct { MinTimeout time.Duration @@ -907,6 +908,7 @@ func NewContext() { UI.DefaultShowFullName = Cfg.Section("ui").Key("DEFAULT_SHOW_FULL_NAME").MustBool(false) UI.SearchRepoDescription = Cfg.Section("ui").Key("SEARCH_REPO_DESCRIPTION").MustBool(true) UI.UseServiceWorker = Cfg.Section("ui").Key("USE_SERVICE_WORKER").MustBool(true) + UI.ShowSysAdminCommentTag = Cfg.Section("ui").Key("SHOW_SYS_ADMIN_COMMENT_TAG").MustBool(false) HasRobotsTxt = com.IsFile(path.Join(CustomPath, "robots.txt")) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 016211c7f8027..f9f63321916d8 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1075,6 +1075,7 @@ issues.ref_from = `from %[1]s` issues.poster = Poster issues.collaborator = Collaborator issues.owner = Owner +issues.sys_admin = system administrator issues.re_request_review=Re-request review issues.is_stale = There have been changes to this PR since this review issues.remove_request_review=Remove review request diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 159cc5b9f01a9..03ffbff1305c8 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -980,8 +980,23 @@ func commentTag(repo *models.Repository, poster *models.User, issue *models.Issu return models.CommentTagNone, err } if perm.IsOwner() { - return models.CommentTagOwner, nil - } else if perm.CanWrite(models.UnitTypeCode) { + ok, err := models.IsUserRealRepoAdmin(repo, poster) + if err != nil { + return models.CommentTagNone, err + } + + if ok { + return models.CommentTagOwner, nil + } + + if setting.UI.ShowSysAdminCommentTag && poster.IsAdmin { + return models.CommentTagSysAdmin, nil + } + + return models.CommentTagNone, nil + } + + if perm.CanWrite(models.UnitTypeCode) { return models.CommentTagWriter, nil } diff --git a/templates/repo/issue/view_content.tmpl b/templates/repo/issue/view_content.tmpl index 81e2c80c3c48c..d74b981ab7d8c 100644 --- a/templates/repo/issue/view_content.tmpl +++ b/templates/repo/issue/view_content.tmpl @@ -48,6 +48,8 @@ {{$.i18n.Tr "repo.issues.collaborator"}} {{else if eq .Issue.ShowTag 3}} {{$.i18n.Tr "repo.issues.owner"}} + {{else if eq .Issue.ShowTag 4}} + {{$.i18n.Tr "repo.issues.sys_admin"}} {{end}} {{end}} diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 77b02f67a561b..6a6dd9d984326 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -54,6 +54,8 @@ {{$.i18n.Tr "repo.issues.collaborator"}} {{else if eq .ShowTag 3}} {{$.i18n.Tr "repo.issues.owner"}} + {{else if eq .ShowTag 4}} + {{$.i18n.Tr "repo.issues.sys_admin"}} {{end}} {{end}} From 9b145dcb7a3257f18e34357af88ac790b72bd641 Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Tue, 24 Nov 2020 21:20:15 +0800 Subject: [PATCH 2/4] Update custom/conf/app.example.ini --- custom/conf/app.example.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index 10fd9daafd414..dc6df7b9005bc 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -208,7 +208,7 @@ SEARCH_REPO_DESCRIPTION = true ; Whether to enable a Service Worker to cache frontend assets USE_SERVICE_WORKER = true ; show `system administrator` tag on comment header -SHOW_SYS_ADMIN_COMMENT_TAG = true +SHOW_SYS_ADMIN_COMMENT_TAG = false [ui.admin] ; Number of users that are displayed on one page From e6807597613557c0cbbf9553e82be6abb8a63d86 Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Wed, 25 Nov 2020 13:06:26 +0800 Subject: [PATCH 3/4] simplify logic fix logic fix a small bug about original author --- routers/repo/issue.go | 10 +++++++++- templates/repo/issue/view_content/comments.tmpl | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 03ffbff1305c8..6a2aa7ef96546 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -980,6 +980,10 @@ func commentTag(repo *models.Repository, poster *models.User, issue *models.Issu return models.CommentTagNone, err } if perm.IsOwner() { + if !poster.IsAdmin { + return models.CommentTagOwner, nil + } + ok, err := models.IsUserRealRepoAdmin(repo, poster) if err != nil { return models.CommentTagNone, err @@ -993,7 +997,11 @@ func commentTag(repo *models.Repository, poster *models.User, issue *models.Issu return models.CommentTagSysAdmin, nil } - return models.CommentTagNone, nil + if ok, err = repo.IsCollaborator(poster.ID); ok && err == nil { + return models.CommentTagWriter, nil + } + + return models.CommentTagNone, err } if perm.CanWrite(models.UnitTypeCode) { diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 6a6dd9d984326..b797092a4c9ef 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -43,7 +43,7 @@
{{if not $.Repository.IsArchived}} - {{if eq .PosterID .Issue.PosterID }} + {{if or (and (eq .PosterID .Issue.PosterID) (eq .Issue.OriginalAuthorID 0)) (eq .Issue.OriginalAuthorID .OriginalAuthorID) }}
{{$.i18n.Tr "repo.issues.poster"}}
From 4470bdf453fa4dabc0cd12c84c94b80fcc69e8a5 Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Thu, 26 Nov 2020 16:10:23 +0800 Subject: [PATCH 4/4] remove system manager tag --- custom/conf/app.example.ini | 2 - .../doc/advanced/config-cheat-sheet.en-us.md | 1 - .../doc/advanced/config-cheat-sheet.zh-cn.md | 1 - models/issue_comment.go | 1 - modules/setting/setting.go | 40 +++++++++---------- options/locale/locale_en-US.ini | 1 - routers/repo/issue.go | 4 -- templates/repo/issue/view_content.tmpl | 2 - .../repo/issue/view_content/comments.tmpl | 2 - 9 files changed, 19 insertions(+), 35 deletions(-) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index dc6df7b9005bc..1311c5a650036 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -207,8 +207,6 @@ DEFAULT_SHOW_FULL_NAME = false SEARCH_REPO_DESCRIPTION = true ; Whether to enable a Service Worker to cache frontend assets USE_SERVICE_WORKER = true -; show `system administrator` tag on comment header -SHOW_SYS_ADMIN_COMMENT_TAG = false [ui.admin] ; Number of users that are displayed on one page diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index 6ee8413f8ebbc..eaf43da29a7ed 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -172,7 +172,6 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`. - `DEFAULT_SHOW_FULL_NAME`: **false**: Whether the full name of the users should be shown where possible. If the full name isn't set, the username will be used. - `SEARCH_REPO_DESCRIPTION`: **true**: Whether to search within description at repository search on explore page. - `USE_SERVICE_WORKER`: **true**: Whether to enable a Service Worker to cache frontend assets. -- `SHOW_SYS_ADMIN_COMMENT_TAG`: **false**: show `system administrator` tag on comment header ### UI - Admin (`ui.admin`) diff --git a/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md b/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md index 4e159a8d3f044..505fdcdf718e5 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md +++ b/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md @@ -40,7 +40,6 @@ menu: - `ISSUE_PAGING_NUM`: 工单页面每页显示的工单数量。 - `MEMBERS_PAGING_NUM`: **20**: 组织成员页面每页显示的成员数量。 - `FEED_MAX_COMMIT_NUM`: 活动流页面显示的最大提交数量。 -- `SHOW_SYS_ADMIN_COMMENT_TAG`: **false**: 在系统管理员的评论上显示 `系统管理员` 标志 ### UI - Admin (`ui.admin`) diff --git a/models/issue_comment.go b/models/issue_comment.go index 78e1ea614171f..7bcea40b93006 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -111,7 +111,6 @@ const ( CommentTagPoster CommentTagWriter CommentTagOwner - CommentTagSysAdmin ) // Comment represents a comment in commit and issue page. diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 69947817fe487..708dc282337db 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -160,26 +160,25 @@ var ( // UI settings UI = struct { - ExplorePagingNum int - IssuePagingNum int - RepoSearchPagingNum int - MembersPagingNum int - FeedMaxCommitNum int - FeedPagingNum int - GraphMaxCommitNum int - CodeCommentLines int - ReactionMaxUserNum int - ThemeColorMetaTag string - MaxDisplayFileSize int64 - ShowUserEmail bool - DefaultShowFullName bool - DefaultTheme string - Themes []string - Reactions []string - ReactionsMap map[string]bool - SearchRepoDescription bool - UseServiceWorker bool - ShowSysAdminCommentTag bool + ExplorePagingNum int + IssuePagingNum int + RepoSearchPagingNum int + MembersPagingNum int + FeedMaxCommitNum int + FeedPagingNum int + GraphMaxCommitNum int + CodeCommentLines int + ReactionMaxUserNum int + ThemeColorMetaTag string + MaxDisplayFileSize int64 + ShowUserEmail bool + DefaultShowFullName bool + DefaultTheme string + Themes []string + Reactions []string + ReactionsMap map[string]bool + SearchRepoDescription bool + UseServiceWorker bool Notification struct { MinTimeout time.Duration @@ -908,7 +907,6 @@ func NewContext() { UI.DefaultShowFullName = Cfg.Section("ui").Key("DEFAULT_SHOW_FULL_NAME").MustBool(false) UI.SearchRepoDescription = Cfg.Section("ui").Key("SEARCH_REPO_DESCRIPTION").MustBool(true) UI.UseServiceWorker = Cfg.Section("ui").Key("USE_SERVICE_WORKER").MustBool(true) - UI.ShowSysAdminCommentTag = Cfg.Section("ui").Key("SHOW_SYS_ADMIN_COMMENT_TAG").MustBool(false) HasRobotsTxt = com.IsFile(path.Join(CustomPath, "robots.txt")) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index f9f63321916d8..016211c7f8027 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1075,7 +1075,6 @@ issues.ref_from = `from %[1]s` issues.poster = Poster issues.collaborator = Collaborator issues.owner = Owner -issues.sys_admin = system administrator issues.re_request_review=Re-request review issues.is_stale = There have been changes to this PR since this review issues.remove_request_review=Remove review request diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 6a2aa7ef96546..ded9b3c2086c1 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -993,10 +993,6 @@ func commentTag(repo *models.Repository, poster *models.User, issue *models.Issu return models.CommentTagOwner, nil } - if setting.UI.ShowSysAdminCommentTag && poster.IsAdmin { - return models.CommentTagSysAdmin, nil - } - if ok, err = repo.IsCollaborator(poster.ID); ok && err == nil { return models.CommentTagWriter, nil } diff --git a/templates/repo/issue/view_content.tmpl b/templates/repo/issue/view_content.tmpl index d74b981ab7d8c..81e2c80c3c48c 100644 --- a/templates/repo/issue/view_content.tmpl +++ b/templates/repo/issue/view_content.tmpl @@ -48,8 +48,6 @@ {{$.i18n.Tr "repo.issues.collaborator"}} {{else if eq .Issue.ShowTag 3}} {{$.i18n.Tr "repo.issues.owner"}} - {{else if eq .Issue.ShowTag 4}} - {{$.i18n.Tr "repo.issues.sys_admin"}} {{end}}
{{end}} diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index b797092a4c9ef..6a023d8f8ff8b 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -54,8 +54,6 @@ {{$.i18n.Tr "repo.issues.collaborator"}} {{else if eq .ShowTag 3}} {{$.i18n.Tr "repo.issues.owner"}} - {{else if eq .ShowTag 4}} - {{$.i18n.Tr "repo.issues.sys_admin"}} {{end}} {{end}}