Fix "Flash" message usage (#25895)
Resolve https://github.com/go-gitea/gitea/pull/25820/files#r1264309059
This commit is contained in:
parent
faf28b2823
commit
9672085d94
2 changed files with 6 additions and 23 deletions
|
@ -5,17 +5,6 @@ package middleware
|
||||||
|
|
||||||
import "net/url"
|
import "net/url"
|
||||||
|
|
||||||
// flashes enumerates all the flash types
|
|
||||||
const (
|
|
||||||
SuccessFlash = "SuccessMsg"
|
|
||||||
ErrorFlash = "ErrorMsg"
|
|
||||||
WarnFlash = "WarningMsg"
|
|
||||||
InfoFlash = "InfoMsg"
|
|
||||||
)
|
|
||||||
|
|
||||||
// FlashNow FIXME:
|
|
||||||
var FlashNow bool
|
|
||||||
|
|
||||||
// Flash represents a one time data transfer between two requests.
|
// Flash represents a one time data transfer between two requests.
|
||||||
type Flash struct {
|
type Flash struct {
|
||||||
DataStore ContextDataStore
|
DataStore ContextDataStore
|
||||||
|
@ -27,15 +16,12 @@ func (f *Flash) set(name, msg string, current ...bool) {
|
||||||
if f.Values == nil {
|
if f.Values == nil {
|
||||||
f.Values = make(map[string][]string)
|
f.Values = make(map[string][]string)
|
||||||
}
|
}
|
||||||
isShow := false
|
showInCurrentPage := len(current) > 0 && current[0]
|
||||||
if (len(current) == 0 && FlashNow) ||
|
if showInCurrentPage {
|
||||||
(len(current) > 0 && current[0]) {
|
// assign it to the context data, then the template can use ".Flash.XxxMsg" to render the message
|
||||||
isShow = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if isShow {
|
|
||||||
f.DataStore.GetData()["Flash"] = f
|
f.DataStore.GetData()["Flash"] = f
|
||||||
} else {
|
} else {
|
||||||
|
// the message map will be saved into the cookie and be shown in next response (a new page response which decodes the cookie)
|
||||||
f.Set(name, msg)
|
f.Set(name, msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,10 +175,8 @@ func getForkRepository(ctx *context.Context) *repo_model.Repository {
|
||||||
} else if len(orgs) > 0 {
|
} else if len(orgs) > 0 {
|
||||||
ctx.Data["ContextUser"] = orgs[0]
|
ctx.Data["ContextUser"] = orgs[0]
|
||||||
} else {
|
} else {
|
||||||
msg := ctx.Tr("repo.fork_no_valid_owners")
|
|
||||||
ctx.Data["Flash"] = ctx.Flash
|
|
||||||
ctx.Flash.Error(msg)
|
|
||||||
ctx.Data["CanForkRepo"] = false
|
ctx.Data["CanForkRepo"] = false
|
||||||
|
ctx.Flash.Error(ctx.Tr("repo.fork_no_valid_owners"), true)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,8 +192,7 @@ func Fork(ctx *context.Context) {
|
||||||
} else {
|
} else {
|
||||||
maxCreationLimit := ctx.Doer.MaxCreationLimit()
|
maxCreationLimit := ctx.Doer.MaxCreationLimit()
|
||||||
msg := ctx.TrN(maxCreationLimit, "repo.form.reach_limit_of_creation_1", "repo.form.reach_limit_of_creation_n", maxCreationLimit)
|
msg := ctx.TrN(maxCreationLimit, "repo.form.reach_limit_of_creation_1", "repo.form.reach_limit_of_creation_n", maxCreationLimit)
|
||||||
ctx.Data["Flash"] = ctx.Flash
|
ctx.Flash.Error(msg, true)
|
||||||
ctx.Flash.Error(msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getForkRepository(ctx)
|
getForkRepository(ctx)
|
||||||
|
|
Loading…
Reference in a new issue