mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Even more db.DefaultContext
refactor (#27352)
Part of #27065 --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: delvh <dev.lh@web.de>
This commit is contained in:
@@ -62,7 +62,7 @@ func CreateOrg(ctx *context.APIContext) {
|
||||
Visibility: visibility,
|
||||
}
|
||||
|
||||
if err := organization.CreateOrganization(org, ctx.ContextUser); err != nil {
|
||||
if err := organization.CreateOrganization(ctx, org, ctx.ContextUser); err != nil {
|
||||
if user_model.IsErrUserAlreadyExist(err) ||
|
||||
db.IsErrNameReserved(err) ||
|
||||
db.IsErrNameCharsNotAllowed(err) ||
|
||||
|
@@ -25,7 +25,7 @@ func listMembers(ctx *context.APIContext, publicOnly bool) {
|
||||
ListOptions: utils.GetListOptions(ctx),
|
||||
}
|
||||
|
||||
count, err := organization.CountOrgMembers(opts)
|
||||
count, err := organization.CountOrgMembers(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
@@ -75,7 +75,7 @@ func ListMembers(ctx *context.APIContext) {
|
||||
|
||||
publicOnly := true
|
||||
if ctx.Doer != nil {
|
||||
isMember, err := ctx.Org.Organization.IsOrgMember(ctx.Doer.ID)
|
||||
isMember, err := ctx.Org.Organization.IsOrgMember(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "IsOrgMember", err)
|
||||
return
|
||||
@@ -144,12 +144,12 @@ func IsMember(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
if ctx.Doer != nil {
|
||||
userIsMember, err := ctx.Org.Organization.IsOrgMember(ctx.Doer.ID)
|
||||
userIsMember, err := ctx.Org.Organization.IsOrgMember(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "IsOrgMember", err)
|
||||
return
|
||||
} else if userIsMember || ctx.Doer.IsAdmin {
|
||||
userToCheckIsMember, err := ctx.Org.Organization.IsOrgMember(userToCheck.ID)
|
||||
userToCheckIsMember, err := ctx.Org.Organization.IsOrgMember(ctx, userToCheck.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "IsOrgMember", err)
|
||||
} else if userToCheckIsMember {
|
||||
@@ -194,7 +194,7 @@ func IsPublicMember(ctx *context.APIContext) {
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
is, err := organization.IsPublicMembership(ctx.Org.Organization.ID, userToCheck.ID)
|
||||
is, err := organization.IsPublicMembership(ctx, ctx.Org.Organization.ID, userToCheck.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "IsPublicMembership", err)
|
||||
return
|
||||
@@ -240,7 +240,7 @@ func PublicizeMember(ctx *context.APIContext) {
|
||||
ctx.Error(http.StatusForbidden, "", "Cannot publicize another member")
|
||||
return
|
||||
}
|
||||
err := organization.ChangeOrgUserStatus(ctx.Org.Organization.ID, userToPublicize.ID, true)
|
||||
err := organization.ChangeOrgUserStatus(ctx, ctx.Org.Organization.ID, userToPublicize.ID, true)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "ChangeOrgUserStatus", err)
|
||||
return
|
||||
@@ -282,7 +282,7 @@ func ConcealMember(ctx *context.APIContext) {
|
||||
ctx.Error(http.StatusForbidden, "", "Cannot conceal another member")
|
||||
return
|
||||
}
|
||||
err := organization.ChangeOrgUserStatus(ctx.Org.Organization.ID, userToConceal.ID, false)
|
||||
err := organization.ChangeOrgUserStatus(ctx, ctx.Org.Organization.ID, userToConceal.ID, false)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "ChangeOrgUserStatus", err)
|
||||
return
|
||||
|
@@ -30,12 +30,12 @@ func listUserOrgs(ctx *context.APIContext, u *user_model.User) {
|
||||
UserID: u.ID,
|
||||
IncludePrivate: showPrivate,
|
||||
}
|
||||
orgs, err := organization.FindOrgs(opts)
|
||||
orgs, err := organization.FindOrgs(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "FindOrgs", err)
|
||||
return
|
||||
}
|
||||
maxResults, err := organization.CountOrgs(opts)
|
||||
maxResults, err := organization.CountOrgs(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "CountOrgs", err)
|
||||
return
|
||||
@@ -145,7 +145,7 @@ func GetUserOrgsPermissions(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
org := organization.OrgFromUser(o)
|
||||
authorizeLevel, err := org.GetOrgUserMaxAuthorizeLevel(ctx.ContextUser.ID)
|
||||
authorizeLevel, err := org.GetOrgUserMaxAuthorizeLevel(ctx, ctx.ContextUser.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetOrgUserAuthorizeLevel", err)
|
||||
return
|
||||
@@ -164,7 +164,7 @@ func GetUserOrgsPermissions(ctx *context.APIContext) {
|
||||
op.IsOwner = true
|
||||
}
|
||||
|
||||
op.CanCreateRepository, err = org.CanCreateOrgRepo(ctx.ContextUser.ID)
|
||||
op.CanCreateRepository, err = org.CanCreateOrgRepo(ctx, ctx.ContextUser.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "CanCreateOrgRepo", err)
|
||||
return
|
||||
@@ -268,7 +268,7 @@ func Create(ctx *context.APIContext) {
|
||||
Visibility: visibility,
|
||||
RepoAdminChangeTeamAccess: form.RepoAdminChangeTeamAccess,
|
||||
}
|
||||
if err := organization.CreateOrganization(org, ctx.Doer); err != nil {
|
||||
if err := organization.CreateOrganization(ctx, org, ctx.Doer); err != nil {
|
||||
if user_model.IsErrUserAlreadyExist(err) ||
|
||||
db.IsErrNameReserved(err) ||
|
||||
db.IsErrNameCharsNotAllowed(err) ||
|
||||
@@ -429,7 +429,7 @@ func ListOrgActivityFeeds(ctx *context.APIContext) {
|
||||
includePrivate = true
|
||||
} else {
|
||||
org := organization.OrgFromUser(ctx.ContextUser)
|
||||
isMember, err := org.IsOrgMember(ctx.Doer.ID)
|
||||
isMember, err := org.IsOrgMember(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "IsOrgMember", err)
|
||||
return
|
||||
|
@@ -572,7 +572,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
|
||||
}
|
||||
var whitelistTeams, mergeWhitelistTeams, approvalsWhitelistTeams []int64
|
||||
if repo.Owner.IsOrganization() {
|
||||
whitelistTeams, err = organization.GetTeamIDsByNames(repo.OwnerID, form.PushWhitelistTeams, false)
|
||||
whitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.PushWhitelistTeams, false)
|
||||
if err != nil {
|
||||
if organization.IsErrTeamNotExist(err) {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "Team does not exist", err)
|
||||
@@ -581,7 +581,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
|
||||
ctx.Error(http.StatusInternalServerError, "GetTeamIDsByNames", err)
|
||||
return
|
||||
}
|
||||
mergeWhitelistTeams, err = organization.GetTeamIDsByNames(repo.OwnerID, form.MergeWhitelistTeams, false)
|
||||
mergeWhitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.MergeWhitelistTeams, false)
|
||||
if err != nil {
|
||||
if organization.IsErrTeamNotExist(err) {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "Team does not exist", err)
|
||||
@@ -590,7 +590,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
|
||||
ctx.Error(http.StatusInternalServerError, "GetTeamIDsByNames", err)
|
||||
return
|
||||
}
|
||||
approvalsWhitelistTeams, err = organization.GetTeamIDsByNames(repo.OwnerID, form.ApprovalsWhitelistTeams, false)
|
||||
approvalsWhitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.ApprovalsWhitelistTeams, false)
|
||||
if err != nil {
|
||||
if organization.IsErrTeamNotExist(err) {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "Team does not exist", err)
|
||||
@@ -848,7 +848,7 @@ func EditBranchProtection(ctx *context.APIContext) {
|
||||
var whitelistTeams, mergeWhitelistTeams, approvalsWhitelistTeams []int64
|
||||
if repo.Owner.IsOrganization() {
|
||||
if form.PushWhitelistTeams != nil {
|
||||
whitelistTeams, err = organization.GetTeamIDsByNames(repo.OwnerID, form.PushWhitelistTeams, false)
|
||||
whitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.PushWhitelistTeams, false)
|
||||
if err != nil {
|
||||
if organization.IsErrTeamNotExist(err) {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "Team does not exist", err)
|
||||
@@ -861,7 +861,7 @@ func EditBranchProtection(ctx *context.APIContext) {
|
||||
whitelistTeams = protectBranch.WhitelistTeamIDs
|
||||
}
|
||||
if form.MergeWhitelistTeams != nil {
|
||||
mergeWhitelistTeams, err = organization.GetTeamIDsByNames(repo.OwnerID, form.MergeWhitelistTeams, false)
|
||||
mergeWhitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.MergeWhitelistTeams, false)
|
||||
if err != nil {
|
||||
if organization.IsErrTeamNotExist(err) {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "Team does not exist", err)
|
||||
@@ -874,7 +874,7 @@ func EditBranchProtection(ctx *context.APIContext) {
|
||||
mergeWhitelistTeams = protectBranch.MergeWhitelistTeamIDs
|
||||
}
|
||||
if form.ApprovalsWhitelistTeams != nil {
|
||||
approvalsWhitelistTeams, err = organization.GetTeamIDsByNames(repo.OwnerID, form.ApprovalsWhitelistTeams, false)
|
||||
approvalsWhitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.ApprovalsWhitelistTeams, false)
|
||||
if err != nil {
|
||||
if organization.IsErrTeamNotExist(err) {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "Team does not exist", err)
|
||||
|
@@ -123,7 +123,7 @@ func CreateFork(ctx *context.APIContext) {
|
||||
}
|
||||
return
|
||||
}
|
||||
isMember, err := org.IsOrgMember(ctx.Doer.ID)
|
||||
isMember, err := org.IsOrgMember(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "IsOrgMember", err)
|
||||
return
|
||||
|
@@ -844,7 +844,7 @@ func EditIssue(ctx *context.APIContext) {
|
||||
}
|
||||
if form.State != nil {
|
||||
if issue.IsPull {
|
||||
if pr, err := issue.GetPullRequest(); err != nil {
|
||||
if pr, err := issue.GetPullRequest(ctx); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetPullRequest", err)
|
||||
return
|
||||
} else if pr.HasMerged {
|
||||
|
@@ -178,7 +178,7 @@ func CreateIssueAttachment(ctx *context.APIContext) {
|
||||
filename = query
|
||||
}
|
||||
|
||||
attachment, err := attachment.UploadAttachment(file, setting.Attachment.AllowedTypes, header.Size, &repo_model.Attachment{
|
||||
attachment, err := attachment.UploadAttachment(ctx, file, setting.Attachment.AllowedTypes, header.Size, &repo_model.Attachment{
|
||||
Name: filename,
|
||||
UploaderID: ctx.Doer.ID,
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
|
@@ -182,7 +182,7 @@ func CreateIssueCommentAttachment(ctx *context.APIContext) {
|
||||
filename = query
|
||||
}
|
||||
|
||||
attachment, err := attachment.UploadAttachment(file, setting.Attachment.AllowedTypes, header.Size, &repo_model.Attachment{
|
||||
attachment, err := attachment.UploadAttachment(ctx, file, setting.Attachment.AllowedTypes, header.Size, &repo_model.Attachment{
|
||||
Name: filename,
|
||||
UploaderID: ctx.Doer.ID,
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
|
@@ -241,7 +241,7 @@ func ListPinnedPullRequests(ctx *context.APIContext) {
|
||||
|
||||
apiPrs := make([]*api.PullRequest, len(issues))
|
||||
for i, currentIssue := range issues {
|
||||
pr, err := currentIssue.GetPullRequest()
|
||||
pr, err := currentIssue.GetPullRequest(ctx)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetPullRequest", err)
|
||||
return
|
||||
|
@@ -206,7 +206,7 @@ func CheckIssueSubscription(ctx *context.APIContext) {
|
||||
Ignored: !watching,
|
||||
Reason: nil,
|
||||
CreatedAt: issue.CreatedUnix.AsTime(),
|
||||
URL: issue.APIURL() + "/subscriptions",
|
||||
URL: issue.APIURL(ctx) + "/subscriptions",
|
||||
RepositoryURL: ctx.Repo.Repository.APIURL(),
|
||||
})
|
||||
}
|
||||
|
@@ -283,7 +283,7 @@ func ResetIssueTime(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
err = issues_model.DeleteIssueUserTimes(issue, ctx.Doer)
|
||||
err = issues_model.DeleteIssueUserTimes(ctx, issue, ctx.Doer)
|
||||
if err != nil {
|
||||
if db.IsErrNotExist(err) {
|
||||
ctx.Error(http.StatusNotFound, "DeleteIssueUserTimes", err)
|
||||
@@ -356,7 +356,7 @@ func DeleteTime(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
time, err := issues_model.GetTrackedTimeByID(ctx.ParamsInt64(":id"))
|
||||
time, err := issues_model.GetTrackedTimeByID(ctx, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if db.IsErrNotExist(err) {
|
||||
ctx.NotFound(err)
|
||||
@@ -376,7 +376,7 @@ func DeleteTime(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
err = issues_model.DeleteTime(time)
|
||||
err = issues_model.DeleteTime(ctx, time)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "DeleteTime", err)
|
||||
return
|
||||
|
@@ -93,7 +93,7 @@ func Migrate(ctx *context.APIContext) {
|
||||
|
||||
if repoOwner.IsOrganization() {
|
||||
// Check ownership of organization.
|
||||
isOwner, err := organization.OrgFromUser(repoOwner).IsOwnedBy(ctx.Doer.ID)
|
||||
isOwner, err := organization.OrgFromUser(repoOwner).IsOwnedBy(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "IsOwnedBy", err)
|
||||
return
|
||||
|
@@ -176,7 +176,7 @@ func ListPushMirrors(ctx *context.APIContext) {
|
||||
|
||||
responsePushMirrors := make([]*api.PushMirror, 0, len(pushMirrors))
|
||||
for _, mirror := range pushMirrors {
|
||||
m, err := convert.ToPushMirror(mirror)
|
||||
m, err := convert.ToPushMirror(ctx, mirror)
|
||||
if err == nil {
|
||||
responsePushMirrors = append(responsePushMirrors, m)
|
||||
}
|
||||
@@ -232,7 +232,7 @@ func GetPushMirrorByName(ctx *context.APIContext) {
|
||||
ctx.Error(http.StatusNotFound, "GetPushMirrors", err)
|
||||
return
|
||||
}
|
||||
m, err := convert.ToPushMirror(pushMirror)
|
||||
m, err := convert.ToPushMirror(ctx, pushMirror)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetPushMirrorByRemoteName", err)
|
||||
return
|
||||
@@ -381,7 +381,7 @@ func CreatePushMirror(ctx *context.APIContext, mirrorOption *api.CreatePushMirro
|
||||
ctx.ServerError("AddPushMirrorRemote", err)
|
||||
return
|
||||
}
|
||||
m, err := convert.ToPushMirror(pushMirror)
|
||||
m, err := convert.ToPushMirror(ctx, pushMirror)
|
||||
if err != nil {
|
||||
ctx.ServerError("ToPushMirror", err)
|
||||
return
|
||||
|
@@ -1442,7 +1442,7 @@ func GetPullRequestFiles(ctx *context.APIContext) {
|
||||
maxLines := setting.Git.MaxGitDiffLines
|
||||
|
||||
// FIXME: If there are too many files in the repo, may cause some unpredictable issues.
|
||||
diff, err := gitdiff.GetDiff(baseGitRepo,
|
||||
diff, err := gitdiff.GetDiff(ctx, baseGitRepo,
|
||||
&gitdiff.DiffOptions{
|
||||
BeforeCommitID: startCommitID,
|
||||
AfterCommitID: endCommitID,
|
||||
|
@@ -200,7 +200,7 @@ func CreateReleaseAttachment(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
// Create a new attachment and save the file
|
||||
attach, err := attachment.UploadAttachment(file, setting.Repository.Release.AllowedTypes, header.Size, &repo_model.Attachment{
|
||||
attach, err := attachment.UploadAttachment(ctx, file, setting.Repository.Release.AllowedTypes, header.Size, &repo_model.Attachment{
|
||||
Name: filename,
|
||||
UploaderID: ctx.Doer.ID,
|
||||
RepoID: release.RepoID,
|
||||
|
@@ -396,7 +396,7 @@ func Generate(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
if !ctx.Doer.IsAdmin {
|
||||
canCreate, err := organization.OrgFromUser(ctxUser).CanCreateOrgRepo(ctx.Doer.ID)
|
||||
canCreate, err := organization.OrgFromUser(ctxUser).CanCreateOrgRepo(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("CanCreateOrgRepo", err)
|
||||
return
|
||||
@@ -502,7 +502,7 @@ func CreateOrgRepo(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
if !ctx.Doer.IsAdmin {
|
||||
canCreate, err := org.CanCreateOrgRepo(ctx.Doer.ID)
|
||||
canCreate, err := org.CanCreateOrgRepo(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "CanCreateOrgRepo", err)
|
||||
return
|
||||
@@ -982,7 +982,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
|
||||
}
|
||||
|
||||
if len(units)+len(deleteUnitTypes) > 0 {
|
||||
if err := repo_model.UpdateRepositoryUnits(repo, units, deleteUnitTypes); err != nil {
|
||||
if err := repo_model.UpdateRepositoryUnits(ctx, repo, units, deleteUnitTypes); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "UpdateRepositoryUnits", err)
|
||||
return err
|
||||
}
|
||||
|
@@ -68,7 +68,7 @@ func Transfer(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
if newOwner.Type == user_model.UserTypeOrganization {
|
||||
if !ctx.Doer.IsAdmin && newOwner.Visibility == api.VisibleTypePrivate && !organization.OrgFromUser(newOwner).HasMemberWithUserID(ctx.Doer.ID) {
|
||||
if !ctx.Doer.IsAdmin && newOwner.Visibility == api.VisibleTypePrivate && !organization.OrgFromUser(newOwner).HasMemberWithUserID(ctx, ctx.Doer.ID) {
|
||||
// The user shouldn't know about this organization
|
||||
ctx.Error(http.StatusNotFound, "", "The new owner does not exist or cannot be found")
|
||||
return
|
||||
|
@@ -24,7 +24,7 @@ func Notices(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("admin.notices")
|
||||
ctx.Data["PageIsAdminNotices"] = true
|
||||
|
||||
total := system_model.CountNotices()
|
||||
total := system_model.CountNotices(ctx)
|
||||
page := ctx.FormInt("page")
|
||||
if page <= 1 {
|
||||
page = 1
|
||||
|
@@ -290,7 +290,7 @@ func ViewUser(ctx *context.Context) {
|
||||
ctx.Data["Emails"] = emails
|
||||
ctx.Data["EmailsTotal"] = len(emails)
|
||||
|
||||
orgs, err := org_model.FindOrgs(org_model.FindOrgOptions{
|
||||
orgs, err := org_model.FindOrgs(ctx, org_model.FindOrgOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
ListAll: true,
|
||||
},
|
||||
|
@@ -312,12 +312,12 @@ func getOAuthGroupsForUser(ctx go_context.Context, user *user_model.User) ([]str
|
||||
var groups []string
|
||||
for _, org := range orgs {
|
||||
groups = append(groups, org.Name)
|
||||
teams, err := org.LoadTeams()
|
||||
teams, err := org.LoadTeams(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("LoadTeams: %w", err)
|
||||
}
|
||||
for _, team := range teams {
|
||||
if team.IsMember(user.ID) {
|
||||
if team.IsMember(ctx, user.ID) {
|
||||
groups = append(groups, org.Name+":"+team.LowerName)
|
||||
}
|
||||
}
|
||||
|
@@ -38,7 +38,7 @@ func Members(ctx *context.Context) {
|
||||
}
|
||||
|
||||
if ctx.Doer != nil {
|
||||
isMember, err := ctx.Org.Organization.IsOrgMember(ctx.Doer.ID)
|
||||
isMember, err := ctx.Org.Organization.IsOrgMember(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "IsOrgMember")
|
||||
return
|
||||
@@ -47,7 +47,7 @@ func Members(ctx *context.Context) {
|
||||
}
|
||||
ctx.Data["PublicOnly"] = opts.PublicOnly
|
||||
|
||||
total, err := organization.CountOrgMembers(opts)
|
||||
total, err := organization.CountOrgMembers(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "CountOrgMembers")
|
||||
return
|
||||
@@ -70,7 +70,7 @@ func Members(ctx *context.Context) {
|
||||
ctx.Data["Page"] = pager
|
||||
ctx.Data["Members"] = members
|
||||
ctx.Data["MembersIsPublicMember"] = membersIsPublic
|
||||
ctx.Data["MembersIsUserOrgOwner"] = organization.IsUserOrgOwner(members, org.ID)
|
||||
ctx.Data["MembersIsUserOrgOwner"] = organization.IsUserOrgOwner(ctx, members, org.ID)
|
||||
ctx.Data["MembersTwoFaStatus"] = members.GetTwoFaStatus(ctx)
|
||||
|
||||
ctx.HTML(http.StatusOK, tplMembers)
|
||||
@@ -92,13 +92,13 @@ func MembersAction(ctx *context.Context) {
|
||||
ctx.Error(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
err = organization.ChangeOrgUserStatus(org.ID, uid, false)
|
||||
err = organization.ChangeOrgUserStatus(ctx, org.ID, uid, false)
|
||||
case "public":
|
||||
if ctx.Doer.ID != uid && !ctx.Org.IsOwner {
|
||||
ctx.Error(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
err = organization.ChangeOrgUserStatus(org.ID, uid, true)
|
||||
err = organization.ChangeOrgUserStatus(ctx, org.ID, uid, true)
|
||||
case "remove":
|
||||
if !ctx.Org.IsOwner {
|
||||
ctx.Error(http.StatusNotFound)
|
||||
|
@@ -58,7 +58,7 @@ func CreatePost(ctx *context.Context) {
|
||||
RepoAdminChangeTeamAccess: form.RepoAdminChangeTeamAccess,
|
||||
}
|
||||
|
||||
if err := organization.CreateOrganization(org, ctx.Doer); err != nil {
|
||||
if err := organization.CreateOrganization(ctx, org, ctx.Doer); err != nil {
|
||||
ctx.Data["Err_OrgName"] = true
|
||||
switch {
|
||||
case user_model.IsErrUserAlreadyExist(err):
|
||||
|
@@ -159,7 +159,7 @@ func TeamsAction(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if ctx.Org.Team.IsMember(u.ID) {
|
||||
if ctx.Org.Team.IsMember(ctx, u.ID) {
|
||||
ctx.Flash.Error(ctx.Tr("org.teams.add_duplicate_users"))
|
||||
} else {
|
||||
err = models.AddTeamMember(ctx, ctx.Org.Team, u.ID)
|
||||
|
@@ -608,7 +608,7 @@ func disableOrEnableWorkflowFile(ctx *context_module.Context, isEnable bool) {
|
||||
cfg.DisableWorkflow(workflow)
|
||||
}
|
||||
|
||||
if err := repo_model.UpdateRepoUnit(cfgUnit); err != nil {
|
||||
if err := repo_model.UpdateRepoUnit(ctx, cfgUnit); err != nil {
|
||||
ctx.ServerError("UpdateRepoUnit", err)
|
||||
return
|
||||
}
|
||||
|
@@ -45,7 +45,7 @@ func uploadAttachment(ctx *context.Context, repoID int64, allowedTypes string) {
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
attach, err := attachment.UploadAttachment(file, allowedTypes, header.Size, &repo_model.Attachment{
|
||||
attach, err := attachment.UploadAttachment(ctx, file, allowedTypes, header.Size, &repo_model.Attachment{
|
||||
Name: header.Filename,
|
||||
UploaderID: ctx.Doer.ID,
|
||||
RepoID: repoID,
|
||||
|
@@ -305,7 +305,7 @@ func Diff(ctx *context.Context) {
|
||||
maxLines, maxFiles = -1, -1
|
||||
}
|
||||
|
||||
diff, err := gitdiff.GetDiff(gitRepo, &gitdiff.DiffOptions{
|
||||
diff, err := gitdiff.GetDiff(ctx, gitRepo, &gitdiff.DiffOptions{
|
||||
AfterCommitID: commitID,
|
||||
SkipTo: ctx.FormString("skip-to"),
|
||||
MaxLines: maxLines,
|
||||
|
@@ -609,7 +609,7 @@ func PrepareCompareDiff(
|
||||
maxLines, maxFiles = -1, -1
|
||||
}
|
||||
|
||||
diff, err := gitdiff.GetDiff(ci.HeadGitRepo,
|
||||
diff, err := gitdiff.GetDiff(ctx, ci.HeadGitRepo,
|
||||
&gitdiff.DiffOptions{
|
||||
BeforeCommitID: beforeCommitID,
|
||||
AfterCommitID: headCommitID,
|
||||
|
@@ -305,7 +305,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
|
||||
// Check read status
|
||||
if !ctx.IsSigned {
|
||||
issues[i].IsRead = true
|
||||
} else if err = issues[i].GetIsRead(ctx.Doer.ID); err != nil {
|
||||
} else if err = issues[i].GetIsRead(ctx, ctx.Doer.ID); err != nil {
|
||||
ctx.ServerError("GetIsRead", err)
|
||||
return
|
||||
}
|
||||
@@ -1270,7 +1270,7 @@ func roleDescriptor(ctx stdCtx.Context, repo *repo_model.Repository, poster *use
|
||||
}
|
||||
|
||||
// Otherwise check if poster is the real repo admin.
|
||||
ok, err := access_model.IsUserRealRepoAdmin(repo, poster)
|
||||
ok, err := access_model.IsUserRealRepoAdmin(ctx, repo, poster)
|
||||
if err != nil {
|
||||
return roleDescriptor, err
|
||||
}
|
||||
@@ -1554,7 +1554,7 @@ func ViewIssue(ctx *context.Context) {
|
||||
} else {
|
||||
ctx.Data["CanUseTimetracker"] = false
|
||||
}
|
||||
if ctx.Data["WorkingUsers"], err = issues_model.TotalTimesForEachUser(&issues_model.FindTrackedTimesOptions{IssueID: issue.ID}); err != nil {
|
||||
if ctx.Data["WorkingUsers"], err = issues_model.TotalTimesForEachUser(ctx, &issues_model.FindTrackedTimesOptions{IssueID: issue.ID}); err != nil {
|
||||
ctx.ServerError("TotalTimesForEachUser", err)
|
||||
return
|
||||
}
|
||||
@@ -1728,7 +1728,7 @@ func ViewIssue(ctx *context.Context) {
|
||||
comment.Type == issues_model.CommentTypeStopTracking ||
|
||||
comment.Type == issues_model.CommentTypeDeleteTimeManual {
|
||||
// drop error since times could be pruned from DB..
|
||||
_ = comment.LoadTime()
|
||||
_ = comment.LoadTime(ctx)
|
||||
if comment.Content != "" {
|
||||
// Content before v1.21 did store the formated string instead of seconds,
|
||||
// so "|" is used as delimeter to mark the new format
|
||||
@@ -3579,7 +3579,7 @@ func handleTeamMentions(ctx *context.Context) {
|
||||
if ctx.Doer.IsAdmin {
|
||||
isAdmin = true
|
||||
} else {
|
||||
isAdmin, err = org.IsOwnedBy(ctx.Doer.ID)
|
||||
isAdmin, err = org.IsOwnedBy(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("IsOwnedBy", err)
|
||||
return
|
||||
@@ -3587,13 +3587,13 @@ func handleTeamMentions(ctx *context.Context) {
|
||||
}
|
||||
|
||||
if isAdmin {
|
||||
teams, err = org.LoadTeams()
|
||||
teams, err = org.LoadTeams(ctx)
|
||||
if err != nil {
|
||||
ctx.ServerError("LoadTeams", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
teams, err = org.GetUserTeams(ctx.Doer.ID)
|
||||
teams, err = org.GetUserTeams(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetUserTeams", err)
|
||||
return
|
||||
|
@@ -85,7 +85,7 @@ func RetrieveLabels(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
if ctx.Doer != nil {
|
||||
ctx.Org.IsOwner, err = org.IsOwnedBy(ctx.Doer.ID)
|
||||
ctx.Org.IsOwner, err = org.IsOwnedBy(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("org.IsOwnedBy", err)
|
||||
return
|
||||
|
@@ -61,7 +61,7 @@ func DeleteTime(c *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
t, err := issues_model.GetTrackedTimeByID(c.ParamsInt64(":timeid"))
|
||||
t, err := issues_model.GetTrackedTimeByID(c, c.ParamsInt64(":timeid"))
|
||||
if err != nil {
|
||||
if db.IsErrNotExist(err) {
|
||||
c.NotFound("time not found", err)
|
||||
@@ -77,7 +77,7 @@ func DeleteTime(c *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err = issues_model.DeleteTime(t); err != nil {
|
||||
if err = issues_model.DeleteTime(c, t); err != nil {
|
||||
c.ServerError("DeleteTime", err)
|
||||
return
|
||||
}
|
||||
|
@@ -265,7 +265,7 @@ func ForkPost(ctx *context.Context) {
|
||||
|
||||
// Check if user is allowed to create repo's on the organization.
|
||||
if ctxUser.IsOrganization() {
|
||||
isAllowedToFork, err := organization.OrgFromUser(ctxUser).CanCreateOrgRepo(ctx.Doer.ID)
|
||||
isAllowedToFork, err := organization.OrgFromUser(ctxUser).CanCreateOrgRepo(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("CanCreateOrgRepo", err)
|
||||
return
|
||||
@@ -908,7 +908,7 @@ func viewPullFiles(ctx *context.Context, specifiedStartCommit, specifiedEndCommi
|
||||
// as the viewed information is designed to be loaded only on latest PR
|
||||
// diff and if you're signed in.
|
||||
if !ctx.IsSigned || willShowSpecifiedCommit || willShowSpecifiedCommitRange {
|
||||
diff, err = gitdiff.GetDiff(gitRepo, diffOptions, files...)
|
||||
diff, err = gitdiff.GetDiff(ctx, gitRepo, diffOptions, files...)
|
||||
methodWithError = "GetDiff"
|
||||
} else {
|
||||
diff, err = gitdiff.SyncAndGetUserSpecificDiff(ctx, ctx.Doer.ID, pull, gitRepo, diffOptions, files...)
|
||||
|
@@ -119,7 +119,7 @@ func checkContextUser(ctx *context.Context, uid int64) *user_model.User {
|
||||
return nil
|
||||
}
|
||||
if !ctx.Doer.IsAdmin {
|
||||
canCreate, err := organization.OrgFromUser(org).CanCreateOrgRepo(ctx.Doer.ID)
|
||||
canCreate, err := organization.OrgFromUser(org).CanCreateOrgRepo(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("CanCreateOrgRepo", err)
|
||||
return nil
|
||||
|
@@ -70,7 +70,7 @@ func SettingsProtectedBranch(c *context.Context) {
|
||||
c.Data["PageIsSettingsBranches"] = true
|
||||
c.Data["Title"] = c.Tr("repo.settings.protected_branch") + " - " + rule.RuleName
|
||||
|
||||
users, err := access_model.GetRepoReaders(c.Repo.Repository)
|
||||
users, err := access_model.GetRepoReaders(c, c.Repo.Repository)
|
||||
if err != nil {
|
||||
c.ServerError("Repo.Repository.GetReaders", err)
|
||||
return
|
||||
@@ -84,7 +84,7 @@ func SettingsProtectedBranch(c *context.Context) {
|
||||
c.Data["recent_status_checks"] = contexts
|
||||
|
||||
if c.Repo.Owner.IsOrganization() {
|
||||
teams, err := organization.OrgFromUser(c.Repo.Owner).TeamsWithAccessToRepo(c.Repo.Repository.ID, perm.AccessModeRead)
|
||||
teams, err := organization.OrgFromUser(c.Repo.Owner).TeamsWithAccessToRepo(c, c.Repo.Repository.ID, perm.AccessModeRead)
|
||||
if err != nil {
|
||||
c.ServerError("Repo.Owner.TeamsWithAccessToRepo", err)
|
||||
return
|
||||
|
@@ -147,7 +147,7 @@ func setTagsContext(ctx *context.Context) error {
|
||||
}
|
||||
ctx.Data["ProtectedTags"] = protectedTags
|
||||
|
||||
users, err := access_model.GetRepoReaders(ctx.Repo.Repository)
|
||||
users, err := access_model.GetRepoReaders(ctx, ctx.Repo.Repository)
|
||||
if err != nil {
|
||||
ctx.ServerError("Repo.Repository.GetReaders", err)
|
||||
return err
|
||||
@@ -155,7 +155,7 @@ func setTagsContext(ctx *context.Context) error {
|
||||
ctx.Data["Users"] = users
|
||||
|
||||
if ctx.Repo.Owner.IsOrganization() {
|
||||
teams, err := organization.OrgFromUser(ctx.Repo.Owner).TeamsWithAccessToRepo(ctx.Repo.Repository.ID, perm.AccessModeRead)
|
||||
teams, err := organization.OrgFromUser(ctx.Repo.Owner).TeamsWithAccessToRepo(ctx, ctx.Repo.Repository.ID, perm.AccessModeRead)
|
||||
if err != nil {
|
||||
ctx.ServerError("Repo.Owner.TeamsWithAccessToRepo", err)
|
||||
return err
|
||||
|
@@ -594,7 +594,7 @@ func SettingsPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := repo_model.UpdateRepositoryUnits(repo, units, deleteUnitTypes); err != nil {
|
||||
if err := repo_model.UpdateRepositoryUnits(ctx, repo, units, deleteUnitTypes); err != nil {
|
||||
ctx.ServerError("UpdateRepositoryUnits", err)
|
||||
return
|
||||
}
|
||||
@@ -761,7 +761,7 @@ func SettingsPost(ctx *context.Context) {
|
||||
}
|
||||
|
||||
if newOwner.Type == user_model.UserTypeOrganization {
|
||||
if !ctx.Doer.IsAdmin && newOwner.Visibility == structs.VisibleTypePrivate && !organization.OrgFromUser(newOwner).HasMemberWithUserID(ctx.Doer.ID) {
|
||||
if !ctx.Doer.IsAdmin && newOwner.Visibility == structs.VisibleTypePrivate && !organization.OrgFromUser(newOwner).HasMemberWithUserID(ctx, ctx.Doer.ID) {
|
||||
// The user shouldn't know about this organization
|
||||
ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_owner_name"), tplSettingsOptions, nil)
|
||||
return
|
||||
|
@@ -57,7 +57,7 @@ func PrepareContextForProfileBigAvatar(ctx *context.Context) {
|
||||
}
|
||||
|
||||
showPrivate := ctx.IsSigned && (ctx.Doer.IsAdmin || ctx.Doer.ID == ctx.ContextUser.ID)
|
||||
orgs, err := organization.FindOrgs(organization.FindOrgOptions{
|
||||
orgs, err := organization.FindOrgs(ctx, organization.FindOrgOptions{
|
||||
UserID: ctx.ContextUser.ID,
|
||||
IncludePrivate: showPrivate,
|
||||
})
|
||||
@@ -66,7 +66,7 @@ func PrepareContextForProfileBigAvatar(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
ctx.Data["Orgs"] = orgs
|
||||
ctx.Data["HasOrgsVisible"] = organization.HasOrgsVisible(orgs, ctx.Doer)
|
||||
ctx.Data["HasOrgsVisible"] = organization.HasOrgsVisible(ctx, orgs, ctx.Doer)
|
||||
|
||||
badges, _, err := user_model.GetUserBadges(ctx, ctx.ContextUser)
|
||||
if err != nil {
|
||||
|
@@ -219,12 +219,12 @@ func Organization(ctx *context.Context) {
|
||||
opts.Page = 1
|
||||
}
|
||||
|
||||
orgs, err := organization.FindOrgs(opts)
|
||||
orgs, err := organization.FindOrgs(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.ServerError("FindOrgs", err)
|
||||
return
|
||||
}
|
||||
total, err := organization.CountOrgs(opts)
|
||||
total, err := organization.CountOrgs(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.ServerError("CountOrgs", err)
|
||||
return
|
||||
|
Reference in New Issue
Block a user