Skip to content

Commit efe0df8

Browse files
committed
use .SystemConfig
1 parent c3a3bab commit efe0df8

File tree

11 files changed

+25
-33
lines changed

11 files changed

+25
-33
lines changed

modules/setting/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ type RepositoryStruct struct {
5151
OpenWithEditorApps *config.Value[OpenWithEditorAppsType]
5252
}
5353

54-
type ExplorePage struct {
54+
type Explore struct {
5555
RequireSigninView *config.Value[bool]
5656
DisableUsersPage *config.Value[bool]
5757
DisableOrganizationsPage *config.Value[bool]
5858
DisableCodePage *config.Value[bool]
5959
}
6060

6161
type ServiceStruct struct {
62-
ExplorePage *ExplorePage
62+
Explore *Explore
6363
}
6464

6565
type ConfigStruct struct {
@@ -84,7 +84,7 @@ func initDefaultConfig() {
8484
OpenWithEditorApps: config.ValueJSON[OpenWithEditorAppsType]("repository.open-with.editor-apps"),
8585
},
8686
Service: &ServiceStruct{
87-
ExplorePage: &ExplorePage{
87+
Explore: &Explore{
8888
RequireSigninView: config.ValueJSON[bool]("service.explore.require_signin_view").WithFileConfig(config.CfgSecKey{Sec: "service.explore", Key: "REQUIRE_SIGNIN_VIEW"}),
8989
DisableUsersPage: config.ValueJSON[bool]("service.explore.disable_users_page").WithFileConfig(config.CfgSecKey{Sec: "service.explore", Key: "DISABLE_USERS_PAGE"}),
9090
DisableOrganizationsPage: config.ValueJSON[bool]("service.explore.disable_organizations_page").WithFileConfig(config.CfgSecKey{Sec: "service.explore", Key: "DISABLE_ORGANIZATIONS_PAGE"}),

routers/api/v1/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,11 @@ func reqToken() func(ctx *context.APIContext) {
356356

357357
func reqExploreSignInAndUsersExploreEnabled() func(ctx *context.APIContext) {
358358
return func(ctx *context.APIContext) {
359-
if setting.Config().Service.ExplorePage.DisableUsersPage.Value(ctx) {
359+
if setting.Config().Service.Explore.DisableUsersPage.Value(ctx) {
360360
ctx.NotFound()
361361
return
362362
}
363-
if setting.Config().Service.ExplorePage.RequireSigninView.Value(ctx) && !ctx.IsSigned {
363+
if setting.Config().Service.Explore.RequireSigninView.Value(ctx) && !ctx.IsSigned {
364364
ctx.Error(http.StatusUnauthorized, "reqExploreSignIn", "you must be signed in to search for users")
365365
}
366366
}

routers/web/admin/config.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,13 @@ func ChangeConfig(ctx *context.Context) {
231231
return string(b), nil
232232
}
233233
marshallers := map[string]func(string) (string, error){
234-
cfg.Picture.DisableGravatar.DynKey(): marshalBool,
235-
cfg.Picture.EnableFederatedAvatar.DynKey(): marshalBool,
236-
cfg.Repository.OpenWithEditorApps.DynKey(): marshalOpenWithApps,
237-
cfg.Service.ExplorePage.RequireSigninView.DynKey(): marshalBool,
238-
cfg.Service.ExplorePage.DisableUsersPage.DynKey(): marshalBool,
239-
cfg.Service.ExplorePage.DisableOrganizationsPage.DynKey(): marshalBool,
240-
cfg.Service.ExplorePage.DisableCodePage.DynKey(): marshalBool,
234+
cfg.Picture.DisableGravatar.DynKey(): marshalBool,
235+
cfg.Picture.EnableFederatedAvatar.DynKey(): marshalBool,
236+
cfg.Repository.OpenWithEditorApps.DynKey(): marshalOpenWithApps,
237+
cfg.Service.Explore.RequireSigninView.DynKey(): marshalBool,
238+
cfg.Service.Explore.DisableUsersPage.DynKey(): marshalBool,
239+
cfg.Service.Explore.DisableOrganizationsPage.DynKey(): marshalBool,
240+
cfg.Service.Explore.DisableCodePage.DynKey(): marshalBool,
241241
}
242242
marshaller, hasMarshaller := marshallers[key]
243243
if !hasMarshaller {

routers/web/explore/code.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ func Code(ctx *context.Context) {
2525
ctx.Redirect(setting.AppSubURL + "/explore")
2626
return
2727
}
28-
if setting.Config().Service.ExplorePage.DisableCodePage.Value(ctx) {
28+
if setting.Config().Service.Explore.DisableCodePage.Value(ctx) {
2929
ctx.Redirect(setting.AppSubURL + "/explore/repos")
3030
return
3131
}
3232

33-
ctx.Data["UsersIsDisabled"] = setting.Config().Service.ExplorePage.DisableUsersPage.Value(ctx)
34-
ctx.Data["OrganizationsIsDisabled"] = setting.Config().Service.ExplorePage.DisableOrganizationsPage.Value(ctx)
3533
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
3634
ctx.Data["Title"] = ctx.Tr("explore")
3735
ctx.Data["PageIsExplore"] = true

routers/web/explore/org.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ import (
1414

1515
// Organizations render explore organizations page
1616
func Organizations(ctx *context.Context) {
17-
if setting.Config().Service.ExplorePage.DisableOrganizationsPage.Value(ctx) {
17+
if setting.Config().Service.Explore.DisableOrganizationsPage.Value(ctx) {
1818
ctx.Redirect(setting.AppSubURL + "/explore/repos")
1919
return
2020
}
2121

22-
ctx.Data["UsersIsDisabled"] = setting.Config().Service.ExplorePage.DisableUsersPage.Value(ctx)
23-
ctx.Data["CodeIsDisabled"] = setting.Config().Service.ExplorePage.DisableCodePage.Value(ctx)
2422
ctx.Data["Title"] = ctx.Tr("explore")
2523
ctx.Data["PageIsExplore"] = true
2624
ctx.Data["PageIsExploreOrganizations"] = true

routers/web/explore/repo.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,6 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
165165

166166
// Repos render explore repositories page
167167
func Repos(ctx *context.Context) {
168-
ctx.Data["UsersIsDisabled"] = setting.Config().Service.ExplorePage.DisableUsersPage.Value(ctx)
169-
ctx.Data["OrganizationsIsDisabled"] = setting.Config().Service.ExplorePage.DisableOrganizationsPage.Value(ctx)
170-
ctx.Data["CodeIsDisabled"] = setting.Config().Service.ExplorePage.DisableCodePage.Value(ctx)
171168
ctx.Data["Title"] = ctx.Tr("explore")
172169
ctx.Data["PageIsExplore"] = true
173170
ctx.Data["PageIsExploreRepositories"] = true

routers/web/explore/user.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,11 @@ func RenderUserSearch(ctx *context.Context, opts *user_model.SearchUserOptions,
130130

131131
// Users render explore users page
132132
func Users(ctx *context.Context) {
133-
if setting.Config().Service.ExplorePage.DisableUsersPage.Value(ctx) {
133+
if setting.Config().Service.Explore.DisableUsersPage.Value(ctx) {
134134
ctx.Redirect(setting.AppSubURL + "/explore/repos")
135135
return
136136
}
137-
ctx.Data["OrganizationsIsDisabled"] = setting.Config().Service.ExplorePage.DisableOrganizationsPage.Value(ctx)
138-
ctx.Data["CodeIsDisabled"] = setting.Config().Service.ExplorePage.DisableCodePage.Value(ctx)
137+
139138
ctx.Data["Title"] = ctx.Tr("explore")
140139
ctx.Data["PageIsExplore"] = true
141140
ctx.Data["PageIsExploreUsers"] = true

routers/web/home.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func Home(ctx *context.Context) {
6767
// HomeSitemap renders the main sitemap
6868
func HomeSitemap(ctx *context.Context) {
6969
m := sitemap.NewSitemapIndex()
70-
if !setting.Config().Service.ExplorePage.DisableUsersPage.Value(ctx) {
70+
if !setting.Config().Service.Explore.DisableUsersPage.Value(ctx) {
7171
_, cnt, err := user_model.SearchUsers(ctx, &user_model.SearchUserOptions{
7272
Type: user_model.UserTypeIndividual,
7373
ListOptions: db.ListOptions{PageSize: 1},

routers/web/web.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ func registerRoutes(m *web.Router) {
301301
// TODO: rename them to "optSignIn", which means that the "sign-in" could be optional, depends on the VerifyOptions (RequireSignInView)
302302
ignSignIn := verifyAuthWithOptions(&common.VerifyOptions{SignInRequired: setting.Service.RequireSignInView})
303303
ignExploreSignIn := func(ctx *context.Context) {
304-
verifyAuthWithOptions(&common.VerifyOptions{SignInRequired: setting.Service.RequireSignInView || setting.Config().Service.ExplorePage.RequireSigninView.Value(ctx)})(ctx)
304+
verifyAuthWithOptions(&common.VerifyOptions{SignInRequired: setting.Service.RequireSignInView || setting.Config().Service.Explore.RequireSigninView.Value(ctx)})(ctx)
305305
}
306306

307307
validation.AddBindingRules()

templates/admin/config_settings.tmpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,28 +48,28 @@
4848
<dt>{{ctx.Locale.Tr "admin.config.explore_require_signin_view"}}</dt>
4949
<dd>
5050
<div class="ui toggle checkbox" data-tooltip-content="{{ctx.Locale.Tr "admin.config.explore_require_signin_view"}}">
51-
<input type="checkbox" data-config-dyn-key="service.explore.require_signin_view" {{if .SystemConfig.Service.ExplorePage.RequireSigninView.Value ctx}}checked{{end}}><label></label>
51+
<input type="checkbox" data-config-dyn-key="service.explore.require_signin_view" {{if .SystemConfig.Service.Explore.RequireSigninView.Value ctx}}checked{{end}}><label></label>
5252
</div>
5353
</dd>
5454
<div class="divider"></div>
5555
<dt>{{ctx.Locale.Tr "admin.config.explore_disable_users_page"}}</dt>
5656
<dd>
5757
<div class="ui toggle checkbox" data-tooltip-content="{{ctx.Locale.Tr "admin.config.explore_disable_users_page"}}">
58-
<input type="checkbox" data-config-dyn-key="service.explore.disable_users_page" {{if .SystemConfig.Service.ExplorePage.DisableUsersPage.Value ctx}}checked{{end}}><label></label>
58+
<input type="checkbox" data-config-dyn-key="service.explore.disable_users_page" {{if .SystemConfig.Service.Explore.DisableUsersPage.Value ctx}}checked{{end}}><label></label>
5959
</div>
6060
</dd>
6161
<div class="divider"></div>
6262
<dt>{{ctx.Locale.Tr "admin.config.explore_disable_organizations_page"}}</dt>
6363
<dd>
6464
<div class="ui toggle checkbox" data-tooltip-content="{{ctx.Locale.Tr "admin.config.explore_disable_organizations_page"}}">
65-
<input type="checkbox" data-config-dyn-key="service.explore.disable_organizations_page" {{if .SystemConfig.Service.ExplorePage.DisableOrganizationsPage.Value ctx}}checked{{end}}><label></label>
65+
<input type="checkbox" data-config-dyn-key="service.explore.disable_organizations_page" {{if .SystemConfig.Service.Explore.DisableOrganizationsPage.Value ctx}}checked{{end}}><label></label>
6666
</div>
6767
</dd>
6868
<div class="divider"></div>
6969
<dt>{{ctx.Locale.Tr "admin.config.explore_disable_code_page"}}</dt>
7070
<dd>
7171
<div class="ui toggle checkbox" data-tooltip-content="{{ctx.Locale.Tr "admin.config.explore_disable_code_page"}}">
72-
<input type="checkbox" data-config-dyn-key="service.explore.disable_code_page" {{if .SystemConfig.Service.ExplorePage.DisableCodePage.Value ctx}}checked{{end}}><label></label>
72+
<input type="checkbox" data-config-dyn-key="service.explore.disable_code_page" {{if .SystemConfig.Service.Explore.DisableCodePage.Value ctx}}checked{{end}}><label></label>
7373
</div>
7474
</dd>
7575
</dl>

templates/explore/navbar.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
<a class="{{if .PageIsExploreRepositories}}active {{end}}item" href="{{AppSubUrl}}/explore/repos">
44
{{svg "octicon-repo"}} {{ctx.Locale.Tr "explore.repos"}}
55
</a>
6-
{{if not .UsersIsDisabled}}
6+
{{if not (.SystemConfig.Service.Explore.DisableUsersPage.Value ctx)}}
77
<a class="{{if .PageIsExploreUsers}}active {{end}}item" href="{{AppSubUrl}}/explore/users">
88
{{svg "octicon-person"}} {{ctx.Locale.Tr "explore.users"}}
99
</a>
1010
{{end}}
11-
{{if not .OrganizationsIsDisabled}}
11+
{{if not (.SystemConfig.Service.Explore.DisableOrganizationsPage.Value ctx)}}
1212
<a class="{{if .PageIsExploreOrganizations}}active {{end}}item" href="{{AppSubUrl}}/explore/organizations">
1313
{{svg "octicon-organization"}} {{ctx.Locale.Tr "explore.organizations"}}
1414
</a>
1515
{{end}}
16-
{{if and (not ctx.Consts.RepoUnitTypeCode.UnitGlobalDisabled) (and .IsRepoIndexerEnabled (not .CodeIsDisabled))}}
16+
{{if and (not ctx.Consts.RepoUnitTypeCode.UnitGlobalDisabled) (and .IsRepoIndexerEnabled (not (.SystemConfig.Service.Explore.DisableCodePage.Value ctx)))}}
1717
<a class="{{if .PageIsExploreCode}}active {{end}}item" href="{{AppSubUrl}}/explore/code">
1818
{{svg "octicon-code"}} {{ctx.Locale.Tr "explore.code"}}
1919
</a>

0 commit comments

Comments
 (0)