@ -1015,38 +1015,46 @@ func NewIssuePost(ctx *context.Context) {
}
}
}
}
// commentTag returns the CommentTag for a comment in/with the given repo, poster and issue
// roleDescriptor returns the Role Decriptor for a comment in/with the given repo, poster and issue
func commentTag ( repo * models . Repository , poster * models . User , issue * models . Issue ) ( models . CommentTag , error ) {
func roleDescriptor ( repo * models . Repository , poster * models . User , issue * models . Issue ) ( models . RoleDescriptor , error ) {
perm , err := models . GetUserRepoPermission ( repo , poster )
perm , err := models . GetUserRepoPermission ( repo , poster )
if err != nil {
if err != nil {
return models . CommentTag None, err
return models . RoleDescriptor None, err
}
}
if perm . IsOwner ( ) {
if ! poster . IsAdmin {
return models . CommentTagOwner , nil
}
ok , err := models . IsUserRealRepoAdmin ( repo , poster )
// By default the poster has no roles on the comment.
if err != nil {
roleDescriptor := models . RoleDescriptorNone
return models . CommentTagNone , err
}
if ok {
// Check if the poster is owner of the repo.
return models . CommentTagOwner , nil
if perm . IsOwner ( ) {
}
// If the poster isn't a admin, enable the owner role.
if ! poster . IsAdmin {
roleDescriptor = roleDescriptor . WithRole ( models . RoleDescriptorOwner )
} else {
if ok , err = repo . IsCollaborator ( poster . ID ) ; ok && err == nil {
// Otherwise check if poster is the real repo admin.
return models . CommentTagWriter , nil
ok , err := models . IsUserRealRepoAdmin ( repo , poster )
if err != nil {
return models . RoleDescriptorNone , err
}
if ok {
roleDescriptor = roleDescriptor . WithRole ( models . RoleDescriptorOwner )
}
}
}
}
return models . CommentTagNone , err
// Is the poster can write issues or pulls to the repo, enable the Writer role.
// Only enable this if the poster doesn't have the owner role already.
if ! roleDescriptor . HasRole ( "Owner" ) && perm . CanWriteIssuesOrPulls ( issue . IsPull ) {
roleDescriptor = roleDescriptor . WithRole ( models . RoleDescriptorWriter )
}
}
if perm . CanWriteIssuesOrPulls ( issue . IsPull ) {
// If the poster is the actual poster of the issue, enable Poster role.
return models . CommentTagWriter , nil
if issue . IsPoster ( poster . ID ) {
roleDescriptor = roleDescriptor . WithRole ( models . RoleDescriptorPoster )
}
}
return models . CommentTagNone , nil
return roleDescriptor , nil
}
}
func getBranchData ( ctx * context . Context , issue * models . Issue ) {
func getBranchData ( ctx * context . Context , issue * models . Issue ) {
@ -1249,9 +1257,9 @@ func ViewIssue(ctx *context.Context) {
}
}
var (
var (
tag models . CommentTag
role models . RoleDescriptor
ok bool
ok bool
marked = make ( map [ int64 ] models . CommentTag )
marked = make ( map [ int64 ] models . RoleDescriptor )
comment * models . Comment
comment * models . Comment
participants = make ( [ ] * models . User , 1 , 10 )
participants = make ( [ ] * models . User , 1 , 10 )
)
)
@ -1298,11 +1306,11 @@ func ViewIssue(ctx *context.Context) {
// check if dependencies can be created across repositories
// check if dependencies can be created across repositories
ctx . Data [ "AllowCrossRepositoryDependencies" ] = setting . Service . AllowCrossRepositoryDependencies
ctx . Data [ "AllowCrossRepositoryDependencies" ] = setting . Service . AllowCrossRepositoryDependencies
if issue . ShowTag , err = commentTag ( repo , issue . Poster , issue ) ; err != nil {
if issue . ShowRole , err = roleDescriptor ( repo , issue . Poster , issue ) ; err != nil {
ctx . ServerError ( "commentTag " , err )
ctx . ServerError ( "roleDescriptor " , err )
return
return
}
}
marked [ issue . PosterID ] = issue . ShowTag
marked [ issue . PosterID ] = issue . ShowRole
// Render comments and and fetch participants.
// Render comments and and fetch participants.
participants [ 0 ] = issue . Poster
participants [ 0 ] = issue . Poster
@ -1331,18 +1339,18 @@ func ViewIssue(ctx *context.Context) {
return
return
}
}
// Check tag.
// Check tag.
tag , ok = marked [ comment . PosterID ]
role , ok = marked [ comment . PosterID ]
if ok {
if ok {
comment . ShowTag = tag
comment . ShowRole = role
continue
continue
}
}
comment . ShowTag , err = commentTag ( repo , comment . Poster , issue )
comment . ShowRole , err = roleDescriptor ( repo , comment . Poster , issue )
if err != nil {
if err != nil {
ctx . ServerError ( "commentTag " , err )
ctx . ServerError ( "roleDescriptor " , err )
return
return
}
}
marked [ comment . PosterID ] = comment . ShowTag
marked [ comment . PosterID ] = comment . ShowRole
participants = addParticipant ( comment . Poster , participants )
participants = addParticipant ( comment . Poster , participants )
} else if comment . Type == models . CommentTypeLabel {
} else if comment . Type == models . CommentTypeLabel {
if err = comment . LoadLabel ( ) ; err != nil {
if err = comment . LoadLabel ( ) ; err != nil {
@ -1430,18 +1438,18 @@ func ViewIssue(ctx *context.Context) {
for _ , lineComments := range codeComments {
for _ , lineComments := range codeComments {
for _ , c := range lineComments {
for _ , c := range lineComments {
// Check tag.
// Check tag.
tag , ok = marked [ c . PosterID ]
role , ok = marked [ c . PosterID ]
if ok {
if ok {
c . ShowTag = tag
c . ShowRole = role
continue
continue
}
}
c . ShowTag , err = commentTag ( repo , c . Poster , issue )
c . ShowRole , err = roleDescriptor ( repo , c . Poster , issue )
if err != nil {
if err != nil {
ctx . ServerError ( "commentTag " , err )
ctx . ServerError ( "roleDescriptor " , err )
return
return
}
}
marked [ c . PosterID ] = c . ShowTag
marked [ c . PosterID ] = c . ShowRole
participants = addParticipant ( c . Poster , participants )
participants = addParticipant ( c . Poster , participants )
}
}
}
}