Skip to content

Commit a19a972

Browse files
committed
Merge branch 'main' into kerwin612-add-file-tree-to-file-view-page
2 parents 9ae1c85 + 44b4fb2 commit a19a972

File tree

11 files changed

+88
-35
lines changed

11 files changed

+88
-35
lines changed

custom/conf/app.example.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,9 @@ LEVEL = Info
13391339
;; Number of repos that are displayed on one page
13401340
;REPO_PAGING_NUM = 15
13411341

1342+
;; Number of orgs that are displayed on profile page
1343+
;ORG_PAGING_NUM = 15
1344+
13421345
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13431346
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13441347
;[ui.meta]

models/fixtures/label.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,14 @@
9696
num_issues: 0
9797
num_closed_issues: 0
9898
archived_unix: 0
99+
100+
-
101+
id: 10
102+
repo_id: 3
103+
org_id: 0
104+
name: repo3label1
105+
color: '#112233'
106+
exclusive: false
107+
num_issues: 0
108+
num_closed_issues: 0
109+
archived_unix: 0

models/issues/label.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,17 @@ func GetLabelIDsInRepoByNames(ctx context.Context, repoID int64, labelNames []st
349349
Find(&labelIDs)
350350
}
351351

352+
// GetLabelIDsInOrgByNames returns a list of labelIDs by names in a given org.
353+
func GetLabelIDsInOrgByNames(ctx context.Context, orgID int64, labelNames []string) ([]int64, error) {
354+
labelIDs := make([]int64, 0, len(labelNames))
355+
return labelIDs, db.GetEngine(ctx).Table("label").
356+
Where("org_id = ?", orgID).
357+
In("name", labelNames).
358+
Asc("name").
359+
Cols("id").
360+
Find(&labelIDs)
361+
}
362+
352363
// BuildLabelNamesIssueIDsCondition returns a builder where get issue ids match label names
353364
func BuildLabelNamesIssueIDsCondition(labelNames []string) *builder.Builder {
354365
return builder.Select("issue_label.issue_id").

modules/setting/ui.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ var UI = struct {
6363
} `ini:"ui.admin"`
6464
User struct {
6565
RepoPagingNum int
66+
OrgPagingNum int
6667
} `ini:"ui.user"`
6768
Meta struct {
6869
Author string
@@ -127,8 +128,10 @@ var UI = struct {
127128
},
128129
User: struct {
129130
RepoPagingNum int
131+
OrgPagingNum int
130132
}{
131133
RepoPagingNum: 15,
134+
OrgPagingNum: 15,
132135
},
133136
Meta: struct {
134137
Author string

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ joined_on = Joined on %s
649649
repositories = Repositories
650650
activity = Public Activity
651651
followers = Followers
652+
show_more = Show More
652653
starred = Starred Repositories
653654
watched = Watched Repositories
654655
code = Code

routers/api/v1/repo/issue_label.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,18 +335,30 @@ func prepareForReplaceOrAdd(ctx *context.APIContext, form api.IssueLabelsOption)
335335
labelIDs = append(labelIDs, int64(rv.Float()))
336336
case reflect.String:
337337
labelNames = append(labelNames, rv.String())
338+
default:
339+
ctx.Error(http.StatusBadRequest, "InvalidLabel", "a label must be an integer or a string")
340+
return nil, nil, fmt.Errorf("invalid label")
338341
}
339342
}
340343
if len(labelIDs) > 0 && len(labelNames) > 0 {
341344
ctx.Error(http.StatusBadRequest, "InvalidLabels", "labels should be an array of strings or integers")
342345
return nil, nil, fmt.Errorf("invalid labels")
343346
}
344347
if len(labelNames) > 0 {
345-
labelIDs, err = issues_model.GetLabelIDsInRepoByNames(ctx, ctx.Repo.Repository.ID, labelNames)
348+
repoLabelIDs, err := issues_model.GetLabelIDsInRepoByNames(ctx, ctx.Repo.Repository.ID, labelNames)
346349
if err != nil {
347350
ctx.Error(http.StatusInternalServerError, "GetLabelIDsInRepoByNames", err)
348351
return nil, nil, err
349352
}
353+
labelIDs = append(labelIDs, repoLabelIDs...)
354+
if ctx.Repo.Owner.IsOrganization() {
355+
orgLabelIDs, err := issues_model.GetLabelIDsInOrgByNames(ctx, ctx.Repo.Owner.ID, labelNames)
356+
if err != nil {
357+
ctx.Error(http.StatusInternalServerError, "GetLabelIDsInOrgByNames", err)
358+
return nil, nil, err
359+
}
360+
labelIDs = append(labelIDs, orgLabelIDs...)
361+
}
350362
}
351363

352364
labels, err := issues_model.GetLabelsByIDs(ctx, labelIDs, "id", "repo_id", "org_id", "name", "exclusive")

routers/web/shared/user/header.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,20 @@ func PrepareContextForProfileBigAvatar(ctx *context.Context) {
6161
orgs, err := db.Find[organization.Organization](ctx, organization.FindOrgOptions{
6262
UserID: ctx.ContextUser.ID,
6363
IncludePrivate: showPrivate,
64+
ListOptions: db.ListOptions{
65+
Page: 1,
66+
// query one more results (without a separate counting) to see whether we need to add the "show more orgs" link
67+
PageSize: setting.UI.User.OrgPagingNum + 1,
68+
},
6469
})
6570
if err != nil {
6671
ctx.ServerError("FindOrgs", err)
6772
return
6873
}
74+
if len(orgs) > setting.UI.User.OrgPagingNum {
75+
orgs = orgs[:setting.UI.User.OrgPagingNum]
76+
ctx.Data["ShowMoreOrgs"] = true
77+
}
6978
ctx.Data["Orgs"] = orgs
7079
ctx.Data["HasOrgsVisible"] = organization.HasOrgsVisible(ctx, orgs, ctx.Doer)
7180

routers/web/user/profile.go

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
activities_model "code.gitea.io/gitea/models/activities"
1414
"code.gitea.io/gitea/models/db"
15+
"code.gitea.io/gitea/models/organization"
1516
"code.gitea.io/gitea/models/renderhelper"
1617
repo_model "code.gitea.io/gitea/models/repo"
1718
user_model "code.gitea.io/gitea/models/user"
@@ -256,6 +257,21 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDb
256257
ctx.Data["ProfileReadme"] = profileContent
257258
}
258259
}
260+
case "organizations":
261+
orgs, count, err := db.FindAndCount[organization.Organization](ctx, organization.FindOrgOptions{
262+
UserID: ctx.ContextUser.ID,
263+
IncludePrivate: showPrivate,
264+
ListOptions: db.ListOptions{
265+
Page: page,
266+
PageSize: pagingNum,
267+
},
268+
})
269+
if err != nil {
270+
ctx.ServerError("GetUserOrganizations", err)
271+
return
272+
}
273+
ctx.Data["Cards"] = orgs
274+
total = int(count)
259275
default: // default to "repositories"
260276
repos, count, err = repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
261277
ListOptions: db.ListOptions{
@@ -294,31 +310,7 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDb
294310
}
295311

