mirror of https://github.com/go-gitea/gitea.git
Use view as to get public and private profile repo
This commit is contained in:
parent
2d7e6e9482
commit
2969180fd1
|
@ -111,7 +111,22 @@ func home(ctx *context.Context, viewRepositories bool) {
|
|||
ctx.Data["DisableNewPullMirrors"] = setting.Mirror.DisableNewPull
|
||||
ctx.Data["ShowMemberAndTeamTab"] = ctx.Org.IsMember || len(members) > 0
|
||||
|
||||
if !prepareOrgProfileReadme(ctx, viewRepositories) {
|
||||
currentURL := ctx.Req.URL
|
||||
queryParams := currentURL.Query()
|
||||
queryParams.Set("view_as", "member")
|
||||
ctx.Data["QueryForMember"] = queryParams.Encode()
|
||||
queryParams.Set("view_as", "public")
|
||||
ctx.Data["QueryForPublic"] = queryParams.Encode()
|
||||
|
||||
isViewerMember := ctx.FormString("view_as") == "member"
|
||||
ctx.Data["IsViewerMember"] = isViewerMember
|
||||
|
||||
profileType := "Public"
|
||||
if isViewerMember {
|
||||
profileType = "Private"
|
||||
}
|
||||
|
||||
if !prepareOrgProfileReadme(ctx, viewRepositories, profileType) {
|
||||
ctx.Data["PageIsViewRepositories"] = true
|
||||
}
|
||||
|
||||
|
@ -168,28 +183,26 @@ func home(ctx *context.Context, viewRepositories bool) {
|
|||
ctx.HTML(http.StatusOK, tplOrgHome)
|
||||
}
|
||||
|
||||
func prepareOrgProfileReadme(ctx *context.Context, viewRepositories bool) bool {
|
||||
profileDbRepo, profileGitRepo, profileReadme, profileClose := shared_user.FindUserProfileReadme(ctx, ctx.Doer)
|
||||
func prepareOrgProfileReadme(ctx *context.Context, viewRepositories bool, profileType string) bool {
|
||||
profileDbRepo, profileGitRepo, profileReadme, profileClose := shared_user.FindUserProfileReadme(ctx, ctx.Doer, profileType)
|
||||
defer profileClose()
|
||||
ctx.Data["HasProfileReadme"] = profileReadme != nil
|
||||
ctx.Data[fmt.Sprintf("Has%sProfileReadme", profileType)] = profileReadme != nil
|
||||
|
||||
if profileGitRepo == nil || profileReadme == nil || viewRepositories {
|
||||
return false
|
||||
}
|
||||
|
||||
if bytes, err := profileReadme.GetBlobContent(setting.UI.MaxDisplayFileSize); err != nil {
|
||||
log.Error("failed to GetBlobContent: %v", err)
|
||||
log.Error("failed to GetBlobContent for %s profile readme: %v", profileType, err)
|
||||
} else {
|
||||
rctx := renderhelper.NewRenderContextRepoFile(ctx, profileDbRepo, renderhelper.RepoFileOptions{
|
||||
CurrentRefPath: path.Join("branch", util.PathEscapeSegments(profileDbRepo.DefaultBranch)),
|
||||
})
|
||||
if profileContent, err := markdown.RenderString(rctx, bytes); err != nil {
|
||||
log.Error("failed to RenderString: %v", err)
|
||||
log.Error("failed to RenderString for %s profile readme: %v", profileType, err)
|
||||
} else {
|
||||
ctx.Data["ProfileReadme"] = profileContent
|
||||
ctx.Data[fmt.Sprintf("%sProfileReadme", profileType)] = profileContent
|
||||
}
|
||||
}
|
||||
|
||||
ctx.Data["PageIsViewOverview"] = true
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -93,8 +93,12 @@ func PrepareContextForProfileBigAvatar(ctx *context.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
func FindUserProfileReadme(ctx *context.Context, doer *user_model.User) (profileDbRepo *repo_model.Repository, profileGitRepo *git.Repository, profileReadmeBlob *git.Blob, profileClose func()) {
|
||||
profileDbRepo, err := repo_model.GetRepositoryByName(ctx, ctx.ContextUser.ID, ".profile")
|
||||
func FindUserProfileReadme(ctx *context.Context, doer *user_model.User, profileType string) (profileDbRepo *repo_model.Repository, profileGitRepo *git.Repository, profileReadmeBlob *git.Blob, profileClose func()) {
|
||||
profileName := ".profile"
|
||||
if profileType != "Public" {
|
||||
profileName = ".profile-private"
|
||||
}
|
||||
profileDbRepo, err := repo_model.GetRepositoryByName(ctx, ctx.ContextUser.ID, profileName)
|
||||
if err == nil {
|
||||
perm, err := access_model.GetUserRepoPermission(ctx, profileDbRepo, doer)
|
||||
if err == nil && !profileDbRepo.IsEmpty && perm.CanRead(unit.TypeCode) {
|
||||
|
@ -121,9 +125,9 @@ func FindUserProfileReadme(ctx *context.Context, doer *user_model.User) (profile
|
|||
func RenderUserHeader(ctx *context.Context) {
|
||||
prepareContextForCommonProfile(ctx)
|
||||
|
||||
_, _, profileReadmeBlob, profileClose := FindUserProfileReadme(ctx, ctx.Doer)
|
||||
_, _, profileReadmeBlob, profileClose := FindUserProfileReadme(ctx, ctx.Doer, "Public")
|
||||
defer profileClose()
|
||||
ctx.Data["HasProfileReadme"] = profileReadmeBlob != nil
|
||||
ctx.Data["HasPublicProfileReadme"] = profileReadmeBlob != nil
|
||||
}
|
||||
|
||||
func LoadHeaderCount(ctx *context.Context) error {
|
||||
|
@ -165,9 +169,13 @@ func RenderOrgHeader(ctx *context.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
_, _, profileReadmeBlob, profileClose := FindUserProfileReadme(ctx, ctx.Doer)
|
||||
_, _, profileReadmeBlob, profileClose := FindUserProfileReadme(ctx, ctx.Doer, "Public")
|
||||
defer profileClose()
|
||||
ctx.Data["HasProfileReadme"] = profileReadmeBlob != nil
|
||||
ctx.Data["HasPublicProfileReadme"] = profileReadmeBlob != nil
|
||||
|
||||
_, _, profileReadmeBlob, profileClose = FindUserProfileReadme(ctx, ctx.Doer, "Private")
|
||||
defer profileClose()
|
||||
ctx.Data["HasPrivateProfileReadme"] = profileReadmeBlob != nil
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ func userProfile(ctx *context.Context) {
|
|||
ctx.Data["HeatmapTotalContributions"] = activities_model.GetTotalContributionsInHeatmap(data)
|
||||
}
|
||||
|
||||
profileDbRepo, _ /*profileGitRepo*/, profileReadmeBlob, profileClose := shared_user.FindUserProfileReadme(ctx, ctx.Doer)
|
||||
profileDbRepo, _ /*profileGitRepo*/, profileReadmeBlob, profileClose := shared_user.FindUserProfileReadme(ctx, ctx.Doer, "Public")
|
||||
defer profileClose()
|
||||
|
||||
showPrivate := ctx.IsSigned && (ctx.Doer.IsAdmin || ctx.Doer.ID == ctx.ContextUser.ID)
|
||||
|
@ -95,7 +95,7 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDb
|
|||
}
|
||||
}
|
||||
ctx.Data["TabName"] = tab
|
||||
ctx.Data["HasProfileReadme"] = profileReadme != nil
|
||||
ctx.Data["HasPublicProfileReadme"] = profileReadme != nil
|
||||
|
||||
page := ctx.FormInt("page")
|
||||
if page <= 0 {
|
||||
|
@ -253,7 +253,7 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDb
|
|||
if profileContent, err := markdown.RenderString(rctx, bytes); err != nil {
|
||||
log.Error("failed to RenderString: %v", err)
|
||||
} else {
|
||||
ctx.Data["ProfileReadme"] = profileContent
|
||||
ctx.Data["PublicProfileReadme"] = profileContent
|
||||
}
|
||||
}
|
||||
default: // default to "repositories"
|
||||
|
|
|
@ -5,8 +5,14 @@
|
|||
<div class="ui container">
|
||||
<div class="ui mobile reversed stackable grid">
|
||||
<div class="ui {{if .ShowMemberAndTeamTab}}eleven wide{{end}} column">
|
||||
{{if .ProfileReadme}}
|
||||
<div id="readme_profile" class="markup">{{.ProfileReadme}}</div>
|
||||
{{if .IsViewerMember}}
|
||||
{{if .PrivateProfileReadme}}
|
||||
<div id="readme_profile" class="markup">{{.PrivateProfileReadme}}</div>
|
||||
{{end}}
|
||||
{{else}}
|
||||
{{if .PublicProfileReadme}}
|
||||
<div id="readme_profile" class="markup">{{.PublicProfileReadme}}</div>
|
||||
{{end}}
|
||||
{{end}}
|
||||
{{template "shared/repo_search" .}}
|
||||
{{template "explore/repo_list" .}}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
<div class="ui container">
|
||||
<overflow-menu class="ui secondary pointing tabular borderless menu tw-mb-4">
|
||||
<div class="overflow-menu-items">
|
||||
{{if .HasProfileReadme}}
|
||||
{{if or .HasPublicProfileReadme .HasPrivateProfileReadme}}
|
||||
<a class="{{if .PageIsViewOverview}}active {{end}}item" href="{{$.Org.HomeLink}}">
|
||||
{{svg "octicon-info"}} {{ctx.Locale.Tr "user.overview"}}
|
||||
</a>
|
||||
{{end}}
|
||||
<a class="{{if .PageIsViewRepositories}}active {{end}}item" href="{{$.Org.HomeLink}}{{if .HasProfileReadme}}/-/repositories{{end}}">
|
||||
<a class="{{if .PageIsViewRepositories}}active {{end}}item" href="{{$.Org.HomeLink}}{{if or .HasPublicProfileReadme .HasPrivateProfileReadme}}/-/repositories{{end}}">
|
||||
{{svg "octicon-repo"}} {{ctx.Locale.Tr "user.repositories"}}
|
||||
{{if .RepoCount}}
|
||||
<div class="ui small label">{{.RepoCount}}</div>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<overflow-menu class="ui secondary pointing tabular borderless menu">
|
||||
<div class="overflow-menu-items">
|
||||
{{if and .HasProfileReadme .ContextUser.IsIndividual}}
|
||||
{{if and .HasPublicProfileReadme .ContextUser.IsIndividual}}
|
||||
<a class="{{if eq .TabName "overview"}}active {{end}}item" href="{{.ContextUser.HomeLink}}?tab=overview">
|
||||
{{svg "octicon-info"}} {{ctx.Locale.Tr "user.overview"}}
|
||||
</a>
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
{{else if eq .TabName "followers"}}
|
||||
{{template "repo/user_cards" .}}
|
||||
{{else if eq .TabName "overview"}}
|
||||
<div id="readme_profile" class="markup">{{.ProfileReadme}}</div>
|
||||
<div id="readme_profile" class="markup">{{.PublicProfileReadme}}</div>
|
||||
{{else}}
|
||||
{{template "shared/repo_search" .}}
|
||||
{{template "explore/repo_list" .}}
|
||||
|
|
Loading…
Reference in New Issue