Skip to content

Commit c3a3bab

Browse files
committed
use db settings
1 parent b88875b commit c3a3bab

File tree

12 files changed

+84
-29
lines changed

12 files changed

+84
-29
lines changed

modules/setting/config.go

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

54+
type ExplorePage struct {
55+
RequireSigninView *config.Value[bool]
56+
DisableUsersPage *config.Value[bool]
57+
DisableOrganizationsPage *config.Value[bool]
58+
DisableCodePage *config.Value[bool]
59+
}
60+
61+
type ServiceStruct struct {
62+
ExplorePage *ExplorePage
63+
}
64+
5465
type ConfigStruct struct {
5566
Picture *PictureStruct
5667
Repository *RepositoryStruct
68+
Service *ServiceStruct
5769
}
5870

5971
var (
@@ -71,6 +83,14 @@ func initDefaultConfig() {
7183
Repository: &RepositoryStruct{
7284
OpenWithEditorApps: config.ValueJSON[OpenWithEditorAppsType]("repository.open-with.editor-apps"),
7385
},
86+
Service: &ServiceStruct{
87+
ExplorePage: &ExplorePage{
88+
RequireSigninView: config.ValueJSON[bool]("service.explore.require_signin_view").WithFileConfig(config.CfgSecKey{Sec: "service.explore", Key: "REQUIRE_SIGNIN_VIEW"}),
89+
DisableUsersPage: config.ValueJSON[bool]("service.explore.disable_users_page").WithFileConfig(config.CfgSecKey{Sec: "service.explore", Key: "DISABLE_USERS_PAGE"}),
90+
DisableOrganizationsPage: config.ValueJSON[bool]("service.explore.disable_organizations_page").WithFileConfig(config.CfgSecKey{Sec: "service.explore", Key: "DISABLE_ORGANIZATIONS_PAGE"}),
91+
DisableCodePage: config.ValueJSON[bool]("service.explore.disable_code_page").WithFileConfig(config.CfgSecKey{Sec: "service.explore", Key: "DISABLE_CODE_PAGE"}),
92+
},
93+
},
7494
}
7595
}
7696

modules/setting/service.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,6 @@ var Service = struct {
8787
EnableOpenIDSignUp bool
8888
OpenIDWhitelist []*regexp.Regexp
8989
OpenIDBlacklist []*regexp.Regexp
90-
91-
// Explore page settings
92-
Explore struct {
93-
RequireSigninView bool `ini:"REQUIRE_SIGNIN_VIEW"`
94-
DisableUsersPage bool `ini:"DISABLE_USERS_PAGE"`
95-
DisableOrganizationsPage bool `ini:"DISABLE_ORGANIZATIONS_PAGE"`
96-
DisableCodePage bool `ini:"DISABLE_CODE_PAGE"`
97-
} `ini:"service.explore"`
9890
}{
9991
AllowedUserVisibilityModesSlice: []bool{true, true, true},
10092
}
@@ -236,8 +228,6 @@ func loadServiceFrom(rootCfg ConfigProvider) {
236228
}
237229
Service.ValidSiteURLSchemes = schemes
238230

239-
mustMapSetting(rootCfg, "service.explore", &Service.Explore)
240-
241231
loadOpenIDSetting(rootCfg)
242232
}
243233

