Skip to content

Fix missing doer #30914

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions routers/api/v1/notify/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func ListRepoNotifications(ctx *context.APIContext) {

ctx.SetTotalCountHeader(totalCount)

ctx.JSON(http.StatusOK, convert.ToNotifications(ctx, nl))
ctx.JSON(http.StatusOK, convert.ToNotifications(ctx, nl, ctx.Doer))
}

// ReadRepoNotifications mark notification threads as read on a specific repo
Expand Down Expand Up @@ -221,7 +221,7 @@ func ReadRepoNotifications(ctx *context.APIContext) {
return
}
_ = notif.LoadAttributes(ctx)
changed = append(changed, convert.ToNotificationThread(ctx, notif))
changed = append(changed, convert.ToNotificationThread(ctx, notif, ctx.Doer))
}
ctx.JSON(http.StatusResetContent, changed)
}
4 changes: 2 additions & 2 deletions routers/api/v1/notify/threads.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func GetThread(ctx *context.APIContext) {
return
}

ctx.JSON(http.StatusOK, convert.ToNotificationThread(ctx, n))
ctx.JSON(http.StatusOK, convert.ToNotificationThread(ctx, n, ctx.Doer))
}

// ReadThread mark notification as read by ID
Expand Down Expand Up @@ -97,7 +97,7 @@ func ReadThread(ctx *context.APIContext) {
ctx.InternalServerError(err)
return
}
ctx.JSON(http.StatusResetContent, convert.ToNotificationThread(ctx, notif))
ctx.JSON(http.StatusResetContent, convert.ToNotificationThread(ctx, notif, ctx.Doer))
}

func getThread(ctx *context.APIContext) *activities_model.Notification {
Expand Down
4 changes: 2 additions & 2 deletions routers/api/v1/notify/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func ListNotifications(ctx *context.APIContext) {
}

ctx.SetTotalCountHeader(totalCount)
ctx.JSON(http.StatusOK, convert.ToNotifications(ctx, nl))
ctx.JSON(http.StatusOK, convert.ToNotifications(ctx, nl, ctx.Doer))
}

// ReadNotifications mark notification threads as read, unread, or pinned
Expand Down Expand Up @@ -168,7 +168,7 @@ func ReadNotifications(ctx *context.APIContext) {
return
}
_ = notif.LoadAttributes(ctx)
changed = append(changed, convert.ToNotificationThread(ctx, notif))
changed = append(changed, convert.ToNotificationThread(ctx, notif, ctx.Doer))
}

ctx.JSON(http.StatusResetContent, changed)
Expand Down
4 changes: 2 additions & 2 deletions routers/api/v1/org/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ func GetTeamRepos(ctx *context.APIContext) {
ctx.Error(http.StatusInternalServerError, "GetTeamRepos", err)
return
}
repos[i] = convert.ToRepo(ctx, repo, permission)
repos[i] = convert.ToRepo(ctx, repo, permission, ctx.Doer)
}
ctx.SetTotalCountHeader(int64(team.NumRepos))
ctx.JSON(http.StatusOK, repos)
Expand Down Expand Up @@ -640,7 +640,7 @@ func GetTeamRepo(ctx *context.APIContext) {
return
}

ctx.JSON(http.StatusOK, convert.ToRepo(ctx, repo, permission))
ctx.JSON(http.StatusOK, convert.ToRepo(ctx, repo, permission, ctx.Doer))
}

// getRepositoryByParams get repository by a team's organization ID and repo name
Expand Down
4 changes: 2 additions & 2 deletions routers/api/v1/repo/commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func getCommit(ctx *context.APIContext, identifier string, toCommitOpts convert.
return
}

