Skip to content

Commit 5f783c7

Browse files
committed
rename route and filter based on permissions
1 parent 462c5ed commit 5f783c7

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

routers/web/repo/issue_suggestions.go

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

99
"code.gitea.io/gitea/models/db"
1010
issues_model "code.gitea.io/gitea/models/issues"
11+
"code.gitea.io/gitea/models/unit"
1112
issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
13+
"code.gitea.io/gitea/modules/optional"
1214
"code.gitea.io/gitea/services/context"
1315
)
1416

@@ -26,14 +28,24 @@ type issueSuggestion struct {
2628
func IssueSuggestions(ctx *context.Context) {
2729
keyword := ctx.Req.FormValue("q")
2830

31+
canReadIssues := ctx.Repo.CanRead(unit.TypeIssues)
32+
canReadPulls := ctx.Repo.CanRead(unit.TypePullRequests)
33+
34+
var isPull optional.Option[bool]
35+
if canReadPulls && !canReadIssues {
36+
isPull = optional.Some(true)
37+
} else if canReadIssues && !canReadPulls {
38+
isPull = optional.Some(false)
39+
}
40+
2941
searchOpt := &issue_indexer.SearchOptions{
3042
Paginator: &db.ListOptions{
3143
Page: 0,
3244
PageSize: 5,
3345
},
3446
Keyword: keyword,
3547
RepoIDs: []int64{ctx.Repo.Repository.ID},
36-
IsPull: nil,
48+
IsPull: isPull,
3749
IsClosed: nil,
3850
SortBy: issue_indexer.SortByUpdatedDesc,
3951
}

routers/web/web.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,9 +1045,8 @@ func registerRoutes(m *web.Router) {
10451045
m.Group("/migrate", func() {
10461046
m.Get("/status", repo.MigrateStatus)
10471047
})
1048-
m.Get("/issues/suggestions", repo.IssueSuggestions)
10491048
}, ignSignIn, context.RepoAssignment, reqRepoCodeReader)
1050-
// end "/{username}/{reponame}/-": migrate, issue suggestions
1049+
// end "/{username}/{reponame}/-": migrate
10511050

10521051
m.Group("/{username}/{reponame}/settings", func() {
10531052
m.Group("", func() {
@@ -1179,6 +1178,7 @@ func registerRoutes(m *web.Router) {
11791178
})
11801179
})
11811180
}, context.RepoRef())
1181+
m.Get("/issues/suggestions", repo.IssueSuggestions)
11821182
}, ignSignIn, context.RepoAssignment, reqRepoIssuesOrPullsReader)
11831183
// end "/{username}/{reponame}": view milestone, label, issue, pull, etc
11841184

web_src/js/utils/match.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export function matchMention(queryText: string): MentionSuggestion[] {
4646
}
4747

4848
export async function matchIssue(owner: string, repo: string, issueIndexStr: string, query: string): Promise<Issue[]> {
49-
const res = await GET(`${window.config.appSubUrl}/${owner}/${repo}/-/issues/suggestions?q=${encodeURIComponent(query)}`);
49+
const res = await GET(`${window.config.appSubUrl}/${owner}/${repo}/issues/suggestions?q=${encodeURIComponent(query)}`);
5050

5151
const issues: Issue[] = await res.json();
5252
const issueIndex = parseInt(issueIndexStr);

0 commit comments

Comments
 (0)