@@ -1230,79 +1230,80 @@ func NewIssuePost(ctx *context.Context) {
1230
1230
1231
1231
// roleDescriptor returns the Role Descriptor for a comment in/with the given repo, poster and issue
1232
1232
func roleDescriptor (ctx stdCtx.Context , repo * repo_model.Repository , poster * user_model.User , issue * issues_model.Issue , hasOriginalAuthor bool ) (issues_model.RoleDescriptor , error ) {
1233
+ roleDescriptor := issues_model.RoleDescriptor {}
1234
+
1233
1235
if hasOriginalAuthor {
1234
- return issues_model . RoleDescriptorNone , nil
1236
+ return roleDescriptor , nil
1235
1237
}
1236
1238
1237
1239
perm , err := access_model .GetUserRepoPermission (ctx , repo , poster )
1238
1240
if err != nil {
1239
- return issues_model . RoleDescriptorNone , err
1241
+ return roleDescriptor , err
1240
1242
}
1241
1243
1242
- // By default the poster has no roles on the comment.
1243
- roleDescriptor := issues_model .RoleDescriptorNone
1244
-
1245
1244
// If the poster is the actual poster of the issue, enable Poster role.
1246
1245
if issue .IsPoster (poster .ID ) {
1247
- roleDescriptor = roleDescriptor . WithRole ( issues_model . RoleDescriptorPoster )
1246
+ roleDescriptor . IsPoster = util . OptionalBoolTrue
1248
1247
}
1249
1248
1250
1249
// Check if the poster is owner of the repo.
1251
1250
if perm .IsOwner () {
1252
1251
// If the poster isn't a admin, enable the owner role.
1253
1252
if ! poster .IsAdmin {
1254
- roleDescriptor = roleDescriptor . WithRole ( issues_model .RoleDescriptorOwner )
1253
+ roleDescriptor . Role = issues_model .RoleDescriptorOwner
1255
1254
return roleDescriptor , nil
1256
1255
}
1257
1256
1258
1257
// Otherwise check if poster is the real repo admin.
1259
1258
ok , err := access_model .IsUserRealRepoAdmin (repo , poster )
1260
1259
if err != nil {
1261
- return issues_model . RoleDescriptorNone , err
1260
+ return roleDescriptor , err
1262
1261
}
1263
1262
if ok {
1264
- roleDescriptor = roleDescriptor . WithRole ( issues_model .RoleDescriptorOwner )
1263
+ roleDescriptor . Role = issues_model .RoleDescriptorOwner
1265
1264
return roleDescriptor , nil
1266
1265
}
1267
1266
}
1268
1267
1269
1268
// If repo is organization, check Member role
1270
1269
if err := repo .LoadOwner (ctx ); err != nil {
1271
- return issues_model . RoleDescriptorNone , err
1270
+ return roleDescriptor , err
1272
1271
}
1273
1272
if repo .Owner .IsOrganization () {
1274
1273
if isMember , err := organization .IsOrganizationMember (ctx , repo .Owner .ID , poster .ID ); err != nil {
1275
- return issues_model . RoleDescriptorNone , err
1274
+ return roleDescriptor , err
1276
1275
} else if isMember {
1277
- roleDescriptor = roleDescriptor . WithRole ( issues_model .RoleDescriptorMember )
1276
+ roleDescriptor . Role = issues_model .RoleDescriptorMember
1278
1277
return roleDescriptor , nil
1279
1278
}
1280
1279
}
1281
1280
1282
1281
// If the poster is the collaborator of the repo
1283
1282
if isCollaborator , err := repo_model .IsCollaborator (ctx , repo .ID , poster .ID ); err != nil {
1284
- return issues_model . RoleDescriptorNone , err
1283
+ return roleDescriptor , err
1285
1284
} else if isCollaborator {
1286
- roleDescriptor = roleDescriptor . WithRole ( issues_model .RoleDescriptorCollaborator )
1285
+ roleDescriptor . Role = issues_model .RoleDescriptorCollaborator
1287
1286
return roleDescriptor , nil
1288
1287
}
1289
1288
1290
1289
// If the poster is the contributor of the repo
1291
1290
searchOpt := & issue_indexer.SearchOptions {
1292
1291
Paginator : & db.ListOptions {
1293
1292
Page : 1 ,
1294
- PageSize : 2 ,
1293
+ PageSize : 1 ,
1295
1294
},
1296
1295
RepoIDs : []int64 {repo .ID },
1296
+ IsClosed : util .OptionalBoolTrue ,
1297
1297
IsPull : util .OptionalBoolTrue ,
1298
1298
PosterID : & poster .ID ,
1299
1299
}
1300
1300
if _ , total , err := issue_indexer .SearchIssues (ctx , searchOpt ); err != nil {
1301
- return issues_model .RoleDescriptorNone , err
1302
- } else if total == 1 {
1303
- roleDescriptor = roleDescriptor .WithRole (issues_model .RoleDescriptorFirstTimeContributor )
1304
- } else if total > 1 {
1305
- roleDescriptor = roleDescriptor .WithRole (issues_model .RoleDescriptorContributor )
1301
+ return roleDescriptor , err
1302
+ } else if total > 0 {
1303
+ roleDescriptor .Role = issues_model .RoleDescriptorContributor
1304
+ } else if total == 0 && issue .IsPull && ! issue .IsClosed {
1305
+ // only display first time contributor in the first opening pull request
1306
+ roleDescriptor .Role = issues_model .RoleDescriptorFirstTimeContributor
1306
1307
}
1307
1308
1308
1309
return roleDescriptor , nil
0 commit comments