@@ -1228,47 +1228,70 @@ func NewIssuePost(ctx *context.Context) {
12281228 }
12291229}
12301230
1231- // roleDescriptor returns the Role Descriptor for a comment in/with the given repo, poster and issue
1231+ // roleDescriptor returns the role descriptor for a comment in/with the given repo, poster and issue
12321232func 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+
12331235 if hasOriginalAuthor {
1234- return issues_model . RoleDescriptorNone , nil
1236+ return roleDescriptor , nil
12351237 }
12361238
12371239 perm , err := access_model .GetUserRepoPermission (ctx , repo , poster )
12381240 if err != nil {
1239- return issues_model . RoleDescriptorNone , err
1241+ return roleDescriptor , err
12401242 }
12411243
1242- // By default the poster has no roles on the comment .
1243- roleDescriptor := issues_model . RoleDescriptorNone
1244+ // If the poster is the actual poster of the issue, enable Poster role .
1245+ roleDescriptor . IsPoster = issue . IsPoster ( poster . ID )
12441246
12451247 // Check if the poster is owner of the repo.
12461248 if perm .IsOwner () {
1247- // If the poster isn't a admin, enable the owner role.
1249+ // If the poster isn't an admin, enable the owner role.
12481250 if ! poster .IsAdmin {
1249- roleDescriptor = roleDescriptor .WithRole (issues_model .RoleDescriptorOwner )
1250- } else {
1251+ roleDescriptor .RoleInRepo = issues_model .RoleRepoOwner
1252+ return roleDescriptor , nil
1253+ }
12511254
1252- // Otherwise check if poster is the real repo admin.
1253- ok , err := access_model .IsUserRealRepoAdmin (repo , poster )
1254- if err != nil {
1255- return issues_model . RoleDescriptorNone , err
1256- }
1257- if ok {
1258- roleDescriptor = roleDescriptor . WithRole ( issues_model .RoleDescriptorOwner )
1259- }
1255+ // Otherwise check if poster is the real repo admin.
1256+ ok , err := access_model .IsUserRealRepoAdmin (repo , poster )
1257+ if err != nil {
1258+ return roleDescriptor , err
1259+ }
1260+ if ok {
1261+ roleDescriptor . RoleInRepo = issues_model .RoleRepoOwner
1262+ return roleDescriptor , nil
12601263 }
12611264 }
12621265
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 )
1266+ // If repo is organization, check Member role
1267+ if err := repo .LoadOwner (ctx ); err != nil {
1268+ return roleDescriptor , err
1269+ }
1270+ if repo .Owner .IsOrganization () {
1271+ if isMember , err := organization .IsOrganizationMember (ctx , repo .Owner .ID , poster .ID ); err != nil {
1272+ return roleDescriptor , err
1273+ } else if isMember {
1274+ roleDescriptor .RoleInRepo = issues_model .RoleRepoMember
1275+ return roleDescriptor , nil
1276+ }
12671277 }
12681278
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 )
1279+ // If the poster is the collaborator of the repo
1280+ if isCollaborator , err := repo_model .IsCollaborator (ctx , repo .ID , poster .ID ); err != nil {
1281+ return roleDescriptor , err
1282+ } else if isCollaborator {
1283+ roleDescriptor .RoleInRepo = issues_model .RoleRepoCollaborator
1284+ return roleDescriptor , nil
1285+ }
1286+
1287+ hasMergedPR , err := issues_model .HasMergedPullRequestInRepo (ctx , repo .ID , poster .ID )
1288+ if err != nil {
1289+ return roleDescriptor , err
1290+ } else if hasMergedPR {
1291+ roleDescriptor .RoleInRepo = issues_model .RoleRepoContributor
1292+ } else {
1293+ // only display first time contributor in the first opening pull request
1294+ roleDescriptor .RoleInRepo = issues_model .RoleRepoFirstTimeContributor
12721295 }
12731296
12741297 return roleDescriptor , nil
0 commit comments