mirror of
https://github.com/go-gitea/gitea.git
synced 2026-11-02 13:44:16 +09:00
fix(projects): hide linked pull requests the viewer cannot read (#40016)
Project board cards list the pull requests that reference their issue, but loaded them without checking the viewer's access. A private pull request mentioning a public issue showed its title, number and state on that issue's board to anyone who can view the board, anonymous visitors included. Repository and organization boards now skip linked pull requests in repositories where the viewer cannot read pull requests, matching how the issue page already hides such references. --------- Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: bircni <bircni@icloud.com> Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
4 files changed
+68
-38
No files matched your search
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"gitea.dev/models/db"
|
||||
issues_model "gitea.dev/models/issues"
|
||||
access_model "gitea.dev/models/perm/access"
|
||||
project_model "gitea.dev/models/project"
|
||||
user_model "gitea.dev/models/user"
|
||||
"gitea.dev/modules/optional"
|
||||
@@ -258,6 +259,48 @@ func LoadIssuesFromProject(ctx context.Context, project *project_model.Project,
|
||||
return results, nil
|
||||
}
|
||||
|
||||
// LoadLinkedPullRequests returns, per issue, the pull requests referencing it that the doer can read
|
||||
func LoadLinkedPullRequests(ctx context.Context, issuesMap map[int64]issues_model.IssueList, doer *user_model.User) (map[int64][]*issues_model.Issue, error) {
|
||||
linkedPrsMap := make(map[int64][]*issues_model.Issue)
|
||||
canReadPulls := make(map[int64]bool)
|
||||
for _, issuesList := range issuesMap {
|
||||
for _, issue := range issuesList {
|
||||
var referencedIDs []int64
|
||||
for _, comment := range issue.Comments {
|
||||
if comment.RefIssueID != 0 && comment.RefIsPull {
|
||||
referencedIDs = append(referencedIDs, comment.RefIssueID)
|
||||
}
|
||||
}
|
||||
if len(referencedIDs) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
linkedPrs, err := issues_model.Issues(ctx, &issues_model.IssuesOptions{
|
||||
IssueIDs: referencedIDs,
|
||||
IsPull: optional.Some(true),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, pr := range linkedPrs {
|
||||
canRead, ok := canReadPulls[pr.RepoID]
|
||||
if !ok {
|
||||
perm, err := access_model.GetDoerRepoPermission(ctx, pr.Repo, doer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
canRead = perm.CanReadIssuesOrPulls(true)
|
||||
canReadPulls[pr.RepoID] = canRead
|
||||
}
|
||||
if canRead {
|
||||
linkedPrsMap[issue.ID] = append(linkedPrsMap[issue.ID], pr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return linkedPrsMap, nil
|
||||
}
|
||||
|
||||
// NumClosedIssues return counter of closed issues assigned to a project
|
||||
func loadNumClosedIssues(ctx context.Context, p *project_model.Project) error {
|
||||
cnt, err := db.GetEngine(ctx).Table("project_issue").
|
||||
|
||||
Reference in new issue
Block a user