Skip to content

Merge explore orgs into explore users #29816

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

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 15 additions & 12 deletions models/user/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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})
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions models/user/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion modules/setting/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion modules/web/middleware/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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, <a href="%s">show unfiltered results</a>.
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
Expand Down
3 changes: 2 additions & 1 deletion routers/api/v1/admin/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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},
Expand Down
2 changes: 1 addition & 1 deletion routers/api/v1/admin/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion routers/api/v1/org/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down
3 changes: 2 additions & 1 deletion routers/api/v1/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion routers/web/admin/orgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion routers/web/admin/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
48 changes: 0 additions & 48 deletions routers/web/explore/org.go

This file was deleted.

9 changes: 7 additions & 2 deletions routers/web/explore/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion routers/web/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
3 changes: 2 additions & 1 deletion routers/web/user/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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,
})
Expand Down
1 change: 0 additions & 1 deletion routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions templates/base/head_navbar.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
{{end}}
{{end}}
<a class="item{{if .PageIsExplore}} active{{end}}" href="{{AppSubUrl}}/explore/repos">{{ctx.Locale.Tr "explore"}}</a>
{{else if .IsLandingPageOrganizations}}
<a class="item{{if .PageIsExplore}} active{{end}}" href="{{AppSubUrl}}/explore/organizations">{{ctx.Locale.Tr "explore"}}</a>
{{else if .IsLandingPageExploreUsers}}
<a class="item{{if .PageIsExplore}} active{{end}}" href="{{AppSubUrl}}/explore/users">{{ctx.Locale.Tr "explore"}}</a>
{{else}}
<a class="item{{if .PageIsExplore}} active{{end}}" href="{{AppSubUrl}}/explore/repos">{{ctx.Locale.Tr "explore"}}</a>
{{end}}
Expand Down
3 changes: 0 additions & 3 deletions templates/explore/navbar.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
{{svg "octicon-person"}} {{ctx.Locale.Tr "explore.users"}}
</a>
{{end}}
<a class="{{if .PageIsExploreOrganizations}}active {{end}}item" href="{{AppSubUrl}}/explore/organizations">
{{svg "octicon-organization"}} {{ctx.Locale.Tr "explore.organizations"}}
</a>
{{if and (not $.UnitTypeCode.UnitGlobalDisabled) .IsRepoIndexerEnabled}}
<a class="{{if .PageIsExploreCode}}active {{end}}item" href="{{AppSubUrl}}/explore/code">
{{svg "octicon-code"}} {{ctx.Locale.Tr "explore.code"}}
Expand Down
7 changes: 7 additions & 0 deletions templates/explore/user_list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
</div>
<div class="flex-item-main">
<div class="flex-item-title">
{{if .IsOrganization}}
<span class="tw-flex tw-justify-center tw-flex-wrap" data-tooltip-content title="{{ctx.Locale.Tr "explore.user_is_organization" .DisplayName}}">{{svg "octicon-organization"}}</span>
Copy link
Member

@silverwind silverwind Mar 15, 2024

Choose a reason for hiding this comment

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

Not tw-items-center instead of tw-justify-center?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have no idea.
I simply translated your suggestion into tailwind.
Also, I see no improvement when adding tw-items-center

Copy link
Member

Choose a reason for hiding this comment

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

Ah, sorry gt-ac is actually tw-content-center.

Copy link
Member Author

Choose a reason for hiding this comment

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

Still no difference

Copy link
Member

Choose a reason for hiding this comment

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

I will check later. Maybe we should also move the icon into second row and add a User/Organization/Bot text besides it.

Copy link
Member Author

Choose a reason for hiding this comment

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

(the text is currently a tooltip)

{{else if .IsBot}}
<span class="tw-flex tw-justify-center tw-flex-wrap" data-tooltip-content title="{{ctx.Locale.Tr "explore.user_is_bot" .DisplayName}}">{{svg "octicon-dependabot"}}</span>
{{else}}
<span class="tw-flex tw-justify-center tw-flex-wrap" data-tooltip-content title="{{ctx.Locale.Tr "explore.user_is_individual" .DisplayName}}">{{svg "octicon-person"}}</span>
{{end}}
{{template "shared/user/name" .}}
{{if .Visibility.IsPrivate}}
<span class="ui basic tiny label">{{ctx.Locale.Tr "repo.desc.private"}}</span>
Expand Down
4 changes: 0 additions & 4 deletions tests/integration/links_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/setting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", "/")
Expand Down