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 DISABLE_ORGANIZATIONS_PAGE and DISABLE_CODE_PAGE settings for explore pages and fix an issue related to user search #32288

Merged
merged 17 commits into from
Oct 22, 2024
Merged
18 changes: 18 additions & 0 deletions custom/conf/app.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,24 @@ LEVEL = Info
;; Valid site url schemes for user profiles
;VALID_SITE_URL_SCHEMES=http,https

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;[service.explore]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Only allow signed in users to view the explore pages.
;REQUIRE_SIGNIN_VIEW = false
Zettat123 marked this conversation as resolved.
Show resolved Hide resolved
;;
;; Disable the users explore page.
;DISABLE_USERS_PAGE = false
;;
;; Disable the organizations explore page.
;DISABLE_ORGANIZATIONS_PAGE = false
;;
;; Disable the code explore page.
;DISABLE_CODE_PAGE = false
;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down
6 changes: 4 additions & 2 deletions modules/setting/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ var Service = struct {

// Explore page settings
Explore struct {
RequireSigninView bool `ini:"REQUIRE_SIGNIN_VIEW"`
DisableUsersPage bool `ini:"DISABLE_USERS_PAGE"`
RequireSigninView bool `ini:"REQUIRE_SIGNIN_VIEW"`
DisableUsersPage bool `ini:"DISABLE_USERS_PAGE"`
DisableOrganizationsPage bool `ini:"DISABLE_ORGANIZATIONS_PAGE"`
DisableCodePage bool `ini:"DISABLE_CODE_PAGE"`
} `ini:"service.explore"`
}{
AllowedUserVisibilityModesSlice: []bool{true, true, true},
Expand Down
12 changes: 8 additions & 4 deletions routers/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,12 @@ func reqToken() func(ctx *context.APIContext) {
}
}

func reqExploreSignIn() func(ctx *context.APIContext) {
func reqExploreSignInAndUsersExploreEnabled() func(ctx *context.APIContext) {
return func(ctx *context.APIContext) {
if setting.Service.Explore.DisableUsersPage {
ctx.NotFound()
return
}
if setting.Service.Explore.RequireSigninView && !ctx.IsSigned {
ctx.Error(http.StatusUnauthorized, "reqExploreSignIn", "you must be signed in to search for users")
}
Expand Down Expand Up @@ -955,16 +959,16 @@ func Routes() *web.Router {

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

m.Group("/{username}", func() {
m.Get("", reqExploreSignIn(), user.GetInfo)
m.Get("", reqExploreSignInAndUsersExploreEnabled(), user.GetInfo)
Zettat123 marked this conversation as resolved.
Show resolved Hide resolved

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

m.Get("/repos", tokenRequiresScopes(auth_model.AccessTokenScopeCategoryRepository), reqExploreSignIn(), user.ListUserRepos)
m.Get("/repos", tokenRequiresScopes(auth_model.AccessTokenScopeCategoryRepository), reqExploreSignInAndUsersExploreEnabled(), user.ListUserRepos)
m.Group("/tokens", func() {
m.Combo("").Get(user.ListAccessTokens).
Post(bind(api.CreateAccessTokenOption{}), reqToken(), user.CreateAccessToken)
Expand Down
5 changes: 5 additions & 0 deletions routers/web/explore/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ func Code(ctx *context.Context) {
ctx.Redirect(setting.AppSubURL + "/explore")
return
}
if setting.Service.Explore.DisableCodePage {
Zettat123 marked this conversation as resolved.
Show resolved Hide resolved
ctx.Redirect(setting.AppSubURL + "/explore/repos")
return
}

ctx.Data["UsersIsDisabled"] = setting.Service.Explore.DisableUsersPage
ctx.Data["OrganizationsIsDisabled"] = setting.Service.Explore.DisableOrganizationsPage
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
ctx.Data["Title"] = ctx.Tr("explore")
ctx.Data["PageIsExplore"] = true
Expand Down
6 changes: 6 additions & 0 deletions routers/web/explore/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ import (

// Organizations render explore organizations page
func Organizations(ctx *context.Context) {
if setting.Service.Explore.DisableOrganizationsPage {
ctx.Redirect(setting.AppSubURL + "/explore/repos")
return
}

ctx.Data["UsersIsDisabled"] = setting.Service.Explore.DisableUsersPage
ctx.Data["CodeIsDisabled"] = setting.Service.Explore.DisableCodePage
ctx.Data["Title"] = ctx.Tr("explore")
ctx.Data["PageIsExplore"] = true
ctx.Data["PageIsExploreOrganizations"] = true
Expand Down
2 changes: 2 additions & 0 deletions routers/web/explore/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
// Repos render explore repositories page
func Repos(ctx *context.Context) {
ctx.Data["UsersIsDisabled"] = setting.Service.Explore.DisableUsersPage
ctx.Data["OrganizationsIsDisabled"] = setting.Service.Explore.DisableOrganizationsPage
ctx.Data["CodeIsDisabled"] = setting.Service.Explore.DisableCodePage
Zettat123 marked this conversation as resolved.
Show resolved Hide resolved
ctx.Data["Title"] = ctx.Tr("explore")
ctx.Data["PageIsExplore"] = true
ctx.Data["PageIsExploreRepositories"] = true
Expand Down
2 changes: 2 additions & 0 deletions routers/web/explore/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ func Users(ctx *context.Context) {
ctx.Redirect(setting.AppSubURL + "/explore/repos")
return
}
ctx.Data["OrganizationsIsDisabled"] = setting.Service.Explore.DisableOrganizationsPage
ctx.Data["CodeIsDisabled"] = setting.Service.Explore.DisableCodePage
ctx.Data["Title"] = ctx.Tr("explore")
ctx.Data["PageIsExplore"] = true
ctx.Data["PageIsExploreUsers"] = true
Expand Down
4 changes: 3 additions & 1 deletion templates/explore/navbar.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
{{svg "octicon-person"}} {{ctx.Locale.Tr "explore.users"}}
</a>
{{end}}
{{if not .OrganizationsIsDisabled}}
<a class="{{if .PageIsExploreOrganizations}}active {{end}}item" href="{{AppSubUrl}}/explore/organizations">
{{svg "octicon-organization"}} {{ctx.Locale.Tr "explore.organizations"}}
</a>
{{if and (not ctx.Consts.RepoUnitTypeCode.UnitGlobalDisabled) .IsRepoIndexerEnabled}}
{{end}}
{{if and (not ctx.Consts.RepoUnitTypeCode.UnitGlobalDisabled) (and .IsRepoIndexerEnabled (not .CodeIsDisabled))}}
Zettat123 marked this conversation as resolved.
Show resolved Hide resolved
<a class="{{if .PageIsExploreCode}}active {{end}}item" href="{{AppSubUrl}}/explore/code">
{{svg "octicon-code"}} {{ctx.Locale.Tr "explore.code"}}
</a>
Expand Down
Loading