mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
refactor organization menu (#33928)
Fix missing items in organization menu. **Menu** <details> <summary>Show</summary> Before:  After:  </details> **Packages** <details> keep it consistent with the other pages. <summary>Show</summary> Before:  After:  </details> --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -24,19 +24,8 @@ import (
|
||||
"code.gitea.io/gitea/services/context"
|
||||
)
|
||||
|
||||
// prepareContextForCommonProfile store some common data into context data for user's profile related pages (including the nav menu)
|
||||
// It is designed to be fast and safe to be called multiple times in one request
|
||||
func prepareContextForCommonProfile(ctx *context.Context) {
|
||||
ctx.Data["IsPackageEnabled"] = setting.Packages.Enabled
|
||||
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
|
||||
ctx.Data["EnableFeed"] = setting.Other.EnableFeed
|
||||
ctx.Data["FeedURL"] = ctx.ContextUser.HomeLink()
|
||||
}
|
||||
|
||||
// PrepareContextForProfileBigAvatar set the context for big avatar view on the profile page
|
||||
func PrepareContextForProfileBigAvatar(ctx *context.Context) {
|
||||
prepareContextForCommonProfile(ctx)
|
||||
|
||||
// prepareContextForProfileBigAvatar set the context for big avatar view on the profile page
|
||||
func prepareContextForProfileBigAvatar(ctx *context.Context) {
|
||||
ctx.Data["IsFollowing"] = ctx.Doer != nil && user_model.IsFollowing(ctx, ctx.Doer.ID, ctx.ContextUser.ID)
|
||||
ctx.Data["ShowUserEmail"] = setting.UI.ShowUserEmail && ctx.ContextUser.Email != "" && ctx.IsSigned && !ctx.ContextUser.KeepEmailPrivate
|
||||
if setting.Service.UserLocationMapURL != "" {
|
||||
@@ -138,16 +127,44 @@ func FindOwnerProfileReadme(ctx *context.Context, doer *user_model.User, optProf
|
||||
return profileDbRepo, profileReadmeBlob
|
||||
}
|
||||
|
||||
func RenderUserHeader(ctx *context.Context) {
|
||||
prepareContextForCommonProfile(ctx)
|
||||
|
||||
_, profileReadmeBlob := FindOwnerProfileReadme(ctx, ctx.Doer)
|
||||
ctx.Data["HasUserProfileReadme"] = profileReadmeBlob != nil
|
||||
type PrepareOwnerHeaderResult struct {
|
||||
ProfilePublicRepo *repo_model.Repository
|
||||
ProfilePublicReadmeBlob *git.Blob
|
||||
ProfilePrivateRepo *repo_model.Repository
|
||||
ProfilePrivateReadmeBlob *git.Blob
|
||||
HasOrgProfileReadme bool
|
||||
}
|
||||
|
||||
func LoadHeaderCount(ctx *context.Context) error {
|
||||
prepareContextForCommonProfile(ctx)
|
||||
const (
|
||||
RepoNameProfilePrivate = ".profile-private"
|
||||
RepoNameProfile = ".profile"
|
||||
)
|
||||
|
||||
func RenderUserOrgHeader(ctx *context.Context) (result *PrepareOwnerHeaderResult, err error) {
|
||||
ctx.Data["IsPackageEnabled"] = setting.Packages.Enabled
|
||||
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
|
||||
ctx.Data["EnableFeed"] = setting.Other.EnableFeed
|
||||
ctx.Data["FeedURL"] = ctx.ContextUser.HomeLink()
|
||||
|
||||
if err := loadHeaderCount(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result = &PrepareOwnerHeaderResult{}
|
||||
if ctx.ContextUser.IsOrganization() {
|
||||
result.ProfilePublicRepo, result.ProfilePublicReadmeBlob = FindOwnerProfileReadme(ctx, ctx.Doer)
|
||||
result.ProfilePrivateRepo, result.ProfilePrivateReadmeBlob = FindOwnerProfileReadme(ctx, ctx.Doer, RepoNameProfilePrivate)
|
||||
result.HasOrgProfileReadme = result.ProfilePublicReadmeBlob != nil || result.ProfilePrivateReadmeBlob != nil
|
||||
ctx.Data["HasOrgProfileReadme"] = result.HasOrgProfileReadme // many pages need it to show the "overview" tab
|
||||
} else {
|
||||
_, profileReadmeBlob := FindOwnerProfileReadme(ctx, ctx.Doer)
|
||||
ctx.Data["HasUserProfileReadme"] = profileReadmeBlob != nil
|
||||
prepareContextForProfileBigAvatar(ctx)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func loadHeaderCount(ctx *context.Context) error {
|
||||
repoCount, err := repo_model.CountRepository(ctx, &repo_model.SearchRepoOptions{
|
||||
Actor: ctx.Doer,
|
||||
OwnerID: ctx.ContextUser.ID,
|
||||
@@ -178,29 +195,3 @@ func LoadHeaderCount(ctx *context.Context) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
const (
|
||||
RepoNameProfilePrivate = ".profile-private"
|
||||
RepoNameProfile = ".profile"
|
||||
)
|
||||
|
||||
type PrepareOrgHeaderResult struct {
|
||||
ProfilePublicRepo *repo_model.Repository
|
||||
ProfilePublicReadmeBlob *git.Blob
|
||||
ProfilePrivateRepo *repo_model.Repository
|
||||
ProfilePrivateReadmeBlob *git.Blob
|
||||
HasOrgProfileReadme bool
|
||||
}
|
||||
|
||||
func PrepareOrgHeader(ctx *context.Context) (result *PrepareOrgHeaderResult, err error) {
|
||||
if err = LoadHeaderCount(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result = &PrepareOrgHeaderResult{}
|
||||
result.ProfilePublicRepo, result.ProfilePublicReadmeBlob = FindOwnerProfileReadme(ctx, ctx.Doer)
|
||||
result.ProfilePrivateRepo, result.ProfilePrivateReadmeBlob = FindOwnerProfileReadme(ctx, ctx.Doer, RepoNameProfilePrivate)
|
||||
result.HasOrgProfileReadme = result.ProfilePublicReadmeBlob != nil || result.ProfilePrivateReadmeBlob != nil
|
||||
ctx.Data["HasOrgProfileReadme"] = result.HasOrgProfileReadme // many pages need it to show the "overview" tab
|
||||
return result, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user