mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-05 10:26:15 +02:00
refactor: fix legacy problems in cmd/serv.go (#38505)
1. use var names "reqOwnerName, reqRepoName", because these values are from request and should not be really used for path construction 2. simplify enable-pprof logic, don't "log.Fatal" 3. don't make runServe command to guess the repo storage path, instead, let server return RepoStoragePath 4. don't process lfs verbs when the repo is a wiki 5. construct the request URI path correctly for the lfs transfer backend (moved to the caller) 6. don't call "owner, err := user_model.GetUserByName", the "owner rename redirection" has been done before 7. fix incorrect "repo.OwnerName = ownerName", the real owner might have been "redirected" 8. fix incorrect "inactive owner" check, it should be checked even if the repo is redirected Use general error functions to handle responses, error handling code is hugely simplified.
This commit is contained in:
@@ -5,10 +5,12 @@ package context
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"gitea.dev/modules/graceful"
|
||||
"gitea.dev/modules/log"
|
||||
"gitea.dev/modules/private"
|
||||
"gitea.dev/modules/process"
|
||||
"gitea.dev/modules/web"
|
||||
@@ -50,12 +52,14 @@ func (ctx *PrivateContext) Err() error {
|
||||
return ctx.Base.Err()
|
||||
}
|
||||
|
||||
func (ctx *PrivateContext) PrivateError(status int, err error, userMsg string) {
|
||||
errMsg := ""
|
||||
if err != nil {
|
||||
errMsg = err.Error()
|
||||
}
|
||||
ctx.JSON(status, private.Response{Err: errMsg, UserMsg: userMsg})
|
||||
func (ctx *PrivateContext) PrivateInternalErrorf(format string, args ...any) {
|
||||
s := fmt.Sprintf(format, args...)
|
||||
log.ErrorWithSkip(1, "Internal error: %s", s)
|
||||
ctx.JSON(http.StatusInternalServerError, private.Response{Err: s})
|
||||
}
|
||||
|
||||
func (ctx *PrivateContext) PrivateUserErrorf(status int, format string, args ...any) {
|
||||
ctx.JSON(status, private.Response{UserMsg: fmt.Sprintf(format, args...)})
|
||||
}
|
||||
|
||||
type privateContextKeyType struct{}
|
||||
|
||||
@@ -72,6 +72,9 @@ func DeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_mod
|
||||
|
||||
// PushCreateRepo creates a repository when a new repository is pushed to an appropriate namespace
|
||||
func PushCreateRepo(ctx context.Context, authUser, owner *user_model.User, repoName string) (*repo_model.Repository, error) {
|
||||
if authUser == nil {
|
||||
return nil, errors.New("cannot push-create repository anonymously")
|
||||
}
|
||||
if !authUser.IsAdmin {
|
||||
if owner.IsOrganization() {
|
||||
if ok, err := organization.CanCreateOrgRepo(ctx, owner.ID, authUser.ID); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user