Add member
, collaborator
, contributor
, and first-time contributor
roles and tooltips (#26658)
GitHub like role descriptor    --------- Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
0d55f64e6c
commit
d2e4039def
5 changed files with 106 additions and 73 deletions
|
@ -23,6 +23,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/references"
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/translation"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"xorm.io/builder"
|
||||
|
@ -181,40 +182,32 @@ func (t CommentType) HasAttachmentSupport() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// RoleDescriptor defines comment tag type
|
||||
type RoleDescriptor int
|
||||
// RoleInRepo presents the user's participation in the repo
|
||||
type RoleInRepo string
|
||||
|
||||
// RoleDescriptor defines comment "role" tags
|
||||
type RoleDescriptor struct {
|
||||
IsPoster bool
|
||||
RoleInRepo RoleInRepo
|
||||
}
|
||||
|
||||
// Enumerate all the role tags.
|
||||
const (
|
||||
RoleDescriptorNone RoleDescriptor = iota
|
||||
RoleDescriptorPoster
|
||||
RoleDescriptorWriter
|
||||
RoleDescriptorOwner
|
||||
RoleRepoOwner RoleInRepo = "owner"
|
||||
RoleRepoMember RoleInRepo = "member"
|
||||
RoleRepoCollaborator RoleInRepo = "collaborator"
|
||||
RoleRepoFirstTimeContributor RoleInRepo = "first_time_contributor"
|
||||
RoleRepoContributor RoleInRepo = "contributor"
|
||||
)
|
||||
|
||||
// WithRole enable a specific tag on the RoleDescriptor.
|
||||
func (rd RoleDescriptor) WithRole(role RoleDescriptor) RoleDescriptor {
|
||||
return rd | (1 << role)
|
||||
// LocaleString returns the locale string name of the role
|
||||
func (r RoleInRepo) LocaleString(lang translation.Locale) string {
|
||||
return lang.Tr("repo.issues.role." + string(r))
|
||||
}
|
||||
|
||||
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)
|
||||
// LocaleHelper returns the locale tooltip of the role
|
||||
func (r RoleInRepo) LocaleHelper(lang translation.Locale) string {
|
||||
return lang.Tr("repo.issues.role." + string(r) + "_helper")
|
||||
}
|
||||
|
||||
// Comment represents a comment in commit and issue page.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue