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
|
@ -1228,47 +1228,70 @@ func NewIssuePost(ctx *context.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
// roleDescriptor returns the Role Descriptor for a comment in/with the given repo, poster and issue
|
||||
// roleDescriptor returns the role descriptor for a comment in/with the given repo, poster and issue
|
||||
func roleDescriptor(ctx stdCtx.Context, repo *repo_model.Repository, poster *user_model.User, issue *issues_model.Issue, hasOriginalAuthor bool) (issues_model.RoleDescriptor, error) {
|
||||
roleDescriptor := issues_model.RoleDescriptor{}
|
||||
|
||||
if hasOriginalAuthor {
|
||||
return issues_model.RoleDescriptorNone, nil
|
||||
return roleDescriptor, nil
|
||||
}
|
||||
|
||||
perm, err := access_model.GetUserRepoPermission(ctx, repo, poster)
|
||||
if err != nil {
|
||||
return issues_model.RoleDescriptorNone, err
|
||||
}
|
||||
|
||||
// By default the poster has no roles on the comment.
|
||||
roleDescriptor := issues_model.RoleDescriptorNone
|
||||
|
||||
// Check if the poster is owner of the repo.
|
||||
if perm.IsOwner() {
|
||||
// If the poster isn't a admin, enable the owner role.
|
||||
if !poster.IsAdmin {
|
||||
roleDescriptor = roleDescriptor.WithRole(issues_model.RoleDescriptorOwner)
|
||||
} else {
|
||||
|
||||
// Otherwise check if poster is the real repo admin.
|
||||
ok, err := access_model.IsUserRealRepoAdmin(repo, poster)
|
||||
if err != nil {
|
||||
return issues_model.RoleDescriptorNone, err
|
||||
}
|
||||
if ok {
|
||||
roleDescriptor = roleDescriptor.WithRole(issues_model.RoleDescriptorOwner)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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(issues_model.RoleDescriptorWriter)
|
||||
return roleDescriptor, err
|
||||
}
|
||||
|
||||
// If the poster is the actual poster of the issue, enable Poster role.
|
||||
if issue.IsPoster(poster.ID) {
|
||||
roleDescriptor = roleDescriptor.WithRole(issues_model.RoleDescriptorPoster)
|
||||
roleDescriptor.IsPoster = issue.IsPoster(poster.ID)
|
||||
|
||||
// Check if the poster is owner of the repo.
|
||||
if perm.IsOwner() {
|
||||
// If the poster isn't an admin, enable the owner role.
|
||||
if !poster.IsAdmin {
|
||||
roleDescriptor.RoleInRepo = issues_model.RoleRepoOwner
|
||||
return roleDescriptor, nil
|
||||
}
|
||||
|
||||
// Otherwise check if poster is the real repo admin.
|
||||
ok, err := access_model.IsUserRealRepoAdmin(repo, poster)
|
||||
if err != nil {
|
||||
return roleDescriptor, err
|
||||
}
|
||||
if ok {
|
||||
roleDescriptor.RoleInRepo = issues_model.RoleRepoOwner
|
||||
return roleDescriptor, nil
|
||||
}
|
||||
}
|
||||
|
||||
// If repo is organization, check Member role
|
||||
if err := repo.LoadOwner(ctx); err != nil {
|
||||
return roleDescriptor, err
|
||||
}
|
||||
if repo.Owner.IsOrganization() {
|
||||
if isMember, err := organization.IsOrganizationMember(ctx, repo.Owner.ID, poster.ID); err != nil {
|
||||
return roleDescriptor, err
|
||||
} else if isMember {
|
||||
roleDescriptor.RoleInRepo = issues_model.RoleRepoMember
|
||||
return roleDescriptor, nil
|
||||
}
|
||||
}
|
||||
|
||||
// If the poster is the collaborator of the repo
|
||||
if isCollaborator, err := repo_model.IsCollaborator(ctx, repo.ID, poster.ID); err != nil {
|
||||
return roleDescriptor, err
|
||||
} else if isCollaborator {
|
||||
roleDescriptor.RoleInRepo = issues_model.RoleRepoCollaborator
|
||||
return roleDescriptor, nil
|
||||
}
|
||||
|
||||
hasMergedPR, err := issues_model.HasMergedPullRequestInRepo(ctx, repo.ID, poster.ID)
|
||||
if err != nil {
|
||||
return roleDescriptor, err
|
||||
} else if hasMergedPR {
|
||||
roleDescriptor.RoleInRepo = issues_model.RoleRepoContributor
|
||||
} else {
|
||||
// only display first time contributor in the first opening pull request
|
||||
roleDescriptor.RoleInRepo = issues_model.RoleRepoFirstTimeContributor
|
||||
}
|
||||
|
||||
return roleDescriptor, nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue