Skip to content
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

Add ui.explore settings to control view of explore pages (2) #14094

Merged
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
03f50d7
Add ui.explore settings to control view of explore pages
zeripath Nov 24, 2020
ed89cc3
chinese translation
a1012112796 Nov 24, 2020
9936ff4
Merge pull request #8 from a1012112796/pr/13687
zeripath Nov 24, 2020
b73f311
Fix test
zeripath Nov 24, 2020
99aa69d
fix test (2)
zeripath Nov 24, 2020
127ee03
oops ignExploreSignIn should use an or
zeripath Nov 24, 2020
a6f0714
Fix test (3)
zeripath Nov 24, 2020
11881c0
attempt to placate mssql
zeripath Nov 25, 2020
adc8b60
Fix for MSSQL
zeripath Nov 25, 2020
be0e163
Merge remote-tracking branch 'origin/master' into fix-2908-explore-pa…
zeripath Dec 21, 2020
d35b5fe
drop the public repos code
zeripath Dec 21, 2020
57e18b5
Merge remote-tracking branch 'origin/master' into fix-2908-no-user-ex…
zeripath Feb 19, 2021
d8596b8
Update docs/content/doc/advanced/config-cheat-sheet.zh-cn.md
zeripath Mar 3, 2021
080e2cd
Merge branch 'master' into fix-2908-no-user-explore-page-settings
6543 Mar 5, 2021
4d8c1d5
Place the entirety of /api/v1/users/... under reqExploreSignIn
zeripath Mar 5, 2021
dd1c221
Move heatmap out of reqExploreSignIn
zeripath Mar 5, 2021
272d19b
Move ui.explore to service.explore
zeripath Mar 10, 2021
e061509
Merge branch 'master' into fix-2908-no-user-explore-page-settings
zeripath Mar 10, 2021
ad4e0bd
remove extraneous comment
zeripath Mar 10, 2021
a3093c1
Handle MapTo error
6543 Mar 11, 2021
da875e9
Merge branch 'master' into fix-2908-no-user-explore-page-settings
6543 Mar 11, 2021
0802ff5
Merge branch 'master' into fix-2908-no-user-explore-page-settings
6543 Mar 11, 2021
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
6 changes: 6 additions & 0 deletions docs/content/doc/advanced/config-cheat-sheet.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,12 @@ relation to port exhaustion.
The user's email will be replaced with a concatenation of the user name in lower case, "@" and NO_REPLY_ADDRESS.
- `USER_DELETE_WITH_COMMENTS_MAX_TIME`: **0** Minimum amount of time a user must exist before comments are kept when the user is deleted.

### Service - Expore (`service.explore`)

- `REQUIRE_SIGNIN_VIEW`: **false**: Only allow signed in users to view the explore pages.
- `DISABLE_USERS_PAGE`: **false**: Disable the users explore page.


## SSH Minimum Key Sizes (`ssh.minimum_key_sizes`)

Define allowed algorithms and their minimum key length (use -1 to disable a type):
Expand Down
5 changes: 5 additions & 0 deletions docs/content/doc/advanced/config-cheat-sheet.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ menu:
- `ENABLE_REVERSE_PROXY_AUTO_REGISTRATION`: 允许通过反向认证做自动注册。
- `ENABLE_CAPTCHA`: 注册时使用图片验证码。

### Service - Expore (`service.explore`)

- `REQUIRE_SIGNIN_VIEW`: **false**: 仅允许已登录的用户查看探索页面。
- `DISABLE_USERS_PAGE`: **false**: 不显示用户探索页面。

## Webhook (`webhook`)

- `QUEUE_LENGTH`: 说明: Hook 任务队列长度。
Expand Down
8 changes: 8 additions & 0 deletions modules/setting/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ var Service struct {
EnableOpenIDSignUp bool
OpenIDWhitelist []*regexp.Regexp
OpenIDBlacklist []*regexp.Regexp

// Explore page settings
Explore struct {
RequireSigninView bool `ini:"REQUIRE_SIGNIN_VIEW"`
DisableUsersPage bool `ini:"DISABLE_USERS_PAGE"`
} `ini:"service.explore"`
}

func newService() {
Expand Down Expand Up @@ -108,6 +114,8 @@ func newService() {
Service.DefaultOrgMemberVisible = sec.Key("DEFAULT_ORG_MEMBER_VISIBLE").MustBool()
Service.UserDeleteWithCommentsMaxTime = sec.Key("USER_DELETE_WITH_COMMENTS_MAX_TIME").MustDuration(0)

Cfg.Section("service.explore").MapTo(&Service.Explore)

sec = Cfg.Section("openid")
Service.EnableOpenIDSignIn = sec.Key("ENABLE_OPENID_SIGNIN").MustBool(!InstallLock)
Service.EnableOpenIDSignUp = sec.Key("ENABLE_OPENID_SIGNUP").MustBool(!Service.DisableRegistration && Service.EnableOpenIDSignIn)
Expand Down
14 changes: 11 additions & 3 deletions routers/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ func reqToken() func(ctx *context.APIContext) {
}
}

func reqExploreSignIn() func(ctx *context.APIContext) {
return func(ctx *context.APIContext) {
if setting.Service.Explore.RequireSigninView && !ctx.IsSigned {
ctx.Error(http.StatusUnauthorized, "reqExploreSignIn", "you must be signed in to search for users")
}
}
}

func reqBasicAuth() func(ctx *context.APIContext) {
return func(ctx *context.APIContext) {
if !ctx.Context.IsBasicAuth {
Expand Down Expand Up @@ -603,16 +611,16 @@ func Routes() *web.Route {

// Users
m.Group("/users", func() {
m.Get("/search", user.Search)
m.Get("/search", reqExploreSignIn(), user.Search)

m.Group("/{username}", func() {
m.Get("", user.GetInfo)
m.Get("", reqExploreSignIn(), user.GetInfo)

if setting.Service.EnableUserHeatmap {
m.Get("/heatmap", user.GetUserHeatmapData)
}

m.Get("/repos", user.ListUserRepos)
m.Get("/repos", reqExploreSignIn(), user.ListUserRepos)
m.Group("/tokens", func() {
m.Combo("").Get(user.ListAccessTokens).
Post(bind(api.CreateAccessTokenOption{}), user.CreateAccessToken)
Expand Down
7 changes: 7 additions & 0 deletions routers/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {

// ExploreRepos render explore repositories page
func ExploreRepos(ctx *context.Context) {
ctx.Data["UsersIsDisabled"] = setting.Service.Explore.DisableUsersPage
ctx.Data["Title"] = ctx.Tr("explore")
ctx.Data["PageIsExplore"] = true
ctx.Data["PageIsExploreRepositories"] = true
Expand Down Expand Up @@ -247,6 +248,10 @@ func RenderUserSearch(ctx *context.Context, opts *models.SearchUserOptions, tplN

// ExploreUsers render explore users page
func ExploreUsers(ctx *context.Context) {
if setting.Service.Explore.DisableUsersPage {
ctx.Redirect(setting.AppSubURL + "/explore/repos")
return
}
ctx.Data["Title"] = ctx.Tr("explore")
ctx.Data["PageIsExplore"] = true
ctx.Data["PageIsExploreUsers"] = true
Expand All @@ -263,6 +268,7 @@ func ExploreUsers(ctx *context.Context) {

// ExploreOrganizations render explore organizations page
func ExploreOrganizations(ctx *context.Context) {
ctx.Data["UsersIsDisabled"] = setting.Service.Explore.DisableUsersPage
ctx.Data["Title"] = ctx.Tr("explore")
ctx.Data["PageIsExplore"] = true
ctx.Data["PageIsExploreOrganizations"] = true
Expand All @@ -288,6 +294,7 @@ func ExploreCode(ctx *context.Context) {
return
}

ctx.Data["UsersIsDisabled"] = setting.Service.Explore.DisableUsersPage
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
ctx.Data["Title"] = ctx.Tr("explore")
ctx.Data["PageIsExplore"] = true
Expand Down
3 changes: 2 additions & 1 deletion routers/routes/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ func goGet(ctx *context.Context) {
func RegisterRoutes(m *web.Route) {
reqSignIn := context.Toggle(&context.ToggleOptions{SignInRequired: true})
ignSignIn := context.Toggle(&context.ToggleOptions{SignInRequired: setting.Service.RequireSignInView})
ignExploreSignIn := context.Toggle(&context.ToggleOptions{SignInRequired: setting.Service.RequireSignInView || setting.Service.Explore.RequireSigninView})
ignSignInAndCsrf := context.Toggle(&context.ToggleOptions{DisableCSRF: true})
reqSignOut := context.Toggle(&context.ToggleOptions{SignOutRequired: true})

Expand Down Expand Up @@ -335,7 +336,7 @@ func RegisterRoutes(m *web.Route) {
m.Get("/users", routers.ExploreUsers)
m.Get("/organizations", routers.ExploreOrganizations)
m.Get("/code", routers.ExploreCode)
}, ignSignIn)
}, ignExploreSignIn)
m.Get("/issues", reqSignIn, user.Issues)
m.Get("/pulls", reqSignIn, user.Pulls)
m.Get("/milestones", reqSignIn, reqMilestonesDashboardPageEnabled, user.Milestones)
Expand Down
8 changes: 5 additions & 3 deletions templates/explore/navbar.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
<a class="{{if .PageIsExploreRepositories}}active{{end}} item" href="{{AppSubUrl}}/explore/repos">
{{svg "octicon-repo"}} {{.i18n.Tr "explore.repos"}}
</a>
<a class="{{if .PageIsExploreUsers}}active{{end}} item" href="{{AppSubUrl}}/explore/users">
{{svg "octicon-person"}} {{.i18n.Tr "explore.users"}}
</a>
{{if not .UsersIsDisabled}}
<a class="{{if .PageIsExploreUsers}}active{{end}} item" href="{{AppSubUrl}}/explore/users">
{{svg "octicon-person"}} {{.i18n.Tr "explore.users"}}
</a>
{{end}}
<a class="{{if .PageIsExploreOrganizations}}active{{end}} item" href="{{AppSubUrl}}/explore/organizations">
{{svg "octicon-organization"}} {{.i18n.Tr "explore.organizations"}}
</a>
Expand Down