From dbd89acf980d7ab9f28cdcd33657a9699e65f52d Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 16 Jan 2020 22:18:30 +0800 Subject: [PATCH] Remove unnecessary permissions load (#9796) Co-authored-by: Lauris BH Co-authored-by: techknowlogick --- routers/api/v1/repo/pull.go | 8 +------- routers/repo/issue.go | 7 +------ routers/repo/milestone.go | 9 ++------- 3 files changed, 4 insertions(+), 20 deletions(-) diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index bca756aea16..e2e6c2799bd 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -600,13 +600,7 @@ func MergePullRequest(ctx *context.APIContext, form auth.MergePullRequestForm) { return } - perm, err := models.GetUserRepoPermission(ctx.Repo.Repository, ctx.User) - if err != nil { - ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err) - return - } - - allowedMerge, err := pull_service.IsUserAllowedToMerge(pr, perm, ctx.User) + allowedMerge, err := pull_service.IsUserAllowedToMerge(pr, ctx.Repo.Permission, ctx.User) if err != nil { ctx.Error(http.StatusInternalServerError, "IsUSerAllowedToMerge", err) return diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 2fb42b0f22c..4d837737746 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -316,12 +316,7 @@ func Issues(ctx *context.Context) { return } - perm, err := models.GetUserRepoPermission(ctx.Repo.Repository, ctx.User) - if err != nil { - ctx.ServerError("GetUserRepoPermission", err) - return - } - ctx.Data["CanWriteIssuesOrPulls"] = perm.CanWriteIssuesOrPulls(isPullList) + ctx.Data["CanWriteIssuesOrPulls"] = ctx.Repo.CanWriteIssuesOrPulls(isPullList) ctx.HTML(200, tplIssues) } diff --git a/routers/repo/milestone.go b/routers/repo/milestone.go index b4056cc6d1a..3e81ea04523 100644 --- a/routers/repo/milestone.go +++ b/routers/repo/milestone.go @@ -268,13 +268,8 @@ func MilestoneIssuesAndPulls(ctx *context.Context) { issues(ctx, milestoneID, util.OptionalBoolNone) - perm, err := models.GetUserRepoPermission(ctx.Repo.Repository, ctx.User) - if err != nil { - ctx.ServerError("GetUserRepoPermission", err) - return - } - ctx.Data["CanWriteIssues"] = perm.CanWriteIssuesOrPulls(false) - ctx.Data["CanWritePulls"] = perm.CanWriteIssuesOrPulls(true) + ctx.Data["CanWriteIssues"] = ctx.Repo.CanWriteIssuesOrPulls(false) + ctx.Data["CanWritePulls"] = ctx.Repo.CanWriteIssuesOrPulls(true) ctx.HTML(200, tplMilestoneIssues) }