json, err := convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, commit, nil, toCommitOpts)
json, err := convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, commit, nil, ctx.Doer, toCommitOpts)
if err != nil {
ctx.Error(http.StatusInternalServerError, "toCommit", err)
return
Expand Down Expand Up @@ -257,7 +257,7 @@ func GetAllCommits(ctx *context.APIContext) {

for i, commit := range commits {
// Create json struct
apiCommits[i], err = convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, commit, userCache, convert.ParseCommitOptions(ctx))
apiCommits[i], err = convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, commit, userCache, ctx.Doer, convert.ParseCommitOptions(ctx))
if err != nil {
ctx.Error(http.StatusInternalServerError, "toCommit", err)
return
Expand Down
2 changes: 1 addition & 1 deletion routers/api/v1/repo/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func CompareDiff(ctx *context.APIContext) {
apiCommits := make([]*api.Commit, 0, len(ci.Commits))
userCache := make(map[string]*user_model.User)
for i := 0; i < len(ci.Commits); i++ {
apiCommit, err := convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, ci.Commits[i], userCache,
apiCommit, err := convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, ci.Commits[i], userCache, ctx.Doer,
convert.ToCommitOptions{
Stat: true,
Verification: verification,
Expand Down
4 changes: 2 additions & 2 deletions routers/api/v1/repo/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func ListForks(ctx *context.APIContext) {
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
return
}
apiForks[i] = convert.ToRepo(ctx, fork, permission)
apiForks[i] = convert.ToRepo(ctx, fork, permission, ctx.Doer)
}

ctx.SetTotalCountHeader(int64(ctx.Repo.Repository.NumForks))
Expand Down Expand Up @@ -158,5 +158,5 @@ func CreateFork(ctx *context.APIContext) {
}

// TODO change back to 201
ctx.JSON(http.StatusAccepted, convert.ToRepo(ctx, fork, access_model.Permission{AccessMode: perm.AccessModeOwner}))
ctx.JSON(http.StatusAccepted, convert.ToRepo(ctx, fork, access_model.Permission{AccessMode: perm.AccessModeOwner}, ctx.Doer))
}
2 changes: 1 addition & 1 deletion routers/api/v1/repo/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func TestHook(ctx *context.APIContext) {
Commits: []*api.PayloadCommit{commit},
TotalCommits: 1,
HeadCommit: commit,
Repo: convert.ToRepo(ctx, ctx.Repo.Repository, access_model.Permission{AccessMode: perm.AccessModeNone}),
Repo: convert.ToRepo(ctx, ctx.Repo.Repository, access_model.Permission{AccessMode: perm.AccessModeNone}, ctx.Doer),
Pusher: convert.ToUserWithAccessMode(ctx, ctx.Doer, perm.AccessModeNone),
Sender: convert.ToUserWithAccessMode(ctx, ctx.Doer, perm.AccessModeNone),
}); err != nil {
Expand Down
10 changes: 5 additions & 5 deletions routers/api/v1/repo/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func ListIssueComments(ctx *context.APIContext) {
apiComments := make([]*api.Comment, len(comments))
for i, comment := range comments {
comment.Issue = issue
apiComments[i] = convert.ToAPIComment(ctx, ctx.Repo.Repository, comments[i])
apiComments[i] = convert.ToAPIComment(ctx, ctx.Repo.Repository, comments[i], ctx.Doer)
}

ctx.SetTotalCountHeader(totalCount)
Expand Down Expand Up @@ -332,7 +332,7 @@ func ListRepoIssueComments(ctx *context.APIContext) {
return
}
for i := range comments {
apiComments[i] = convert.ToAPIComment(ctx, ctx.Repo.Repository, comments[i])
apiComments[i] = convert.ToAPIComment(ctx, ctx.Repo.Repository, comments[i], ctx.Doer)
}

ctx.SetTotalCountHeader(totalCount)
Expand Down Expand Up @@ -406,7 +406,7 @@ func CreateIssueComment(ctx *context.APIContext) {
return
}

ctx.JSON(http.StatusCreated, convert.ToAPIComment(ctx, ctx.Repo.Repository, comment))
ctx.JSON(http.StatusCreated, convert.ToAPIComment(ctx, ctx.Repo.Repository, comment, ctx.Doer))
}

// GetIssueComment Get a comment by ID
Expand Down Expand Up @@ -479,7 +479,7 @@ func GetIssueComment(ctx *context.APIContext) {
return
}

ctx.JSON(http.StatusOK, convert.ToAPIComment(ctx, ctx.Repo.Repository, comment))
ctx.JSON(http.StatusOK, convert.ToAPIComment(ctx, ctx.Repo.Repository, comment, ctx.Doer))
}

// EditIssueComment modify a comment of an issue
Expand Down Expand Up @@ -620,7 +620,7 @@ func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption)
return
}

