2019-12-14 14:36:59 +08:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
2022-11-27 13:20:29 -05:00
|
|
|
// SPDX-License-Identifier: MIT
|
2019-12-14 14:36:59 +08:00
|
|
|
|
|
|
|
package org
|
|
|
|
|
|
|
|
import (
|
2021-04-05 17:30:52 +02:00
|
|
|
"net/http"
|
2024-01-15 09:49:24 +01:00
|
|
|
"path"
|
2022-03-02 01:37:32 +00:00
|
|
|
"strings"
|
2019-12-14 14:36:59 +08:00
|
|
|
|
2021-09-24 19:32:56 +08:00
|
|
|
"code.gitea.io/gitea/models/db"
|
2022-03-29 14:29:02 +08:00
|
|
|
"code.gitea.io/gitea/models/organization"
|
2024-11-24 16:18:57 +08:00
|
|
|
"code.gitea.io/gitea/models/renderhelper"
|
2021-12-10 09:27:50 +08:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2024-12-31 12:22:09 +08:00
|
|
|
"code.gitea.io/gitea/modules/git"
|
2023-11-09 15:05:52 +01:00
|
|
|
"code.gitea.io/gitea/modules/log"
|
2020-11-15 17:28:08 +01:00
|
|
|
"code.gitea.io/gitea/modules/markup/markdown"
|
2019-12-14 14:36:59 +08:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2024-12-22 23:33:19 +08:00
|
|
|
"code.gitea.io/gitea/modules/templates"
|
2023-12-27 16:32:27 +08:00
|
|
|
"code.gitea.io/gitea/modules/util"
|
2023-08-11 19:08:05 +02:00
|
|
|
shared_user "code.gitea.io/gitea/routers/web/shared/user"
|
2024-02-27 15:12:22 +08:00
|
|
|
"code.gitea.io/gitea/services/context"
|
2019-12-14 14:36:59 +08:00
|
|
|
)
|
|
|
|
|
2024-12-31 12:22:09 +08:00
|
|
|
const tplOrgHome templates.TplName = "org/home"
|
2019-12-14 14:36:59 +08:00
|
|
|
|
|
|
|
// Home show organization home page
|
|
|
|
func Home(ctx *context.Context) {
|
2024-12-24 21:47:45 +08:00
|
|
|
uname := ctx.PathParam("username")
|
2022-03-02 01:37:32 +00:00
|
|
|
|
|
|
|
if strings.HasSuffix(uname, ".keys") || strings.HasSuffix(uname, ".gpg") {
|
|
|
|
ctx.NotFound("", nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-12-24 21:47:45 +08:00
|
|
|
ctx.SetPathParam("org", uname)
|
2019-12-14 14:36:59 +08:00
|
|
|
context.HandleOrgAssignment(ctx)
|
|
|
|
if ctx.Written() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-08-27 10:54:12 +08:00
|
|
|
home(ctx, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Repositories(ctx *context.Context) {
|
|
|
|
home(ctx, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func home(ctx *context.Context, viewRepositories bool) {
|
2019-12-14 14:36:59 +08:00
|
|
|
org := ctx.Org.Organization
|
|
|
|
|
2020-09-11 07:41:43 +01:00
|
|
|
ctx.Data["PageIsUserProfile"] = true
|
2019-12-14 14:36:59 +08:00
|
|
|
ctx.Data["Title"] = org.DisplayName()
|
|
|
|
|
2021-11-24 17:49:20 +08:00
|
|
|
var orderBy db.SearchOrderBy
|
2024-09-02 01:55:05 +09:00
|
|
|
sortOrder := ctx.FormString("sort")
|
|
|
|
if _, ok := repo_model.OrderByFlatMap[sortOrder]; !ok {
|
|
|
|
sortOrder = setting.UI.ExploreDefaultSort // TODO: add new default sort order for org home?
|
2019-12-14 14:36:59 +08:00
|
|
|
}
|
2024-09-02 01:55:05 +09:00
|
|
|
ctx.Data["SortType"] = sortOrder
|
|
|
|
orderBy = repo_model.OrderByFlatMap[sortOrder]
|
2019-12-14 14:36:59 +08:00
|
|
|
|
2021-08-11 17:08:52 +02:00
|
|
|
keyword := ctx.FormTrim("q")
|
2019-12-14 14:36:59 +08:00
|
|
|
ctx.Data["Keyword"] = keyword
|
|
|
|
|
2022-01-28 13:29:04 +02:00
|
|
|
language := ctx.FormTrim("language")
|
|
|
|
ctx.Data["Language"] = language
|
|
|
|
|
2021-07-29 09:42:15 +08:00
|
|
|
page := ctx.FormInt("page")
|
2019-12-14 14:36:59 +08:00
|
|
|
if page <= 0 {
|
|
|
|
page = 1
|
|
|
|
}
|
|
|
|
|
2024-03-03 11:18:34 +01:00
|
|
|
archived := ctx.FormOptionalBool("archived")
|
|
|
|
ctx.Data["IsArchived"] = archived
|
|
|
|
|
|
|
|
fork := ctx.FormOptionalBool("fork")
|
|
|
|
ctx.Data["IsFork"] = fork
|
|
|
|
|
|
|
|
mirror := ctx.FormOptionalBool("mirror")
|
|
|
|
ctx.Data["IsMirror"] = mirror
|
|
|
|
|
|
|
|
template := ctx.FormOptionalBool("template")
|
|
|
|
ctx.Data["IsTemplate"] = template
|
|
|
|
|
|
|
|
private := ctx.FormOptionalBool("private")
|
|
|
|
ctx.Data["IsPrivate"] = private
|
|
|
|
|
2024-08-27 10:54:12 +08:00
|
|
|
err := shared_user.LoadHeaderCount(ctx)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("LoadHeaderCount", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
opts := &organization.FindOrgMembersOpts{
|
2024-11-11 01:38:30 +01:00
|
|
|
Doer: ctx.Doer,
|
|
|
|
OrgID: org.ID,
|
|
|
|
IsDoerMember: ctx.Org.IsMember,
|
|
|
|
ListOptions: db.ListOptions{Page: 1, PageSize: 25},
|
2024-08-27 10:54:12 +08:00
|
|
|
}
|
2024-11-11 01:38:30 +01:00
|
|
|
|
2024-08-27 10:54:12 +08:00
|
|
|
members, _, err := organization.FindOrgMembers(ctx, opts)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("FindOrgMembers", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ctx.Data["Members"] = members
|
|
|
|
ctx.Data["Teams"] = ctx.Org.Teams
|
|
|
|
ctx.Data["DisableNewPullMirrors"] = setting.Mirror.DisableNewPull
|
|
|
|
ctx.Data["ShowMemberAndTeamTab"] = ctx.Org.IsMember || len(members) > 0
|
|
|
|
|
2024-12-31 12:22:09 +08:00
|
|
|
prepareResult, err := shared_user.PrepareOrgHeader(ctx)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("PrepareOrgHeader", err)
|
|
|
|
return
|
2024-08-27 10:54:12 +08:00
|
|
|
}
|
|
|
|
|
2024-12-31 12:22:09 +08:00
|
|
|
// if no profile readme, it still means "view repositories"
|
|
|
|
isViewOverview := !viewRepositories && prepareOrgProfileReadme(ctx, prepareResult)
|
|
|
|
ctx.Data["PageIsViewRepositories"] = !isViewOverview
|
|
|
|
ctx.Data["PageIsViewOverview"] = isViewOverview
|
|
|
|
ctx.Data["ShowOrgProfileReadmeSelector"] = isViewOverview && prepareResult.ProfilePublicReadmeBlob != nil && prepareResult.ProfilePrivateReadmeBlob != nil
|
|
|
|
|
|
|
|
repos, count, err := repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
|
2021-09-24 19:32:56 +08:00
|
|
|
ListOptions: db.ListOptions{
|
2020-01-24 19:00:29 +00:00
|
|
|
PageSize: setting.UI.User.RepoPagingNum,
|
|
|
|
Page: page,
|
|
|
|
},
|
2019-12-14 14:36:59 +08:00
|
|
|
Keyword: keyword,
|
|
|
|
OwnerID: org.ID,
|
|
|
|
OrderBy: orderBy,
|
|
|
|
Private: ctx.IsSigned,
|
2022-03-22 08:03:22 +01:00
|
|
|
Actor: ctx.Doer,
|
2022-01-28 13:29:04 +02:00
|
|
|
Language: language,
|
2019-12-14 14:36:59 +08:00
|
|
|
IncludeDescription: setting.UI.SearchRepoDescription,
|
2024-03-03 11:18:34 +01:00
|
|
|
Archived: archived,
|
|
|
|
Fork: fork,
|
|
|
|
Mirror: mirror,
|
|
|
|
Template: template,
|
|
|
|
IsPrivate: private,
|
2019-12-14 14:36:59 +08:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("SearchRepository", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Data["Repos"] = repos
|
|
|
|
ctx.Data["Total"] = count
|
2023-08-11 19:08:05 +02:00
|
|
|
|
2019-12-14 14:36:59 +08:00
|
|
|
pager := context.NewPagination(int(count), setting.UI.User.RepoPagingNum, page, 5)
|
2024-12-30 09:57:38 +08:00
|
|
|
pager.AddParamFromRequest(ctx.Req)
|
2019-12-14 14:36:59 +08:00
|
|
|
ctx.Data["Page"] = pager
|
|
|
|
|
2021-04-05 17:30:52 +02:00
|
|
|
ctx.HTML(http.StatusOK, tplOrgHome)
|
2019-12-14 14:36:59 +08:00
|
|
|
}
|
2023-11-09 15:05:52 +01:00
|
|
|
|
2024-12-31 12:22:09 +08:00
|
|
|
func prepareOrgProfileReadme(ctx *context.Context, prepareResult *shared_user.PrepareOrgHeaderResult) bool {
|
|
|
|
viewAs := ctx.FormString("view_as", util.Iif(ctx.Org.IsMember, "member", "public"))
|
|
|
|
viewAsMember := viewAs == "member"
|
2023-11-09 15:05:52 +01:00
|
|
|
|
2024-12-31 12:22:09 +08:00
|
|
|
var profileRepo *repo_model.Repository
|
|
|
|
var readmeBlob *git.Blob
|
|
|
|
if viewAsMember {
|
|
|
|
if prepareResult.ProfilePrivateReadmeBlob != nil {
|
|
|
|
profileRepo, readmeBlob = prepareResult.ProfilePrivateRepo, prepareResult.ProfilePrivateReadmeBlob
|
|
|
|
} else {
|
|
|
|
profileRepo, readmeBlob = prepareResult.ProfilePublicRepo, prepareResult.ProfilePublicReadmeBlob
|
|
|
|
viewAsMember = false
|
|
|
|
}
|
2023-11-09 15:05:52 +01:00
|
|
|
} else {
|
2024-12-31 12:22:09 +08:00
|
|
|
if prepareResult.ProfilePublicReadmeBlob != nil {
|
|
|
|
profileRepo, readmeBlob = prepareResult.ProfilePublicRepo, prepareResult.ProfilePublicReadmeBlob
|
2023-11-09 15:05:52 +01:00
|
|
|
} else {
|
2024-12-31 12:22:09 +08:00
|
|
|
profileRepo, readmeBlob = prepareResult.ProfilePrivateRepo, prepareResult.ProfilePrivateReadmeBlob
|
|
|
|
viewAsMember = true
|
2023-11-09 15:05:52 +01:00
|
|
|
}
|
|
|
|
}
|
2024-12-31 12:22:09 +08:00
|
|
|
if readmeBlob == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
readmeBytes, err := readmeBlob.GetBlobContent(setting.UI.MaxDisplayFileSize)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("failed to GetBlobContent for profile %q (view as %q) readme: %v", profileRepo.FullName(), viewAs, err)
|
|
|
|
return false
|
|
|
|
}
|
2024-08-27 10:54:12 +08:00
|
|
|
|
2024-12-31 12:22:09 +08:00
|
|
|
rctx := renderhelper.NewRenderContextRepoFile(ctx, profileRepo, renderhelper.RepoFileOptions{
|
|
|
|
CurrentRefPath: path.Join("branch", util.PathEscapeSegments(profileRepo.DefaultBranch)),
|
|
|
|
})
|
|
|
|
ctx.Data["ProfileReadmeContent"], err = markdown.RenderString(rctx, readmeBytes)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("failed to GetBlobContent for profile %q (view as %q) readme: %v", profileRepo.FullName(), viewAs, err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
ctx.Data["IsViewingOrgAsMember"] = viewAsMember
|
2024-08-27 10:54:12 +08:00
|
|
|
return true
|
2023-11-09 15:05:52 +01:00
|
|
|
}
|