Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redundant query in collaborator API #516

Merged
merged 1 commit into from
Dec 28, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 4 additions & 24 deletions routers/api/v1/repo/collaborators.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ import (

// ListCollaborators list a repository's collaborators
func ListCollaborators(ctx *context.APIContext) {
access, err := models.AccessLevel(ctx.User, ctx.Repo.Repository)
if err != nil {
ctx.Error(500, "AccessLevel", err)
return
}
if access < models.AccessModeWrite {
if !ctx.Repo.IsWriter() {
ctx.Error(403, "", "User does not have push access")
return
}
Expand All @@ -36,12 +31,7 @@ func ListCollaborators(ctx *context.APIContext) {

// IsCollaborator check if a user is a collaborator of a repository
func IsCollaborator(ctx *context.APIContext) {
access, err := models.AccessLevel(ctx.User, ctx.Repo.Repository)
if err != nil {
ctx.Error(500, "AccessLevel", err)
return
}
if access < models.AccessModeWrite {
if !ctx.Repo.IsWriter() {
ctx.Error(403, "", "User does not have push access")
return
}
Expand All @@ -68,12 +58,7 @@ func IsCollaborator(ctx *context.APIContext) {

// AddCollaborator add a collaborator of a repository
func AddCollaborator(ctx *context.APIContext, form api.AddCollaboratorOption) {
access, err := models.AccessLevel(ctx.User, ctx.Repo.Repository)
if err != nil {
ctx.Error(500, "AccessLevel", err)
return
}
if access < models.AccessModeWrite {
if !ctx.Repo.IsWriter() {
ctx.Error(403, "", "User does not have push access")
return
}
Expand Down Expand Up @@ -104,12 +89,7 @@ func AddCollaborator(ctx *context.APIContext, form api.AddCollaboratorOption) {

// DeleteCollaborator delete a collaborator from a repository
func DeleteCollaborator(ctx *context.APIContext) {
access, err := models.AccessLevel(ctx.User, ctx.Repo.Repository)
if err != nil {
ctx.Error(500, "AccessLevel", err)
return
}
if access < models.AccessModeWrite {
if !ctx.Repo.IsWriter() {
ctx.Error(403, "", "User does not have push access")
return
}
Expand Down