ctx.JSON(http.StatusOK, convert.ToAPIComment(ctx, ctx.Repo.Repository, comment))
ctx.JSON(http.StatusOK, convert.ToAPIComment(ctx, ctx.Repo.Repository, comment, ctx.Doer))
}

// DeleteIssueComment delete a comment from an issue
Expand Down
11 changes: 6 additions & 5 deletions routers/api/v1/repo/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/models/perm"
access_model "code.gitea.io/gitea/models/perm/access"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/web"
Expand All @@ -25,16 +26,16 @@ import (
)

// appendPrivateInformation appends the owner and key type information to api.PublicKey
func appendPrivateInformation(ctx stdCtx.Context, apiKey *api.DeployKey, key *asymkey_model.DeployKey, repository *repo_model.Repository) (*api.DeployKey, error) {
func appendPrivateInformation(ctx stdCtx.Context, apiKey *api.DeployKey, key *asymkey_model.DeployKey, repository *repo_model.Repository, doer *user_model.User) (*api.DeployKey, error) {
apiKey.ReadOnly = key.Mode == perm.AccessModeRead
if repository.ID == key.RepoID {
apiKey.Repository = convert.ToRepo(ctx, repository, access_model.Permission{AccessMode: key.Mode})
apiKey.Repository = convert.ToRepo(ctx, repository, access_model.Permission{AccessMode: key.Mode}, doer)
} else {
repo, err := repo_model.GetRepositoryByID(ctx, key.RepoID)
if err != nil {
return apiKey, err
}
apiKey.Repository = convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: key.Mode})
apiKey.Repository = convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: key.Mode}, doer)
}
return apiKey, nil
}
Expand Down Expand Up @@ -105,7 +106,7 @@ func ListDeployKeys(ctx *context.APIContext) {
}
apiKeys[i] = convert.ToDeployKey(apiLink, keys[i])
if ctx.Doer.IsAdmin || ((ctx.Repo.Repository.ID == keys[i].RepoID) && (ctx.Doer.ID == ctx.Repo.Owner.ID)) {
apiKeys[i], _ = appendPrivateInformation(ctx, apiKeys[i], keys[i], ctx.Repo.Repository)
apiKeys[i], _ = appendPrivateInformation(ctx, apiKeys[i], keys[i], ctx.Repo.Repository, ctx.Doer)
}
}

Expand Down Expand Up @@ -167,7 +168,7 @@ func GetDeployKey(ctx *context.APIContext) {
apiLink := composeDeployKeysAPILink(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
apiKey := convert.ToDeployKey(apiLink, key)
if ctx.Doer.IsAdmin || ((ctx.Repo.Repository.ID == key.RepoID) && (ctx.Doer.ID == ctx.Repo.Owner.ID)) {
apiKey, _ = appendPrivateInformation(ctx, apiKey, key, ctx.Repo.Repository)
apiKey, _ = appendPrivateInformation(ctx, apiKey, key, ctx.Repo.Repository, ctx.Doer)
}
ctx.JSON(http.StatusOK, apiKey)
}
Expand Down
2 changes: 1 addition & 1 deletion routers/api/v1/repo/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func Migrate(ctx *context.APIContext) {
}

log.Trace("Repository migrated: %s/%s", repoOwner.Name, form.RepoName)
ctx.JSON(http.StatusCreated, convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeAdmin}))
ctx.JSON(http.StatusCreated, convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeAdmin}, ctx.Doer))
}

