diff options
Diffstat (limited to 'models')
-rw-r--r-- | models/issue.go | 2 | ||||
-rw-r--r-- | models/issue_comment.go | 42 |
2 files changed, 35 insertions, 9 deletions
diff --git a/models/issue.go b/models/issue.go index f36267c945..0d34bdcaf3 100644 --- a/models/issue.go +++ b/models/issue.go @@ -71,7 +71,7 @@ type Issue struct { IsLocked bool `xorm:"NOT NULL DEFAULT false"` // For view issue page. - ShowTag CommentTag `xorm:"-"` + ShowRole RoleDescriptor `xorm:"-"` } var ( diff --git a/models/issue_comment.go b/models/issue_comment.go index ad10b53b37..a41f4cb298 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -105,17 +105,43 @@ const ( CommentTypeDismissReview ) -// CommentTag defines comment tag type -type CommentTag int +// RoleDescriptor defines comment tag type +type RoleDescriptor int -// Enumerate all the comment tag types +// Enumerate all the role tags. const ( - CommentTagNone CommentTag = iota - CommentTagPoster - CommentTagWriter - CommentTagOwner + RoleDescriptorNone RoleDescriptor = iota + RoleDescriptorPoster + RoleDescriptorWriter + RoleDescriptorOwner ) +// WithRole enable a specific tag on the RoleDescriptor. +func (rd RoleDescriptor) WithRole(role RoleDescriptor) RoleDescriptor { + rd |= (1 << role) + return rd +} + +func stringToRoleDescriptor(role string) RoleDescriptor { + switch role { + case "Poster": + return RoleDescriptorPoster + case "Writer": + return RoleDescriptorWriter + case "Owner": + return RoleDescriptorOwner + default: + return RoleDescriptorNone + } +} + +// HasRole returns if a certain role is enabled on the RoleDescriptor. +func (rd RoleDescriptor) HasRole(role string) bool { + roleDescriptor := stringToRoleDescriptor(role) + bitValue := rd & (1 << roleDescriptor) + return (bitValue > 0) +} + // Comment represents a comment in commit and issue page. type Comment struct { ID int64 `xorm:"pk autoincr"` @@ -174,7 +200,7 @@ type Comment struct { Reactions ReactionList `xorm:"-"` // For view issue page. - ShowTag CommentTag `xorm:"-"` + ShowRole RoleDescriptor `xorm:"-"` Review *Review `xorm:"-"` ReviewID int64 `xorm:"index"` |