Skip to content

Role issue #18093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 26, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .revive.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ warningCode = 1
[rule.indent-error-flow]
[rule.errorf]
[rule.duplicated-imports]
[rule.modifies-value-receiver]
5 changes: 2 additions & 3 deletions models/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,8 @@ const (
)

// WithRole enable a specific tag on the RoleDescriptor.
func (rd RoleDescriptor) WithRole(role RoleDescriptor) RoleDescriptor {
rd |= (1 << role)
return rd
func (rd *RoleDescriptor) WithRole(role RoleDescriptor) {
*rd |= (1 << role)
}

func stringToRoleDescriptor(role string) RoleDescriptor {
Expand Down
12 changes: 6 additions & 6 deletions routers/web/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -1034,13 +1034,13 @@ func roleDescriptor(repo *repo_model.Repository, poster *user_model.User, issue
}

// By default the poster has no roles on the comment.
roleDescriptor := models.RoleDescriptorNone
roleDescriptor := new(models.RoleDescriptor)

// 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(models.RoleDescriptorOwner)
roleDescriptor.WithRole(models.RoleDescriptorOwner)
} else {

// Otherwise check if poster is the real repo admin.
Expand All @@ -1049,23 +1049,23 @@ func roleDescriptor(repo *repo_model.Repository, poster *user_model.User, issue
return models.RoleDescriptorNone, err
}
if ok {
roleDescriptor = roleDescriptor.WithRole(models.RoleDescriptorOwner)
roleDescriptor.WithRole(models.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(models.RoleDescriptorWriter)
roleDescriptor.WithRole(models.RoleDescriptorWriter)
}

// If the poster is the actual poster of the issue, enable Poster role.
if issue.IsPoster(poster.ID) {
roleDescriptor = roleDescriptor.WithRole(models.RoleDescriptorPoster)
roleDescriptor.WithRole(models.RoleDescriptorPoster)
}

return roleDescriptor, nil
return *roleDescriptor, nil
}

func getBranchData(ctx *context.Context, issue *models.Issue) {
Expand Down