func handleMigrateError(ctx *context.APIContext, repoOwner *user_model.User, err error) {
Expand Down
2 changes: 1 addition & 1 deletion routers/api/v1/repo/notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func getNote(ctx *context.APIContext, identifier string) {
verification := ctx.FormString("verification") == "" || ctx.FormBool("verification")
files := ctx.FormString("files") == "" || ctx.FormBool("files")

cmt, err := convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, note.Commit, nil,
cmt, err := convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, note.Commit, nil, ctx.Doer,
convert.ToCommitOptions{
Stat: true,
Verification: verification,
Expand Down
2 changes: 1 addition & 1 deletion routers/api/v1/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -1473,7 +1473,7 @@ func GetPullRequestCommits(ctx *context.APIContext) {

apiCommits := make([]*api.Commit, 0, limit)
for i := start; i < start+limit; i++ {
apiCommit, err := convert.ToCommit(ctx, ctx.Repo.Repository, baseGitRepo, commits[i], userCache,
apiCommit, err := convert.ToCommit(ctx, ctx.Repo.Repository, baseGitRepo, commits[i], userCache, ctx.Doer,
convert.ToCommitOptions{
Stat: true,
Verification: verification,
Expand Down
10 changes: 5 additions & 5 deletions routers/api/v1/repo/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func GetRelease(ctx *context.APIContext) {
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
return
}
ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, release))
ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, release, ctx.Doer))
}

// GetLatestRelease gets the most recent non-prerelease, non-draft release of a repository, sorted by created_at
Expand Down Expand Up @@ -107,7 +107,7 @@ func GetLatestRelease(ctx *context.APIContext) {
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
return
}
ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, release))
ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, release, ctx.Doer))
}

// ListReleases list a repository's releases
Expand Down Expand Up @@ -171,7 +171,7 @@ func ListReleases(ctx *context.APIContext) {
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
return
}
rels[i] = convert.ToAPIRelease(ctx, ctx.Repo.Repository, release)
rels[i] = convert.ToAPIRelease(ctx, ctx.Repo.Repository, release, ctx.Doer)
}

filteredCount, err := db.Count[repo_model.Release](ctx, opts)
Expand Down Expand Up @@ -280,7 +280,7 @@ func CreateRelease(ctx *context.APIContext) {
return
}
}
ctx.JSON(http.StatusCreated, convert.ToAPIRelease(ctx, ctx.Repo.Repository, rel))
ctx.JSON(http.StatusCreated, convert.ToAPIRelease(ctx, ctx.Repo.Repository, rel, ctx.Doer))
}

// EditRelease edit a release
Expand Down Expand Up @@ -364,7 +364,7 @@ func EditRelease(ctx *context.APIContext) {
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
return
}
ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, rel))
ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, rel, ctx.Doer))
}

// DeleteRelease delete a release from a repository
Expand Down
2 changes: 1 addition & 1 deletion routers/api/v1/repo/release_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func ListReleaseAttachments(ctx *context.APIContext) {
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
return
}
ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, release).Attachments)
ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, release, ctx.Doer).Attachments)
}

// CreateReleaseAttachment creates an attachment and saves the given file
Expand Down
2 changes: 1 addition & 1 deletion routers/api/v1/repo/release_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func GetReleaseByTag(ctx *context.APIContext) {
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
return
}
ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, release))
ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, release, ctx.Doer))
}

