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 11 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
5 changes: 5 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 @@ -181,6 +181,11 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
- `NOTICE_PAGING_NUM`: **25**: Number of notices that are shown in one page.
- `ORG_PAGING_NUM`: **50**: Number of organizations that are shown in one page.

### UI - Expore (`ui.explore`)

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

### UI - Metadata (`ui.meta`)

- `AUTHOR`: **Gitea - Git with a cup of tea**: Author meta tag of the homepage.
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 @@ -50,6 +50,11 @@ menu:
- `NOTICE_PAGING_NUM`: 系统提示页面每页显示的提示数量。
- `ORG_PAGING_NUM`: 组织管理页面每页显示的组织数量。

### UI - Expore (`ui.explore`)

- `REQUIRE_SIGNIN_VIEW`: **false**: 仅允许已登录的用户查看探索页面。
- `DISABLE_USERS_PAGE`: **false**: 。
zeripath marked this conversation as resolved.
Show resolved Hide resolved

## Markdown (`markdown`)

- `ENABLE_HARD_LINE_BREAK`: 是否启用硬换行扩展。
Expand Down
9 changes: 9 additions & 0 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ var (
Description string
Keywords string
} `ini:"ui.meta"`
// Explore page settings
Explore struct {
RequireSigninView bool `ini:"REQUIRE_SIGNIN_VIEW"`
DisableUsersPage bool `ini:"DISABLE_USERS_PAGE"`
} `ini:"ui.explore"`
}{
ExplorePagingNum: 20,
IssuePagingNum: 10,
Expand Down Expand Up @@ -253,6 +258,10 @@ var (
Description: "Gitea (Git with a cup of tea) is a painless self-hosted Git service written in Go",
Keywords: "go,git,self-hosted,gitea",
},
Explore: struct {
RequireSigninView bool `ini:"REQUIRE_SIGNIN_VIEW"`
DisableUsersPage bool `ini:"DISABLE_USERS_PAGE"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe move this to service is better? We need a feature to disable all the user explore include APIs. A standalone setting for UI search seems not enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really think we have way too much stuff in [service] already - so if it's going in there it should go in [service.explore] I think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on [service.explore]

}{},
}

// Markdown settings
Expand Down
10 changes: 9 additions & 1 deletion routers/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ func reqToken() macaron.Handler {
}
}

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

func reqBasicAuth() macaron.Handler {
return func(ctx *context.APIContext) {
if !ctx.Context.IsBasicAuth {
Expand Down Expand Up @@ -538,7 +546,7 @@ func RegisterRoutes(m *macaron.Macaron) {

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

m.Group("/:username", func() {
m.Get("", user.GetInfo)
Expand Down
7 changes: 7 additions & 0 deletions routers/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {

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

// ExploreUsers render explore users page
func ExploreUsers(ctx *context.Context) {
if setting.UI.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 @@ -262,6 +267,7 @@ func ExploreUsers(ctx *context.Context) {

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

ctx.Data["UsersIsDisabled"] = setting.UI.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/macaron.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ func RegisterMacaronInstallRoute(m *macaron.Macaron) {
func RegisterMacaronRoutes(m *macaron.Macaron) {
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.UI.Explore.RequireSigninView})
ignSignInAndCsrf := context.Toggle(&context.ToggleOptions{DisableCSRF: true})
reqSignOut := context.Toggle(&context.ToggleOptions{SignOutRequired: true})

Expand Down Expand Up @@ -196,7 +197,7 @@ func RegisterMacaronRoutes(m *macaron.Macaron) {
m.Get("/users", routers.ExploreUsers)
m.Get("/organizations", routers.ExploreOrganizations)
m.Get("/code", routers.ExploreCode)
}, ignSignIn)
}, ignExploreSignIn)
m.Combo("/install", routers.InstallInit).Get(routers.Install).
Post(bindIgnErr(auth.InstallForm{}), routers.InstallPost)
m.Get("/^:type(issues|pulls)$", reqSignIn, user.Issues)
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