Move almost all functions' parameter db.Engine to context.Context (#19748)
* Move almost all functions' parameter db.Engine to context.Context * remove some unnecessary wrap functions
This commit is contained in:
parent
d81e31ad78
commit
fd7d83ace6
232 changed files with 1463 additions and 2108 deletions
|
@ -85,7 +85,7 @@ func AdoptRepository(ctx *context.APIContext) {
|
|||
ownerName := ctx.Params(":username")
|
||||
repoName := ctx.Params(":reponame")
|
||||
|
||||
ctxUser, err := user_model.GetUserByName(ownerName)
|
||||
ctxUser, err := user_model.GetUserByName(ctx, ownerName)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.NotFound()
|
||||
|
@ -96,7 +96,7 @@ func AdoptRepository(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
// check not a repo
|
||||
has, err := repo_model.IsRepositoryExist(ctxUser, repoName)
|
||||
has, err := repo_model.IsRepositoryExist(ctx, ctxUser, repoName)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
|
@ -147,7 +147,7 @@ func DeleteUnadoptedRepository(ctx *context.APIContext) {
|
|||
ownerName := ctx.Params(":username")
|
||||
repoName := ctx.Params(":reponame")
|
||||
|
||||
ctxUser, err := user_model.GetUserByName(ownerName)
|
||||
ctxUser, err := user_model.GetUserByName(ctx, ownerName)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.NotFound()
|
||||
|
@ -158,7 +158,7 @@ func DeleteUnadoptedRepository(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
// check not a repo
|
||||
has, err := repo_model.IsRepositoryExist(ctxUser, repoName)
|
||||
has, err := repo_model.IsRepositoryExist(ctx, ctxUser, repoName)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
|
|
|
@ -269,7 +269,7 @@ func EditUser(ctx *context.APIContext) {
|
|||
ctx.ContextUser.IsRestricted = *form.Restricted
|
||||
}
|
||||
|
||||
if err := user_model.UpdateUser(ctx.ContextUser, emailChanged); err != nil {
|
||||
if err := user_model.UpdateUser(ctx, ctx.ContextUser, emailChanged); err != nil {
|
||||
if user_model.IsErrEmailAlreadyUsed(err) ||
|
||||
user_model.IsErrEmailCharIsNotSupported(err) ||
|
||||
user_model.IsErrEmailInvalid(err) {
|
||||
|
|
|
@ -108,7 +108,7 @@ func sudo() func(ctx *context.APIContext) {
|
|||
|
||||
if len(sudo) > 0 {
|
||||
if ctx.IsSigned && ctx.Doer.IsAdmin {
|
||||
user, err := user_model.GetUserByName(sudo)
|
||||
user, err := user_model.GetUserByName(ctx, sudo)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.NotFound()
|
||||
|
@ -143,7 +143,7 @@ func repoAssignment() func(ctx *context.APIContext) {
|
|||
if ctx.IsSigned && ctx.Doer.LowerName == strings.ToLower(userName) {
|
||||
owner = ctx.Doer
|
||||
} else {
|
||||
owner, err = user_model.GetUserByName(userName)
|
||||
owner, err = user_model.GetUserByName(ctx, userName)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
if redirectUserID, err := user_model.LookupUserRedirect(userName); err == nil {
|
||||
|
@ -467,7 +467,7 @@ func orgAssignment(args ...bool) func(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
if assignTeam {
|
||||
ctx.Org.Team, err = organization.GetTeamByID(ctx.ParamsInt64(":teamid"))
|
||||
ctx.Org.Team, err = organization.GetTeamByID(ctx, ctx.ParamsInt64(":teamid"))
|
||||
if err != nil {
|
||||
if organization.IsErrTeamNotExist(err) {
|
||||
ctx.NotFound()
|
||||
|
|
|
@ -22,7 +22,7 @@ func NewAvailable(ctx *context.APIContext) {
|
|||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/NotificationCount"
|
||||
ctx.JSON(http.StatusOK, api.NotificationCount{New: models.CountUnread(ctx.Doer)})
|
||||
ctx.JSON(http.StatusOK, api.NotificationCount{New: models.CountUnread(ctx, ctx.Doer.ID)})
|
||||
}
|
||||
|
||||
func getFindNotificationOptions(ctx *context.APIContext) *models.FindNotificationOptions {
|
||||
|
|
|
@ -115,7 +115,7 @@ func ListRepoNotifications(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
nl, err := models.GetNotifications(opts)
|
||||
nl, err := models.GetNotifications(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
|
@ -203,7 +203,7 @@ func ReadRepoNotifications(ctx *context.APIContext) {
|
|||
opts.Status = statusStringsToNotificationStatuses(statuses, []string{"unread"})
|
||||
log.Error("%v", opts.Status)
|
||||
}
|
||||
nl, err := models.GetNotifications(opts)
|
||||
nl, err := models.GetNotifications(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
|
|
|
@ -75,7 +75,7 @@ func ListNotifications(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
nl, err := models.GetNotifications(opts)
|
||||
nl, err := models.GetNotifications(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
|
@ -148,7 +148,7 @@ func ReadNotifications(ctx *context.APIContext) {
|
|||
statuses := ctx.FormStrings("status-types")
|
||||
opts.Status = statusStringsToNotificationStatuses(statuses, []string{"unread"})
|
||||
}
|
||||
nl, err := models.GetNotifications(opts)
|
||||
nl, err := models.GetNotifications(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
|
|
|
@ -51,7 +51,7 @@ func ListHooks(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
orgHooks, err := webhook.ListWebhooksByOpts(opts)
|
||||
orgHooks, err := webhook.ListWebhooksByOpts(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
|
|
|
@ -43,7 +43,7 @@ func ListLabels(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/LabelList"
|
||||
|
||||
labels, err := models.GetLabelsByOrgID(ctx.Org.Organization.ID, ctx.FormString("sort"), utils.GetListOptions(ctx))
|
||||
labels, err := models.GetLabelsByOrgID(ctx, ctx.Org.Organization.ID, ctx.FormString("sort"), utils.GetListOptions(ctx))
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetLabelsByOrgID", err)
|
||||
return
|
||||
|
@ -136,9 +136,9 @@ func GetLabel(ctx *context.APIContext) {
|
|||
)
|
||||
strID := ctx.Params(":id")
|
||||
if intID, err2 := strconv.ParseInt(strID, 10, 64); err2 != nil {
|
||||
label, err = models.GetLabelInOrgByName(ctx.Org.Organization.ID, strID)
|
||||
label, err = models.GetLabelInOrgByName(ctx, ctx.Org.Organization.ID, strID)
|
||||
} else {
|
||||
label, err = models.GetLabelInOrgByID(ctx.Org.Organization.ID, intID)
|
||||
label, err = models.GetLabelInOrgByID(ctx, ctx.Org.Organization.ID, intID)
|
||||
}
|
||||
if err != nil {
|
||||
if models.IsErrOrgLabelNotExist(err) {
|
||||
|
@ -183,7 +183,7 @@ func EditLabel(ctx *context.APIContext) {
|
|||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
form := web.GetForm(ctx).(*api.EditLabelOption)
|
||||
label, err := models.GetLabelInOrgByID(ctx.Org.Organization.ID, ctx.ParamsInt64(":id"))
|
||||
label, err := models.GetLabelInOrgByID(ctx, ctx.Org.Organization.ID, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if models.IsErrOrgLabelNotExist(err) {
|
||||
ctx.NotFound()
|
||||
|
|
|
@ -70,7 +70,7 @@ func GetBranch(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
branchProtection, err := models.GetProtectedBranchBy(ctx.Repo.Repository.ID, branchName)
|
||||
branchProtection, err := models.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branchName)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err)
|
||||
return
|
||||
|
@ -206,7 +206,7 @@ func CreateBranch(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
branchProtection, err := models.GetProtectedBranchBy(ctx.Repo.Repository.ID, branch.Name)
|
||||
branchProtection, err := models.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branch.Name)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err)
|
||||
return
|
||||
|
@ -271,7 +271,7 @@ func ListBranches(ctx *context.APIContext) {
|
|||
ctx.Error(http.StatusInternalServerError, "GetCommit", err)
|
||||
return
|
||||
}
|
||||
branchProtection, err := models.GetProtectedBranchBy(ctx.Repo.Repository.ID, branches[i].Name)
|
||||
branchProtection, err := models.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branches[i].Name)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err)
|
||||
return
|
||||
|
@ -320,7 +320,7 @@ func GetBranchProtection(ctx *context.APIContext) {
|
|||
|
||||
repo := ctx.Repo.Repository
|
||||
bpName := ctx.Params(":name")
|
||||
bp, err := models.GetProtectedBranchBy(repo.ID, bpName)
|
||||
bp, err := models.GetProtectedBranchBy(ctx, repo.ID, bpName)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetProtectedBranchByID", err)
|
||||
return
|
||||
|
@ -412,7 +412,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
protectBranch, err := models.GetProtectedBranchBy(repo.ID, form.BranchName)
|
||||
protectBranch, err := models.GetProtectedBranchBy(ctx, repo.ID, form.BranchName)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetProtectBranchOfRepoByName", err)
|
||||
return
|
||||
|
@ -523,7 +523,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
// Reload from db to get all whitelists
|
||||
bp, err := models.GetProtectedBranchBy(ctx.Repo.Repository.ID, form.BranchName)
|
||||
bp, err := models.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, form.BranchName)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetProtectedBranchByID", err)
|
||||
return
|
||||
|
@ -575,7 +575,7 @@ func EditBranchProtection(ctx *context.APIContext) {
|
|||
form := web.GetForm(ctx).(*api.EditBranchProtectionOption)
|
||||
repo := ctx.Repo.Repository
|
||||
bpName := ctx.Params(":name")
|
||||
protectBranch, err := models.GetProtectedBranchBy(repo.ID, bpName)
|
||||
protectBranch, err := models.GetProtectedBranchBy(ctx, repo.ID, bpName)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetProtectedBranchByID", err)
|
||||
return
|
||||
|
@ -758,7 +758,7 @@ func EditBranchProtection(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
// Reload from db to ensure get all whitelists
|
||||
bp, err := models.GetProtectedBranchBy(repo.ID, bpName)
|
||||
bp, err := models.GetProtectedBranchBy(ctx, repo.ID, bpName)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetProtectedBranchBy", err)
|
||||
return
|
||||
|
@ -802,7 +802,7 @@ func DeleteBranchProtection(ctx *context.APIContext) {
|
|||
|
||||
repo := ctx.Repo.Repository
|
||||
bpName := ctx.Params(":name")
|
||||
bp, err := models.GetProtectedBranchBy(repo.ID, bpName)
|
||||
bp, err := models.GetProtectedBranchBy(ctx, repo.ID, bpName)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetProtectedBranchByID", err)
|
||||
return
|
||||
|
|
|
@ -103,7 +103,7 @@ func IsCollaborator(ctx *context.APIContext) {
|
|||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
user, err := user_model.GetUserByName(ctx.Params(":collaborator"))
|
||||
user, err := user_model.GetUserByName(ctx, ctx.Params(":collaborator"))
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
||||
|
@ -159,7 +159,7 @@ func AddCollaborator(ctx *context.APIContext) {
|
|||
|
||||
form := web.GetForm(ctx).(*api.AddCollaboratorOption)
|
||||
|
||||
collaborator, err := user_model.GetUserByName(ctx.Params(":collaborator"))
|
||||
collaborator, err := user_model.GetUserByName(ctx, ctx.Params(":collaborator"))
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
||||
|
@ -218,7 +218,7 @@ func DeleteCollaborator(ctx *context.APIContext) {
|
|||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
collaborator, err := user_model.GetUserByName(ctx.Params(":collaborator"))
|
||||
collaborator, err := user_model.GetUserByName(ctx, ctx.Params(":collaborator"))
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
||||
|
@ -271,7 +271,7 @@ func GetRepoPermissions(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
collaborator, err := user_model.GetUserByName(ctx.Params(":collaborator"))
|
||||
collaborator, err := user_model.GetUserByName(ctx, ctx.Params(":collaborator"))
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.Error(http.StatusNotFound, "GetUserByName", err)
|
||||
|
|
|
@ -60,7 +60,7 @@ func ListHooks(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
hooks, err := webhook.ListWebhooksByOpts(opts)
|
||||
hooks, err := webhook.ListWebhooksByOpts(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
|
|
|
@ -145,7 +145,7 @@ func SearchIssues(ctx *context.APIContext) {
|
|||
opts.AllLimited = true
|
||||
}
|
||||
if ctx.FormString("owner") != "" {
|
||||
owner, err := user_model.GetUserByName(ctx.FormString("owner"))
|
||||
owner, err := user_model.GetUserByName(ctx, ctx.FormString("owner"))
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.Error(http.StatusBadRequest, "Owner not found", err)
|
||||
|
@ -164,7 +164,7 @@ func SearchIssues(ctx *context.APIContext) {
|
|||
ctx.Error(http.StatusBadRequest, "", "Owner organisation is required for filtering on team")
|
||||
return
|
||||
}
|
||||
team, err := organization.GetTeam(opts.OwnerID, ctx.FormString("team"))
|
||||
team, err := organization.GetTeam(ctx, opts.OwnerID, ctx.FormString("team"))
|
||||
if err != nil {
|
||||
if organization.IsErrTeamNotExist(err) {
|
||||
ctx.Error(http.StatusBadRequest, "Team not found", err)
|
||||
|
@ -502,7 +502,7 @@ func getUserIDForFilter(ctx *context.APIContext, queryName string) int64 {
|
|||
return 0
|
||||
}
|
||||
|
||||
user, err := user_model.GetUserByName(userName)
|
||||
user, err := user_model.GetUserByName(ctx, userName)
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.NotFound(err)
|
||||
return 0
|
||||
|
|
|
@ -79,7 +79,7 @@ func ListIssueComments(ctx *context.APIContext) {
|
|||
Type: models.CommentTypeComment,
|
||||
}
|
||||
|
||||
comments, err := models.FindComments(opts)
|
||||
comments, err := models.FindComments(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "FindComments", err)
|
||||
return
|
||||
|
@ -172,7 +172,7 @@ func ListIssueCommentsAndTimeline(ctx *context.APIContext) {
|
|||
Type: models.CommentTypeUnknown,
|
||||
}
|
||||
|
||||
comments, err := models.FindComments(opts)
|
||||
comments, err := models.FindComments(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "FindComments", err)
|
||||
return
|
||||
|
@ -269,7 +269,7 @@ func ListRepoIssueComments(ctx *context.APIContext) {
|
|||
Before: before,
|
||||
}
|
||||
|
||||
comments, err := models.FindComments(opts)
|
||||
comments, err := models.FindComments(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "FindComments", err)
|
||||
return
|
||||
|
@ -399,7 +399,7 @@ func GetIssueComment(ctx *context.APIContext) {
|
|||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
|
||||
comment, err := models.GetCommentByID(ctx, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if models.IsErrCommentNotExist(err) {
|
||||
ctx.NotFound(err)
|
||||
|
@ -526,7 +526,7 @@ func EditIssueCommentDeprecated(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption) {
|
||||
comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
|
||||
comment, err := models.GetCommentByID(ctx, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if models.IsErrCommentNotExist(err) {
|
||||
ctx.NotFound(err)
|
||||
|
@ -629,7 +629,7 @@ func DeleteIssueCommentDeprecated(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
func deleteIssueComment(ctx *context.APIContext) {
|
||||
comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
|
||||
comment, err := models.GetCommentByID(ctx, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if models.IsErrCommentNotExist(err) {
|
||||
ctx.NotFound(err)
|
||||
|
|
|
@ -111,7 +111,7 @@ func AddIssueLabels(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
labels, err = models.GetLabelsByIssueID(issue.ID)
|
||||
labels, err = models.GetLabelsByIssueID(ctx, issue.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetLabelsByIssueID", err)
|
||||
return
|
||||
|
@ -173,7 +173,7 @@ func DeleteIssueLabel(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
label, err := models.GetLabelByID(ctx.ParamsInt64(":id"))
|
||||
label, err := models.GetLabelByID(ctx, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if models.IsErrLabelNotExist(err) {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
||||
|
@ -237,7 +237,7 @@ func ReplaceIssueLabels(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
labels, err = models.GetLabelsByIssueID(issue.ID)
|
||||
labels, err = models.GetLabelsByIssueID(ctx, issue.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetLabelsByIssueID", err)
|
||||
return
|
||||
|
|
|
@ -49,7 +49,7 @@ func GetIssueCommentReactions(ctx *context.APIContext) {
|
|||
// "403":
|
||||
// "$ref": "#/responses/forbidden"
|
||||
|
||||
comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
|
||||
comment, err := models.GetCommentByID(ctx, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if models.IsErrCommentNotExist(err) {
|
||||
ctx.NotFound(err)
|
||||
|
@ -176,7 +176,7 @@ func DeleteIssueCommentReaction(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
func changeIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOption, isCreateType bool) {
|
||||
comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
|
||||
comment, err := models.GetCommentByID(ctx, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if models.IsErrCommentNotExist(err) {
|
||||
ctx.NotFound(err)
|
||||
|
|
|
@ -116,7 +116,7 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) {
|
|||
return
|
||||
}
|
||||
|
||||
user, err := user_model.GetUserByName(ctx.Params(":user"))
|
||||
user, err := user_model.GetUserByName(ctx, ctx.Params(":user"))
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.NotFound()
|
||||
|
@ -263,7 +263,7 @@ func GetIssueSubscribers(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
iwl, err := models.GetIssueWatchers(issue.ID, utils.GetListOptions(ctx))
|
||||
iwl, err := models.GetIssueWatchers(ctx, issue.ID, utils.GetListOptions(ctx))
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetIssueWatchers", err)
|
||||
return
|
||||
|
@ -284,7 +284,7 @@ func GetIssueSubscribers(ctx *context.APIContext) {
|
|||
apiUsers = append(apiUsers, convert.ToUser(v, ctx.Doer))
|
||||
}
|
||||
|
||||
count, err := models.CountIssueWatchers(issue.ID)
|
||||
count, err := models.CountIssueWatchers(ctx, issue.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "CountIssueWatchers", err)
|
||||
return
|
||||
|
|
|
@ -94,7 +94,7 @@ func ListTrackedTimes(ctx *context.APIContext) {
|
|||
|
||||
qUser := ctx.FormTrim("user")
|
||||
if qUser != "" {
|
||||
user, err := user_model.GetUserByName(qUser)
|
||||
user, err := user_model.GetUserByName(ctx, qUser)
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.Error(http.StatusNotFound, "User does not exist", err)
|
||||
} else if err != nil {
|
||||
|
@ -128,7 +128,7 @@ func ListTrackedTimes(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
trackedTimes, err := models.GetTrackedTimes(opts)
|
||||
trackedTimes, err := models.GetTrackedTimes(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetTrackedTimes", err)
|
||||
return
|
||||
|
@ -203,7 +203,7 @@ func AddTime(ctx *context.APIContext) {
|
|||
if form.User != "" {
|
||||
if (ctx.IsUserRepoAdmin() && ctx.Doer.Name != form.User) || ctx.Doer.IsAdmin {
|
||||
// allow only RepoAdmin, Admin and User to add time
|
||||
user, err = user_model.GetUserByName(form.User)
|
||||
user, err = user_model.GetUserByName(ctx, form.User)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
|
||||
}
|
||||
|
@ -415,7 +415,7 @@ func ListTrackedTimesByUser(ctx *context.APIContext) {
|
|||
ctx.Error(http.StatusBadRequest, "", "time tracking disabled")
|
||||
return
|
||||
}
|
||||
user, err := user_model.GetUserByName(ctx.Params(":timetrackingusername"))
|
||||
user, err := user_model.GetUserByName(ctx, ctx.Params(":timetrackingusername"))
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.NotFound(err)
|
||||
|
@ -439,7 +439,7 @@ func ListTrackedTimesByUser(ctx *context.APIContext) {
|
|||
RepositoryID: ctx.Repo.Repository.ID,
|
||||
}
|
||||
|
||||
trackedTimes, err := models.GetTrackedTimes(opts)
|
||||
trackedTimes, err := models.GetTrackedTimes(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetTrackedTimes", err)
|
||||
return
|
||||
|
@ -512,7 +512,7 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) {
|
|||
// Filters
|
||||
qUser := ctx.FormTrim("user")
|
||||
if qUser != "" {
|
||||
user, err := user_model.GetUserByName(qUser)
|
||||
user, err := user_model.GetUserByName(ctx, qUser)
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.Error(http.StatusNotFound, "User does not exist", err)
|
||||
} else if err != nil {
|
||||
|
@ -547,7 +547,7 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
trackedTimes, err := models.GetTrackedTimes(opts)
|
||||
trackedTimes, err := models.GetTrackedTimes(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetTrackedTimes", err)
|
||||
return
|
||||
|
@ -609,7 +609,7 @@ func ListMyTrackedTimes(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
trackedTimes, err := models.GetTrackedTimes(opts)
|
||||
trackedTimes, err := models.GetTrackedTimes(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetTrackedTimesByUser", err)
|
||||
return
|
||||
|
|
|
@ -49,7 +49,7 @@ func ListLabels(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/LabelList"
|
||||
|
||||
labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, ctx.FormString("sort"), utils.GetListOptions(ctx))
|
||||
labels, err := models.GetLabelsByRepoID(ctx, ctx.Repo.Repository.ID, ctx.FormString("sort"), utils.GetListOptions(ctx))
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetLabelsByRepoID", err)
|
||||
return
|
||||
|
@ -99,9 +99,9 @@ func GetLabel(ctx *context.APIContext) {
|
|||
)
|
||||
strID := ctx.Params(":id")
|
||||
if intID, err2 := strconv.ParseInt(strID, 10, 64); err2 != nil {
|
||||
label, err = models.GetLabelInRepoByName(ctx.Repo.Repository.ID, strID)
|
||||
label, err = models.GetLabelInRepoByName(ctx, ctx.Repo.Repository.ID, strID)
|
||||
} else {
|
||||
label, err = models.GetLabelInRepoByID(ctx.Repo.Repository.ID, intID)
|
||||
label, err = models.GetLabelInRepoByID(ctx, ctx.Repo.Repository.ID, intID)
|
||||
}
|
||||
if err != nil {
|
||||
if models.IsErrRepoLabelNotExist(err) {
|
||||
|
@ -206,7 +206,7 @@ func EditLabel(ctx *context.APIContext) {
|
|||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.EditLabelOption)
|
||||
label, err := models.GetLabelInRepoByID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
|
||||
label, err := models.GetLabelInRepoByID(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if models.IsErrRepoLabelNotExist(err) {
|
||||
ctx.NotFound()
|
||||
|
|
|
@ -68,7 +68,7 @@ func GetLanguages(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/LanguageStatistics"
|
||||
|
||||
langs, err := repo_model.GetLanguageStats(ctx.Repo.Repository)
|
||||
langs, err := repo_model.GetLanguageStats(ctx, ctx.Repo.Repository)
|
||||
if err != nil {
|
||||
log.Error("GetLanguageStats failed: %v", err)
|
||||
ctx.InternalServerError(err)
|
||||
|
|
|
@ -65,7 +65,7 @@ func Migrate(ctx *context.APIContext) {
|
|||
err error
|
||||
)
|
||||
if len(form.RepoOwner) != 0 {
|
||||
repoOwner, err = user_model.GetUserByName(form.RepoOwner)
|
||||
repoOwner, err = user_model.GetUserByName(ctx, form.RepoOwner)
|
||||
} else if form.RepoOwnerID != 0 {
|
||||
repoOwner, err = user_model.GetUserByID(form.RepoOwnerID)
|
||||
} else {
|
||||
|
|
|
@ -50,7 +50,7 @@ func MirrorSync(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
if _, err := repo_model.GetMirrorByRepoID(repo.ID); err != nil {
|
||||
if _, err := repo_model.GetMirrorByRepoID(ctx, repo.ID); err != nil {
|
||||
if errors.Is(err, repo_model.ErrMirrorNotExist) {
|
||||
ctx.Error(http.StatusBadRequest, "MirrorSync", "Repository is not a mirror")
|
||||
return
|
||||
|
|
|
@ -160,7 +160,7 @@ func GetPullRequest(ctx *context.APIContext) {
|
|||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
pr, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
if models.IsErrPullRequestNotExist(err) {
|
||||
ctx.NotFound()
|
||||
|
@ -220,7 +220,7 @@ func DownloadPullDiffOrPatch(ctx *context.APIContext) {
|
|||
// "$ref": "#/responses/string"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
pr, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
if models.IsErrPullRequestNotExist(err) {
|
||||
ctx.NotFound()
|
||||
|
@ -470,7 +470,7 @@ func EditPullRequest(ctx *context.APIContext) {
|
|||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.EditPullRequestOption)
|
||||
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
pr, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
if models.IsErrPullRequestNotExist(err) {
|
||||
ctx.NotFound()
|
||||
|
@ -632,7 +632,7 @@ func EditPullRequest(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
// Refetch from database
|
||||
pr, err = models.GetPullRequestByIndex(ctx.Repo.Repository.ID, pr.Index)
|
||||
pr, err = models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, pr.Index)
|
||||
if err != nil {
|
||||
if models.IsErrPullRequestNotExist(err) {
|
||||
ctx.NotFound()
|
||||
|
@ -676,7 +676,7 @@ func IsPullRequestMerged(ctx *context.APIContext) {
|
|||
// "404":
|
||||
// description: pull request has not been merged
|
||||
|
||||
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
pr, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
if models.IsErrPullRequestNotExist(err) {
|
||||
ctx.NotFound()
|
||||
|
@ -730,7 +730,7 @@ func MergePullRequest(ctx *context.APIContext) {
|
|||
|
||||
form := web.GetForm(ctx).(*forms.MergePullRequestForm)
|
||||
|
||||
pr, err := models.GetPullRequestByIndexCtx(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
pr, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
if models.IsErrPullRequestNotExist(err) {
|
||||
ctx.NotFound("GetPullRequestByIndex", err)
|
||||
|
@ -938,7 +938,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
|
|||
headBranch = headInfos[0]
|
||||
|
||||
} else if len(headInfos) == 2 {
|
||||
headUser, err = user_model.GetUserByName(headInfos[0])
|
||||
headUser, err = user_model.GetUserByName(ctx, headInfos[0])
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.NotFound("GetUserByName")
|
||||
|
@ -1079,7 +1079,7 @@ func UpdatePullRequest(ctx *context.APIContext) {
|
|||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
pr, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
if models.IsErrPullRequestNotExist(err) {
|
||||
ctx.NotFound()
|
||||
|
@ -1177,7 +1177,7 @@ func CancelScheduledAutoMerge(ctx *context.APIContext) {
|
|||
// "$ref": "#/responses/notFound"
|
||||
|
||||
pullIndex := ctx.ParamsInt64(":index")
|
||||
pull, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, pullIndex)
|
||||
pull, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, pullIndex)
|
||||
if err != nil {
|
||||
if models.IsErrPullRequestNotExist(err) {
|
||||
ctx.NotFound()
|
||||
|
@ -1198,7 +1198,7 @@ func CancelScheduledAutoMerge(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
if ctx.Doer.ID != autoMerge.DoerID {
|
||||
allowed, err := access_model.IsUserRepoAdminCtx(ctx, ctx.Repo.Repository, ctx.Doer)
|
||||
allowed, err := access_model.IsUserRepoAdmin(ctx, ctx.Repo.Repository, ctx.Doer)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
|
@ -1254,7 +1254,7 @@ func GetPullRequestCommits(ctx *context.APIContext) {
|
|||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
pr, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
if models.IsErrPullRequestNotExist(err) {
|
||||
ctx.NotFound()
|
||||
|
|
|
@ -61,7 +61,7 @@ func ListPullReviews(ctx *context.APIContext) {
|
|||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
pr, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
if models.IsErrPullRequestNotExist(err) {
|
||||
ctx.NotFound("GetPullRequestByIndex", err)
|
||||
|
@ -87,7 +87,7 @@ func ListPullReviews(ctx *context.APIContext) {
|
|||
IssueID: pr.IssueID,
|
||||
}
|
||||
|
||||
allReviews, err := models.FindReviews(opts)
|
||||
allReviews, err := models.FindReviews(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
|
@ -307,7 +307,7 @@ func CreatePullReview(ctx *context.APIContext) {
|
|||
// "$ref": "#/responses/validationError"
|
||||
|
||||
opts := web.GetForm(ctx).(*api.CreatePullReviewOptions)
|
||||
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
pr, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
if models.IsErrPullRequestNotExist(err) {
|
||||
ctx.NotFound("GetPullRequestByIndex", err)
|
||||
|
@ -526,7 +526,7 @@ func preparePullReviewType(ctx *context.APIContext, pr *models.PullRequest, even
|
|||
|
||||
// prepareSingleReview return review, related pull and false or nil, nil and true if an error happen
|
||||
func prepareSingleReview(ctx *context.APIContext) (*models.Review, *models.PullRequest, bool) {
|
||||
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
pr, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
if models.IsErrPullRequestNotExist(err) {
|
||||
ctx.NotFound("GetPullRequestByIndex", err)
|
||||
|
@ -536,7 +536,7 @@ func prepareSingleReview(ctx *context.APIContext) (*models.Review, *models.PullR
|
|||
return nil, nil, true
|
||||
}
|
||||
|
||||
review, err := models.GetReviewByID(ctx.ParamsInt64(":id"))
|
||||
review, err := models.GetReviewByID(ctx, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if models.IsErrReviewNotExist(err) {
|
||||
ctx.NotFound("GetReviewByID", err)
|
||||
|
@ -648,7 +648,7 @@ func DeleteReviewRequests(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions, isAdd bool) {
|
||||
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
pr, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
if models.IsErrPullRequestNotExist(err) {
|
||||
ctx.NotFound("GetPullRequestByIndex", err)
|
||||
|
@ -676,7 +676,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
|
|||
if strings.Contains(r, "@") {
|
||||
reviewer, err = user_model.GetUserByEmail(r)
|
||||
} else {
|
||||
reviewer, err = user_model.GetUserByName(r)
|
||||
reviewer, err = user_model.GetUserByName(ctx, r)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
@ -727,7 +727,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
|
|||
teamReviewers := make([]*organization.Team, 0, len(opts.TeamReviewers))
|
||||
for _, t := range opts.TeamReviewers {
|
||||
var teamReviewer *organization.Team
|
||||
teamReviewer, err = organization.GetTeam(ctx.Repo.Owner.ID, t)
|
||||
teamReviewer, err = organization.GetTeam(ctx, ctx.Repo.Owner.ID, t)
|
||||
if err != nil {
|
||||
if organization.IsErrTeamNotExist(err) {
|
||||
ctx.NotFound("TeamNotExist", fmt.Sprintf("Team '%s' not exist", t))
|
||||
|
@ -892,7 +892,7 @@ func dismissReview(ctx *context.APIContext, msg string, isDismiss bool) {
|
|||
return
|
||||
}
|
||||
|
||||
if review, err = models.GetReviewByID(review.ID); err != nil {
|
||||
if review, err = models.GetReviewByID(ctx, review.ID); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetReviewByID", err)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ func GetReleaseAttachment(ctx *context.APIContext) {
|
|||
|
||||
releaseID := ctx.ParamsInt64(":id")
|
||||
attachID := ctx.ParamsInt64(":asset")
|
||||
attach, err := repo_model.GetAttachmentByID(attachID)
|
||||
attach, err := repo_model.GetAttachmentByID(ctx, attachID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetAttachmentByID", err)
|
||||
return
|
||||
|
@ -242,7 +242,7 @@ func EditReleaseAttachment(ctx *context.APIContext) {
|
|||
// Check if release exists an load release
|
||||
releaseID := ctx.ParamsInt64(":id")
|
||||
attachID := ctx.ParamsInt64(":asset")
|
||||
attach, err := repo_model.GetAttachmentByID(attachID)
|
||||
attach, err := repo_model.GetAttachmentByID(ctx, attachID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetAttachmentByID", err)
|
||||
return
|
||||
|
@ -257,7 +257,7 @@ func EditReleaseAttachment(ctx *context.APIContext) {
|
|||
attach.Name = form.Name
|
||||
}
|
||||
|
||||
if err := repo_model.UpdateAttachment(attach); err != nil {
|
||||
if err := repo_model.UpdateAttachment(ctx, attach); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "UpdateAttachment", attach)
|
||||
}
|
||||
ctx.JSON(http.StatusCreated, convert.ToReleaseAttachment(attach))
|
||||
|
@ -300,7 +300,7 @@ func DeleteReleaseAttachment(ctx *context.APIContext) {
|
|||
// Check if release exists an load release
|
||||
releaseID := ctx.ParamsInt64(":id")
|
||||
attachID := ctx.ParamsInt64(":asset")
|
||||
attach, err := repo_model.GetAttachmentByID(attachID)
|
||||
attach, err := repo_model.GetAttachmentByID(ctx, attachID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetAttachmentByID", err)
|
||||
return
|
||||
|
|
|
@ -365,7 +365,7 @@ func Generate(ctx *context.APIContext) {
|
|||
ctxUser := ctx.Doer
|
||||
var err error
|
||||
if form.Owner != ctxUser.Name {
|
||||
ctxUser, err = user_model.GetUserByName(form.Owner)
|
||||
ctxUser, err = user_model.GetUserByName(ctx, form.Owner)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.JSON(http.StatusNotFound, map[string]interface{}{
|
||||
|
@ -962,7 +962,7 @@ func updateMirror(ctx *context.APIContext, opts api.EditRepoOption) error {
|
|||
}
|
||||
|
||||
// get the mirror from the repo
|
||||
mirror, err := repo_model.GetMirrorByRepoID(repo.ID)
|
||||
mirror, err := repo_model.GetMirrorByRepoID(ctx, repo.ID)
|
||||
if err != nil {
|
||||
log.Error("Failed to get mirror: %s", err)
|
||||
ctx.Error(http.StatusInternalServerError, "MirrorInterval", err)
|
||||
|
@ -1000,7 +1000,7 @@ func updateMirror(ctx *context.APIContext, opts api.EditRepoOption) error {
|
|||
}
|
||||
|
||||
// finally update the mirror in the DB
|
||||
if err := repo_model.UpdateMirror(mirror); err != nil {
|
||||
if err := repo_model.UpdateMirror(ctx, mirror); err != nil {
|
||||
log.Error("Failed to Set Mirror Interval: %s", err)
|
||||
ctx.Error(http.StatusUnprocessableEntity, "MirrorInterval", err)
|
||||
return err
|
||||
|
|
|
@ -253,7 +253,7 @@ func GetCombinedCommitStatusByRef(ctx *context.APIContext) {
|
|||
|
||||
repo := ctx.Repo.Repository
|
||||
|
||||
statuses, count, err := models.GetLatestCommitStatus(repo.ID, sha, utils.GetListOptions(ctx))
|
||||
statuses, count, err := models.GetLatestCommitStatus(ctx, repo.ID, sha, utils.GetListOptions(ctx))
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetLatestCommitStatus", fmt.Errorf("GetLatestCommitStatus[%s, %s]: %v", repo.FullName(), sha, err))
|
||||
return
|
||||
|
|
|
@ -41,7 +41,7 @@ func ListTeams(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
teams, err := organization.GetRepoTeams(ctx.Repo.Repository)
|
||||
teams, err := organization.GetRepoTeams(ctx, ctx.Repo.Repository)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
|
@ -216,7 +216,7 @@ func changeRepoTeam(ctx *context.APIContext, add bool) {
|
|||
}
|
||||
|
||||
func getTeamByParam(ctx *context.APIContext) *organization.Team {
|
||||
team, err := organization.GetTeam(ctx.Repo.Owner.ID, ctx.Params(":team"))
|
||||
team, err := organization.GetTeam(ctx, ctx.Repo.Owner.ID, ctx.Params(":team"))
|
||||
if err != nil {
|
||||
if organization.IsErrTeamNotExist(err) {
|
||||
ctx.Error(http.StatusNotFound, "TeamNotExit", err)
|
||||
|
|
|
@ -57,7 +57,7 @@ func Transfer(ctx *context.APIContext) {
|
|||
|
||||
opts := web.GetForm(ctx).(*api.TransferRepoOption)
|
||||
|
||||
newOwner, err := user_model.GetUserByName(opts.NewOwner)
|
||||
newOwner, err := user_model.GetUserByName(ctx, opts.NewOwner)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.Error(http.StatusNotFound, "", "The new owner does not exist or cannot be found")
|
||||
|
@ -84,7 +84,7 @@ func Transfer(ctx *context.APIContext) {
|
|||
|
||||
org := convert.ToOrganization(organization.OrgFromUser(newOwner))
|
||||
for _, tID := range *opts.TeamIDs {
|
||||
team, err := organization.GetTeamByID(tID)
|
||||
team, err := organization.GetTeamByID(ctx, tID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "team", fmt.Errorf("team %d not found", tID))
|
||||
return
|
||||
|
|
|
@ -213,7 +213,7 @@ func CreateOauth2Application(ctx *context.APIContext) {
|
|||
|
||||
data := web.GetForm(ctx).(*api.CreateOAuth2ApplicationOptions)
|
||||
|
||||
app, err := auth.CreateOAuth2Application(auth.CreateOAuth2ApplicationOptions{
|
||||
app, err := auth.CreateOAuth2Application(ctx, auth.CreateOAuth2ApplicationOptions{
|
||||
Name: data.Name,
|
||||
UserID: ctx.Doer.ID,
|
||||
RedirectURIs: data.RedirectURIs,
|
||||
|
@ -320,7 +320,7 @@ func GetOauth2Application(ctx *context.APIContext) {
|
|||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
appID := ctx.ParamsInt64(":id")
|
||||
app, err := auth.GetOAuth2ApplicationByID(appID)
|
||||
app, err := auth.GetOAuth2ApplicationByID(ctx, appID)
|
||||
if err != nil {
|
||||
if auth.IsErrOauthClientIDInvalid(err) || auth.IsErrOAuthApplicationNotFound(err) {
|
||||
ctx.NotFound()
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
// GetUserByParamsName get user by name
|
||||
func GetUserByParamsName(ctx *context.APIContext, name string) *user_model.User {
|
||||
username := ctx.Params(name)
|
||||
user, err := user_model.GetUserByName(username)
|
||||
user, err := user_model.GetUserByName(ctx, username)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
if redirectUserID, err2 := user_model.LookupUserRedirect(username); err2 == nil {
|
||||
|
|
|
@ -74,7 +74,7 @@ func UpdateUserSettings(ctx *context.APIContext) {
|
|||
ctx.Doer.KeepActivityPrivate = *form.HideActivity
|
||||
}
|
||||
|
||||
if err := user_model.UpdateUser(ctx.Doer, false); err != nil {
|
||||
if err := user_model.UpdateUser(ctx, ctx.Doer, false); err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ func IsStarring(ctx *context.APIContext) {
|
|||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
if repo_model.IsStaring(ctx.Doer.ID, ctx.Repo.Repository.ID) {
|
||||
if repo_model.IsStaring(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID) {
|
||||
ctx.Status(http.StatusNoContent)
|
||||
} else {
|
||||
ctx.NotFound()
|
||||
|
|
|
@ -98,7 +98,7 @@ func GetInfo(ctx *context.APIContext) {
|
|||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
if !user_model.IsUserVisibleToViewer(ctx.ContextUser, ctx.Doer) {
|
||||
if !user_model.IsUserVisibleToViewer(ctx, ctx.ContextUser, ctx.Doer) {
|
||||
// fake ErrUserNotExist error message to not leak information about existence
|
||||
ctx.NotFound("GetUserByName", user_model.ErrUserNotExist{Name: ctx.Params(":username")})
|
||||
return
|
||||
|
|
|
@ -156,7 +156,7 @@ func Watch(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/WatchInfo"
|
||||
|
||||
err := repo_model.WatchRepo(ctx.Doer.ID, ctx.Repo.Repository.ID, true)
|
||||
err := repo_model.WatchRepo(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID, true)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "WatchRepo", err)
|
||||
return
|
||||
|
@ -191,7 +191,7 @@ func Unwatch(ctx *context.APIContext) {
|
|||
// "204":
|
||||
// "$ref": "#/responses/empty"
|
||||
|
||||
err := repo_model.WatchRepo(ctx.Doer.ID, ctx.Repo.Repository.ID, false)
|
||||
err := repo_model.WatchRepo(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID, false)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "UnwatchRepo", err)
|
||||
return
|
||||
|
|
|
@ -521,7 +521,7 @@ func SubmitInstall(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
log.Info("Admin account already exist")
|
||||
u, _ = user_model.GetUserByName(u.Name)
|
||||
u, _ = user_model.GetUserByName(ctx, u.Name)
|
||||
}
|
||||
|
||||
days := 86400 * setting.LogInRememberDays
|
||||
|
|
|
@ -106,7 +106,7 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) {
|
|||
|
||||
repo.IsPrivate = opts.GitPushOptions.Bool(private.GitPushOptionRepoPrivate, repo.IsPrivate)
|
||||
repo.IsTemplate = opts.GitPushOptions.Bool(private.GitPushOptionRepoTemplate, repo.IsTemplate)
|
||||
if err := repo_model.UpdateRepositoryCols(repo, "is_private", "is_template"); err != nil {
|
||||
if err := repo_model.UpdateRepositoryCols(ctx, repo, "is_private", "is_template"); err != nil {
|
||||
log.Error("Failed to Update: %s/%s Error: %v", ownerName, repoName, err)
|
||||
ctx.JSON(http.StatusInternalServerError, private.HookPostReceiveResult{
|
||||
Err: fmt.Sprintf("Failed to Update: %s/%s Error: %v", ownerName, repoName, err),
|
||||
|
@ -141,7 +141,7 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) {
|
|||
continue
|
||||
}
|
||||
|
||||
pr, err := models.GetPullRequestByIndex(repo.ID, pullIndex)
|
||||
pr, err := models.GetPullRequestByIndex(ctx, repo.ID, pullIndex)
|
||||
if err != nil && !models.IsErrPullRequestNotExist(err) {
|
||||
log.Error("Failed to get PR by index %v Error: %v", pullIndex, err)
|
||||
ctx.JSON(http.StatusInternalServerError, private.Response{
|
||||
|
|
|
@ -155,7 +155,7 @@ func preReceiveBranch(ctx *preReceiveContext, oldCommitID, newCommitID, refFullN
|
|||
return
|
||||
}
|
||||
|
||||
protectBranch, err := models.GetProtectedBranchBy(repo.ID, branchName)
|
||||
protectBranch, err := models.GetProtectedBranchBy(ctx, repo.ID, branchName)
|
||||
if err != nil {
|
||||
log.Error("Unable to get protected branch: %s in %-v Error: %v", branchName, repo, err)
|
||||
ctx.JSON(http.StatusInternalServerError, private.Response{
|
||||
|
|
|
@ -25,7 +25,7 @@ func UpdatePublicKeyInRepo(ctx *context.PrivateContext) {
|
|||
return
|
||||
}
|
||||
|
||||
deployKey, err := asymkey_model.GetDeployKeyByRepo(keyID, repoID)
|
||||
deployKey, err := asymkey_model.GetDeployKeyByRepo(ctx, keyID, repoID)
|
||||
if err != nil {
|
||||
if asymkey_model.IsErrDeployKeyNotExist(err) {
|
||||
ctx.PlainText(http.StatusOK, "success")
|
||||
|
@ -52,7 +52,7 @@ func UpdatePublicKeyInRepo(ctx *context.PrivateContext) {
|
|||
func AuthorizedPublicKeyByContent(ctx *context.PrivateContext) {
|
||||
content := ctx.FormString("content")
|
||||
|
||||
publicKey, err := asymkey_model.SearchPublicKeyByContent(content)
|
||||
publicKey, err := asymkey_model.SearchPublicKeyByContent(ctx, content)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusInternalServerError, private.Response{
|
||||
Err: err.Error(),
|
||||
|
|
|
@ -44,7 +44,7 @@ func SendEmail(ctx *context.PrivateContext) {
|
|||
var emails []string
|
||||
if len(mail.To) > 0 {
|
||||
for _, uname := range mail.To {
|
||||
user, err := user_model.GetUserByName(uname)
|
||||
user, err := user_model.GetUserByName(ctx, uname)
|
||||
if err != nil {
|
||||
err := fmt.Sprintf("Failed to get user information: %v", err)
|
||||
log.Error(err)
|
||||
|
|
|
@ -109,7 +109,7 @@ func ServCommand(ctx *context.PrivateContext) {
|
|||
results.RepoName = repoName[:len(repoName)-5]
|
||||
}
|
||||
|
||||
owner, err := user_model.GetUserByName(results.OwnerName)
|
||||
owner, err := user_model.GetUserByName(ctx, results.OwnerName)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
// User is fetching/cloning a non-existent repository
|
||||
|
@ -230,7 +230,7 @@ func ServCommand(ctx *context.PrivateContext) {
|
|||
var user *user_model.User
|
||||
if key.Type == asymkey_model.KeyTypeDeploy {
|
||||
var err error
|
||||
deployKey, err = asymkey_model.GetDeployKeyByRepo(key.ID, repo.ID)
|
||||
deployKey, err = asymkey_model.GetDeployKeyByRepo(ctx, key.ID, repo.ID)
|
||||
if err != nil {
|
||||
if asymkey_model.IsErrDeployKeyNotExist(err) {
|
||||
ctx.JSON(http.StatusNotFound, private.ErrServCommand{
|
||||
|
@ -345,7 +345,7 @@ func ServCommand(ctx *context.PrivateContext) {
|
|||
|
||||
// We already know we aren't using a deploy key
|
||||
if !repoExist {
|
||||
owner, err := user_model.GetUserByName(ownerName)
|
||||
owner, err := user_model.GetUserByName(ctx, ownerName)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusInternalServerError, private.ErrServCommand{
|
||||
Results: results,
|
||||
|
|
|
@ -35,7 +35,7 @@ func DefaultOrSystemWebhooks(ctx *context.Context) {
|
|||
|
||||
sys["Title"] = ctx.Tr("admin.systemhooks")
|
||||
sys["Description"] = ctx.Tr("admin.systemhooks.desc")
|
||||
sys["Webhooks"], err = webhook.GetSystemWebhooks(util.OptionalBoolNone)
|
||||
sys["Webhooks"], err = webhook.GetSystemWebhooks(ctx, util.OptionalBoolNone)
|
||||
sys["BaseLink"] = setting.AppSubURL + "/admin/hooks"
|
||||
sys["BaseLinkNew"] = setting.AppSubURL + "/admin/system-hooks"
|
||||
if err != nil {
|
||||
|
@ -45,7 +45,7 @@ func DefaultOrSystemWebhooks(ctx *context.Context) {
|
|||
|
||||
def["Title"] = ctx.Tr("admin.defaulthooks")
|
||||
def["Description"] = ctx.Tr("admin.defaulthooks.desc")
|
||||
def["Webhooks"], err = webhook.GetDefaultWebhooks()
|
||||
def["Webhooks"], err = webhook.GetDefaultWebhooks(ctx)
|
||||
def["BaseLink"] = setting.AppSubURL + "/admin/hooks"
|
||||
def["BaseLinkNew"] = setting.AppSubURL + "/admin/default-hooks"
|
||||
if err != nil {
|
||||
|
|
|
@ -121,7 +121,7 @@ func AdoptOrDeleteRepository(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
ctxUser, err := user_model.GetUserByName(dirSplit[0])
|
||||
ctxUser, err := user_model.GetUserByName(ctx, dirSplit[0])
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
log.Debug("User does not exist: %s", dirSplit[0])
|
||||
|
@ -135,7 +135,7 @@ func AdoptOrDeleteRepository(ctx *context.Context) {
|
|||
repoName := dirSplit[1]
|
||||
|
||||
// check not a repo
|
||||
has, err := repo_model.IsRepositoryExist(ctxUser, repoName)
|
||||
has, err := repo_model.IsRepositoryExist(ctx, ctxUser, repoName)
|
||||
if err != nil {
|
||||
ctx.ServerError("IsRepositoryExist", err)
|
||||
return
|
||||
|
|
|
@ -389,7 +389,7 @@ func EditUserPost(ctx *context.Context) {
|
|||
u.ProhibitLogin = form.ProhibitLogin
|
||||
}
|
||||
|
||||
if err := user_model.UpdateUser(u, emailChanged); err != nil {
|
||||
if err := user_model.UpdateUser(ctx, u, emailChanged); err != nil {
|
||||
if user_model.IsErrEmailAlreadyUsed(err) {
|
||||
ctx.Data["Err_Email"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplUserEdit, &form)
|
||||
|
|
|
@ -47,7 +47,7 @@ func TestNewUserPost_MustChangePassword(t *testing.T) {
|
|||
|
||||
assert.NotEmpty(t, ctx.Flash.SuccessMsg)
|
||||
|
||||
u, err := user_model.GetUserByName(username)
|
||||
u, err := user_model.GetUserByName(ctx, username)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, username, u.Name)
|
||||
|
@ -84,7 +84,7 @@ func TestNewUserPost_MustChangePasswordFalse(t *testing.T) {
|
|||
|
||||
assert.NotEmpty(t, ctx.Flash.SuccessMsg)
|
||||
|
||||
u, err := user_model.GetUserByName(username)
|
||||
u, err := user_model.GetUserByName(ctx, username)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, username, u.Name)
|
||||
|
@ -151,7 +151,7 @@ func TestNewUserPost_VisibilityDefaultPublic(t *testing.T) {
|
|||
|
||||
assert.NotEmpty(t, ctx.Flash.SuccessMsg)
|
||||
|
||||
u, err := user_model.GetUserByName(username)
|
||||
u, err := user_model.GetUserByName(ctx, username)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, username, u.Name)
|
||||
|
@ -190,7 +190,7 @@ func TestNewUserPost_VisibilityPrivate(t *testing.T) {
|
|||
|
||||
assert.NotEmpty(t, ctx.Flash.SuccessMsg)
|
||||
|
||||
u, err := user_model.GetUserByName(username)
|
||||
u, err := user_model.GetUserByName(ctx, username)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, username, u.Name)
|
||||
|
|
|
@ -64,7 +64,7 @@ func AutoSignIn(ctx *context.Context) (bool, error) {
|
|||
}
|
||||
}()
|
||||
|
||||
u, err := user_model.GetUserByName(uname)
|
||||
u, err := user_model.GetUserByName(ctx, uname)
|
||||
if err != nil {
|
||||
if !user_model.IsErrUserNotExist(err) {
|
||||
return false, fmt.Errorf("GetUserByName: %v", err)
|
||||
|
|
|
@ -70,7 +70,7 @@ func LinkAccount(ctx *context.Context) {
|
|||
ctx.Data["user_exists"] = true
|
||||
}
|
||||
} else if len(uname) != 0 {
|
||||
u, err := user_model.GetUserByName(uname)
|
||||
u, err := user_model.GetUserByName(ctx, uname)
|
||||
if err != nil && !user_model.IsErrUserNotExist(err) {
|
||||
ctx.ServerError("UserSignIn", err)
|
||||
return
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
package auth
|
||||
|
||||
import (
|
||||
stdContext "context"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
@ -135,9 +136,9 @@ type AccessTokenResponse struct {
|
|||
IDToken string `json:"id_token,omitempty"`
|
||||
}
|
||||
|
||||
func newAccessTokenResponse(grant *auth.OAuth2Grant, serverKey, clientKey oauth2.JWTSigningKey) (*AccessTokenResponse, *AccessTokenError) {
|
||||
func newAccessTokenResponse(ctx stdContext.Context, grant *auth.OAuth2Grant, serverKey, clientKey oauth2.JWTSigningKey) (*AccessTokenResponse, *AccessTokenError) {
|
||||
if setting.OAuth2.InvalidateRefreshTokens {
|
||||
if err := grant.IncreaseCounter(); err != nil {
|
||||
if err := grant.IncreaseCounter(ctx); err != nil {
|
||||
return nil, &AccessTokenError{
|
||||
ErrorCode: AccessTokenErrorCodeInvalidGrant,
|
||||
ErrorDescription: "cannot increase the grant counter",
|
||||
|
@ -182,7 +183,7 @@ func newAccessTokenResponse(grant *auth.OAuth2Grant, serverKey, clientKey oauth2
|
|||
// generate OpenID Connect id_token
|
||||
signedIDToken := ""
|
||||
if grant.ScopeContains("openid") {
|
||||
app, err := auth.GetOAuth2ApplicationByID(grant.ApplicationID)
|
||||
app, err := auth.GetOAuth2ApplicationByID(ctx, grant.ApplicationID)
|
||||
if err != nil {
|
||||
return nil, &AccessTokenError{
|
||||
ErrorCode: AccessTokenErrorCodeInvalidRequest,
|
||||
|
@ -333,9 +334,9 @@ func IntrospectOAuth(ctx *context.Context) {
|
|||
token, err := oauth2.ParseToken(form.Token, oauth2.DefaultSigningKey)
|
||||
if err == nil {
|
||||
if token.Valid() == nil {
|
||||
grant, err := auth.GetOAuth2GrantByID(token.GrantID)
|
||||
grant, err := auth.GetOAuth2GrantByID(ctx, token.GrantID)
|
||||
if err == nil && grant != nil {
|
||||
app, err := auth.GetOAuth2ApplicationByID(grant.ApplicationID)
|
||||
app, err := auth.GetOAuth2ApplicationByID(ctx, grant.ApplicationID)
|
||||
if err == nil && app != nil {
|
||||
response.Active = true
|
||||
response.Scope = grant.Scope
|
||||
|
@ -364,7 +365,7 @@ func AuthorizeOAuth(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
app, err := auth.GetOAuth2ApplicationByClientID(form.ClientID)
|
||||
app, err := auth.GetOAuth2ApplicationByClientID(ctx, form.ClientID)
|
||||
if err != nil {
|
||||
if auth.IsErrOauthClientIDInvalid(err) {
|
||||
handleAuthorizeError(ctx, AuthorizeError{
|
||||
|
@ -438,7 +439,7 @@ func AuthorizeOAuth(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
grant, err := app.GetGrantByUserID(ctx.Doer.ID)
|
||||
grant, err := app.GetGrantByUserID(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
handleServerError(ctx, form.State, form.RedirectURI)
|
||||
return
|
||||
|
@ -446,7 +447,7 @@ func AuthorizeOAuth(ctx *context.Context) {
|
|||
|
||||
// Redirect if user already granted access
|
||||
if grant != nil {
|
||||
code, err := grant.GenerateNewAuthorizationCode(form.RedirectURI, form.CodeChallenge, form.CodeChallengeMethod)
|
||||
code, err := grant.GenerateNewAuthorizationCode(ctx, form.RedirectURI, form.CodeChallenge, form.CodeChallengeMethod)
|
||||
if err != nil {
|
||||
handleServerError(ctx, form.State, form.RedirectURI)
|
||||
return
|
||||
|
@ -458,7 +459,7 @@ func AuthorizeOAuth(ctx *context.Context) {
|
|||
}
|
||||
// Update nonce to reflect the new session
|
||||
if len(form.Nonce) > 0 {
|
||||
err := grant.SetNonce(form.Nonce)
|
||||
err := grant.SetNonce(ctx, form.Nonce)
|
||||
if err != nil {
|
||||
log.Error("Unable to update nonce: %v", err)
|
||||
}
|
||||
|
@ -510,12 +511,12 @@ func GrantApplicationOAuth(ctx *context.Context) {
|
|||
ctx.Error(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
app, err := auth.GetOAuth2ApplicationByClientID(form.ClientID)
|
||||
app, err := auth.GetOAuth2ApplicationByClientID(ctx, form.ClientID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetOAuth2ApplicationByClientID", err)
|
||||
return
|
||||
}
|
||||
grant, err := app.CreateGrant(ctx.Doer.ID, form.Scope)
|
||||
grant, err := app.CreateGrant(ctx, ctx.Doer.ID, form.Scope)
|
||||
if err != nil {
|
||||
handleAuthorizeError(ctx, AuthorizeError{
|
||||
State: form.State,
|
||||
|
@ -525,7 +526,7 @@ func GrantApplicationOAuth(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
if len(form.Nonce) > 0 {
|
||||
err := grant.SetNonce(form.Nonce)
|
||||
err := grant.SetNonce(ctx, form.Nonce)
|
||||
if err != nil {
|
||||
log.Error("Unable to update nonce: %v", err)
|
||||
}
|
||||
|
@ -535,7 +536,7 @@ func GrantApplicationOAuth(ctx *context.Context) {
|
|||
codeChallenge, _ = ctx.Session.Get("CodeChallenge").(string)
|
||||
codeChallengeMethod, _ = ctx.Session.Get("CodeChallengeMethod").(string)
|
||||
|
||||
code, err := grant.GenerateNewAuthorizationCode(form.RedirectURI, codeChallenge, codeChallengeMethod)
|
||||
code, err := grant.GenerateNewAuthorizationCode(ctx, form.RedirectURI, codeChallenge, codeChallengeMethod)
|
||||
if err != nil {
|
||||
handleServerError(ctx, form.State, form.RedirectURI)
|
||||
return
|
||||
|
@ -648,7 +649,7 @@ func handleRefreshToken(ctx *context.Context, form forms.AccessTokenForm, server
|
|||
return
|
||||
}
|
||||
// get grant before increasing counter
|
||||
grant, err := auth.GetOAuth2GrantByID(token.GrantID)
|
||||
grant, err := auth.GetOAuth2GrantByID(ctx, token.GrantID)
|
||||
if err != nil || grant == nil {
|
||||
handleAccessTokenError(ctx, AccessTokenError{
|
||||
ErrorCode: AccessTokenErrorCodeInvalidGrant,
|
||||
|
@ -666,7 +667,7 @@ func handleRefreshToken(ctx *context.Context, form forms.AccessTokenForm, server
|
|||
log.Warn("A client tried to use a refresh token for grant_id = %d was used twice!", grant.ID)
|
||||
return
|
||||
}
|
||||
accessToken, tokenErr := newAccessTokenResponse(grant, serverKey, clientKey)
|
||||
accessToken, tokenErr := newAccessTokenResponse(ctx, grant, serverKey, clientKey)
|
||||
if tokenErr != nil {
|
||||
handleAccessTokenError(ctx, *tokenErr)
|
||||
return
|
||||
|
@ -675,7 +676,7 @@ func handleRefreshToken(ctx *context.Context, form forms.AccessTokenForm, server
|
|||
}
|
||||
|
||||
func handleAuthorizationCode(ctx *context.Context, form forms.AccessTokenForm, serverKey, clientKey oauth2.JWTSigningKey) {
|
||||
app, err := auth.GetOAuth2ApplicationByClientID(form.ClientID)
|
||||
app, err := auth.GetOAuth2ApplicationByClientID(ctx, form.ClientID)
|
||||
if err != nil {
|
||||
handleAccessTokenError(ctx, AccessTokenError{
|
||||
ErrorCode: AccessTokenErrorCodeInvalidClient,
|
||||
|
@ -697,7 +698,7 @@ func handleAuthorizationCode(ctx *context.Context, form forms.AccessTokenForm, s
|
|||
})
|
||||
return
|
||||
}
|
||||
authorizationCode, err := auth.GetOAuth2AuthorizationByCode(form.Code)
|
||||
authorizationCode, err := auth.GetOAuth2AuthorizationByCode(ctx, form.Code)
|
||||
if err != nil || authorizationCode == nil {
|
||||
handleAccessTokenError(ctx, AccessTokenError{
|
||||
ErrorCode: AccessTokenErrorCodeUnauthorizedClient,
|
||||
|
@ -722,13 +723,13 @@ func handleAuthorizationCode(ctx *context.Context, form forms.AccessTokenForm, s
|
|||
return
|
||||
}
|
||||
// remove token from database to deny duplicate usage
|
||||
if err := authorizationCode.Invalidate(); err != nil {
|
||||
if err := authorizationCode.Invalidate(ctx); err != nil {
|
||||
handleAccessTokenError(ctx, AccessTokenError{
|
||||
ErrorCode: AccessTokenErrorCodeInvalidRequest,
|
||||
ErrorDescription: "cannot proceed your request",
|
||||
})
|
||||
}
|
||||
resp, tokenErr := newAccessTokenResponse(authorizationCode.Grant, serverKey, clientKey)
|
||||
resp, tokenErr := newAccessTokenResponse(ctx, authorizationCode.Grant, serverKey, clientKey)
|
||||
if tokenErr != nil {
|
||||
handleAccessTokenError(ctx, *tokenErr)
|
||||
return
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/auth"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/services/auth/source/oauth2"
|
||||
|
@ -21,7 +22,7 @@ func createAndParseToken(t *testing.T, grant *auth.OAuth2Grant) *oauth2.OIDCToke
|
|||
assert.NoError(t, err)
|
||||
assert.NotNil(t, signingKey)
|
||||
|
||||
response, terr := newAccessTokenResponse(grant, signingKey, signingKey)
|
||||
response, terr := newAccessTokenResponse(db.DefaultContext, grant, signingKey, signingKey)
|
||||
assert.Nil(t, terr)
|
||||
assert.NotNil(t, response)
|
||||
|
||||
|
@ -43,7 +44,7 @@ func createAndParseToken(t *testing.T, grant *auth.OAuth2Grant) *oauth2.OIDCToke
|
|||
func TestNewAccessTokenResponse_OIDCToken(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
grants, err := auth.GetOAuth2GrantsByUserID(3)
|
||||
grants, err := auth.GetOAuth2GrantsByUserID(db.DefaultContext, 3)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, grants, 1)
|
||||
|
||||
|
@ -59,7 +60,7 @@ func TestNewAccessTokenResponse_OIDCToken(t *testing.T) {
|
|||
assert.False(t, oidcToken.EmailVerified)
|
||||
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}).(*user_model.User)
|
||||
grants, err = auth.GetOAuth2GrantsByUserID(user.ID)
|
||||
grants, err = auth.GetOAuth2GrantsByUserID(db.DefaultContext, user.ID)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, grants, 1)
|
||||
|
||||
|
|
|
@ -217,7 +217,7 @@ func signInOpenIDVerify(ctx *context.Context) {
|
|||
}
|
||||
|
||||
if u == nil && nickname != "" {
|
||||
u, _ = user_model.GetUserByName(nickname)
|
||||
u, _ = user_model.GetUserByName(ctx, nickname)
|
||||
if err != nil {
|
||||
if !user_model.IsErrUserNotExist(err) {
|
||||
ctx.RenderWithErr(err.Error(), tplSignInOpenID, &forms.SignInOpenIDForm{
|
||||
|
@ -307,7 +307,7 @@ func ConnectOpenIDPost(ctx *context.Context) {
|
|||
|
||||
// add OpenID for the user
|
||||
userOID := &user_model.UserOpenID{UID: u.ID, URI: oid}
|
||||
if err = user_model.AddUserOpenID(userOID); err != nil {
|
||||
if err = user_model.AddUserOpenID(ctx, userOID); err != nil {
|
||||
if user_model.IsErrOpenIDAlreadyUsed(err) {
|
||||
ctx.RenderWithErr(ctx.Tr("form.openid_been_used", oid), tplConnectOID, &form)
|
||||
return
|
||||
|
@ -434,7 +434,7 @@ func RegisterOpenIDPost(ctx *context.Context) {
|
|||
|
||||
// add OpenID for the user
|
||||
userOID := &user_model.UserOpenID{UID: u.ID, URI: oid}
|
||||
if err = user_model.AddUserOpenID(userOID); err != nil {
|
||||
if err = user_model.AddUserOpenID(ctx, userOID); err != nil {
|
||||
if user_model.IsErrOpenIDAlreadyUsed(err) {
|
||||
ctx.RenderWithErr(ctx.Tr("form.openid_been_used", oid), tplSignUpOID, &form)
|
||||
return
|
||||
|
|
|
@ -17,7 +17,7 @@ import (
|
|||
|
||||
// RetrieveLabels find all the labels of an organization
|
||||
func RetrieveLabels(ctx *context.Context) {
|
||||
labels, err := models.GetLabelsByOrgID(ctx.Org.Organization.ID, ctx.FormString("sort"), db.ListOptions{})
|
||||
labels, err := models.GetLabelsByOrgID(ctx, ctx.Org.Organization.ID, ctx.FormString("sort"), db.ListOptions{})
|
||||
if err != nil {
|
||||
ctx.ServerError("RetrieveLabels.GetLabels", err)
|
||||
return
|
||||
|
@ -59,7 +59,7 @@ func NewLabel(ctx *context.Context) {
|
|||
// UpdateLabel update a label's name and color
|
||||
func UpdateLabel(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.CreateLabelForm)
|
||||
l, err := models.GetLabelInOrgByID(ctx.Org.Organization.ID, form.ID)
|
||||
l, err := models.GetLabelInOrgByID(ctx, ctx.Org.Organization.ID, form.ID)
|
||||
if err != nil {
|
||||
switch {
|
||||
case models.IsErrOrgLabelNotExist(err):
|
||||
|
|
|
@ -66,7 +66,7 @@ func SettingsPost(ctx *context.Context) {
|
|||
|
||||
// Check if organization name has been changed.
|
||||
if org.LowerName != strings.ToLower(form.Name) {
|
||||
isExist, err := user_model.IsUserExist(org.ID, form.Name)
|
||||
isExist, err := user_model.IsUserExist(ctx, org.ID, form.Name)
|
||||
if err != nil {
|
||||
ctx.ServerError("IsUserExist", err)
|
||||
return
|
||||
|
@ -110,7 +110,7 @@ func SettingsPost(ctx *context.Context) {
|
|||
visibilityChanged := form.Visibility != org.Visibility
|
||||
org.Visibility = form.Visibility
|
||||
|
||||
if err := user_model.UpdateUser(org.AsUser(), false); err != nil {
|
||||
if err := user_model.UpdateUser(ctx, org.AsUser(), false); err != nil {
|
||||
ctx.ServerError("UpdateUser", err)
|
||||
return
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ func Webhooks(ctx *context.Context) {
|
|||
ctx.Data["BaseLinkNew"] = ctx.Org.OrgLink + "/settings/hooks"
|
||||
ctx.Data["Description"] = ctx.Tr("org.settings.hooks_desc")
|
||||
|
||||
ws, err := webhook.ListWebhooksByOpts(&webhook.ListWebhookOptions{OrgID: ctx.Org.Organization.ID})
|
||||
ws, err := webhook.ListWebhooksByOpts(ctx, &webhook.ListWebhookOptions{OrgID: ctx.Org.Organization.ID})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetWebhooksByOrgId", err)
|
||||
return
|
||||
|
|
|
@ -122,7 +122,7 @@ func TeamsAction(ctx *context.Context) {
|
|||
}
|
||||
uname := utils.RemoveUsernameParameterSuffix(strings.ToLower(ctx.FormString("uname")))
|
||||
var u *user_model.User
|
||||
u, err = user_model.GetUserByName(uname)
|
||||
u, err = user_model.GetUserByName(ctx, uname)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.Flash.Error(ctx.Tr("form.user_not_exist"))
|
||||
|
|
|
@ -64,7 +64,7 @@ func uploadAttachment(ctx *context.Context, repoID int64, allowedTypes string) {
|
|||
// DeleteAttachment response for deleting issue's attachment
|
||||
func DeleteAttachment(ctx *context.Context) {
|
||||
file := ctx.FormString("file")
|
||||
attach, err := repo_model.GetAttachmentByUUID(file)
|
||||
attach, err := repo_model.GetAttachmentByUUID(ctx, file)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusBadRequest, err.Error())
|
||||
return
|
||||
|
@ -85,7 +85,7 @@ func DeleteAttachment(ctx *context.Context) {
|
|||
|
||||
// GetAttachment serve attachements
|
||||
func GetAttachment(ctx *context.Context) {
|
||||
attach, err := repo_model.GetAttachmentByUUID(ctx.Params(":uuid"))
|
||||
attach, err := repo_model.GetAttachmentByUUID(ctx, ctx.Params(":uuid"))
|
||||
if err != nil {
|
||||
if repo_model.IsErrAttachmentNotExist(err) {
|
||||
ctx.Error(http.StatusNotFound)
|
||||
|
|
|
@ -335,7 +335,7 @@ func Diff(ctx *context.Context) {
|
|||
ctx.Data["Commit"] = commit
|
||||
ctx.Data["Diff"] = diff
|
||||
|
||||
statuses, _, err := models.GetLatestCommitStatus(ctx.Repo.Repository.ID, commitID, db.ListOptions{})
|
||||
statuses, _, err := models.GetLatestCommitStatus(ctx, ctx.Repo.Repository.ID, commitID, db.ListOptions{})
|
||||
if err != nil {
|
||||
log.Error("GetLatestCommitStatus: %v", err)
|
||||
}
|
||||
|
|
|
@ -254,7 +254,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
|
|||
} else if len(headInfos) == 2 {
|
||||
headInfosSplit := strings.Split(headInfos[0], "/")
|
||||
if len(headInfosSplit) == 1 {
|
||||
ci.HeadUser, err = user_model.GetUserByName(headInfos[0])
|
||||
ci.HeadUser, err = user_model.GetUserByName(ctx, headInfos[0])
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.NotFound("GetUserByName", nil)
|
||||
|
|
|
@ -255,7 +255,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
|
|||
}
|
||||
|
||||
issueList := models.IssueList(issues)
|
||||
approvalCounts, err := issueList.GetApprovalCounts()
|
||||
approvalCounts, err := issueList.GetApprovalCounts(ctx)
|
||||
if err != nil {
|
||||
ctx.ServerError("ApprovalCounts", err)
|
||||
return
|
||||
|
@ -294,14 +294,14 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
|
|||
return
|
||||
}
|
||||
|
||||
labels, err := models.GetLabelsByRepoID(repo.ID, "", db.ListOptions{})
|
||||
labels, err := models.GetLabelsByRepoID(ctx, repo.ID, "", db.ListOptions{})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetLabelsByRepoID", err)
|
||||
return
|
||||
}
|
||||
|
||||
if repo.Owner.IsOrganization() {
|
||||
orgLabels, err := models.GetLabelsByOrgID(repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{})
|
||||
orgLabels, err := models.GetLabelsByOrgID(ctx, repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetLabelsByOrgID", err)
|
||||
return
|
||||
|
@ -343,7 +343,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
|
|||
}
|
||||
|
||||
if ctx.Repo.CanWriteIssuesOrPulls(ctx.Params(":type") == "pulls") {
|
||||
projects, _, err := project_model.GetProjects(project_model.SearchOptions{
|
||||
projects, _, err := project_model.GetProjects(ctx, project_model.SearchOptions{
|
||||
RepoID: repo.ID,
|
||||
Type: project_model.TypeRepository,
|
||||
IsClosed: util.OptionalBoolOf(isShowClosed),
|
||||
|
@ -453,7 +453,7 @@ func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *repo_model.R
|
|||
func retrieveProjects(ctx *context.Context, repo *repo_model.Repository) {
|
||||
var err error
|
||||
|
||||
ctx.Data["OpenProjects"], _, err = project_model.GetProjects(project_model.SearchOptions{
|
||||
ctx.Data["OpenProjects"], _, err = project_model.GetProjects(ctx, project_model.SearchOptions{
|
||||
RepoID: repo.ID,
|
||||
Page: -1,
|
||||
IsClosed: util.OptionalBoolFalse,
|
||||
|
@ -464,7 +464,7 @@ func retrieveProjects(ctx *context.Context, repo *repo_model.Repository) {
|
|||
return
|
||||
}
|
||||
|
||||
ctx.Data["ClosedProjects"], _, err = project_model.GetProjects(project_model.SearchOptions{
|
||||
ctx.Data["ClosedProjects"], _, err = project_model.GetProjects(ctx, project_model.SearchOptions{
|
||||
RepoID: repo.ID,
|
||||
Page: -1,
|
||||
IsClosed: util.OptionalBoolTrue,
|
||||
|
@ -673,14 +673,14 @@ func RetrieveRepoMetas(ctx *context.Context, repo *repo_model.Repository, isPull
|
|||
return nil
|
||||
}
|
||||
|
||||
labels, err := models.GetLabelsByRepoID(repo.ID, "", db.ListOptions{})
|
||||
labels, err := models.GetLabelsByRepoID(ctx, repo.ID, "", db.ListOptions{})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetLabelsByRepoID", err)
|
||||
return nil
|
||||
}
|
||||
ctx.Data["Labels"] = labels
|
||||
if repo.Owner.IsOrganization() {
|
||||
orgLabels, err := models.GetLabelsByOrgID(repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{})
|
||||
orgLabels, err := models.GetLabelsByOrgID(ctx, repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{})
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
@ -761,10 +761,10 @@ func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleDirs,
|
|||
ctx.Data[issueTemplateTitleKey] = meta.Title
|
||||
ctx.Data[ctxDataKey] = templateBody
|
||||
labelIDs := make([]string, 0, len(meta.Labels))
|
||||
if repoLabels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, "", db.ListOptions{}); err == nil {
|
||||
if repoLabels, err := models.GetLabelsByRepoID(ctx, ctx.Repo.Repository.ID, "", db.ListOptions{}); err == nil {
|
||||
ctx.Data["Labels"] = repoLabels
|
||||
if ctx.Repo.Owner.IsOrganization() {
|
||||
if orgLabels, err := models.GetLabelsByOrgID(ctx.Repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{}); err == nil {
|
||||
if orgLabels, err := models.GetLabelsByOrgID(ctx, ctx.Repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{}); err == nil {
|
||||
ctx.Data["OrgLabels"] = orgLabels
|
||||
repoLabels = append(repoLabels, orgLabels...)
|
||||
}
|
||||
|
@ -818,7 +818,7 @@ func NewIssue(ctx *context.Context) {
|
|||
|
||||
projectID := ctx.FormInt64("project")
|
||||
if projectID > 0 {
|
||||
project, err := project_model.GetProjectByID(projectID)
|
||||
project, err := project_model.GetProjectByID(ctx, projectID)
|
||||
if err != nil {
|
||||
log.Error("GetProjectByID: %d: %v", projectID, err)
|
||||
} else if project.RepoID != ctx.Repo.Repository.ID {
|
||||
|
@ -930,7 +930,7 @@ func ValidateRepoMetas(ctx *context.Context, form forms.CreateIssueForm, isPull
|
|||
}
|
||||
|
||||
if form.ProjectID > 0 {
|
||||
p, err := project_model.GetProjectByID(form.ProjectID)
|
||||
p, err := project_model.GetProjectByID(ctx, form.ProjectID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetProjectByID", err)
|
||||
return nil, nil, 0, 0
|
||||
|
@ -1237,7 +1237,7 @@ func ViewIssue(ctx *context.Context) {
|
|||
for i := range issue.Labels {
|
||||
labelIDMark[issue.Labels[i].ID] = true
|
||||
}
|
||||
labels, err := models.GetLabelsByRepoID(repo.ID, "", db.ListOptions{})
|
||||
labels, err := models.GetLabelsByRepoID(ctx, repo.ID, "", db.ListOptions{})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetLabelsByRepoID", err)
|
||||
return
|
||||
|
@ -1245,7 +1245,7 @@ func ViewIssue(ctx *context.Context) {
|
|||
ctx.Data["Labels"] = labels
|
||||
|
||||
if repo.Owner.IsOrganization() {
|
||||
orgLabels, err := models.GetLabelsByOrgID(repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{})
|
||||
orgLabels, err := models.GetLabelsByOrgID(ctx, repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetLabelsByOrgID", err)
|
||||
return
|
||||
|
@ -1277,7 +1277,7 @@ func ViewIssue(ctx *context.Context) {
|
|||
if issue.IsPull {
|
||||
canChooseReviewer := ctx.Repo.CanWrite(unit.TypePullRequests)
|
||||
if !canChooseReviewer && ctx.Doer != nil && ctx.IsSigned {
|
||||
canChooseReviewer, err = models.IsOfficialReviewer(issue, ctx.Doer)
|
||||
canChooseReviewer, err = models.IsOfficialReviewer(ctx, issue, ctx.Doer)
|
||||
if err != nil {
|
||||
ctx.ServerError("IsOfficialReviewer", err)
|
||||
return
|
||||
|
@ -1312,7 +1312,7 @@ func ViewIssue(ctx *context.Context) {
|
|||
if !ctx.Data["IsStopwatchRunning"].(bool) {
|
||||
var exists bool
|
||||
var sw *models.Stopwatch
|
||||
if exists, sw, err = models.HasUserStopwatch(ctx.Doer.ID); err != nil {
|
||||
if exists, sw, err = models.HasUserStopwatch(ctx, ctx.Doer.ID); err != nil {
|
||||
ctx.ServerError("HasUserStopwatch", err)
|
||||
return
|
||||
}
|
||||
|
@ -1688,12 +1688,12 @@ func ViewIssue(ctx *context.Context) {
|
|||
}
|
||||
|
||||
// Get Dependencies
|
||||
ctx.Data["BlockedByDependencies"], err = issue.BlockedByDependencies()
|
||||
ctx.Data["BlockedByDependencies"], err = issue.BlockedByDependencies(ctx)
|
||||
if err != nil {
|
||||
ctx.ServerError("BlockedByDependencies", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["BlockingDependencies"], err = issue.BlockingDependencies()
|
||||
ctx.Data["BlockingDependencies"], err = issue.BlockingDependencies(ctx)
|
||||
if err != nil {
|
||||
ctx.ServerError("BlockingDependencies", err)
|
||||
return
|
||||
|
@ -1767,7 +1767,7 @@ func getActionIssues(ctx *context.Context) []*models.Issue {
|
|||
}
|
||||
issueIDs = append(issueIDs, issueID)
|
||||
}
|
||||
issues, err := models.GetIssuesByIDs(issueIDs)
|
||||
issues, err := models.GetIssuesByIDs(ctx, issueIDs)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetIssuesByIDs", err)
|
||||
return nil
|
||||
|
@ -1873,7 +1873,7 @@ func UpdateIssueContent(ctx *context.Context) {
|
|||
|
||||
// when update the request doesn't intend to update attachments (eg: change checkbox state), ignore attachment updates
|
||||
if !ctx.FormBool("ignore_attachments") {
|
||||
if err := updateAttachments(issue, ctx.FormStrings("files[]")); err != nil {
|
||||
if err := updateAttachments(ctx, issue, ctx.FormStrings("files[]")); err != nil {
|
||||
ctx.ServerError("UpdateAttachments", err)
|
||||
return
|
||||
}
|
||||
|
@ -2047,7 +2047,7 @@ func UpdatePullReviewRequest(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
team, err := organization.GetTeamByID(-reviewID)
|
||||
team, err := organization.GetTeamByID(ctx, -reviewID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetTeamByID", err)
|
||||
return
|
||||
|
@ -2160,7 +2160,7 @@ func SearchIssues(ctx *context.Context) {
|
|||
opts.AllLimited = true
|
||||
}
|
||||
if ctx.FormString("owner") != "" {
|
||||
owner, err := user_model.GetUserByName(ctx.FormString("owner"))
|
||||
owner, err := user_model.GetUserByName(ctx, ctx.FormString("owner"))
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.Error(http.StatusBadRequest, "Owner not found", err.Error())
|
||||
|
@ -2179,7 +2179,7 @@ func SearchIssues(ctx *context.Context) {
|
|||
ctx.Error(http.StatusBadRequest, "", "Owner organisation is required for filtering on team")
|
||||
return
|
||||
}
|
||||
team, err := organization.GetTeam(opts.OwnerID, ctx.FormString("team"))
|
||||
team, err := organization.GetTeam(ctx, opts.OwnerID, ctx.FormString("team"))
|
||||
if err != nil {
|
||||
if organization.IsErrTeamNotExist(err) {
|
||||
ctx.Error(http.StatusBadRequest, "Team not found", err.Error())
|
||||
|
@ -2307,7 +2307,7 @@ func getUserIDForFilter(ctx *context.Context, queryName string) int64 {
|
|||
return 0
|
||||
}
|
||||
|
||||
user, err := user_model.GetUserByName(userName)
|
||||
user, err := user_model.GetUserByName(ctx, userName)
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.NotFound("", err)
|
||||
return 0
|
||||
|
@ -2631,7 +2631,7 @@ func NewComment(ctx *context.Context) {
|
|||
|
||||
// UpdateCommentContent change comment of issue's content
|
||||
func UpdateCommentContent(ctx *context.Context) {
|
||||
comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
|
||||
comment, err := models.GetCommentByID(ctx, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
ctx.NotFoundOrServerError("GetCommentByID", models.IsErrCommentNotExist, err)
|
||||
return
|
||||
|
@ -2672,7 +2672,7 @@ func UpdateCommentContent(ctx *context.Context) {
|
|||
|
||||
// when the update request doesn't intend to update attachments (eg: change checkbox state), ignore attachment updates
|
||||
if !ctx.FormBool("ignore_attachments") {
|
||||
if err := updateAttachments(comment, ctx.FormStrings("files[]")); err != nil {
|
||||
if err := updateAttachments(ctx, comment, ctx.FormStrings("files[]")); err != nil {
|
||||
ctx.ServerError("UpdateAttachments", err)
|
||||
return
|
||||
}
|
||||
|
@ -2697,7 +2697,7 @@ func UpdateCommentContent(ctx *context.Context) {
|
|||
|
||||
// DeleteComment delete comment of issue
|
||||
func DeleteComment(ctx *context.Context) {
|
||||
comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
|
||||
comment, err := models.GetCommentByID(ctx, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
ctx.NotFoundOrServerError("GetCommentByID", models.IsErrCommentNotExist, err)
|
||||
return
|
||||
|
@ -2823,7 +2823,7 @@ func ChangeIssueReaction(ctx *context.Context) {
|
|||
// ChangeCommentReaction create a reaction for comment
|
||||
func ChangeCommentReaction(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.ReactionForm)
|
||||
comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
|
||||
comment, err := models.GetCommentByID(ctx, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
ctx.NotFoundOrServerError("GetCommentByID", models.IsErrCommentNotExist, err)
|
||||
return
|
||||
|
@ -2968,7 +2968,7 @@ func GetIssueAttachments(ctx *context.Context) {
|
|||
|
||||
// GetCommentAttachments returns attachments for the comment
|
||||
func GetCommentAttachments(ctx *context.Context) {
|
||||
comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
|
||||
comment, err := models.GetCommentByID(ctx, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
ctx.NotFoundOrServerError("GetCommentByID", models.IsErrCommentNotExist, err)
|
||||
return
|
||||
|
@ -2986,7 +2986,7 @@ func GetCommentAttachments(ctx *context.Context) {
|
|||
ctx.JSON(http.StatusOK, attachments)
|
||||
}
|
||||
|
||||
func updateAttachments(item interface{}, files []string) error {
|
||||
func updateAttachments(ctx *context.Context, item interface{}, files []string) error {
|
||||
var attachments []*repo_model.Attachment
|
||||
switch content := item.(type) {
|
||||
case *models.Issue:
|
||||
|
@ -3020,9 +3020,9 @@ func updateAttachments(item interface{}, files []string) error {
|
|||
}
|
||||
switch content := item.(type) {
|
||||
case *models.Issue:
|
||||
content.Attachments, err = repo_model.GetAttachmentsByIssueID(content.ID)
|
||||
content.Attachments, err = repo_model.GetAttachmentsByIssueID(ctx, content.ID)
|
||||
case *models.Comment:
|
||||
content.Attachments, err = repo_model.GetAttachmentsByCommentID(content.ID)
|
||||
content.Attachments, err = repo_model.GetAttachmentsByCommentID(ctx, content.ID)
|
||||
default:
|
||||
return fmt.Errorf("unknown Type: %T", content)
|
||||
}
|
||||
|
|
|
@ -130,7 +130,7 @@ func GetContentHistoryDetail(ctx *context.Context) {
|
|||
var comment *models.Comment
|
||||
if history.CommentID != 0 {
|
||||
var err error
|
||||
if comment, err = models.GetCommentByID(history.CommentID); err != nil {
|
||||
if comment, err = models.GetCommentByID(ctx, history.CommentID); err != nil {
|
||||
log.Error("can not get comment for issue content history %v. err=%v", historyID, err)
|
||||
return
|
||||
}
|
||||
|
@ -190,7 +190,7 @@ func SoftDeleteContentHistory(ctx *context.Context) {
|
|||
var history *issuesModel.ContentHistory
|
||||
var err error
|
||||
if commentID != 0 {
|
||||
if comment, err = models.GetCommentByID(commentID); err != nil {
|
||||
if comment, err = models.GetCommentByID(ctx, commentID); err != nil {
|
||||
log.Error("can not get comment for issue content history %v. err=%v", historyID, err)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ func InitializeLabels(ctx *context.Context) {
|
|||
|
||||
// RetrieveLabels find all the labels of a repository and organization
|
||||
func RetrieveLabels(ctx *context.Context) {
|
||||
labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, ctx.FormString("sort"), db.ListOptions{})
|
||||
labels, err := models.GetLabelsByRepoID(ctx, ctx.Repo.Repository.ID, ctx.FormString("sort"), db.ListOptions{})
|
||||
if err != nil {
|
||||
ctx.ServerError("RetrieveLabels.GetLabels", err)
|
||||
return
|
||||
|
@ -69,7 +69,7 @@ func RetrieveLabels(ctx *context.Context) {
|
|||
ctx.Data["Labels"] = labels
|
||||
|
||||
if ctx.Repo.Owner.IsOrganization() {
|
||||
orgLabels, err := models.GetLabelsByOrgID(ctx.Repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{})
|
||||
orgLabels, err := models.GetLabelsByOrgID(ctx, ctx.Repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetLabelsByOrgID", err)
|
||||
return
|
||||
|
@ -127,7 +127,7 @@ func NewLabel(ctx *context.Context) {
|
|||
// UpdateLabel update a label's name and color
|
||||
func UpdateLabel(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.CreateLabelForm)
|
||||
l, err := models.GetLabelInRepoByID(ctx.Repo.Repository.ID, form.ID)
|
||||
l, err := models.GetLabelInRepoByID(ctx, ctx.Repo.Repository.ID, form.ID)
|
||||
if err != nil {
|
||||
switch {
|
||||
case models.IsErrRepoLabelNotExist(err):
|
||||
|
@ -177,7 +177,7 @@ func UpdateIssueLabel(ctx *context.Context) {
|
|||
}
|
||||
}
|
||||
case "attach", "detach", "toggle":
|
||||
label, err := models.GetLabelByID(ctx.FormInt64("id"))
|
||||
label, err := models.GetLabelByID(ctx, ctx.FormInt64("id"))
|
||||
if err != nil {
|
||||
if models.IsErrRepoLabelNotExist(err) {
|
||||
ctx.Error(http.StatusNotFound, "GetLabelByID")
|
||||
|
@ -191,7 +191,7 @@ func UpdateIssueLabel(ctx *context.Context) {
|
|||
// detach if any issues already have label, otherwise attach
|
||||
action = "attach"
|
||||
for _, issue := range issues {
|
||||
if models.HasIssueLabel(issue.ID, label.ID) {
|
||||
if models.HasIssueLabel(ctx, issue.ID, label.ID) {
|
||||
action = "detach"
|
||||
break
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ func GetActiveStopwatch(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
_, sw, err := models.HasUserStopwatch(ctx.Doer.ID)
|
||||
_, sw, err := models.HasUserStopwatch(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("HasUserStopwatch", err)
|
||||
return
|
||||
|
|
|
@ -70,7 +70,7 @@ func Projects(ctx *context.Context) {
|
|||
total = repo.NumClosedProjects
|
||||
}
|
||||
|
||||
projects, count, err := project_model.GetProjects(project_model.SearchOptions{
|
||||
projects, count, err := project_model.GetProjects(ctx, project_model.SearchOptions{
|
||||
RepoID: repo.ID,
|
||||
Page: page,
|
||||
IsClosed: util.OptionalBoolOf(isShowClosed),
|
||||
|
@ -182,7 +182,7 @@ func ChangeProjectStatus(ctx *context.Context) {
|
|||
|
||||
// DeleteProject delete a project
|
||||
func DeleteProject(ctx *context.Context) {
|
||||
p, err := project_model.GetProjectByID(ctx.ParamsInt64(":id"))
|
||||
p, err := project_model.GetProjectByID(ctx, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if project_model.IsErrProjectNotExist(err) {
|
||||
ctx.NotFound("", nil)
|
||||
|
@ -213,7 +213,7 @@ func EditProject(ctx *context.Context) {
|
|||
ctx.Data["PageIsEditProjects"] = true
|
||||
ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(unit.TypeProjects)
|
||||
|
||||
p, err := project_model.GetProjectByID(ctx.ParamsInt64(":id"))
|
||||
p, err := project_model.GetProjectByID(ctx, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if project_model.IsErrProjectNotExist(err) {
|
||||
ctx.NotFound("", nil)
|
||||
|
@ -245,7 +245,7 @@ func EditProjectPost(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
p, err := project_model.GetProjectByID(ctx.ParamsInt64(":id"))
|
||||
p, err := project_model.GetProjectByID(ctx, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if project_model.IsErrProjectNotExist(err) {
|
||||
ctx.NotFound("", nil)
|
||||
|
@ -261,7 +261,7 @@ func EditProjectPost(ctx *context.Context) {
|
|||
|
||||
p.Title = form.Title
|
||||
p.Description = form.Content
|
||||
if err = project_model.UpdateProject(p); err != nil {
|
||||
if err = project_model.UpdateProject(ctx, p); err != nil {
|
||||
ctx.ServerError("UpdateProjects", err)
|
||||
return
|
||||
}
|
||||
|
@ -272,7 +272,7 @@ func EditProjectPost(ctx *context.Context) {
|
|||
|
||||
// ViewProject renders the project board for a project
|
||||
func ViewProject(ctx *context.Context) {
|
||||
project, err := project_model.GetProjectByID(ctx.ParamsInt64(":id"))
|
||||
project, err := project_model.GetProjectByID(ctx, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if project_model.IsErrProjectNotExist(err) {
|
||||
ctx.NotFound("", nil)
|
||||
|
@ -286,7 +286,7 @@ func ViewProject(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
boards, err := project_model.GetBoards(project.ID)
|
||||
boards, err := project_model.GetBoards(ctx, project.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetProjectBoards", err)
|
||||
return
|
||||
|
@ -385,7 +385,7 @@ func DeleteProjectBoard(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
project, err := project_model.GetProjectByID(ctx.ParamsInt64(":id"))
|
||||
project, err := project_model.GetProjectByID(ctx, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if project_model.IsErrProjectNotExist(err) {
|
||||
ctx.NotFound("", nil)
|
||||
|
@ -395,7 +395,7 @@ func DeleteProjectBoard(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
pb, err := project_model.GetBoard(ctx.ParamsInt64(":boardID"))
|
||||
pb, err := project_model.GetBoard(ctx, ctx.ParamsInt64(":boardID"))
|
||||
if err != nil {
|
||||
ctx.ServerError("GetProjectBoard", err)
|
||||
return
|
||||
|
@ -434,7 +434,7 @@ func AddBoardToProjectPost(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
project, err := project_model.GetProjectByID(ctx.ParamsInt64(":id"))
|
||||
project, err := project_model.GetProjectByID(ctx, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if project_model.IsErrProjectNotExist(err) {
|
||||
ctx.NotFound("", nil)
|
||||
|
@ -474,7 +474,7 @@ func checkProjectBoardChangePermissions(ctx *context.Context) (*project_model.Pr
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
project, err := project_model.GetProjectByID(ctx.ParamsInt64(":id"))
|
||||
project, err := project_model.GetProjectByID(ctx, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if project_model.IsErrProjectNotExist(err) {
|
||||
ctx.NotFound("", nil)
|
||||
|
@ -484,7 +484,7 @@ func checkProjectBoardChangePermissions(ctx *context.Context) (*project_model.Pr
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
board, err := project_model.GetBoard(ctx.ParamsInt64(":boardID"))
|
||||
board, err := project_model.GetBoard(ctx, ctx.ParamsInt64(":boardID"))
|
||||
if err != nil {
|
||||
ctx.ServerError("GetProjectBoard", err)
|
||||
return nil, nil
|
||||
|
@ -523,7 +523,7 @@ func EditProjectBoard(ctx *context.Context) {
|
|||
board.Sorting = form.Sorting
|
||||
}
|
||||
|
||||
if err := project_model.UpdateBoard(board); err != nil {
|
||||
if err := project_model.UpdateBoard(ctx, board); err != nil {
|
||||
ctx.ServerError("UpdateProjectBoard", err)
|
||||
return
|
||||
}
|
||||
|
@ -566,7 +566,7 @@ func MoveIssues(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
project, err := project_model.GetProjectByID(ctx.ParamsInt64(":id"))
|
||||
project, err := project_model.GetProjectByID(ctx, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if project_model.IsErrProjectNotExist(err) {
|
||||
ctx.NotFound("ProjectNotExist", nil)
|
||||
|
@ -589,7 +589,7 @@ func MoveIssues(ctx *context.Context) {
|
|||
Title: ctx.Tr("repo.projects.type.uncategorized"),
|
||||
}
|
||||
} else {
|
||||
board, err = project_model.GetBoard(ctx.ParamsInt64(":boardID"))
|
||||
board, err = project_model.GetBoard(ctx, ctx.ParamsInt64(":boardID"))
|
||||
if err != nil {
|
||||
if project_model.IsErrProjectBoardNotExist(err) {
|
||||
ctx.NotFound("ProjectBoardNotExist", nil)
|
||||
|
@ -622,7 +622,7 @@ func MoveIssues(ctx *context.Context) {
|
|||
issueIDs = append(issueIDs, issue.IssueID)
|
||||
sortedIssueIDs[issue.Sorting] = issue.IssueID
|
||||
}
|
||||
movedIssues, err := models.GetIssuesByIDs(issueIDs)
|
||||
movedIssues, err := models.GetIssuesByIDs(ctx, issueIDs)
|
||||
if err != nil {
|
||||
if models.IsErrIssueNotExist(err) {
|
||||
ctx.NotFound("IssueNotExisting", nil)
|
||||
|
|
|
@ -377,7 +377,7 @@ func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) *git.C
|
|||
|
||||
if len(compareInfo.Commits) != 0 {
|
||||
sha := compareInfo.Commits[0].ID.String()
|
||||
commitStatuses, _, err := models.GetLatestCommitStatus(ctx.Repo.Repository.ID, sha, db.ListOptions{})
|
||||
commitStatuses, _, err := models.GetLatestCommitStatus(ctx, ctx.Repo.Repository.ID, sha, db.ListOptions{})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetLatestCommitStatus", err)
|
||||
return nil
|
||||
|
@ -438,7 +438,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare
|
|||
ctx.ServerError(fmt.Sprintf("GetRefCommitID(%s)", pull.GetGitRefName()), err)
|
||||
return nil
|
||||
}
|
||||
commitStatuses, _, err := models.GetLatestCommitStatus(repo.ID, sha, db.ListOptions{})
|
||||
commitStatuses, _, err := models.GetLatestCommitStatus(ctx, repo.ID, sha, db.ListOptions{})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetLatestCommitStatus", err)
|
||||
return nil
|
||||
|
@ -528,7 +528,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare
|
|||
return nil
|
||||
}
|
||||
|
||||
commitStatuses, _, err := models.GetLatestCommitStatus(repo.ID, sha, db.ListOptions{})
|
||||
commitStatuses, _, err := models.GetLatestCommitStatus(ctx, repo.ID, sha, db.ListOptions{})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetLatestCommitStatus", err)
|
||||
return nil
|
||||
|
@ -767,7 +767,7 @@ func ViewPullFiles(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
currentReview, err := models.GetCurrentReview(ctx.Doer, issue)
|
||||
currentReview, err := models.GetCurrentReview(ctx, ctx.Doer, issue)
|
||||
if err != nil && !models.IsErrReviewNotExist(err) {
|
||||
ctx.ServerError("GetCurrentReview", err)
|
||||
return
|
||||
|
@ -1354,7 +1354,7 @@ func DownloadPullPatch(ctx *context.Context) {
|
|||
|
||||
// DownloadPullDiffOrPatch render a pull's raw diff or patch
|
||||
func DownloadPullDiffOrPatch(ctx *context.Context, patch bool) {
|
||||
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
pr, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
if models.IsErrPullRequestNotExist(err) {
|
||||
ctx.NotFound("GetPullRequestByIndex", err)
|
||||
|
@ -1447,7 +1447,7 @@ func UpdatePullRequestTarget(ctx *context.Context) {
|
|||
func SetAllowEdits(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.UpdateAllowEditsForm)
|
||||
|
||||
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
pr, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
if models.IsErrPullRequestNotExist(err) {
|
||||
ctx.NotFound("GetPullRequestByIndex", err)
|
||||
|
|
|
@ -31,7 +31,7 @@ func RenderNewCodeCommentForm(ctx *context.Context) {
|
|||
if !issue.IsPull {
|
||||
return
|
||||
}
|
||||
currentReview, err := models.GetCurrentReview(ctx.Doer, issue)
|
||||
currentReview, err := models.GetCurrentReview(ctx, ctx.Doer, issue)
|
||||
if err != nil && !models.IsErrReviewNotExist(err) {
|
||||
ctx.ServerError("GetCurrentReview", err)
|
||||
return
|
||||
|
@ -107,7 +107,7 @@ func UpdateResolveConversation(ctx *context.Context) {
|
|||
action := ctx.FormString("action")
|
||||
commentID := ctx.FormInt64("comment_id")
|
||||
|
||||
comment, err := models.GetCommentByID(commentID)
|
||||
comment, err := models.GetCommentByID(ctx, commentID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetIssueByID", err)
|
||||
return
|
||||
|
|
|
@ -126,7 +126,7 @@ func releasesOrTags(ctx *context.Context, isTagList bool) {
|
|||
return
|
||||
}
|
||||
|
||||
if err = models.GetReleaseAttachments(releases...); err != nil {
|
||||
if err = models.GetReleaseAttachments(ctx, releases...); err != nil {
|
||||
ctx.ServerError("GetReleaseAttachments", err)
|
||||
return
|
||||
}
|
||||
|
@ -202,7 +202,7 @@ func SingleRelease(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
err = models.GetReleaseAttachments(release)
|
||||
err = models.GetReleaseAttachments(ctx, release)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetReleaseAttachments", err)
|
||||
return
|
||||
|
|
|
@ -285,9 +285,9 @@ func Action(ctx *context.Context) {
|
|||
var err error
|
||||
switch ctx.Params(":action") {
|
||||
case "watch":
|
||||
err = repo_model.WatchRepo(ctx.Doer.ID, ctx.Repo.Repository.ID, true)
|
||||
err = repo_model.WatchRepo(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID, true)
|
||||
case "unwatch":
|
||||
err = repo_model.WatchRepo(ctx.Doer.ID, ctx.Repo.Repository.ID, false)
|
||||
err = repo_model.WatchRepo(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID, false)
|
||||
case "star":
|
||||
err = repo_model.StarRepo(ctx.Doer.ID, ctx.Repo.Repository.ID, true)
|
||||
case "unstar":
|
||||
|
@ -369,7 +369,7 @@ func RedirectDownload(ctx *context.Context) {
|
|||
}
|
||||
if len(releases) == 1 {
|
||||
release := releases[0]
|
||||
att, err := repo_model.GetAttachmentByReleaseIDFileName(release.ID, fileName)
|
||||
att, err := repo_model.GetAttachmentByReleaseIDFileName(ctx, release.ID, fileName)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusNotFound)
|
||||
return
|
||||
|
|
|
@ -72,14 +72,14 @@ func Settings(ctx *context.Context) {
|
|||
ctx.Data["CodeIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
|
||||
if ctx.Doer.IsAdmin {
|
||||
if setting.Indexer.RepoIndexerEnabled {
|
||||
status, err := repo_model.GetIndexerStatus(ctx.Repo.Repository, repo_model.RepoIndexerTypeCode)
|
||||
status, err := repo_model.GetIndexerStatus(ctx, ctx.Repo.Repository, repo_model.RepoIndexerTypeCode)
|
||||
if err != nil {
|
||||
ctx.ServerError("repo.indexer_status", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["CodeIndexerStatus"] = status
|
||||
}
|
||||
status, err := repo_model.GetIndexerStatus(ctx.Repo.Repository, repo_model.RepoIndexerTypeStats)
|
||||
status, err := repo_model.GetIndexerStatus(ctx, ctx.Repo.Repository, repo_model.RepoIndexerTypeStats)
|
||||
if err != nil {
|
||||
ctx.ServerError("repo.indexer_status", err)
|
||||
return
|
||||
|
@ -195,7 +195,7 @@ func SettingsPost(ctx *context.Context) {
|
|||
ctx.Repo.Mirror.EnablePrune = form.EnablePrune
|
||||
ctx.Repo.Mirror.Interval = interval
|
||||
ctx.Repo.Mirror.ScheduleNextUpdate()
|
||||
if err := repo_model.UpdateMirror(ctx.Repo.Mirror); err != nil {
|
||||
if err := repo_model.UpdateMirror(ctx, ctx.Repo.Mirror); err != nil {
|
||||
ctx.Data["Err_Interval"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("repo.mirror_interval_invalid"), tplSettingsOptions, &form)
|
||||
return
|
||||
|
@ -241,7 +241,7 @@ func SettingsPost(ctx *context.Context) {
|
|||
|
||||
ctx.Repo.Mirror.LFS = form.LFS
|
||||
ctx.Repo.Mirror.LFSEndpoint = form.LFSEndpoint
|
||||
if err := repo_model.UpdateMirror(ctx.Repo.Mirror); err != nil {
|
||||
if err := repo_model.UpdateMirror(ctx, ctx.Repo.Mirror); err != nil {
|
||||
ctx.ServerError("UpdateMirror", err)
|
||||
return
|
||||
}
|
||||
|
@ -642,7 +642,7 @@ func SettingsPost(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
newOwner, err := user_model.GetUserByName(ctx.FormString("new_owner_name"))
|
||||
newOwner, err := user_model.GetUserByName(ctx, ctx.FormString("new_owner_name"))
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_owner_name"), tplSettingsOptions, nil)
|
||||
|
@ -840,7 +840,7 @@ func Collaboration(ctx *context.Context) {
|
|||
}
|
||||
ctx.Data["Collaborators"] = users
|
||||
|
||||
teams, err := organization.GetRepoTeams(ctx.Repo.Repository)
|
||||
teams, err := organization.GetRepoTeams(ctx, ctx.Repo.Repository)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetRepoTeams", err)
|
||||
return
|
||||
|
@ -863,7 +863,7 @@ func CollaborationPost(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
u, err := user_model.GetUserByName(name)
|
||||
u, err := user_model.GetUserByName(ctx, name)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.Flash.Error(ctx.Tr("form.user_not_exist"))
|
||||
|
@ -983,7 +983,7 @@ func DeleteTeam(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
team, err := organization.GetTeamByID(ctx.FormInt64("id"))
|
||||
team, err := organization.GetTeamByID(ctx, ctx.FormInt64("id"))
|
||||
if err != nil {
|
||||
ctx.ServerError("GetTeamByID", err)
|
||||
return
|
||||
|
@ -1215,6 +1215,7 @@ func selectPushMirrorByForm(form *forms.RepoSettingForm, repo *repo_model.Reposi
|
|||
|
||||
for _, m := range pushMirrors {
|
||||
if m.ID == id {
|
||||
m.Repo = repo
|
||||
return m, nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -111,7 +111,7 @@ func SettingsProtectedBranch(c *context.Context) {
|
|||
c.Data["Title"] = c.Tr("repo.settings.protected_branch") + " - " + branch
|
||||
c.Data["PageIsSettingsBranches"] = true
|
||||
|
||||
protectBranch, err := models.GetProtectedBranchBy(c.Repo.Repository.ID, branch)
|
||||
protectBranch, err := models.GetProtectedBranchBy(c, c.Repo.Repository.ID, branch)
|
||||
if err != nil {
|
||||
if !git.IsErrBranchNotExist(err) {
|
||||
c.ServerError("GetProtectBranchOfRepoByName", err)
|
||||
|
@ -184,7 +184,7 @@ func SettingsProtectedBranchPost(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
protectBranch, err := models.GetProtectedBranchBy(ctx.Repo.Repository.ID, branch)
|
||||
protectBranch, err := models.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branch)
|
||||
if err != nil {
|
||||
if !git.IsErrBranchNotExist(err) {
|
||||
ctx.ServerError("GetProtectBranchOfRepoByName", err)
|
||||
|
|
|
@ -684,7 +684,7 @@ func checkHomeCodeViewable(ctx *context.Context) {
|
|||
|
||||
if ctx.IsSigned {
|
||||
// Set repo notification-status read if unread
|
||||
if err := models.SetRepoReadBy(ctx.Repo.Repository.ID, ctx.Doer.ID); err != nil {
|
||||
if err := models.SetRepoReadBy(ctx, ctx.Repo.Repository.ID, ctx.Doer.ID); err != nil {
|
||||
ctx.ServerError("ReadBy", err)
|
||||
return
|
||||
}
|
||||
|
@ -839,7 +839,7 @@ func renderDirectoryFiles(ctx *context.Context, timeout time.Duration) git.Entri
|
|||
ctx.Data["LatestCommitUser"] = user_model.ValidateCommitWithEmail(latestCommit)
|
||||
}
|
||||
|
||||
statuses, _, err := models.GetLatestCommitStatus(ctx.Repo.Repository.ID, ctx.Repo.Commit.ID.String(), db.ListOptions{})
|
||||
statuses, _, err := models.GetLatestCommitStatus(ctx, ctx.Repo.Repository.ID, ctx.Repo.Commit.ID.String(), db.ListOptions{})
|
||||
if err != nil {
|
||||
log.Error("GetLatestCommitStatus: %v", err)
|
||||
}
|
||||
|
@ -901,7 +901,7 @@ func renderCode(ctx *context.Context) {
|
|||
// it's possible for a repository to be non-empty by that flag but still 500
|
||||
// because there are no branches - only tags -or the default branch is non-extant as it has been 0-pushed.
|
||||
ctx.Repo.Repository.IsEmpty = false
|
||||
if err = repo_model.UpdateRepositoryCols(ctx.Repo.Repository, "is_empty"); err != nil {
|
||||
if err = repo_model.UpdateRepositoryCols(ctx, ctx.Repo.Repository, "is_empty"); err != nil {
|
||||
ctx.ServerError("UpdateRepositoryCols", err)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ func Webhooks(ctx *context.Context) {
|
|||
ctx.Data["BaseLinkNew"] = ctx.Repo.RepoLink + "/settings/hooks"
|
||||
ctx.Data["Description"] = ctx.Tr("repo.settings.hooks_desc", "https://docs.gitea.io/en-us/webhooks/")
|
||||
|
||||
ws, err := webhook.ListWebhooksByOpts(&webhook.ListWebhookOptions{RepoID: ctx.Repo.Repository.ID})
|
||||
ws, err := webhook.ListWebhooksByOpts(ctx, &webhook.ListWebhookOptions{RepoID: ctx.Repo.Repository.ID})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetWebhooksByRepoID", err)
|
||||
return
|
||||
|
|
|
@ -30,7 +30,7 @@ func AvatarByUserName(ctx *context.Context) {
|
|||
var user *user_model.User
|
||||
if strings.ToLower(userName) != "ghost" {
|
||||
var err error
|
||||
if user, err = user_model.GetUserByName(userName); err != nil {
|
||||
if user, err = user_model.GetUserByName(ctx, userName); err != nil {
|
||||
ctx.ServerError("Invalid user: "+userName, err)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -615,7 +615,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
|
|||
|
||||
ctx.Data["Issues"] = issues
|
||||
|
||||
approvalCounts, err := models.IssueList(issues).GetApprovalCounts()
|
||||
approvalCounts, err := models.IssueList(issues).GetApprovalCounts(ctx)
|
||||
if err != nil {
|
||||
ctx.ServerError("ApprovalCounts", err)
|
||||
return
|
||||
|
|
|
@ -34,7 +34,7 @@ func GetNotificationCount(c *context.Context) {
|
|||
}
|
||||
|
||||
c.Data["NotificationUnreadCount"] = func() int64 {
|
||||
count, err := models.GetNotificationCount(c.Doer, models.NotificationStatusUnread)
|
||||
count, err := models.GetNotificationCount(c, c.Doer, models.NotificationStatusUnread)
|
||||
if err != nil {
|
||||
c.ServerError("GetNotificationCount", err)
|
||||
return -1
|
||||
|
@ -79,7 +79,7 @@ func getNotifications(c *context.Context) {
|
|||
status = models.NotificationStatusUnread
|
||||
}
|
||||
|
||||
total, err := models.GetNotificationCount(c.Doer, status)
|
||||
total, err := models.GetNotificationCount(c, c.Doer, status)
|
||||
if err != nil {
|
||||
c.ServerError("ErrGetNotificationCount", err)
|
||||
return
|
||||
|
@ -93,7 +93,7 @@ func getNotifications(c *context.Context) {
|
|||
}
|
||||
|
||||
statuses := []models.NotificationStatus{status, models.NotificationStatusPinned}
|
||||
notifications, err := models.NotificationsForUser(c.Doer, statuses, page, perPage)
|
||||
notifications, err := models.NotificationsForUser(c, c.Doer, statuses, page, perPage)
|
||||
if err != nil {
|
||||
c.ServerError("ErrNotificationsForUser", err)
|
||||
return
|
||||
|
@ -195,5 +195,5 @@ func NotificationPurgePost(c *context.Context) {
|
|||
|
||||
// NewAvailable returns the notification counts
|
||||
func NewAvailable(ctx *context.Context) {
|
||||
ctx.JSON(http.StatusOK, structs.NotificationCount{New: models.CountUnread(ctx.Doer)})
|
||||
ctx.JSON(http.StatusOK, structs.NotificationCount{New: models.CountUnread(ctx, ctx.Doer.ID)})
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ func Profile(ctx *context.Context) {
|
|||
}
|
||||
|
||||
// check view permissions
|
||||
if !user_model.IsUserVisibleToViewer(ctx.ContextUser, ctx.Doer) {
|
||||
if !user_model.IsUserVisibleToViewer(ctx, ctx.ContextUser, ctx.Doer) {
|
||||
ctx.NotFound("user", fmt.Errorf(ctx.ContextUser.Name))
|
||||
return
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ func Profile(ctx *context.Context) {
|
|||
|
||||
total = int(count)
|
||||
case "projects":
|
||||
ctx.Data["OpenProjects"], _, err = project_model.GetProjects(project_model.SearchOptions{
|
||||
ctx.Data["OpenProjects"], _, err = project_model.GetProjects(ctx, project_model.SearchOptions{
|
||||
Page: -1,
|
||||
IsClosed: util.OptionalBoolFalse,
|
||||
Type: project_model.TypeIndividual,
|
||||
|
|
|
@ -181,7 +181,7 @@ func EmailPost(ctx *context.Context) {
|
|||
Email: form.Email,
|
||||
IsActivated: !setting.Service.RegisterEmailConfirm,
|
||||
}
|
||||
if err := user_model.AddEmailAddress(email); err != nil {
|
||||
if err := user_model.AddEmailAddress(ctx, email); err != nil {
|
||||
if user_model.IsErrEmailAlreadyUsed(err) {
|
||||
loadAccountData(ctx)
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ func AdoptOrDeleteRepository(ctx *context.Context) {
|
|||
root := user_model.UserPath(ctxUser.LowerName)
|
||||
|
||||
// check not a repo
|
||||
has, err := repo_model.IsRepositoryExist(ctxUser, dir)
|
||||
has, err := repo_model.IsRepositoryExist(ctx, ctxUser, dir)
|
||||
if err != nil {
|
||||
ctx.ServerError("IsRepositoryExist", err)
|
||||
return
|
||||
|
|
|
@ -93,12 +93,12 @@ func loadApplicationsData(ctx *context.Context) {
|
|||
ctx.Data["Tokens"] = tokens
|
||||
ctx.Data["EnableOAuth2"] = setting.OAuth2.Enable
|
||||
if setting.OAuth2.Enable {
|
||||
ctx.Data["Applications"], err = auth.GetOAuth2ApplicationsByUserID(ctx.Doer.ID)
|
||||
ctx.Data["Applications"], err = auth.GetOAuth2ApplicationsByUserID(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetOAuth2ApplicationsByUserID", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["Grants"], err = auth.GetOAuth2GrantsByUserID(ctx.Doer.ID)
|
||||
ctx.Data["Grants"], err = auth.GetOAuth2GrantsByUserID(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetOAuth2GrantsByUserID", err)
|
||||
return
|
||||
|
|
|
@ -34,7 +34,7 @@ func OAuthApplicationsPost(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
// TODO validate redirect URI
|
||||
app, err := auth.CreateOAuth2Application(auth.CreateOAuth2ApplicationOptions{
|
||||
app, err := auth.CreateOAuth2Application(ctx, auth.CreateOAuth2ApplicationOptions{
|
||||
Name: form.Name,
|
||||
RedirectURIs: []string{form.RedirectURI},
|
||||
UserID: ctx.Doer.ID,
|
||||
|
@ -85,7 +85,7 @@ func OAuthApplicationsRegenerateSecret(ctx *context.Context) {
|
|||
ctx.Data["Title"] = ctx.Tr("settings")
|
||||
ctx.Data["PageIsSettingsApplications"] = true
|
||||
|
||||
app, err := auth.GetOAuth2ApplicationByID(ctx.ParamsInt64("id"))
|
||||
app, err := auth.GetOAuth2ApplicationByID(ctx, ctx.ParamsInt64("id"))
|
||||
if err != nil {
|
||||
if auth.IsErrOAuthApplicationNotFound(err) {
|
||||
ctx.NotFound("Application not found", err)
|
||||
|
@ -110,7 +110,7 @@ func OAuthApplicationsRegenerateSecret(ctx *context.Context) {
|
|||
|
||||
// OAuth2ApplicationShow displays the given application
|
||||
func OAuth2ApplicationShow(ctx *context.Context) {
|
||||
app, err := auth.GetOAuth2ApplicationByID(ctx.ParamsInt64("id"))
|
||||
app, err := auth.GetOAuth2ApplicationByID(ctx, ctx.ParamsInt64("id"))
|
||||
if err != nil {
|
||||
if auth.IsErrOAuthApplicationNotFound(err) {
|
||||
ctx.NotFound("Application not found", err)
|
||||
|
@ -147,7 +147,7 @@ func RevokeOAuth2Grant(ctx *context.Context) {
|
|||
ctx.ServerError("RevokeOAuth2Grant", fmt.Errorf("user id or grant id is zero"))
|
||||
return
|
||||
}
|
||||
if err := auth.RevokeOAuth2Grant(ctx.FormInt64("id"), ctx.Doer.ID); err != nil {
|
||||
if err := auth.RevokeOAuth2Grant(ctx, ctx.FormInt64("id"), ctx.Doer.ID); err != nil {
|
||||
ctx.ServerError("RevokeOAuth2Grant", err)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -180,7 +180,7 @@ func UpdateAvatarSetting(ctx *context.Context, form *forms.AvatarForm, ctxUser *
|
|||
} else if ctxUser.UseCustomAvatar && ctxUser.Avatar == "" {
|
||||
// No avatar is uploaded but setting has been changed to enable,
|
||||
// generate a random one when needed.
|
||||
if err := user_model.GenerateRandomAvatar(ctxUser); err != nil {
|
||||
if err := user_model.GenerateRandomAvatar(ctx, ctxUser); err != nil {
|
||||
log.Error("GenerateRandomAvatar[%d]: %v", ctxUser.ID, err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ func settingsOpenIDVerify(ctx *context.Context) {
|
|||
log.Trace("Verified ID: " + id)
|
||||
|
||||
oid := &user_model.UserOpenID{UID: ctx.Doer.ID, URI: id}
|
||||
if err = user_model.AddUserOpenID(oid); err != nil {
|
||||
if err = user_model.AddUserOpenID(ctx, oid); err != nil {
|
||||
if user_model.IsErrOpenIDAlreadyUsed(err) {
|
||||
ctx.RenderWithErr(ctx.Tr("form.openid_been_used", id), tplSettingsSecurity, &forms.AddOpenIDForm{Openid: id})
|
||||
return
|
||||
|
|
|
@ -59,7 +59,7 @@ func WebfingerQuery(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
u, err = user_model.GetUserByNameCtx(ctx, parts[0])
|
||||
u, err = user_model.GetUserByName(ctx, parts[0])
|
||||
case "mailto":
|
||||
u, err = user_model.GetUserByEmailContext(ctx, resource.Opaque)
|
||||
if u != nil && u.KeepEmailPrivate {
|
||||
|
@ -79,7 +79,7 @@ func WebfingerQuery(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if !user_model.IsUserVisibleToViewer(u, ctx.Doer) {
|
||||
if !user_model.IsUserVisibleToViewer(ctx, u, ctx.Doer) {
|
||||
ctx.Error(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue