Skip to content

Commit 639bec5

Browse files
lunnyGiteaBot
authored andcommitted
Users with read permission of pull requests can be assigned too (go-gitea#27263)
This PR will also keep the consistent between list assigned users and check assigned users.
1 parent e75594f commit 639bec5

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

models/perm/access/repo_permission.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ func HasAccessUnit(ctx context.Context, user *user_model.User, repo *repo_model.
332332

333333
// CanBeAssigned return true if user can be assigned to issue or pull requests in repo
334334
// Currently any write access (code, issues or pr's) is assignable, to match assignee list in user interface.
335-
// FIXME: user could send PullRequest also could be assigned???
336335
func CanBeAssigned(ctx context.Context, user *user_model.User, repo *repo_model.Repository, _ bool) (bool, error) {
337336
if user.IsOrganization() {
338337
return false, fmt.Errorf("Organization can't be added as assignee [user_id: %d, repo_id: %d]", user.ID, repo.ID)
@@ -341,7 +340,8 @@ func CanBeAssigned(ctx context.Context, user *user_model.User, repo *repo_model.
341340
if err != nil {
342341
return false, err
343342
}
344-
return perm.CanAccessAny(perm_model.AccessModeWrite, unit.TypeCode, unit.TypeIssues, unit.TypePullRequests), nil
343+
return perm.CanAccessAny(perm_model.AccessModeWrite, unit.AllRepoUnitTypes...) ||
344+
perm.CanAccessAny(perm_model.AccessModeRead, unit.TypePullRequests), nil
345345
}
346346

347347
// HasAccess returns true if user has access to repo

models/repo/user_repo.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"code.gitea.io/gitea/models/db"
1010
"code.gitea.io/gitea/models/perm"
11+
"code.gitea.io/gitea/models/unit"
1112
user_model "code.gitea.io/gitea/models/user"
1213
"code.gitea.io/gitea/modules/container"
1314
api "code.gitea.io/gitea/modules/structs"
@@ -78,7 +79,8 @@ func GetRepoAssignees(ctx context.Context, repo *Repository) (_ []*user_model.Us
7879
if err = e.Table("team_user").
7980
Join("INNER", "team_repo", "`team_repo`.team_id = `team_user`.team_id").
8081
Join("INNER", "team_unit", "`team_unit`.team_id = `team_user`.team_id").
81-
Where("`team_repo`.repo_id = ? AND `team_unit`.access_mode >= ?", repo.ID, perm.AccessModeWrite).
82+
Where("`team_repo`.repo_id = ? AND (`team_unit`.access_mode >= ? OR (`team_unit`.access_mode = ? AND `team_unit`.`type` = ?))",
83+
repo.ID, perm.AccessModeWrite, perm.AccessModeRead, unit.TypePullRequests).
8284
Distinct("`team_user`.uid").
8385
Select("`team_user`.uid").
8486
Find(&additionalUserIDs); err != nil {

0 commit comments

Comments
 (0)