Skip to content

Commit 0aebdbf

Browse files
committed
improve permission check
1 parent 07e904d commit 0aebdbf

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
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: 6 additions & 3 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,9 +86,10 @@ 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 {
91+
perm, err := access_model.GetUserRepoPermission(ctx, profileDbRepo, doer)
92+
if err == nil && !profileDbRepo.IsEmpty && perm.CanRead(unit.TypeCode) {
9093
if profileGitRepo, err = git.OpenRepository(ctx, profileDbRepo.RepoPath()); err != nil {
9194
log.Error("FindUserProfileReadme failed to OpenRepository: %v", err)
9295
} else {
@@ -107,7 +110,7 @@ func FindUserProfileReadme(ctx *context.Context) (profileGitRepo *git.Repository
107110
func RenderUserHeader(ctx *context.Context) {
108111
prepareContextForCommonProfile(ctx)
109112

110-
_, profileReadmeBlob, profileClose := FindUserProfileReadme(ctx)
113+
_, profileReadmeBlob, profileClose := FindUserProfileReadme(ctx, ctx.Doer)
111114
defer profileClose()
112115
ctx.Data["HasProfileReadme"] = profileReadmeBlob != nil
113116
}

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)

0 commit comments

Comments
 (0)