From 1e5247d424de7f8a480c73b0b72119ae5482edf1 Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Sat, 28 Nov 2020 23:52:29 +0800 Subject: [PATCH] ui: show 'owner' tag for real owner (#13689) * ui: show 'owner' tag for real owner Signed-off-by: a1012112796 <1012112796@qq.com> * Update custom/conf/app.example.ini * simplify logic fix logic fix a small bug about original author * remove system manager tag Co-authored-by: techknowlogick Co-authored-by: Lauris BH --- models/repo_permission.go | 21 +++++++++++++++++ routers/repo/issue.go | 23 +++++++++++++++++-- .../repo/issue/view_content/comments.tmpl | 2 +- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/models/repo_permission.go b/models/repo_permission.go index 7768bb625..138613b2e 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/routers/repo/issue.go b/routers/repo/issue.go index 159cc5b9f..ded9b3c20 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -980,8 +980,27 @@ 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) { + if !poster.IsAdmin { + return models.CommentTagOwner, nil + } + + ok, err := models.IsUserRealRepoAdmin(repo, poster) + if err != nil { + return models.CommentTagNone, err + } + + if ok { + return models.CommentTagOwner, nil + } + + if ok, err = repo.IsCollaborator(poster.ID); ok && err == nil { + return models.CommentTagWriter, nil + } + + return models.CommentTagNone, err + } + + if perm.CanWrite(models.UnitTypeCode) { return models.CommentTagWriter, nil } diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index d1e380ebf..2bd2d8643 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"}}