Skip to content

Commit 97f0d6b

Browse files
author
Gusted
committed
Change naming
1 parent 5cc9694 commit 97f0d6b

File tree

5 files changed

+62
-62
lines changed

5 files changed

+62
-62
lines changed

models/issue.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ type Issue struct {
7070
IsLocked bool `xorm:"NOT NULL DEFAULT false"`
7171

7272
// For view issue page.
73-
ShowTag CommentTag `xorm:"-"`
73+
ShowRole RoleDescriptor `xorm:"-"`
7474
}
7575

7676
var (

models/issue_comment.go

+22-22
Original file line numberDiff line numberDiff line change
@@ -105,40 +105,40 @@ const (
105105
CommentTypeDismissReview
106106
)
107107

108-
// CommentTag defines comment tag type
109-
type CommentTag int
108+
// RoleDescriptor defines comment tag type
109+
type RoleDescriptor int
110110

111-
// Enumerate all the comment tag types
111+
// Enumerate all the role tags.
112112
const (
113-
CommentTagNone CommentTag = iota
114-
CommentTagPoster
115-
CommentTagWriter
116-
CommentTagOwner
113+
RoleDescriptorNone RoleDescriptor = iota
114+
RoleDescriptorPoster
115+
RoleDescriptorWriter
116+
RoleDescriptorOwner
117117
)
118118

119-
// WithTag enable a specific tag on the CommentTag.
120-
func (ct CommentTag) WithTag(tag CommentTag) CommentTag {
121-
ct |= (1 << tag)
122-
return ct
119+
// WithRole enable a specific tag on the RoleDescriptor.
120+
func (rd RoleDescriptor) WithRole(role RoleDescriptor) RoleDescriptor {
121+
rd |= (1 << role)
122+
return rd
123123
}
124124

125-
func stringToCommentTag(tag string) CommentTag {
126-
switch tag {
125+
func stringToRoleDescriptor(role string) RoleDescriptor {
126+
switch role {
127127
case "Poster":
128-
return CommentTagPoster
128+
return RoleDescriptorPoster
129129
case "Writer":
130-
return CommentTagWriter
130+
return RoleDescriptorWriter
131131
case "Owner":
132-
return CommentTagOwner
132+
return RoleDescriptorOwner
133133
default:
134-
return CommentTagNone
134+
return RoleDescriptorNone
135135
}
136136
}
137137

138-
// HasTag returns if a certain tag is enabled on the CommentTag.
139-
func (ct CommentTag) HasTag(compareTag string) bool {
140-
checkCommentTag := stringToCommentTag(compareTag)
141-
bitValue := ct & (1 << checkCommentTag)
138+
// HasRole returns if a certain role is enabled on the RoleDescriptor.
139+
func (rd RoleDescriptor) HasRole(role string) bool {
140+
roleDescriptor := stringToRoleDescriptor(role)
141+
bitValue := rd & (1 << roleDescriptor)
142142
return (bitValue > 0)
143143
}
144144

@@ -200,7 +200,7 @@ type Comment struct {
200200
Reactions ReactionList `xorm:"-"`
201201

202202
// For view issue page.
203-
ShowTag CommentTag `xorm:"-"`
203+
ShowRole RoleDescriptor `xorm:"-"`
204204

205205
Review *Review `xorm:"-"`
206206
ReviewID int64 `xorm:"index"`

routers/web/repo/issue.go

+30-30
Original file line numberDiff line numberDiff line change
@@ -1014,46 +1014,46 @@ func NewIssuePost(ctx *context.Context) {
10141014
}
10151015
}
10161016

1017-
// commentTag returns the CommentTag for a comment in/with the given repo, poster and issue
1018-
func commentTag(repo *models.Repository, poster *models.User, issue *models.Issue) (models.CommentTag, error) {
1017+
// roleDescriptor returns the Role Decriptor for a comment in/with the given repo, poster and issue
1018+
func roleDescriptor(repo *models.Repository, poster *models.User, issue *models.Issue) (models.RoleDescriptor, error) {
10191019
perm, err := models.GetUserRepoPermission(repo, poster)
10201020
if err != nil {
1021-
return models.CommentTagNone, err
1021+
return models.RoleDescriptorNone, err
10221022
}
10231023

1024-
// By default the comment has no tags.
1025-
commentTag := models.CommentTagNone
1024+
// By default the poster has no roles on the comment.
1025+
roleDescriptor := models.RoleDescriptorNone
10261026

10271027
// Check if the poster is owner of the repo.
10281028
if perm.IsOwner() {
1029-
// If the poster isn't a admin, enable the owner Tag.
1029+
// If the poster isn't a admin, enable the owner role.
10301030
if !poster.IsAdmin {
1031-
commentTag = commentTag.WithTag(models.CommentTagOwner)
1031+
roleDescriptor = roleDescriptor.WithRole(models.RoleDescriptorOwner)
10321032
} else {
10331033

10341034
// Otherwise check if poster is the real repo admin.
10351035
ok, err := models.IsUserRealRepoAdmin(repo, poster)
10361036
if err != nil {
1037-
return models.CommentTagNone, err
1037+
return models.RoleDescriptorNone, err
10381038
}
10391039
if ok {
1040-
commentTag = commentTag.WithTag(models.CommentTagOwner)
1040+
roleDescriptor = roleDescriptor.WithRole(models.RoleDescriptorOwner)
10411041
}
10421042
}
10431043
}
10441044

1045-
// Is the poster can write issues or pulls to the repo, enable the Writer tag.
1046-
// Only enable this if the poster doesn't have the owner tag already.
1047-
if !commentTag.HasTag("Owner") && perm.CanWriteIssuesOrPulls(issue.IsPull) {
1048-
commentTag = commentTag.WithTag(models.CommentTagWriter)
1045+
// Is the poster can write issues or pulls to the repo, enable the Writer role.
1046+
// Only enable this if the poster doesn't have the owner role already.
1047+
if !roleDescriptor.HasRole("Owner") && perm.CanWriteIssuesOrPulls(issue.IsPull) {
1048+
roleDescriptor = roleDescriptor.WithRole(models.RoleDescriptorWriter)
10491049
}
1050-
1051-
// If the poster is the actual poster of the issue, enable Poster tag.
1050+
1051+
// If the poster is the actual poster of the issue, enable Poster role.
10521052
if issue.IsPoster(poster.ID) {
1053-
commentTag = commentTag.WithTag(models.CommentTagPoster)
1053+
roleDescriptor = roleDescriptor.WithRole(models.RoleDescriptorPoster)
10541054
}
10551055

1056-
return commentTag, nil
1056+
return roleDescriptor, nil
10571057
}
10581058

10591059
func getBranchData(ctx *context.Context, issue *models.Issue) {
@@ -1256,9 +1256,9 @@ func ViewIssue(ctx *context.Context) {
12561256
}
12571257

12581258
var (
1259-
tag models.CommentTag
1259+
tag models.RoleDescriptor
12601260
ok bool
1261-
marked = make(map[int64]models.CommentTag)
1261+
marked = make(map[int64]models.RoleDescriptor)
12621262
comment *models.Comment
12631263
participants = make([]*models.User, 1, 10)
12641264
)
@@ -1305,11 +1305,11 @@ func ViewIssue(ctx *context.Context) {
13051305
// check if dependencies can be created across repositories
13061306
ctx.Data["AllowCrossRepositoryDependencies"] = setting.Service.AllowCrossRepositoryDependencies
13071307

1308-
if issue.ShowTag, err = commentTag(repo, issue.Poster, issue); err != nil {
1309-
ctx.ServerError("commentTag", err)
1308+
if issue.ShowRole, err = roleDescriptor(repo, issue.Poster, issue); err != nil {
1309+
ctx.ServerError("roleDescriptor", err)
13101310
return
13111311
}
1312-
marked[issue.PosterID] = issue.ShowTag
1312+
marked[issue.PosterID] = issue.ShowRole
13131313

13141314
// Render comments and and fetch participants.
13151315
participants[0] = issue.Poster
@@ -1340,16 +1340,16 @@ func ViewIssue(ctx *context.Context) {
13401340
// Check tag.
13411341
tag, ok = marked[comment.PosterID]
13421342
if ok {
1343-
comment.ShowTag = tag
1343+
comment.ShowRole = tag
13441344
continue
13451345
}
13461346

1347-
comment.ShowTag, err = commentTag(repo, comment.Poster, issue)
1347+
comment.ShowRole, err = roleDescriptor(repo, comment.Poster, issue)
13481348
if err != nil {
1349-
ctx.ServerError("commentTag", err)
1349+
ctx.ServerError("roleDescriptor", err)
13501350
return
13511351
}
1352-
marked[comment.PosterID] = comment.ShowTag
1352+
marked[comment.PosterID] = comment.ShowRole
13531353
participants = addParticipant(comment.Poster, participants)
13541354
} else if comment.Type == models.CommentTypeLabel {
13551355
if err = comment.LoadLabel(); err != nil {
@@ -1439,16 +1439,16 @@ func ViewIssue(ctx *context.Context) {
14391439
// Check tag.
14401440
tag, ok = marked[c.PosterID]
14411441
if ok {
1442-
c.ShowTag = tag
1442+
c.ShowRole = tag
14431443
continue
14441444
}
14451445

1446-
c.ShowTag, err = commentTag(repo, c.Poster, issue)
1446+
c.ShowRole, err = roleDescriptor(repo, c.Poster, issue)
14471447
if err != nil {
1448-
ctx.ServerError("commentTag", err)
1448+
ctx.ServerError("roleDescriptor", err)
14491449
return
14501450
}
1451-
marked[c.PosterID] = c.ShowTag
1451+
marked[c.PosterID] = c.ShowRole
14521452
participants = addParticipant(c.Poster, participants)
14531453
}
14541454
}

templates/repo/issue/view_content.tmpl

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@
4949
</div>
5050
<div class="comment-header-right actions df ac">
5151
{{if not $.Repository.IsArchived}}
52-
{{if gt .Issue.ShowTag 0}}
53-
{{if (.Issue.ShowTag.HasTag "Writer")}}
52+
{{if gt .Issue.ShowRole 0}}
53+
{{if (.Issue.ShowRole.HasRole "Writer")}}
5454
<div class="ui basic label">
5555
{{$.i18n.Tr "repo.issues.collaborator"}}
5656
</div>
5757
{{end}}
58-
{{if (.Issue.ShowTag.HasTag "Owner")}}
58+
{{if (.Issue.ShowRole.HasRole "Owner")}}
5959
<div class="ui basic label">
6060
{{$.i18n.Tr "repo.issues.owner"}}
6161
</div>

templates/repo/issue/view_content/comments.tmpl

+6-6
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@
4444
</div>
4545
<div class="comment-header-right actions df ac">
4646
{{if not $.Repository.IsArchived}}
47-
{{if (.ShowTag.HasTag "Poster")}}
47+
{{if (.ShowRole.HasRole "Poster")}}
4848
<div class="ui basic label">
4949
{{$.i18n.Tr "repo.issues.poster"}}
5050
</div>
5151
{{end}}
52-
{{if (.ShowTag.HasTag "Writer")}}
52+
{{if (.ShowRole.HasRole "Writer")}}
5353
<div class="ui basic label">
5454
{{$.i18n.Tr "repo.issues.collaborator"}}
5555
</div>
5656
{{end}}
57-
{{if (.ShowTag.HasTag "Owner")}}
57+
{{if (.ShowRole.HasRole "Owner")}}
5858
<div class="ui basic label">
5959
{{$.i18n.Tr "repo.issues.owner"}}
6060
</div>
@@ -550,17 +550,17 @@
550550
</span>
551551
</div>
552552
<div class="comment-header-right actions df ac">
553-
{{if (.ShowTag.HasTag "Poster")}}
553+
{{if (.ShowRole.HasRole "Poster")}}
554554
<div class="ui basic label">
555555
{{$.i18n.Tr "repo.issues.poster"}}
556556
</div>
557557
{{end}}
558-
{{if (.ShowTag.HasTag "Writer")}}
558+
{{if (.ShowRole.HasRole "Writer")}}
559559
<div class="ui basic label">
560560
{{$.i18n.Tr "repo.issues.collaborator"}}
561561
</div>
562562
{{end}}
563-
{{if (.ShowTag.HasTag "Owner")}}
563+
{{if (.ShowRole.HasRole "Owner")}}
564564
<div class="ui basic label">
565565
{{$.i18n.Tr "repo.issues.owner"}}
566566
</div>

0 commit comments

Comments
 (0)