diff --git a/models/user/search.go b/models/user/search.go index 45b051187ea07..6678a95d78d79 100644 --- a/models/user/search.go +++ b/models/user/search.go @@ -22,7 +22,7 @@ type SearchUserOptions struct { db.ListOptions Keyword string - Type UserType + Type optional.Option[UserType] UID int64 LoginName string // this option should be used only for admin user SourceID int64 // this option should be used only for admin user @@ -44,17 +44,20 @@ type SearchUserOptions struct { } func (opts *SearchUserOptions) toSearchQueryBase(ctx context.Context) *xorm.Session { - var cond builder.Cond - cond = builder.Eq{"type": opts.Type} - if opts.IncludeReserved { - if opts.Type == UserTypeIndividual { - cond = cond.Or(builder.Eq{"type": UserTypeUserReserved}).Or( - builder.Eq{"type": UserTypeBot}, - ).Or( - builder.Eq{"type": UserTypeRemoteUser}, - ) - } else if opts.Type == UserTypeOrganization { - cond = cond.Or(builder.Eq{"type": UserTypeOrganizationReserved}) + cond := builder.NewCond() + + if opts.Type.Has() { + cond = builder.Eq{"type": opts.Type.Value()} + if opts.IncludeReserved { + if opts.Type.Value() == UserTypeIndividual { + cond = cond.Or(builder.Eq{"type": UserTypeUserReserved}).Or( + builder.Eq{"type": UserTypeBot}, + ).Or( + builder.Eq{"type": UserTypeRemoteUser}, + ) + } else if opts.Type.Value() == UserTypeOrganization { + cond = cond.Or(builder.Eq{"type": UserTypeOrganizationReserved}) + } } } diff --git a/models/user/user_test.go b/models/user/user_test.go index f4efd071eade1..8993a4176b653 100644 --- a/models/user/user_test.go +++ b/models/user/user_test.go @@ -75,7 +75,7 @@ func TestSearchUsers(t *testing.T) { // test orgs testOrgSuccess := func(opts *user_model.SearchUserOptions, expectedOrgIDs []int64) { - opts.Type = user_model.UserTypeOrganization + opts.Type = optional.Some(user_model.UserTypeOrganization) testSuccess(opts, expectedOrgIDs) } @@ -96,7 +96,7 @@ func TestSearchUsers(t *testing.T) { // test users testUserSuccess := func(opts *user_model.SearchUserOptions, expectedUserIDs []int64) { - opts.Type = user_model.UserTypeIndividual + opts.Type = optional.Some(user_model.UserTypeIndividual) testSuccess(opts, expectedUserIDs) } diff --git a/modules/setting/server.go b/modules/setting/server.go index 0dea4e1ac75b8..5a0e65b078507 100644 --- a/modules/setting/server.go +++ b/modules/setting/server.go @@ -36,7 +36,7 @@ type LandingPage string const ( LandingPageHome LandingPage = "/" LandingPageExplore LandingPage = "/explore" - LandingPageOrganizations LandingPage = "/explore/organizations" + LandingPageOrganizations LandingPage = "/explore/users" // TODO: Support `user` directly without the confusing `organization` key LandingPageLogin LandingPage = "/user/login" ) diff --git a/modules/web/middleware/data.go b/modules/web/middleware/data.go index 08d83f94be7f1..49117d3e24a23 100644 --- a/modules/web/middleware/data.go +++ b/modules/web/middleware/data.go @@ -47,7 +47,7 @@ func GetContextData(c context.Context) ContextData { func CommonTemplateContextData() ContextData { return ContextData{ - "IsLandingPageOrganizations": setting.LandingPageURL == setting.LandingPageOrganizations, + "IsLandingPageExploreUsers": setting.LandingPageURL == setting.LandingPageOrganizations, "ShowRegistrationButton": setting.Service.ShowRegistrationButton, "ShowMilestonesDashboardPage": setting.Service.ShowMilestonesDashboardPage, diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index dc16d78fc7e6e..0e9d85e4ae619 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -373,12 +373,14 @@ issues.in_your_repos = In your repositories [explore] repos = Repositories users = Users -organizations = Organizations go_to = Go to code = Code code_last_indexed_at = Last indexed %s relevant_repositories_tooltip = Repositories that are forks or that have no topic, no icon, and no description are hidden. relevant_repositories = Only relevant repositories are being shown, show unfiltered results. +user_is_individual = "%s is a normal user" +user_is_bot = "%s is a bot" +user_is_organization = "%s is an organization" [auth] create_new_account = Register Account diff --git a/routers/api/v1/admin/org.go b/routers/api/v1/admin/org.go index a5c299bbf01c8..0893e4947bd59 100644 --- a/routers/api/v1/admin/org.go +++ b/routers/api/v1/admin/org.go @@ -10,6 +10,7 @@ import ( "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/organization" user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/optional" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/routers/api/v1/utils" @@ -103,7 +104,7 @@ func GetAllOrgs(ctx *context.APIContext) { users, maxResults, err := user_model.SearchUsers(ctx, &user_model.SearchUserOptions{ Actor: ctx.Doer, - Type: user_model.UserTypeOrganization, + Type: optional.Some(user_model.UserTypeOrganization), OrderBy: db.SearchOrderByAlphabetically, ListOptions: listOptions, Visible: []api.VisibleType{api.VisibleTypePublic, api.VisibleTypeLimited, api.VisibleTypePrivate}, diff --git a/routers/api/v1/admin/user.go b/routers/api/v1/admin/user.go index 87a5b28fad0a6..44dc9347831ca 100644 --- a/routers/api/v1/admin/user.go +++ b/routers/api/v1/admin/user.go @@ -423,7 +423,7 @@ func SearchUsers(ctx *context.APIContext) { users, maxResults, err := user_model.SearchUsers(ctx, &user_model.SearchUserOptions{ Actor: ctx.Doer, - Type: user_model.UserTypeIndividual, + Type: optional.Some(user_model.UserTypeIndividual), LoginName: ctx.FormTrim("login_name"), SourceID: ctx.FormInt64("source_id"), OrderBy: db.SearchOrderByAlphabetically, diff --git a/routers/api/v1/org/org.go b/routers/api/v1/org/org.go index e848d95181094..740c218443a49 100644 --- a/routers/api/v1/org/org.go +++ b/routers/api/v1/org/org.go @@ -203,7 +203,7 @@ func GetAll(ctx *context.APIContext) { publicOrgs, maxResults, err := user_model.SearchUsers(ctx, &user_model.SearchUserOptions{ Actor: ctx.Doer, ListOptions: listOptions, - Type: user_model.UserTypeOrganization, + Type: optional.Some(user_model.UserTypeOrganization), OrderBy: db.SearchOrderByAlphabetically, Visible: vMode, }) diff --git a/routers/api/v1/user/user.go b/routers/api/v1/user/user.go index 09147cd2ae00b..36105f8e3a0f8 100644 --- a/routers/api/v1/user/user.go +++ b/routers/api/v1/user/user.go @@ -9,6 +9,7 @@ import ( activities_model "code.gitea.io/gitea/models/activities" user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/optional" "code.gitea.io/gitea/routers/api/v1/utils" "code.gitea.io/gitea/services/context" "code.gitea.io/gitea/services/convert" @@ -71,7 +72,7 @@ func Search(ctx *context.APIContext) { Actor: ctx.Doer, Keyword: ctx.FormTrim("q"), UID: uid, - Type: user_model.UserTypeIndividual, + Type: optional.Some(user_model.UserTypeIndividual), ListOptions: listOptions, }) if err != nil { diff --git a/routers/web/admin/orgs.go b/routers/web/admin/orgs.go index c5454db71e39c..839ba4ec912c5 100644 --- a/routers/web/admin/orgs.go +++ b/routers/web/admin/orgs.go @@ -8,6 +8,7 @@ import ( "code.gitea.io/gitea/models/db" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" + "code.gitea.io/gitea/modules/optional" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/routers/web/explore" @@ -29,7 +30,7 @@ func Organizations(ctx *context.Context) { explore.RenderUserSearch(ctx, &user_model.SearchUserOptions{ Actor: ctx.Doer, - Type: user_model.UserTypeOrganization, + Type: optional.Some(user_model.UserTypeOrganization), IncludeReserved: true, // administrator needs to list all acounts include reserved ListOptions: db.ListOptions{ PageSize: setting.UI.Admin.OrgPagingNum, diff --git a/routers/web/admin/users.go b/routers/web/admin/users.go index 6dfcfc3d9a1a7..c46c770902ac8 100644 --- a/routers/web/admin/users.go +++ b/routers/web/admin/users.go @@ -71,7 +71,7 @@ func Users(ctx *context.Context) { explore.RenderUserSearch(ctx, &user_model.SearchUserOptions{ Actor: ctx.Doer, - Type: user_model.UserTypeIndividual, + Type: optional.Some(user_model.UserTypeIndividual), ListOptions: db.ListOptions{ PageSize: setting.UI.Admin.UserPagingNum, }, diff --git a/routers/web/explore/org.go b/routers/web/explore/org.go deleted file mode 100644 index f8fd6ec38efb6..0000000000000 --- a/routers/web/explore/org.go +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2021 The Gitea Authors. All rights reserved. -// SPDX-License-Identifier: MIT - -package explore - -import ( - "code.gitea.io/gitea/models/db" - user_model "code.gitea.io/gitea/models/user" - "code.gitea.io/gitea/modules/container" - "code.gitea.io/gitea/modules/setting" - "code.gitea.io/gitea/modules/structs" - "code.gitea.io/gitea/services/context" -) - -// Organizations render explore organizations page -func Organizations(ctx *context.Context) { - ctx.Data["UsersIsDisabled"] = setting.Service.Explore.DisableUsersPage - ctx.Data["Title"] = ctx.Tr("explore") - ctx.Data["PageIsExplore"] = true - ctx.Data["PageIsExploreOrganizations"] = true - ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled - - visibleTypes := []structs.VisibleType{structs.VisibleTypePublic} - if ctx.Doer != nil { - visibleTypes = append(visibleTypes, structs.VisibleTypeLimited, structs.VisibleTypePrivate) - } - - supportedSortOrders := container.SetOf( - "newest", - "oldest", - "alphabetically", - "reversealphabetically", - ) - sortOrder := ctx.FormString("sort") - if sortOrder == "" { - sortOrder = "newest" - ctx.SetFormString("sort", sortOrder) - } - - RenderUserSearch(ctx, &user_model.SearchUserOptions{ - Actor: ctx.Doer, - Type: user_model.UserTypeOrganization, - ListOptions: db.ListOptions{PageSize: setting.UI.ExplorePagingNum}, - Visible: visibleTypes, - - SupportedSortOrders: supportedSortOrders, - }, tplExploreUsers) -} diff --git a/routers/web/explore/user.go b/routers/web/explore/user.go index b79a79fb2c86f..db32798e6d4b9 100644 --- a/routers/web/explore/user.go +++ b/routers/web/explore/user.go @@ -151,12 +151,17 @@ func Users(ctx *context.Context) { ctx.SetFormString("sort", sortOrder) } + visibleTypes := []structs.VisibleType{structs.VisibleTypePublic} + if ctx.Doer != nil { + visibleTypes = append(visibleTypes, structs.VisibleTypeLimited, structs.VisibleTypePrivate) + } + RenderUserSearch(ctx, &user_model.SearchUserOptions{ Actor: ctx.Doer, - Type: user_model.UserTypeIndividual, + Type: optional.None[user_model.UserType](), ListOptions: db.ListOptions{PageSize: setting.UI.ExplorePagingNum}, IsActive: optional.Some(true), - Visible: []structs.VisibleType{structs.VisibleTypePublic, structs.VisibleTypeLimited, structs.VisibleTypePrivate}, + Visible: visibleTypes, SupportedSortOrders: supportedSortOrders, }, tplExploreUsers) diff --git a/routers/web/home.go b/routers/web/home.go index d4be0931e850d..a0572ccaf4a0f 100644 --- a/routers/web/home.go +++ b/routers/web/home.go @@ -69,7 +69,7 @@ func HomeSitemap(ctx *context.Context) { m := sitemap.NewSitemapIndex() if !setting.Service.Explore.DisableUsersPage { _, cnt, err := user_model.SearchUsers(ctx, &user_model.SearchUserOptions{ - Type: user_model.UserTypeIndividual, + Type: optional.Some(user_model.UserTypeIndividual), ListOptions: db.ListOptions{PageSize: 1}, IsActive: optional.Some(true), Visible: []structs.VisibleType{structs.VisibleTypePublic}, diff --git a/routers/web/user/search.go b/routers/web/user/search.go index fb7729bbe1419..f95a3cf324bc8 100644 --- a/routers/web/user/search.go +++ b/routers/web/user/search.go @@ -8,6 +8,7 @@ import ( "code.gitea.io/gitea/models/db" user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/optional" "code.gitea.io/gitea/services/context" "code.gitea.io/gitea/services/convert" ) @@ -23,7 +24,7 @@ func Search(ctx *context.Context) { Actor: ctx.Doer, Keyword: ctx.FormTrim("q"), UID: ctx.FormInt64("uid"), - Type: user_model.UserTypeIndividual, + Type: optional.Some(user_model.UserTypeIndividual), IsActive: ctx.FormOptionalBool("active"), ListOptions: listOptions, }) diff --git a/routers/web/web.go b/routers/web/web.go index fc1432873f0da..70ea89dce5b90 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -484,7 +484,6 @@ func registerRoutes(m *web.Route) { m.Get("/repos/sitemap-{idx}.xml", sitemapEnabled, explore.Repos) m.Get("/users", explore.Users) m.Get("/users/sitemap-{idx}.xml", sitemapEnabled, explore.Users) - m.Get("/organizations", explore.Organizations) m.Get("/code", func(ctx *context.Context) { if unit.TypeCode.UnitGlobalDisabled() { ctx.NotFound(unit.TypeCode.String(), nil) diff --git a/templates/base/head_navbar.tmpl b/templates/base/head_navbar.tmpl index 4f48dc82c3270..d36a3d16ba0d8 100644 --- a/templates/base/head_navbar.tmpl +++ b/templates/base/head_navbar.tmpl @@ -39,8 +39,8 @@ {{end}} {{end}} {{ctx.Locale.Tr "explore"}} - {{else if .IsLandingPageOrganizations}} - {{ctx.Locale.Tr "explore"}} + {{else if .IsLandingPageExploreUsers}} + {{ctx.Locale.Tr "explore"}} {{else}} {{ctx.Locale.Tr "explore"}} {{end}} diff --git a/templates/explore/navbar.tmpl b/templates/explore/navbar.tmpl index 8841613b9f128..52bb96621d829 100644 --- a/templates/explore/navbar.tmpl +++ b/templates/explore/navbar.tmpl @@ -8,9 +8,6 @@ {{svg "octicon-person"}} {{ctx.Locale.Tr "explore.users"}} {{end}} - - {{svg "octicon-organization"}} {{ctx.Locale.Tr "explore.organizations"}} - {{if and (not $.UnitTypeCode.UnitGlobalDisabled) .IsRepoIndexerEnabled}} {{svg "octicon-code"}} {{ctx.Locale.Tr "explore.code"}} diff --git a/templates/explore/user_list.tmpl b/templates/explore/user_list.tmpl index fb86fbbea2342..62390c5aa22f9 100644 --- a/templates/explore/user_list.tmpl +++ b/templates/explore/user_list.tmpl @@ -6,6 +6,13 @@
+ {{if .IsOrganization}} + {{svg "octicon-organization"}} + {{else if .IsBot}} + {{svg "octicon-dependabot"}} + {{else}} + {{svg "octicon-person"}} + {{end}} {{template "shared/user/name" .}} {{if .Visibility.IsPrivate}} {{ctx.Locale.Tr "repo.desc.private"}} diff --git a/tests/integration/links_test.go b/tests/integration/links_test.go index d103e2b0a90bc..746490d357538 100644 --- a/tests/integration/links_test.go +++ b/tests/integration/links_test.go @@ -25,8 +25,6 @@ func TestLinksNoLogin(t *testing.T) { "/explore/repos?q=test", "/explore/users", "/explore/users?q=test", - "/explore/organizations", - "/explore/organizations?q=test", "/", "/user/sign_up", "/user/login", @@ -86,8 +84,6 @@ func testLinksAsUser(userName string, t *testing.T) { "/explore/repos?q=test", "/explore/users", "/explore/users?q=test", - "/explore/organizations", - "/explore/organizations?q=test", "/", "/user/forgot_password", "/api/swagger", diff --git a/tests/integration/setting_test.go b/tests/integration/setting_test.go index 9dad9ca716a06..0e2141ec2fcdf 100644 --- a/tests/integration/setting_test.go +++ b/tests/integration/setting_test.go @@ -107,7 +107,7 @@ func TestSettingLandingPage(t *testing.T) { setting.LandingPageURL = setting.LandingPageOrganizations req = NewRequest(t, "GET", "/") resp = MakeRequest(t, req, http.StatusSeeOther) - assert.Equal(t, "/explore/organizations", resp.Header().Get("Location")) + assert.Equal(t, "/explore/users", resp.Header().Get("Location")) setting.LandingPageURL = setting.LandingPageLogin req = NewRequest(t, "GET", "/")