// DeleteReleaseByTag delete a release from a repository by tag name
Expand Down
12 changes: 6 additions & 6 deletions routers/api/v1/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func Search(ctx *context.APIContext) {
Error: err.Error(),
})
}
results[i] = convert.ToRepo(ctx, repo, permission)
results[i] = convert.ToRepo(ctx, repo, permission, ctx.Doer)
}
ctx.SetLinkHeader(int(count), opts.PageSize)
ctx.SetTotalCountHeader(count)
Expand Down Expand Up @@ -278,7 +278,7 @@ func CreateUserRepo(ctx *context.APIContext, owner *user_model.User, opt api.Cre
ctx.Error(http.StatusInternalServerError, "GetRepositoryByID", err)
}

ctx.JSON(http.StatusCreated, convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeOwner}))
ctx.JSON(http.StatusCreated, convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeOwner}, ctx.Doer))
}

// Create one repository of mine
Expand Down Expand Up @@ -426,7 +426,7 @@ func Generate(ctx *context.APIContext) {
}
log.Trace("Repository generated [%d]: %s/%s", repo.ID, ctxUser.Name, repo.Name)

ctx.JSON(http.StatusCreated, convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeOwner}))
ctx.JSON(http.StatusCreated, convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeOwner}, ctx.Doer))
}

// CreateOrgRepoDeprecated create one repository of the organization
Expand Down Expand Up @@ -548,7 +548,7 @@ func Get(ctx *context.APIContext) {
return
}

ctx.JSON(http.StatusOK, convert.ToRepo(ctx, ctx.Repo.Repository, ctx.Repo.Permission))
ctx.JSON(http.StatusOK, convert.ToRepo(ctx, ctx.Repo.Repository, ctx.Repo.Permission, ctx.Doer))
}

// GetByID returns a single Repository
Expand Down Expand Up @@ -589,7 +589,7 @@ func GetByID(ctx *context.APIContext) {
ctx.NotFound()
return
}
ctx.JSON(http.StatusOK, convert.ToRepo(ctx, repo, permission))
ctx.JSON(http.StatusOK, convert.ToRepo(ctx, repo, permission, ctx.Doer))
}

// Edit edit repository properties
Expand Down Expand Up @@ -653,7 +653,7 @@ func Edit(ctx *context.APIContext) {
return
}

ctx.JSON(http.StatusOK, convert.ToRepo(ctx, repo, ctx.Repo.Permission))
ctx.JSON(http.StatusOK, convert.ToRepo(ctx, repo, ctx.Repo.Permission, ctx.Doer))
}

// updateBasicProperties updates the basic properties of a repo: Name, Description, Website and Visibility
Expand Down
6 changes: 3 additions & 3 deletions routers/api/v1/repo/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func NewCommitStatus(ctx *context.APIContext) {
return
}

ctx.JSON(http.StatusCreated, convert.ToCommitStatus(ctx, status))
ctx.JSON(http.StatusCreated, convert.ToCommitStatus(ctx, status, ctx.Doer))
}

// GetCommitStatuses returns all statuses for any given commit hash
Expand Down Expand Up @@ -209,7 +209,7 @@ func getCommitStatuses(ctx *context.APIContext, sha string) {

apiStatuses := make([]*api.CommitStatus, 0, len(statuses))
for _, status := range statuses {
apiStatuses = append(apiStatuses, convert.ToCommitStatus(ctx, status))
apiStatuses = append(apiStatuses, convert.ToCommitStatus(ctx, status, ctx.Doer))
}

ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
Expand Down Expand Up @@ -275,7 +275,7 @@ func GetCombinedCommitStatusByRef(ctx *context.APIContext) {
return
}

combiStatus := convert.ToCombinedStatus(ctx, statuses, convert.ToRepo(ctx, repo, ctx.Repo.Permission))
combiStatus := convert.ToCombinedStatus(ctx, statuses, convert.ToRepo(ctx, repo, ctx.Repo.Permission, ctx.Doer), ctx.Doer)

ctx.SetTotalCountHeader(count)
ctx.JSON(http.StatusOK, combiStatus)
Expand Down
Loading
Loading