Skip to content

Commit 089ac06

Browse files
yp05327silverwind
andauthored
Improve profile for Organizations (#27982)
Fixes some problems in #27955: - autofocus of the search box before: if access the home page will jump to the search box ![image](https://github.com/go-gitea/gitea/assets/18380374/7f100e8d-2bd6-4563-85ba-d6008ffc71d7) after: will not jump to the search box ![image](https://github.com/go-gitea/gitea/assets/18380374/9aab382c-8ebe-4d18-b990-4adbb6c341ad) - incorrect display of overview tab before: ![image](https://github.com/go-gitea/gitea/assets/18380374/b24c79e8-9b79-4576-9276-43bd19172043) after: ![image](https://github.com/go-gitea/gitea/assets/18380374/7aab5827-f086-4874-bd84-39bd81b872f3) - improve the permission check to the private profile repo In #26295, we simply added access control to the private profile. But if user have access to the private profile repo , we should also display the profile. - add a button which can jump to the repo list? I agree @wxiaoguang 's opinion here: #27955 (comment) But it seems that this feature is sponsored. So can we add a button which can quickly jump to the repo list or just move profile to the `overview` page? --------- Co-authored-by: silverwind <[email protected]>
1 parent 340055a commit 089ac06

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

routers/web/org/home.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func Home(ctx *context.Context) {
157157

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

160-
profileGitRepo, profileReadmeBlob, profileClose := shared_user.FindUserProfileReadme(ctx)
160+
profileGitRepo, profileReadmeBlob, profileClose := shared_user.FindUserProfileReadme(ctx, ctx.Doer)
161161
defer profileClose()
162162
prepareOrgProfileReadme(ctx, profileGitRepo, profileReadmeBlob)
163163

routers/web/shared/user/header.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ package user
66
import (
77
"code.gitea.io/gitea/models/db"
88
"code.gitea.io/gitea/models/organization"
9+
access_model "code.gitea.io/gitea/models/perm/access"
910
repo_model "code.gitea.io/gitea/models/repo"
11+
"code.gitea.io/gitea/models/unit"
1012
user_model "code.gitea.io/gitea/models/user"
1113
"code.gitea.io/gitea/modules/context"
1214
"code.gitea.io/gitea/modules/git"
@@ -84,18 +86,23 @@ func PrepareContextForProfileBigAvatar(ctx *context.Context) {
8486
}
8587
}
8688

87-
func FindUserProfileReadme(ctx *context.Context) (profileGitRepo *git.Repository, profileReadmeBlob *git.Blob, profileClose func()) {
89+
func FindUserProfileReadme(ctx *context.Context, doer *user_model.User) (profileGitRepo *git.Repository, profileReadmeBlob *git.Blob, profileClose func()) {
8890
profileDbRepo, err := repo_model.GetRepositoryByName(ctx, ctx.ContextUser.ID, ".profile")
89-
if err == nil && !profileDbRepo.IsEmpty && !profileDbRepo.IsPrivate {
90-
if profileGitRepo, err = git.OpenRepository(ctx, profileDbRepo.RepoPath()); err != nil {
91-
log.Error("FindUserProfileReadme failed to OpenRepository: %v", err)
92-
} else {
93-
if commit, err := profileGitRepo.GetBranchCommit(profileDbRepo.DefaultBranch); err != nil {
94-
log.Error("FindUserProfileReadme failed to GetBranchCommit: %v", err)
91+
if err == nil {
92+
perm, err := access_model.GetUserRepoPermission(ctx, profileDbRepo, doer)
93+
if err == nil && !profileDbRepo.IsEmpty && perm.CanRead(unit.TypeCode) {
94+
if profileGitRepo, err = git.OpenRepository(ctx, profileDbRepo.RepoPath()); err != nil {
95+
log.Error("FindUserProfileReadme failed to OpenRepository: %v", err)
9596
} else {
96-
profileReadmeBlob, _ = commit.GetBlobByPath("README.md")
97+
if commit, err := profileGitRepo.GetBranchCommit(profileDbRepo.DefaultBranch); err != nil {
98+
log.Error("FindUserProfileReadme failed to GetBranchCommit: %v", err)
99+
} else {
100+
profileReadmeBlob, _ = commit.GetBlobByPath("README.md")
101+
}
97102
}
98103
}
104+
} else if !repo_model.IsErrRepoNotExist(err) {
105+
log.Error("FindUserProfileReadme failed to GetRepositoryByName: %v", err)
99106
}
100107
return profileGitRepo, profileReadmeBlob, func() {
101108
if profileGitRepo != nil {
@@ -107,7 +114,7 @@ func FindUserProfileReadme(ctx *context.Context) (profileGitRepo *git.Repository
107114
func RenderUserHeader(ctx *context.Context) {
108115
prepareContextForCommonProfile(ctx)
109116

110-
_, profileReadmeBlob, profileClose := FindUserProfileReadme(ctx)
117+
_, profileReadmeBlob, profileClose := FindUserProfileReadme(ctx, ctx.Doer)
111118
defer profileClose()
112119
ctx.Data["HasProfileReadme"] = profileReadmeBlob != nil
113120
}

routers/web/user/profile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func userProfile(ctx *context.Context) {
6464
ctx.Data["HeatmapTotalContributions"] = activities_model.GetTotalContributionsInHeatmap(data)
6565
}
6666

67-
profileGitRepo, profileReadmeBlob, profileClose := shared_user.FindUserProfileReadme(ctx)
67+
profileGitRepo, profileReadmeBlob, profileClose := shared_user.FindUserProfileReadme(ctx, ctx.Doer)
6868
defer profileClose()
6969

7070
showPrivate := ctx.IsSigned && (ctx.Doer.IsAdmin || ctx.Doer.ID == ctx.ContextUser.ID)

templates/explore/repo_search.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<input type="hidden" name="sort" value="{{$.SortType}}">
44
<input type="hidden" name="language" value="{{$.Language}}">
55
<div class="ui fluid action input">
6-
{{template "shared/searchinput" dict "Value" .Keyword "AutoFocus" true}}
6+
{{template "shared/searchinput" dict "Value" .Keyword "AutoFocus" (not .ProfileReadme)}}
77
{{if .PageIsExploreRepositories}}
88
<input type="hidden" name="only_show_relevant" value="{{.OnlyShowRelevant}}">
99
{{else if .TabName}}

templates/user/overview/header.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="ui secondary stackable pointing menu">
2-
{{if .HasProfileReadme}}
2+
{{if and .HasProfileReadme .ContextUser.IsIndividual}}
33
<a class="{{if eq .TabName "overview"}}active {{end}}item" href="{{.ContextUser.HomeLink}}?tab=overview">
44
{{svg "octicon-info"}} {{ctx.Locale.Tr "user.overview"}}
55
</a>

0 commit comments

Comments
 (0)