@@ -1229,7 +1229,7 @@ func NewIssuePost(ctx *context.Context) {
1229
1229
}
1230
1230
1231
1231
// roleDescriptor returns the Role Descriptor for a comment in/with the given repo, poster and issue
1232
- func roleDescriptor (ctx stdCtx.Context , repo * repo_model.Repository , poster * user_model.User , issue * issues_model.Issue , hasOriginalAuthor bool ) (issues_model.RoleDescriptor , error ) {
1232
+ func roleDescriptor (ctx stdCtx.Context , repo * repo_model.Repository , poster * user_model.User , issue * issues_model.Issue , gitRepo * git. Repository , hasOriginalAuthor bool ) (issues_model.RoleDescriptor , error ) {
1233
1233
if hasOriginalAuthor {
1234
1234
return issues_model .RoleDescriptorNone , nil
1235
1235
}
@@ -1242,33 +1242,61 @@ func roleDescriptor(ctx stdCtx.Context, repo *repo_model.Repository, poster *use
1242
1242
// By default the poster has no roles on the comment.
1243
1243
roleDescriptor := issues_model .RoleDescriptorNone
1244
1244
1245
+ // If the poster is the actual poster of the issue, enable Poster role.
1246
+ if issue .IsPoster (poster .ID ) {
1247
+ roleDescriptor = roleDescriptor .WithRole (issues_model .RoleDescriptorPoster )
1248
+ }
1249
+
1245
1250
// Check if the poster is owner of the repo.
1246
1251
if perm .IsOwner () {
1247
1252
// If the poster isn't a admin, enable the owner role.
1248
1253
if ! poster .IsAdmin {
1249
1254
roleDescriptor = roleDescriptor .WithRole (issues_model .RoleDescriptorOwner )
1255
+ return roleDescriptor , nil
1250
1256
} else {
1251
-
1252
1257
// Otherwise check if poster is the real repo admin.
1253
1258
ok , err := access_model .IsUserRealRepoAdmin (repo , poster )
1254
1259
if err != nil {
1255
1260
return issues_model .RoleDescriptorNone , err
1256
1261
}
1257
1262
if ok {
1258
1263
roleDescriptor = roleDescriptor .WithRole (issues_model .RoleDescriptorOwner )
1264
+ return roleDescriptor , nil
1259
1265
}
1260
1266
}
1261
1267
}
1262
1268
1263
- // Is the poster can write issues or pulls to the repo, enable the Writer role.
1264
- // Only enable this if the poster doesn't have the owner role already.
1265
- if ! roleDescriptor .HasRole ("Owner" ) && perm .CanWriteIssuesOrPulls (issue .IsPull ) {
1266
- roleDescriptor = roleDescriptor .WithRole (issues_model .RoleDescriptorWriter )
1269
+ // If repo is organization, check Member role
1270
+ if err := repo .LoadOwner (ctx ); err != nil {
1271
+ return issues_model .RoleDescriptorNone , err
1272
+ }
1273
+ if repo .Owner .IsOrganization () {
1274
+ if isMember , err := organization .IsOrganizationMember (ctx , repo .Owner .ID , poster .ID ); err != nil {
1275
+ return issues_model .RoleDescriptorNone , err
1276
+ } else if isMember {
1277
+ roleDescriptor = roleDescriptor .WithRole (issues_model .RoleDescriptorMember )
1278
+ return roleDescriptor , nil
1279
+ }
1267
1280
}
1268
1281
1269
- // If the poster is the actual poster of the issue, enable Poster role.
1270
- if issue .IsPoster (poster .ID ) {
1271
- roleDescriptor = roleDescriptor .WithRole (issues_model .RoleDescriptorPoster )
1282
+ // If the poster is the collaborator of the repo
1283
+ if isCollaborator , err := repo_model .IsCollaborator (ctx , repo .ID , poster .ID ); err != err {
1284
+ return issues_model .RoleDescriptorNone , err
1285
+ } else if isCollaborator {
1286
+ roleDescriptor = roleDescriptor .WithRole (issues_model .RoleDescriptorCollaborator )
1287
+ return roleDescriptor , nil
1288
+ }
1289
+
1290
+ if commits , err := gitRepo .SearchCommits (git.SearchCommitsOptions {
1291
+ Authors : []string {poster .Name },
1292
+ All : true ,
1293
+ Limit : 2 ,
1294
+ }); err != nil {
1295
+ return issues_model .RoleDescriptorNone , err
1296
+ } else if len (commits ) == 1 {
1297
+ roleDescriptor = roleDescriptor .WithRole (issues_model .RoleDescriptorContributor )
1298
+ } else if len (commits ) > 1 {
1299
+ roleDescriptor = roleDescriptor .WithRole (issues_model .RoleDescriptorFirstTimeContributor )
1272
1300
}
1273
1301
1274
1302
return roleDescriptor , nil
@@ -1526,7 +1554,7 @@ func ViewIssue(ctx *context.Context) {
1526
1554
// check if dependencies can be created across repositories
1527
1555
ctx .Data ["AllowCrossRepositoryDependencies" ] = setting .Service .AllowCrossRepositoryDependencies
1528
1556
1529
- if issue .ShowRole , err = roleDescriptor (ctx , repo , issue .Poster , issue , issue .HasOriginalAuthor ()); err != nil {
1557
+ if issue .ShowRole , err = roleDescriptor (ctx , repo , issue .Poster , issue , ctx . Repo . GitRepo , issue .HasOriginalAuthor ()); err != nil {
1530
1558
ctx .ServerError ("roleDescriptor" , err )
1531
1559
return
1532
1560
}
@@ -1565,7 +1593,7 @@ func ViewIssue(ctx *context.Context) {
1565
1593
continue
1566
1594
}
1567
1595
1568
- comment .ShowRole , err = roleDescriptor (ctx , repo , comment .Poster , issue , comment .HasOriginalAuthor ())
1596
+ comment .ShowRole , err = roleDescriptor (ctx , repo , comment .Poster , issue , ctx . Repo . GitRepo , comment .HasOriginalAuthor ())
1569
1597
if err != nil {
1570
1598
ctx .ServerError ("roleDescriptor" , err )
1571
1599
return
@@ -1664,7 +1692,7 @@ func ViewIssue(ctx *context.Context) {
1664
1692
continue
1665
1693
}
1666
1694
1667
- c .ShowRole , err = roleDescriptor (ctx , repo , c .Poster , issue , c .HasOriginalAuthor ())
1695
+ c .ShowRole , err = roleDescriptor (ctx , repo , c .Poster , issue , ctx . Repo . GitRepo , c .HasOriginalAuthor ())
1668
1696
if err != nil {
1669
1697
ctx .ServerError ("roleDescriptor" , err )
1670
1698
return
0 commit comments