options/locale/locale_en-US.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3300,6 +3300,10 @@ config.picture_service = Picture Service
33003300
config.disable_gravatar = Disable Gravatar
33013301
config.enable_federated_avatar = Enable Federated Avatars
33023302
config.open_with_editor_app_help = The "Open with" editors for the clone menu. If left empty, the default will be used. Expand to see the default.
3303+
config.explore_require_signin_view = Only signed-in users can view the explore pages
3304+
config.explore_disable_users_page = Disable users explore page
3305+
config.explore_disable_organizations_page = Disable organizations explore page
3306+
config.explore_disable_code_page = Disable code explore page
33033307
33043308
config.git_config = Git Configuration
33053309
config.git_disable_diff_highlight = Disable Diff Syntax Highlight

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.Service.Explore.DisableUsersPage {
359+
if setting.Config().Service.ExplorePage.DisableUsersPage.Value(ctx) {
360360
ctx.NotFound()
361361
return
362362
}
363-
if setting.Service.Explore.RequireSigninView && !ctx.IsSigned {
363+
if setting.Config().Service.ExplorePage.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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +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,
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,
237241
}
238242
marshaller, hasMarshaller := marshallers[key]
239243
if !hasMarshaller {

routers/web/explore/code.go

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

33-
ctx.Data["UsersIsDisabled"] = setting.Service.Explore.DisableUsersPage
34-
ctx.Data["OrganizationsIsDisabled"] = setting.Service.Explore.DisableOrganizationsPage
33+
ctx.Data["UsersIsDisabled"] = setting.Config().Service.ExplorePage.DisableUsersPage.Value(ctx)
34+
ctx.Data["OrganizationsIsDisabled"] = setting.Config().Service.ExplorePage.DisableOrganizationsPage.Value(ctx)
3535
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
3636
ctx.Data["Title"] = ctx.Tr("explore")
3737
ctx.Data["PageIsExplore"] = true

routers/web/explore/org.go

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

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

22-
ctx.Data["UsersIsDisabled"] = setting.Service.Explore.DisableUsersPage
23-
ctx.Data["CodeIsDisabled"] = setting.Service.Explore.DisableCodePage
22+
ctx.Data["UsersIsDisabled"] = setting.Config().Service.ExplorePage.DisableUsersPage.Value(ctx)
23+
ctx.Data["CodeIsDisabled"] = setting.Config().Service.ExplorePage.DisableCodePage.Value(ctx)
2424
ctx.Data["Title"] = ctx.Tr("explore")
2525
ctx.Data["PageIsExplore"] = true
2626
ctx.Data["PageIsExploreOrganizations"] = true

routers/web/explore/repo.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ 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.Service.Explore.DisableUsersPage
169-
ctx.Data["OrganizationsIsDisabled"] = setting.Service.Explore.DisableOrganizationsPage
170-
ctx.Data["CodeIsDisabled"] = setting.Service.Explore.DisableCodePage
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)
171171
ctx.Data["Title"] = ctx.Tr("explore")
172172
ctx.Data["PageIsExplore"] = true
173173
ctx.Data["PageIsExploreRepositories"] = true

routers/web/explore/user.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ 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.Service.Explore.DisableUsersPage {
133+
if setting.Config().Service.ExplorePage.DisableUsersPage.Value(ctx) {
134134
ctx.Redirect(setting.AppSubURL + "/explore/repos")
135135
return
136136
}
137-
ctx.Data["OrganizationsIsDisabled"] = setting.Service.Explore.DisableOrganizationsPage
138-
ctx.Data["CodeIsDisabled"] = setting.Service.Explore.DisableCodePage
137+
ctx.Data["OrganizationsIsDisabled"] = setting.Config().Service.ExplorePage.DisableOrganizationsPage.Value(ctx)
138+
ctx.Data["CodeIsDisabled"] = setting.Config().Service.ExplorePage.DisableCodePage.Value(ctx)
139139
ctx.Data["Title"] = ctx.Tr("explore")
140140
ctx.Data["PageIsExplore"] = true
141141
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.Service.Explore.DisableUsersPage {
70+
if !setting.Config().Service.ExplorePage.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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,9 @@ func registerRoutes(m *web.Router) {
300300
reqSignOut := verifyAuthWithOptions(&common.VerifyOptions{SignOutRequired: true})
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})
303-
ignExploreSignIn := verifyAuthWithOptions(&common.VerifyOptions{SignInRequired: setting.Service.RequireSignInView || setting.Service.Explore.RequireSigninView})
303+
ignExploreSignIn := func(ctx *context.Context) {
304+
verifyAuthWithOptions(&common.VerifyOptions{SignInRequired: setting.Service.RequireSignInView || setting.Config().Service.ExplorePage.RequireSigninView.Value(ctx)})(ctx)
305+
}
304306

305307
validation.AddBindingRules()
306308

templates/admin/config_settings.tmpl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,39 @@
3939
</div>
4040
</form>
4141
</div>
42+
43+
<h4 class="ui top attached header">
44+
{{ctx.Locale.Tr "admin.config.service_config"}}
45+
</h4>
46+
<div class="ui attached table segment">
47+
<dl class="admin-dl-horizontal">
48+
<dt>{{ctx.Locale.Tr "admin.config.explore_require_signin_view"}}</dt>
49+
<dd>
50+
<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>
52+
</div>
53+
</dd>
54+
<div class="divider"></div>
55+
<dt>{{ctx.Locale.Tr "admin.config.explore_disable_users_page"}}</dt>
56+
<dd>
57+
<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>
59+
</div>
60+
</dd>
61+
<div class="divider"></div>
62+
<dt>{{ctx.Locale.Tr "admin.config.explore_disable_organizations_page"}}</dt>
63+
<dd>
64+
<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>
66+
</div>
67+
</dd>
68+
<div class="divider"></div>
69+
<dt>{{ctx.Locale.Tr "admin.config.explore_disable_code_page"}}</dt>
70+
<dd>
71+
<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>
73+
</div>
74+
</dd>
75+
</dl>
76+
</div>
4277
{{template "admin/layout_footer" .}}

0 commit comments

Comments
 (0)