Skip to content

Improve profile for Organizations #27982

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
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion routers/web/org/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func Home(ctx *context.Context) {

ctx.Data["ShowMemberAndTeamTab"] = ctx.Org.IsMember || len(members) > 0

profileGitRepo, profileReadmeBlob, profileClose := shared_user.FindUserProfileReadme(ctx)
profileGitRepo, profileReadmeBlob, profileClose := shared_user.FindUserProfileReadme(ctx, ctx.Doer)
defer profileClose()
prepareOrgProfileReadme(ctx, profileGitRepo, profileReadmeBlob)

Expand Down
9 changes: 6 additions & 3 deletions routers/web/shared/user/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ package user
import (
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/organization"
access_model "code.gitea.io/gitea/models/perm/access"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
Expand Down Expand Up @@ -84,9 +86,10 @@ func PrepareContextForProfileBigAvatar(ctx *context.Context) {
}
}

func FindUserProfileReadme(ctx *context.Context) (profileGitRepo *git.Repository, profileReadmeBlob *git.Blob, profileClose func()) {
func FindUserProfileReadme(ctx *context.Context, doer *user_model.User) (profileGitRepo *git.Repository, profileReadmeBlob *git.Blob, profileClose func()) {
profileDbRepo, err := repo_model.GetRepositoryByName(ctx, ctx.ContextUser.ID, ".profile")
if err == nil && !profileDbRepo.IsEmpty && !profileDbRepo.IsPrivate {
perm, err := access_model.GetUserRepoPermission(ctx, profileDbRepo, doer)
if err == nil && !profileDbRepo.IsEmpty && perm.CanRead(unit.TypeCode) {
if profileGitRepo, err = git.OpenRepository(ctx, profileDbRepo.RepoPath()); err != nil {
log.Error("FindUserProfileReadme failed to OpenRepository: %v", err)
} else {
Expand All @@ -107,7 +110,7 @@ func FindUserProfileReadme(ctx *context.Context) (profileGitRepo *git.Repository
func RenderUserHeader(ctx *context.Context) {
prepareContextForCommonProfile(ctx)

_, profileReadmeBlob, profileClose := FindUserProfileReadme(ctx)
_, profileReadmeBlob, profileClose := FindUserProfileReadme(ctx, ctx.Doer)
defer profileClose()
ctx.Data["HasProfileReadme"] = profileReadmeBlob != nil
}
Expand Down
2 changes: 1 addition & 1 deletion routers/web/user/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func userProfile(ctx *context.Context) {
ctx.Data["HeatmapTotalContributions"] = activities_model.GetTotalContributionsInHeatmap(data)
}

profileGitRepo, profileReadmeBlob, profileClose := shared_user.FindUserProfileReadme(ctx)
profileGitRepo, profileReadmeBlob, profileClose := shared_user.FindUserProfileReadme(ctx, ctx.Doer)
defer profileClose()

showPrivate := ctx.IsSigned && (ctx.Doer.IsAdmin || ctx.Doer.ID == ctx.ContextUser.ID)
Expand Down
38 changes: 19 additions & 19 deletions templates/explore/repo_search.tmpl
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<div class="ui secondary filter menu gt-ac gt-mx-0">
<form class="ui form ignore-dirty gt-f1">
<input type="hidden" name="sort" value="{{$.SortType}}">
<input type="hidden" name="language" value="{{$.Language}}">
<input type="hidden" name="language" value="{{$.ctxData.Language}}">
<div class="ui fluid action input">
{{template "shared/searchinput" dict "Value" .Keyword "AutoFocus" true}}
{{if .PageIsExploreRepositories}}
<input type="hidden" name="only_show_relevant" value="{{.OnlyShowRelevant}}">
{{else if .TabName}}
<input type="hidden" name="tab" value="{{.TabName}}">
{{template "shared/searchinput" dict "Value" .ctxData.Keyword "AutoFocus" .AutoFocus}}
{{if .ctxData.PageIsExploreRepositories}}
<input type="hidden" name="only_show_relevant" value="{{.ctxData.OnlyShowRelevant}}">
{{else if .ctxData.TabName}}
<input type="hidden" name="tab" value="{{.ctxData.TabName}}">
{{end}}
<button class="ui primary button">{{ctx.Locale.Tr "explore.search"}}</button>
</div>
Expand All @@ -19,24 +19,24 @@
</span>
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
<div class="menu">
<a class="{{if eq .SortType "newest"}}active {{end}}item" href="{{$.Link}}?tab={{$.TabName}}&sort=newest&q={{$.Keyword}}&language={{$.Language}}">{{ctx.Locale.Tr "repo.issues.filter_sort.latest"}}</a>
<a class="{{if eq .SortType "oldest"}}active {{end}}item" href="{{$.Link}}?tab={{$.TabName}}&sort=oldest&q={{$.Keyword}}&language={{$.Language}}">{{ctx.Locale.Tr "repo.issues.filter_sort.oldest"}}</a>
<a class="{{if eq .SortType "alphabetically"}}active {{end}}item" href="{{$.Link}}?tab={{$.TabName}}&sort=alphabetically&q={{$.Keyword}}&language={{$.Language}}">{{ctx.Locale.Tr "repo.issues.label.filter_sort.alphabetically"}}</a>
<a class="{{if eq .SortType "reversealphabetically"}}active {{end}}item" href="{{$.Link}}?tab={{$.TabName}}&sort=reversealphabetically&q={{$.Keyword}}&language={{$.Language}}">{{ctx.Locale.Tr "repo.issues.label.filter_sort.reverse_alphabetically"}}</a>
<a class="{{if eq .SortType "recentupdate"}}active {{end}}item" href="{{$.Link}}?tab={{$.TabName}}&sort=recentupdate&q={{$.Keyword}}&language={{$.Language}}">{{ctx.Locale.Tr "repo.issues.filter_sort.recentupdate"}}</a>
<a class="{{if eq .SortType "leastupdate"}}active {{end}}item" href="{{$.Link}}?tab={{$.TabName}}&sort=leastupdate&q={{$.Keyword}}&language={{$.Language}}">{{ctx.Locale.Tr "repo.issues.filter_sort.leastupdate"}}</a>
{{if not .DisableStars}}
<a class="{{if eq .SortType "moststars"}}active {{end}}item" href="{{$.Link}}?tab={{$.TabName}}&sort=moststars&q={{$.Keyword}}&language={{$.Language}}">{{ctx.Locale.Tr "repo.issues.filter_sort.moststars"}}</a>
<a class="{{if eq .SortType "feweststars"}}active {{end}}item" href="{{$.Link}}?tab={{$.TabName}}&sort=feweststars&q={{$.Keyword}}&language={{$.Language}}">{{ctx.Locale.Tr "repo.issues.filter_sort.feweststars"}}</a>
<a class="{{if eq .ctxData.SortType "newest"}}active {{end}}item" href="{{$.ctxData.Link}}?tab={{$.ctxData.TabName}}&sort=newest&q={{$.ctxData.Keyword}}&language={{$.ctxData.Language}}">{{ctx.Locale.Tr "repo.issues.filter_sort.latest"}}</a>
<a class="{{if eq .ctxData.SortType "oldest"}}active {{end}}item" href="{{$.ctxData.Link}}?tab={{$.ctxData.TabName}}&sort=oldest&q={{$.ctxData.Keyword}}&language={{$.ctxData.Language}}">{{ctx.Locale.Tr "repo.issues.filter_sort.oldest"}}</a>
<a class="{{if eq .ctxData.SortType "alphabetically"}}active {{end}}item" href="{{$.ctxData.Link}}?tab={{$.ctxData.TabName}}&sort=alphabetically&q={{$.ctxData.Keyword}}&language={{$.ctxData.Language}}">{{ctx.Locale.Tr "repo.issues.label.filter_sort.alphabetically"}}</a>
<a class="{{if eq .ctxData.SortType "reversealphabetically"}}active {{end}}item" href="{{$.ctxData.Link}}?tab={{$.ctxData.TabName}}&sort=reversealphabetically&q={{$.ctxData.Keyword}}&language={{$.ctxData.Language}}">{{ctx.Locale.Tr "repo.issues.label.filter_sort.reverse_alphabetically"}}</a>
<a class="{{if eq .ctxData.SortType "recentupdate"}}active {{end}}item" href="{{$.ctxData.Link}}?tab={{$.ctxData.TabName}}&sort=recentupdate&q={{$.ctxData.Keyword}}&language={{$.ctxData.Language}}">{{ctx.Locale.Tr "repo.issues.filter_sort.recentupdate"}}</a>
<a class="{{if eq .ctxData.SortType "leastupdate"}}active {{end}}item" href="{{$.ctxData.Link}}?tab={{$.ctxData.TabName}}&sort=leastupdate&q={{$.ctxData.Keyword}}&language={{$.ctxData.Language}}">{{ctx.Locale.Tr "repo.issues.filter_sort.leastupdate"}}</a>
{{if not .ctxData.DisableStars}}
<a class="{{if eq .ctxData.SortType "moststars"}}active {{end}}item" href="{{$.ctxData.Link}}?tab={{$.ctxData.TabName}}&sort=moststars&q={{$.ctxData.Keyword}}&language={{$.ctxData.Language}}">{{ctx.Locale.Tr "repo.issues.filter_sort.moststars"}}</a>
<a class="{{if eq .ctxData.SortType "feweststars"}}active {{end}}item" href="{{$.ctxData.Link}}?tab={{$.ctxData.TabName}}&sort=feweststars&q={{$.ctxData.Keyword}}&language={{$.ctxData.Language}}">{{ctx.Locale.Tr "repo.issues.filter_sort.feweststars"}}</a>
{{end}}
<a class="{{if eq .SortType "mostforks"}}active {{end}}item" href="{{$.Link}}?tab={{$.TabName}}&sort=mostforks&q={{$.Keyword}}&language={{$.Language}}">{{ctx.Locale.Tr "repo.issues.filter_sort.mostforks"}}</a>
<a class="{{if eq .SortType "fewestforks"}}active {{end}}item" href="{{$.Link}}?tab={{$.TabName}}&sort=fewestforks&q={{$.Keyword}}&language={{$.Language}}">{{ctx.Locale.Tr "repo.issues.filter_sort.fewestforks"}}</a>
<a class="{{if eq .ctxData.SortType "mostforks"}}active {{end}}item" href="{{$.ctxData.Link}}?tab={{$.ctxData.TabName}}&sort=mostforks&q={{$.ctxData.Keyword}}&language={{$.ctxData.Language}}">{{ctx.Locale.Tr "repo.issues.filter_sort.mostforks"}}</a>
<a class="{{if eq .ctxData.SortType "fewestforks"}}active {{end}}item" href="{{$.ctxData.Link}}?tab={{$.ctxData.TabName}}&sort=fewestforks&q={{$.ctxData.Keyword}}&language={{$.ctxData.Language}}">{{ctx.Locale.Tr "repo.issues.filter_sort.fewestforks"}}</a>
</div>
</div>
</div>
{{if and .PageIsExploreRepositories .OnlyShowRelevant}}
{{if and .ctxData.PageIsExploreRepositories .ctxData.OnlyShowRelevant}}
<div class="ui message explore-relevancy-note">
<span data-tooltip-content="{{ctx.Locale.Tr "explore.relevant_repositories_tooltip"}}">{{ctx.Locale.Tr "explore.relevant_repositories" ((printf "?only_show_relevant=0&sort=%s&q=%s&language=%s" $.SortType (QueryEscape $.Keyword) (QueryEscape $.Language))|Escape) | Safe}}</span>
<span data-tooltip-content="{{ctx.Locale.Tr "explore.relevant_repositories_tooltip"}}">{{ctx.Locale.Tr "explore.relevant_repositories" ((printf "?only_show_relevant=0&sort=%s&q=%s&language=%s" $.ctxData.SortType (QueryEscape $.ctxData.Keyword) (QueryEscape $.ctxData.Language))|Escape) | Safe}}</span>
</div>
{{end}}
<div class="divider"></div>
2 changes: 1 addition & 1 deletion templates/explore/repos.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div role="main" aria-label="{{.Title}}" class="page-content explore repositories">
{{template "explore/navbar" .}}
<div class="ui container">
{{template "explore/repo_search" .}}
{{template "explore/repo_search" dict "ctxData" . "AutoFocus" true}}
{{template "explore/repo_list" .}}
{{template "base/paginate" .}}
</div>
Expand Down
5 changes: 4 additions & 1 deletion templates/org/home.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@
<div class="ui {{if .ShowMemberAndTeamTab}}eleven wide{{end}} column">
{{if .ProfileReadme}}
<div id="readme_profile" class="markup">{{.ProfileReadme | Str2html}}</div>
{{template "explore/repo_search" dict "ctxData" . "AutoFocus" false}}
{{else}}
{{template "explore/repo_search" dict "ctxData" . "AutoFocus" true}}
{{end}}
{{template "explore/repo_search" .}}

{{template "explore/repo_list" .}}
{{template "base/paginate" .}}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
{{template "shared/issuelist" dict "." . "listType" "dashboard"}}
{{end}}
{{else}}
{{template "explore/repo_search" .}}
{{template "explore/repo_search" dict "ctxData" . "AutoFocus" true}}
{{template "explore/repo_list" .}}
{{template "base/paginate" .}}
{{end}}
Expand Down
2 changes: 1 addition & 1 deletion templates/user/overview/header.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="ui secondary stackable pointing menu">
{{if .HasProfileReadme}}
{{if and .HasProfileReadme .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>
Expand Down
4 changes: 2 additions & 2 deletions templates/user/profile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{{template "user/dashboard/feeds" .}}
{{else if eq .TabName "stars"}}
<div class="stars">
{{template "explore/repo_search" .}}
{{template "explore/repo_search" dict "ctxData" . "AutoFocus" true}}
{{template "explore/repo_list" .}}
{{template "base/paginate" .}}
</div>
Expand All @@ -31,7 +31,7 @@
{{else if eq .TabName "overview"}}
<div id="readme_profile" class="markup">{{.ProfileReadme | Str2html}}</div>
{{else}}
{{template "explore/repo_search" .}}
{{template "explore/repo_search" dict "ctxData" . "AutoFocus" true}}
{{template "explore/repo_list" .}}
{{template "base/paginate" .}}
{{end}}
Expand Down