296312
pager := context.NewPagination(total, pagingNum, page, 5)
297-
pager.SetDefaultParams(ctx)
298-
pager.AddParamString("tab", tab)
299-
if tab != "followers" && tab != "following" && tab != "activity" && tab != "projects" {
300-
pager.AddParamString("language", language)
301-
}
302-
if tab == "activity" {
303-
if ctx.Data["Date"] != nil {
304-
pager.AddParamString("date", fmt.Sprint(ctx.Data["Date"]))
305-
}
306-
}
307-
if archived.Has() {
308-
pager.AddParamString("archived", fmt.Sprint(archived.Value()))
309-
}
310-
if fork.Has() {
311-
pager.AddParamString("fork", fmt.Sprint(fork.Value()))
312-
}
313-
if mirror.Has() {
314-
pager.AddParamString("mirror", fmt.Sprint(mirror.Value()))
315-
}
316-
if template.Has() {
317-
pager.AddParamString("template", fmt.Sprint(template.Value()))
318-
}
319-
if private.Has() {
320-
pager.AddParamString("private", fmt.Sprint(private.Value()))
321-
}
313+
pager.AddParamFromRequest(ctx.Req)
322314
ctx.Data["Page"] = pager
323315
}
324316

templates/shared/user/profile_big_avatar.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@
9292
</li>
9393
{{end}}
9494
{{end}}
95+
{{if .ShowMoreOrgs}}
96+
<li><a class="tw-align-center" href="{{.ContextUser.HomeLink}}?tab=organizations" data-tooltip-content="{{ctx.Locale.Tr "user.show_more"}}">{{svg "octicon-kebab-horizontal" 28 "icon tw-p-1"}}</a></li>
97+
{{end}}
9598
</ul>
9699
</li>
97100
{{end}}

templates/user/profile.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
{{template "repo/user_cards" .}}
2828
{{else if eq .TabName "overview"}}
2929
<div id="readme_profile" class="markup">{{.ProfileReadme}}</div>
30+
{{else if eq .TabName "organizations"}}
31+
{{template "repo/user_cards" .}}
3032
{{else}}
3133
{{template "shared/repo_search" .}}
3234
{{template "explore/repo_list" .}}

0 commit comments

Comments
 (0)