|
|
@ -6,7 +6,9 @@ package user
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"code.gitea.io/gitea/models/db"
|
|
|
|
"code.gitea.io/gitea/models/db"
|
|
|
|
"code.gitea.io/gitea/models/organization"
|
|
|
|
"code.gitea.io/gitea/models/organization"
|
|
|
|
|
|
|
|
access_model "code.gitea.io/gitea/models/perm/access"
|
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models/unit"
|
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
|
|
|
"code.gitea.io/gitea/modules/context"
|
|
|
|
"code.gitea.io/gitea/modules/context"
|
|
|
|
"code.gitea.io/gitea/modules/git"
|
|
|
|
"code.gitea.io/gitea/modules/git"
|
|
|
@ -84,18 +86,23 @@ 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")
|
|
|
|
profileDbRepo, err := repo_model.GetRepositoryByName(ctx, ctx.ContextUser.ID, ".profile")
|
|
|
|
if err == nil && !profileDbRepo.IsEmpty && !profileDbRepo.IsPrivate {
|
|
|
|
if err == nil {
|
|
|
|
if profileGitRepo, err = git.OpenRepository(ctx, profileDbRepo.RepoPath()); err != nil {
|
|
|
|
perm, err := access_model.GetUserRepoPermission(ctx, profileDbRepo, doer)
|
|
|
|
log.Error("FindUserProfileReadme failed to OpenRepository: %v", err)
|
|
|
|
if err == nil && !profileDbRepo.IsEmpty && perm.CanRead(unit.TypeCode) {
|
|
|
|
} else {
|
|
|
|
if profileGitRepo, err = git.OpenRepository(ctx, profileDbRepo.RepoPath()); err != nil {
|
|
|
|
if commit, err := profileGitRepo.GetBranchCommit(profileDbRepo.DefaultBranch); err != nil {
|
|
|
|
log.Error("FindUserProfileReadme failed to OpenRepository: %v", err)
|
|
|
|
log.Error("FindUserProfileReadme failed to GetBranchCommit: %v", err)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
profileReadmeBlob, _ = commit.GetBlobByPath("README.md")
|
|
|
|
if commit, err := profileGitRepo.GetBranchCommit(profileDbRepo.DefaultBranch); err != nil {
|
|
|
|
|
|
|
|
log.Error("FindUserProfileReadme failed to GetBranchCommit: %v", err)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
profileReadmeBlob, _ = commit.GetBlobByPath("README.md")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if !repo_model.IsErrRepoNotExist(err) {
|
|
|
|
|
|
|
|
log.Error("FindUserProfileReadme failed to GetRepositoryByName: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return profileGitRepo, profileReadmeBlob, func() {
|
|
|
|
return profileGitRepo, profileReadmeBlob, func() {
|
|
|
|
if profileGitRepo != nil {
|
|
|
|
if profileGitRepo != nil {
|
|
|
@ -107,7 +114,7 @@ func FindUserProfileReadme(ctx *context.Context) (profileGitRepo *git.Repository
|
|
|
|
func RenderUserHeader(ctx *context.Context) {
|
|
|
|
func RenderUserHeader(ctx *context.Context) {
|
|
|
|
prepareContextForCommonProfile(ctx)
|
|
|
|
prepareContextForCommonProfile(ctx)
|
|
|
|
|
|
|
|
|
|
|
|
_, profileReadmeBlob, profileClose := FindUserProfileReadme(ctx)
|
|
|
|
_, profileReadmeBlob, profileClose := FindUserProfileReadme(ctx, ctx.Doer)
|
|
|
|
defer profileClose()
|
|
|
|
defer profileClose()
|
|
|
|
ctx.Data["HasProfileReadme"] = profileReadmeBlob != nil
|
|
|
|
ctx.Data["HasProfileReadme"] = profileReadmeBlob != nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|