Skip to content

Commit b0dd52e

Browse files
committed
feat: fix bug in IsPreviewMode()
1 parent d53b598 commit b0dd52e

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

controllers/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (c *ApiController) GetProviders() {
6565
providers = object.GetMaskedProviders(providers, true, user)
6666
c.ResponseOk(providers)
6767
} else {
68-
if !c.IsPreviewMode() && !c.RequireAdmin() {
68+
if !c.RequireAdmin() {
6969
return
7070
}
7171
limit := util.ParseInt(limit)

controllers/store.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ func (c *ApiController) GetGlobalStores() {
4646

4747
c.ResponseOk(stores)
4848
} else {
49-
if !c.IsPreviewMode() && !c.RequireAdmin() {
49+
if !c.RequireAdmin() {
5050
return
5151
}
52+
5253
limit := util.ParseInt(limit)
5354
count, err := object.GetStoreCount(field, value)
5455
if err != nil {

controllers/util.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ func (c *ApiController) CheckSignedIn() (string, bool) {
113113
}
114114

115115
func (c *ApiController) RequireAdmin() bool {
116+
disablePreviewMode, _ := beego.AppConfig.Bool("disablePreviewMode")
117+
if !disablePreviewMode {
118+
return true
119+
}
120+
116121
if !c.IsAdmin() {
117122
c.ResponseError("this operation requires admin privilege")
118123
return false
@@ -131,15 +136,6 @@ func (c *ApiController) IsAdmin() bool {
131136
return res
132137
}
133138

134-
func (c *ApiController) IsPreviewMode() bool {
135-
disablePreviewMode, _ := beego.AppConfig.Bool("disablePreviewMode")
136-
if disablePreviewMode {
137-
c.ResponseError("this operation requires admin privilege")
138-
return false
139-
}
140-
return true
141-
}
142-
143139
func DenyRequest(ctx *context.Context) {
144140
responseError(ctx, "Unauthorized operation")
145141
}

0 commit comments

Comments
 (0)