mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-23 05:42:33 +09:00
The `Repository` struct in `services/context/repo.go` embedded `access_model.Permission` anonymously, causing all permission methods to be promoted directly onto `Repository`. This made it unclear at call sites whether a method belonged to `Repository` itself or to its embedded `Permission`. ### Changes - **`services/context/repo.go`**: Replace anonymous `access_model.Permission` with named field `Permission access_model.Permission` - **49 files** updated to route permission method calls through the named field: ```go // Before ctx.Repo.IsAdmin() ctx.Repo.CanWrite(unit.TypeCode) ctx.Repo.CanReadIssuesOrPulls(isPull) slices.ContainsFunc(unitTypes, ctx.Repo.CanWrite) // After ctx.Repo.Permission.IsAdmin() ctx.Repo.Permission.CanWrite(unit.TypeCode) ctx.Repo.Permission.CanReadIssuesOrPulls(isPull) slices.ContainsFunc(unitTypes, ctx.Repo.Permission.CanWrite) ``` Methods defined directly on `*Repository` (`CanWriteToBranch`, `CanCreateBranch`, etc.) are unchanged. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: wxiaoguang <2114189+wxiaoguang@users.noreply.github.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: Nicolas <bircni@icloud.com>
37 lines
951 B
Go
37 lines
951 B
Go
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package repo
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"code.gitea.io/gitea/models/unit"
|
|
"code.gitea.io/gitea/modules/optional"
|
|
"code.gitea.io/gitea/services/context"
|
|
issue_service "code.gitea.io/gitea/services/issue"
|
|
)
|
|
|
|
// IssueSuggestions returns a list of issue suggestions
|
|
func IssueSuggestions(ctx *context.Context) {
|
|
keyword := ctx.Req.FormValue("q")
|
|
|
|
canReadIssues := ctx.Repo.Permission.CanRead(unit.TypeIssues)
|
|
canReadPulls := ctx.Repo.Permission.CanRead(unit.TypePullRequests)
|
|
|
|
var isPull optional.Option[bool]
|
|
if canReadPulls && !canReadIssues {
|
|
isPull = optional.Some(true)
|
|
} else if canReadIssues && !canReadPulls {
|
|
isPull = optional.Some(false)
|
|
}
|
|
|
|
suggestions, err := issue_service.GetSuggestion(ctx, ctx.Repo.Repository, isPull, keyword)
|
|
if err != nil {
|
|
ctx.ServerError("GetSuggestion", err)
|
|
return
|
|
}
|
|
|
|
ctx.JSON(http.StatusOK, suggestions)
|
|
}
|