Skip to content

Commit

Permalink
Merge branch 'master' into fix/system_webhooks_menu
Browse files Browse the repository at this point in the history
  • Loading branch information
lafriks committed Jan 14, 2021
2 parents 5775cc9 + 84b147c commit d0a71be
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 23 deletions.
4 changes: 2 additions & 2 deletions cmd/serv.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func setup(logPath string, debug bool) {
}
setting.NewContext()
if debug {
setting.ProdMode = false
setting.RunMode = "dev"
}
}

Expand All @@ -76,7 +76,7 @@ func fail(userMessage, logMessage string, args ...interface{}) {
fmt.Fprintln(os.Stderr, "Gitea:", userMessage)

if len(logMessage) > 0 {
if !setting.ProdMode {
if !setting.IsProd() {
fmt.Fprintf(os.Stderr, logMessage+"\n", args...)
}
}
Expand Down
4 changes: 2 additions & 2 deletions models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ func NewTestEngine() (err error) {
}

x.SetMapper(names.GonicMapper{})
x.SetLogger(NewXORMLogger(!setting.ProdMode))
x.ShowSQL(!setting.ProdMode)
x.SetLogger(NewXORMLogger(!setting.IsProd()))
x.ShowSQL(!setting.IsProd())
return x.StoreEngine("InnoDB").Sync2(tables...)
}

Expand Down
2 changes: 1 addition & 1 deletion modules/auth/sso/sspi_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (s *SSPI) Init() error {
Funcs: templates.NewFuncMap(),
Asset: templates.GetAsset,
AssetNames: templates.GetAssetNames,
IsDevelopment: setting.RunMode != "prod",
IsDevelopment: !setting.IsProd(),
})
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion modules/httpcache/httpcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

// GetCacheControl returns a suitable "Cache-Control" header value
func GetCacheControl() string {
if setting.RunMode == "dev" {
if !setting.IsProd() {
return "no-store"
}
return "private, max-age=" + strconv.FormatInt(int64(setting.StaticCacheTime.Seconds()), 10)
Expand Down
6 changes: 5 additions & 1 deletion modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,6 @@ var (
CustomConf string
PIDFile = "/run/gitea.pid"
WritePIDFile bool
ProdMode bool
RunMode string
RunUser string
IsWindows bool
Expand All @@ -388,6 +387,11 @@ var (
UILocation = time.Local
)

// IsProd if it's a production mode
func IsProd() bool {
return strings.EqualFold(RunMode, "prod")
}

func getAppPath() (string, error) {
var appPath string
var err error
Expand Down
8 changes: 4 additions & 4 deletions routers/admin/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func prepareUserInfo(ctx *context.Context) *models.User {
_, err = models.GetTwoFactorByUID(u.ID)
if err != nil {
if !models.IsErrTwoFactorNotEnrolled(err) {
ctx.InternalServerError(err)
ctx.ServerError("IsErrTwoFactorNotEnrolled", err)
return nil
}
ctx.Data["TwoFactorEnabled"] = false
Expand Down Expand Up @@ -268,7 +268,7 @@ func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) {
return
}
if err = u.SetPassword(form.Password); err != nil {
ctx.InternalServerError(err)
ctx.ServerError("SetPassword", err)
return
}
}
Expand All @@ -285,12 +285,12 @@ func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) {
if form.Reset2FA {
tf, err := models.GetTwoFactorByUID(u.ID)
if err != nil && !models.IsErrTwoFactorNotEnrolled(err) {
ctx.InternalServerError(err)
ctx.ServerError("GetTwoFactorByUID", err)
return
}

if err = models.DeleteTwoFactorByID(tf.ID, u.ID); err != nil {
ctx.InternalServerError(err)
ctx.ServerError("DeleteTwoFactorByID", err)
return
}
}
Expand Down
2 changes: 1 addition & 1 deletion routers/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func checkRunMode() {
default:
macaron.Env = macaron.PROD
macaron.ColorLog = false
setting.ProdMode = true
git.Debug = false
}
log.Info("Run Mode: %s", strings.Title(macaron.Env))
}
Expand Down
2 changes: 1 addition & 1 deletion routers/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ func ViewIssue(ctx *context.Context) {
iw.IssueID = issue.ID
iw.IsWatching, err = models.CheckIssueWatch(ctx.User, issue)
if err != nil {
ctx.InternalServerError(err)
ctx.ServerError("CheckIssueWatch", err)
return
}
}
Expand Down
4 changes: 2 additions & 2 deletions routers/repo/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ func DeleteProjectBoard(ctx *context.Context) {

pb, err := models.GetProjectBoard(ctx.ParamsInt64(":boardID"))
if err != nil {
ctx.InternalServerError(err)
ctx.ServerError("GetProjectBoard", err)
return
}
if pb.ProjectID != ctx.ParamsInt64(":id") {
Expand Down Expand Up @@ -445,7 +445,7 @@ func EditProjectBoardTitle(ctx *context.Context, form auth.EditProjectBoardTitle

board, err := models.GetProjectBoard(ctx.ParamsInt64(":boardID"))
if err != nil {
ctx.InternalServerError(err)
ctx.ServerError("GetProjectBoard", err)
return
}
if board.ProjectID != ctx.ParamsInt64(":id") {
Expand Down
4 changes: 2 additions & 2 deletions routers/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,11 +713,11 @@ func UpdatePullRequest(ctx *context.Context) {
}

if err := issue.PullRequest.LoadBaseRepo(); err != nil {
ctx.InternalServerError(err)
ctx.ServerError("LoadBaseRepo", err)
return
}
if err := issue.PullRequest.LoadHeadRepo(); err != nil {
ctx.InternalServerError(err)
ctx.ServerError("LoadHeadRepo", err)
return
}

Expand Down
11 changes: 5 additions & 6 deletions routers/routes/recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@ func (d *dataStore) GetData() map[string]interface{} {
// Although similar to macaron.Recovery() the main difference is that this error will be created
// with the gitea 500 page.
func Recovery() func(next http.Handler) http.Handler {
var isDevelopment = setting.RunMode != "prod"
return func(next http.Handler) http.Handler {
rnd := render.New(render.Options{
Extensions: []string{".tmpl"},
Directory: "templates",
Funcs: templates.NewFuncMap(),
Asset: templates.GetAsset,
AssetNames: templates.GetAssetNames,
IsDevelopment: isDevelopment,
IsDevelopment: !setting.IsProd(),
})

return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
Expand All @@ -50,10 +49,10 @@ func Recovery() func(next http.Handler) http.Handler {
if err := recover(); err != nil {
combinedErr := fmt.Sprintf("PANIC: %v\n%s", err, string(log.Stack(2)))
log.Error(combinedErr)
if isDevelopment {
http.Error(w, combinedErr, 500)
} else {
if setting.IsProd() {
http.Error(w, http.StatusText(500), 500)
} else {
http.Error(w, combinedErr, 500)
}
}
}()
Expand Down Expand Up @@ -94,7 +93,7 @@ func Recovery() func(next http.Handler) http.Handler {

w.Header().Set(`X-Frame-Options`, `SAMEORIGIN`)

if setting.RunMode != "prod" {
if !setting.IsProd() {
store.Data["ErrorMsg"] = combinedErr
}
err = rnd.HTML(w, 500, "status/500", templates.BaseVars().Merge(store.Data))
Expand Down

0 comments on commit d0a71be

Please sign in to comment.