@@ -6,7 +6,9 @@ package user
6
6
import (
7
7
"code.gitea.io/gitea/models/db"
8
8
"code.gitea.io/gitea/models/organization"
9
+ access_model "code.gitea.io/gitea/models/perm/access"
9
10
repo_model "code.gitea.io/gitea/models/repo"
11
+ "code.gitea.io/gitea/models/unit"
10
12
user_model "code.gitea.io/gitea/models/user"
11
13
"code.gitea.io/gitea/modules/context"
12
14
"code.gitea.io/gitea/modules/git"
@@ -84,18 +86,23 @@ func PrepareContextForProfileBigAvatar(ctx *context.Context) {
84
86
}
85
87
}
86
88
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 ()) {
88
90
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 )
95
96
} 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
+ }
97
102
}
98
103
}
104
+ } else if ! repo_model .IsErrRepoNotExist (err ) {
105
+ log .Error ("FindUserProfileReadme failed to GetRepositoryByName: %v" , err )
99
106
}
100
107
return profileGitRepo , profileReadmeBlob , func () {
101
108
if profileGitRepo != nil {
@@ -107,7 +114,7 @@ func FindUserProfileReadme(ctx *context.Context) (profileGitRepo *git.Repository
107
114
func RenderUserHeader (ctx * context.Context ) {
108
115
prepareContextForCommonProfile (ctx )
109
116
110
- _ , profileReadmeBlob , profileClose := FindUserProfileReadme (ctx )
117
+ _ , profileReadmeBlob , profileClose := FindUserProfileReadme (ctx , ctx . Doer )
111
118
defer profileClose ()
112
119
ctx .Data ["HasProfileReadme" ] = profileReadmeBlob != nil
113
120
}
0 commit comments