@@ -6,7 +6,9 @@ package user
66import (
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
107114func 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}
0 commit comments