Skip to content

Fix "Flash" message usage #25895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 deletions modules/web/middleware/flash.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,6 @@ package middleware

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.
type Flash struct {
DataStore ContextDataStore
Expand All @@ -27,15 +16,12 @@ func (f *Flash) set(name, msg string, current ...bool) {
if f.Values == nil {
f.Values = make(map[string][]string)
}
isShow := false
if (len(current) == 0 && FlashNow) ||
(len(current) > 0 && current[0]) {
isShow = true
}

if isShow {
showInCurrentPage := len(current) > 0 && current[0]
if showInCurrentPage {
// assign it to the context data, then the template can use ".Flash.XxxMsg" to render the message
f.DataStore.GetData()["Flash"] = f
} 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)
}
}
Expand Down
7 changes: 2 additions & 5 deletions routers/web/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,8 @@ func getForkRepository(ctx *context.Context) *repo_model.Repository {
} else if len(orgs) > 0 {
ctx.Data["ContextUser"] = orgs[0]
} else {
msg := ctx.Tr("repo.fork_no_valid_owners")
ctx.Data["Flash"] = ctx.Flash
ctx.Flash.Error(msg)
ctx.Data["CanForkRepo"] = false
ctx.Flash.Error(ctx.Tr("repo.fork_no_valid_owners"), true)
return nil
}

Expand All @@ -194,8 +192,7 @@ func Fork(ctx *context.Context) {
} else {
maxCreationLimit := ctx.Doer.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)
ctx.Flash.Error(msg, true)
}

getForkRepository(ctx)
Expand Down