Skip to content

Commit 9672085

Browse files
authored
1 parent faf28b2 commit 9672085

File tree

2 files changed

+6
-23
lines changed

2 files changed

+6
-23
lines changed

modules/web/middleware/flash.go

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,6 @@ package middleware
55

66
import "net/url"
77

8-
// flashes enumerates all the flash types
9-
const (
10-
SuccessFlash = "SuccessMsg"
11-
ErrorFlash = "ErrorMsg"
12-
WarnFlash = "WarningMsg"
13-
InfoFlash = "InfoMsg"
14-
)
15-
16-
// FlashNow FIXME:
17-
var FlashNow bool
18-
198
// Flash represents a one time data transfer between two requests.
209
type Flash struct {
2110
DataStore ContextDataStore
@@ -27,15 +16,12 @@ func (f *Flash) set(name, msg string, current ...bool) {
2716
if f.Values == nil {
2817
f.Values = make(map[string][]string)
2918
}
30-
isShow := false
31-
if (len(current) == 0 && FlashNow) ||
32-
(len(current) > 0 && current[0]) {
33-
isShow = true
34-
}
35-
36-
if isShow {
19+
showInCurrentPage := len(current) > 0 && current[0]
20+
if showInCurrentPage {
21+
// assign it to the context data, then the template can use ".Flash.XxxMsg" to render the message
3722
f.DataStore.GetData()["Flash"] = f
3823
} else {
24+
// the message map will be saved into the cookie and be shown in next response (a new page response which decodes the cookie)
3925
f.Set(name, msg)
4026
}
4127
}

routers/web/repo/pull.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,8 @@ func getForkRepository(ctx *context.Context) *repo_model.Repository {
175175
} else if len(orgs) > 0 {
176176
ctx.Data["ContextUser"] = orgs[0]
177177
} else {
178-
msg := ctx.Tr("repo.fork_no_valid_owners")
179-
ctx.Data["Flash"] = ctx.Flash
180-
ctx.Flash.Error(msg)
181178
ctx.Data["CanForkRepo"] = false
179+
ctx.Flash.Error(ctx.Tr("repo.fork_no_valid_owners"), true)
182180
return nil
183181
}
184182

@@ -194,8 +192,7 @@ func Fork(ctx *context.Context) {
194192
} else {
195193
maxCreationLimit := ctx.Doer.MaxCreationLimit()
196194
msg := ctx.TrN(maxCreationLimit, "repo.form.reach_limit_of_creation_1", "repo.form.reach_limit_of_creation_n", maxCreationLimit)
197-
ctx.Data["Flash"] = ctx.Flash
198-
ctx.Flash.Error(msg)
195+
ctx.Flash.Error(msg, true)
199196
}
200197

201198
getForkRepository(ctx)

0 commit comments

Comments
 (0)