mirror of
https://github.com/go-gitea/gitea.git
synced 2024-12-27 07:56:13 +00:00
Remove redundant query in collaborator API (#516)
This commit is contained in:
parent
8f1c311b90
commit
9fae9f0dc2
@ -13,12 +13,7 @@ import (
|
|||||||
|
|
||||||
// ListCollaborators list a repository's collaborators
|
// ListCollaborators list a repository's collaborators
|
||||||
func ListCollaborators(ctx *context.APIContext) {
|
func ListCollaborators(ctx *context.APIContext) {
|
||||||
access, err := models.AccessLevel(ctx.User, ctx.Repo.Repository)
|
if !ctx.Repo.IsWriter() {
|
||||||
if err != nil {
|
|
||||||
ctx.Error(500, "AccessLevel", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if access < models.AccessModeWrite {
|
|
||||||
ctx.Error(403, "", "User does not have push access")
|
ctx.Error(403, "", "User does not have push access")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -36,12 +31,7 @@ func ListCollaborators(ctx *context.APIContext) {
|
|||||||
|
|
||||||
// IsCollaborator check if a user is a collaborator of a repository
|
// IsCollaborator check if a user is a collaborator of a repository
|
||||||
func IsCollaborator(ctx *context.APIContext) {
|
func IsCollaborator(ctx *context.APIContext) {
|
||||||
access, err := models.AccessLevel(ctx.User, ctx.Repo.Repository)
|
if !ctx.Repo.IsWriter() {
|
||||||
if err != nil {
|
|
||||||
ctx.Error(500, "AccessLevel", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if access < models.AccessModeWrite {
|
|
||||||
ctx.Error(403, "", "User does not have push access")
|
ctx.Error(403, "", "User does not have push access")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -68,12 +58,7 @@ func IsCollaborator(ctx *context.APIContext) {
|
|||||||
|
|
||||||
// AddCollaborator add a collaborator of a repository
|
// AddCollaborator add a collaborator of a repository
|
||||||
func AddCollaborator(ctx *context.APIContext, form api.AddCollaboratorOption) {
|
func AddCollaborator(ctx *context.APIContext, form api.AddCollaboratorOption) {
|
||||||
access, err := models.AccessLevel(ctx.User, ctx.Repo.Repository)
|
if !ctx.Repo.IsWriter() {
|
||||||
if err != nil {
|
|
||||||
ctx.Error(500, "AccessLevel", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if access < models.AccessModeWrite {
|
|
||||||
ctx.Error(403, "", "User does not have push access")
|
ctx.Error(403, "", "User does not have push access")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -104,12 +89,7 @@ func AddCollaborator(ctx *context.APIContext, form api.AddCollaboratorOption) {
|
|||||||
|
|
||||||
// DeleteCollaborator delete a collaborator from a repository
|
// DeleteCollaborator delete a collaborator from a repository
|
||||||
func DeleteCollaborator(ctx *context.APIContext) {
|
func DeleteCollaborator(ctx *context.APIContext) {
|
||||||
access, err := models.AccessLevel(ctx.User, ctx.Repo.Repository)
|
if !ctx.Repo.IsWriter() {
|
||||||
if err != nil {
|
|
||||||
ctx.Error(500, "AccessLevel", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if access < models.AccessModeWrite {
|
|
||||||
ctx.Error(403, "", "User does not have push access")
|
ctx.Error(403, "", "User does not have push access")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user