mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-21 12:55:23 +02:00
Support push via gitea bot
This commit is contained in:
parent
f55253e81d
commit
1ddf3b2d12
@ -13,6 +13,7 @@ import (
|
|||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
||||||
|
bots_model "code.gitea.io/gitea/models/bots"
|
||||||
git_model "code.gitea.io/gitea/models/git"
|
git_model "code.gitea.io/gitea/models/git"
|
||||||
issues_model "code.gitea.io/gitea/models/issues"
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
perm_model "code.gitea.io/gitea/models/perm"
|
perm_model "code.gitea.io/gitea/models/perm"
|
||||||
@ -465,25 +466,41 @@ func (ctx *preReceiveContext) loadPusherAndPermission() bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
user, err := user_model.GetUserByID(ctx.opts.UserID)
|
if ctx.opts.UserID == -2 {
|
||||||
if err != nil {
|
ctx.user = bots_model.NewBotUser()
|
||||||
log.Error("Unable to get User id %d Error: %v", ctx.opts.UserID, err)
|
ctx.userPerm.AccessMode = perm_model.AccessModeAdmin
|
||||||
ctx.JSON(http.StatusInternalServerError, private.Response{
|
if err := ctx.Repo.Repository.LoadUnits(ctx); err != nil {
|
||||||
Err: fmt.Sprintf("Unable to get User id %d Error: %v", ctx.opts.UserID, err),
|
log.Error("Unable to get User id %d Error: %v", ctx.opts.UserID, err)
|
||||||
})
|
ctx.JSON(http.StatusInternalServerError, private.Response{
|
||||||
return false
|
Err: fmt.Sprintf("Unable to get User id %d Error: %v", ctx.opts.UserID, err),
|
||||||
|
})
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
ctx.userPerm.Units = ctx.Repo.Repository.Units
|
||||||
|
ctx.userPerm.UnitsMode = make(map[unit.Type]perm_model.AccessMode)
|
||||||
|
for _, u := range ctx.Repo.Repository.Units {
|
||||||
|
ctx.userPerm.UnitsMode[u.Type] = ctx.userPerm.AccessMode
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
user, err := user_model.GetUserByID(ctx.opts.UserID)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Unable to get User id %d Error: %v", ctx.opts.UserID, err)
|
||||||
|
ctx.JSON(http.StatusInternalServerError, private.Response{
|
||||||
|
Err: fmt.Sprintf("Unable to get User id %d Error: %v", ctx.opts.UserID, err),
|
||||||
|
})
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
ctx.user = user
|
||||||
|
userPerm, err := access_model.GetUserRepoPermission(ctx, ctx.Repo.Repository, user)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Unable to get Repo permission of repo %s/%s of User %s: %v", ctx.Repo.Repository.OwnerName, ctx.Repo.Repository.Name, user.Name, err)
|
||||||
|
ctx.JSON(http.StatusInternalServerError, private.Response{
|
||||||
|
Err: fmt.Sprintf("Unable to get Repo permission of repo %s/%s of User %s: %v", ctx.Repo.Repository.OwnerName, ctx.Repo.Repository.Name, user.Name, err),
|
||||||
|
})
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
ctx.userPerm = userPerm
|
||||||
}
|
}
|
||||||
ctx.user = user
|
|
||||||
|
|
||||||
userPerm, err := access_model.GetUserRepoPermission(ctx, ctx.Repo.Repository, user)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Unable to get Repo permission of repo %s/%s of User %s: %v", ctx.Repo.Repository.OwnerName, ctx.Repo.Repository.Name, user.Name, err)
|
|
||||||
ctx.JSON(http.StatusInternalServerError, private.Response{
|
|
||||||
Err: fmt.Sprintf("Unable to get Repo permission of repo %s/%s of User %s: %v", ctx.Repo.Repository.OwnerName, ctx.Repo.Repository.Name, user.Name, err),
|
|
||||||
})
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
ctx.userPerm = userPerm
|
|
||||||
|
|
||||||
if ctx.opts.DeployKeyID != 0 {
|
if ctx.opts.DeployKeyID != 0 {
|
||||||
deployKey, err := asymkey_model.GetDeployKeyByID(ctx, ctx.opts.DeployKeyID)
|
deployKey, err := asymkey_model.GetDeployKeyByID(ctx, ctx.opts.DeployKeyID)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user