Skip to content

Count only visible repos on profile #25928

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

Merged
merged 8 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions routers/web/org/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/markup/markdown"
"code.gitea.io/gitea/modules/setting"
shared_user "code.gitea.io/gitea/routers/web/shared/user"
)

const (
Expand Down Expand Up @@ -158,6 +159,12 @@ func Home(ctx *context.Context) {
ctx.Data["PageIsViewRepositories"] = true
ctx.Data["IsFollowing"] = isFollowing

err = shared_user.LoadHeaderCount(ctx)
if err != nil {
ctx.ServerError("LoadHeaderCount", err)
return
}

pager := context.NewPagination(int(count), setting.UI.User.RepoPagingNum, page, 5)
pager.SetDefaultParams(ctx)
pager.AddParam(ctx, "language", "Language")
Expand Down
25 changes: 25 additions & 0 deletions routers/web/org/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ func Projects(ctx *context.Context) {
project.RenderedContent = project.Description
}

err = shared_user.LoadHeaderCount(ctx)
if err != nil {
ctx.ServerError("LoadHeaderCount", err)
return
}

numPages := 0
if total > 0 {
numPages = (int(total) - 1/setting.UI.IssuePagingNum)
Expand Down Expand Up @@ -135,6 +141,13 @@ func RenderNewProject(ctx *context.Context) {
ctx.Data["HomeLink"] = ctx.ContextUser.HomeLink()
ctx.Data["CancelLink"] = ctx.ContextUser.HomeLink() + "/-/projects"
shared_user.RenderUserHeader(ctx)

err := shared_user.LoadHeaderCount(ctx)
if err != nil {
ctx.ServerError("LoadHeaderCount", err)
return
}

ctx.HTML(http.StatusOK, tplProjectsNew)
}

Expand Down Expand Up @@ -272,6 +285,12 @@ func EditProjectPost(ctx *context.Context) {

shared_user.RenderUserHeader(ctx)

err := shared_user.LoadHeaderCount(ctx)
if err != nil {
ctx.ServerError("LoadHeaderCount", err)
return
}

if ctx.HasError() {
ctx.HTML(http.StatusOK, tplProjectsNew)
return
Expand Down Expand Up @@ -381,6 +400,12 @@ func ViewProject(ctx *context.Context) {
ctx.Data["Boards"] = boards
shared_user.RenderUserHeader(ctx)

err = shared_user.LoadHeaderCount(ctx)
if err != nil {
ctx.ServerError("LoadHeaderCount", err)
return
}

ctx.HTML(http.StatusOK, tplProjectsView)
}

Expand Down
34 changes: 34 additions & 0 deletions routers/web/shared/user/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/markup/markdown"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
)

// prepareContextForCommonProfile store some common data into context data for user's profile related pages (including the nav menu)
Expand Down Expand Up @@ -110,3 +111,36 @@ func RenderUserHeader(ctx *context.Context) {
defer profileClose()
ctx.Data["HasProfileReadme"] = profileReadmeBlob != nil
}

func LoadHeaderCount(ctx *context.Context) error {
prepareContextForCommonProfile(ctx)

var err error
var showPrivate bool
if ctx.Doer == nil {
showPrivate = false
} else if ctx.ContextUser.IsAdmin {
showPrivate = true
} else if ctx.ContextUser.ID == ctx.Doer.ID {
showPrivate = true
} else if ctx.ContextUser.IsOrganization() {
showPrivate, err = ctx.Org.Organization.IsOrgMember(ctx.Doer.ID)
if err != nil {
return err
}
} else {
showPrivate = false
}

if showPrivate {
ctx.Data["RepoCount"] = ctx.ContextUser.NumRepos
} else {
repoCount, err := repo_model.CountRepositories(ctx, repo_model.CountRepositoryOptions{OwnerID: ctx.ContextUser.ID, Private: util.OptionalBoolFalse})
if err != nil {
return err
}
ctx.Data["RepoCount"] = repoCount
}

return nil
}
18 changes: 18 additions & 0 deletions routers/web/user/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ func ListPackages(ctx *context.Context) {
ctx.Data["Total"] = total
ctx.Data["RepositoryAccessMap"] = repositoryAccessMap

err = shared_user.LoadHeaderCount(ctx)
if err != nil {
ctx.ServerError("LoadHeaderCount", err)
return
}

// TODO: context/org -> HandleOrgAssignment() can not be used
if ctx.ContextUser.IsOrganization() {
org := org_model.OrgFromUser(ctx.ContextUser)
Expand Down Expand Up @@ -255,6 +261,12 @@ func ViewPackageVersion(ctx *context.Context) {
}
ctx.Data["HasRepositoryAccess"] = hasRepositoryAccess

err = shared_user.LoadHeaderCount(ctx)
if err != nil {
ctx.ServerError("LoadHeaderCount", err)
return
}

ctx.HTML(http.StatusOK, tplPackagesView)
}

Expand Down Expand Up @@ -346,6 +358,12 @@ func ListPackageVersions(ctx *context.Context) {

ctx.Data["Total"] = total

err = shared_user.LoadHeaderCount(ctx)
if err != nil {
ctx.ServerError("LoadHeaderCount", err)
return
}

pager := context.NewPagination(int(total), setting.UI.PackagesPagingNum, page, 5)
for k, v := range pagerParams {
pager.AddParamString(k, v)
Expand Down
6 changes: 6 additions & 0 deletions routers/web/user/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileGi
ctx.Data["Repos"] = repos
ctx.Data["Total"] = total

err = shared_user.LoadHeaderCount(ctx)
if err != nil {
ctx.ServerError("LoadHeaderCount", err)
return
}

pager := context.NewPagination(total, pagingNum, page, 5)
pager.SetDefaultParams(ctx)
pager.AddParam(ctx, "tab", "TabName")
Expand Down
4 changes: 2 additions & 2 deletions templates/org/menu.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<div class="ui secondary stackable pointing menu">
<a class="{{if .PageIsViewRepositories}}active {{end}}item" href="{{$.Org.HomeLink}}">
{{svg "octicon-repo"}} {{.locale.Tr "user.repositories"}}
{{if .ContextUser.NumRepos}}
<div class="ui small label">{{.ContextUser.NumRepos}}</div>
{{if .RepoCount}}
<div class="ui small label">{{.RepoCount}}</div>
{{end}}
</a>
{{if .CanReadProjects}}
Expand Down
4 changes: 2 additions & 2 deletions templates/user/overview/header.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
{{end}}
<a class="{{if eq .TabName "repositories"}}active {{end}} item" href="{{.ContextUser.HomeLink}}?tab=repositories">
{{svg "octicon-repo"}} {{.locale.Tr "user.repositories"}}
{{if .ContextUser.NumRepos}}
<div class="ui small label">{{.ContextUser.NumRepos}}</div>
{{if .RepoCount}}
<div class="ui small label">{{.RepoCount}}</div>
{{end}}
</a>
{{if or .ContextUser.IsIndividual (and .ContextUser.IsOrganization .CanReadProjects)}}
Expand Down