mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-10-29 13:31:20 +00:00
## Checklist - [x] go to the last cherry-pick PR (forgejo/forgejo#8040) to figure out how far it went: [gitea@d5bbaee64e](d5bbaee64e) - [x] cherry-pick and open PR (forgejo/forgejo#8198) - [ ] have the PR pass the CI - end-to-end (specially important if there are actions related changes) - [ ] add `run-end-to-end` label - [ ] check the result - [ ] write release notes - [ ] assign reviewers - [ ] 48h later, last call - merge 1 hour after the last call ## Legend - ❓ - No decision about the commit has been made. - 🍒 - The commit has been cherry picked. - ⏩ - The commit has been skipped. - 💡 - The commit has been skipped, but should be ported to Forgejo. - ✍️ - The commit has been skipped, and a port to Forgejo already exists. ## Commits - 🍒 [`gitea`](17cfae82a5) -> [`forgejo`](6397da88d3) Hide href attribute of a tag if there is no target_url ([gitea#34556](https://github.com/go-gitea/gitea/pull/34556)) - 🍒 [`gitea`](b408bf2f0b) -> [`forgejo`](46bc899d57) Fix: skip paths check on tag push events in workflows ([gitea#34602](https://github.com/go-gitea/gitea/pull/34602)) - 🍒 [`gitea`](9165ea8713) -> [`forgejo`](04332f31bf) Only activity tab needs heatmap data loading ([gitea#34652](https://github.com/go-gitea/gitea/pull/34652)) - 🍒 [`gitea`](3f7dbbdaf1) -> [`forgejo`](2a9019fd04) Small fix in Pull Requests page ([gitea#34612](https://github.com/go-gitea/gitea/pull/34612)) - 🍒 [`gitea`](497b83b75d) -> [`forgejo`](9a83cc7bad) Fix migration pull request title too long ([gitea#34577](https://github.com/go-gitea/gitea/pull/34577)) ## TODO - 💡 [`gitea`](6b8b580218) Refactor container and UI ([gitea#34736](https://github.com/go-gitea/gitea/pull/34736)) Packages: Fix for container, needs careful merge. ------ - 💡 [`gitea`](bbee652e29) Prevent duplicate form submissions when creating forks ([gitea#34714](https://github.com/go-gitea/gitea/pull/34714)) Fork: Fix, needs careful merge. ------ - 💡 [`gitea`](d21ce9fa07) Improve the performance when detecting the file editable ([gitea#34653](https://github.com/go-gitea/gitea/pull/34653)) LFS: Performance improvement - needs careful merge. ------ - 💡 [`gitea`](8fed27bf6a) Fix various problems ([gitea#34708](https://github.com/go-gitea/gitea/pull/34708)) Various: Fixes, tests missing. ------ - 💡 [`gitea`](c9505a26b9) Improve instance wide ssh commit signing ([gitea#34341](https://github.com/go-gitea/gitea/pull/34341)) CodeSign: Nice feature - needs careful merge. ------ - 💡 [`gitea`](fbc3796f9e) Fix pull requests API convert panic when head repository is deleted. ([gitea#34685](https://github.com/go-gitea/gitea/pull/34685)) Pull: Fix, needs careful merge. ------ - 💡 [`gitea`](1610a63bfd) Fix commit message rendering and some UI problems ([gitea#34680](https://github.com/go-gitea/gitea/pull/34680)) Various Fixes - needs carefull merge. ------ - 💡 [`gitea`](0082cb51fa) Fix last admin check when syncing users ([gitea#34649](https://github.com/go-gitea/gitea/pull/34649)) oidc: fix "first user is always admin". Needs careful merge. ------ - 💡 [`gitea`](c6b2cbd75d) Fix footnote jump behavior on the issue page. ([gitea#34621](https://github.com/go-gitea/gitea/pull/34621)) Issues: Fix Markdown rendering. Needs carefull merge ------ - 💡 [`gitea`](7a59f5a825) Ignore "Close" error when uploading container blob ([gitea#34620](https://github.com/go-gitea/gitea/pull/34620)) No issue, no test. ------ - 💡 [`gitea`](6d0b24064a) Keeping consistent between UI and API about combined commit status state and fix some bugs ([gitea#34562](https://github.com/go-gitea/gitea/pull/34562)) Next PR in Commit-Status story. ------ - 💡 [`gitea`](f6041441ee) Refactor FindOrgOptions to use enum instead of bool, fix membership visibility ([gitea#34629](https://github.com/go-gitea/gitea/pull/34629)) Just for a common sense here: How should I consider refactorings? ------ - 💡 [`gitea`](cc942e2a86) Fix GetUsersByEmails ([gitea#34643](https://github.com/go-gitea/gitea/pull/34643)) User: Seems to fix email validation - but seems not to be finished. ------ - 💡 [`gitea`](7fa5a88831) Add `--color-logo` for text that should match logo color ([gitea#34639](https://github.com/go-gitea/gitea/pull/34639)) UI: Nice idea - can we adapt this? ------ - 💡 [`gitea`](47d69b7749) Validate hex colors when creating/editing labels ([gitea#34623](https://github.com/go-gitea/gitea/pull/34623)) Label: Color validation but needs careful merge. ------ - 💡 [`gitea`](108db0b04f) Fix possible pull request broken when leave the page immediately after clicking the update button ([gitea#34509](https://github.com/go-gitea/gitea/pull/34509)) Nice fix for a bug hard to trace down. Needs careful merge & think about whether a test is possible. ------ - 💡 [`gitea`](79cc369892) Fix issue label delete incorrect labels webhook payload ([gitea#34575](https://github.com/go-gitea/gitea/pull/34575)) Small fix but would expect a test, showing what was fixed. ------ - 💡 [`gitea`](fe57ee3074) fixed incorrect page navigation with up and down arrow on last item of dashboard repos ([gitea#34570](https://github.com/go-gitea/gitea/pull/34570)) Small & simple - but tests are missing. ------ - 💡 [`gitea`](4e471487fb) Remove unnecessary duplicate code ([gitea#34552](https://github.com/go-gitea/gitea/pull/34552)) Fix arround "Split GetLatestCommitStatus". ------ - 💡 [`gitea`](c5e78fc7ad) Do not mutate incoming options to SearchRepositoryByName ([gitea#34553](https://github.com/go-gitea/gitea/pull/34553)) Large refactoring to simplify options handling. But needs careful merge. ------ - 💡 [`gitea`](f48c0135a6) Fix/improve avatar sync from LDAP ([gitea#34573](https://github.com/go-gitea/gitea/pull/34573)) Nice fix but needs test. ------ - 💡 [`gitea`](e8d8984f7c) Fix some trivial problems ([gitea#34579](https://github.com/go-gitea/gitea/pull/34579)) Various fixes, tests missing. ------ ## Skipped - ⏩ [`gitea`](637070e07b) Fix container range bug ([gitea#34725](https://github.com/go-gitea/gitea/pull/34725)) ------ - ⏩ [`gitea`](0d3e9956cd) [skip ci] Updated translations via Crowdin ------ - ⏩ [`gitea`](28debdbe00) [skip ci] Updated translations via Crowdin ------ - ⏩ [`gitea`](dcc9206a59) Raise minimum Node.js version to 20, test on 24 ([gitea#34713](https://github.com/go-gitea/gitea/pull/34713)) ------ - ⏩ [`gitea`](bc28654b49) [skip ci] Updated translations via Crowdin ------ - ⏩ [`gitea`](65986f423f) Refactor embedded assets and drop unnecessary dependencies ([gitea#34692](https://github.com/go-gitea/gitea/pull/34692)) ------ - ⏩ [`gitea`](18bafcc378) Bump minimum go version to 1.24.4 ([gitea#34699](https://github.com/go-gitea/gitea/pull/34699)) ------ - ⏩ [`gitea`](8d135ef5cf) Update JS deps ([gitea#34701](https://github.com/go-gitea/gitea/pull/34701)) ------ - ⏩ [`gitea`](d5893ee260) Fix markdown wrap ([gitea#34697](https://github.com/go-gitea/gitea/pull/34697)) - gitea UI specific specific ------ - ⏩ [`gitea`](06ccb3a1d4) [skip ci] Updated translations via Crowdin ------ - ⏩ [`gitea`](94db956e31) frontport changelog ([gitea#34689](https://github.com/go-gitea/gitea/pull/34689)) ------ - ⏩ [`gitea`](d5afdccde8) [skip ci] Updated translations via Crowdin ------ - ⏩ [`gitea`](e9f5105e95) Migrate to urfave v3 ([gitea#34510](https://github.com/go-gitea/gitea/pull/34510)) already in Forgejo - see https://codeberg.org/forgejo/forgejo/pulls/8035 ------ - ⏩ [`gitea`](2c341b6803) [skip ci] Updated translations via Crowdin ------ - ⏩ [`gitea`](92e7e98c56) Update x/crypto package and make builtin SSH use default parameters ([gitea#34667](https://github.com/go-gitea/gitea/pull/34667)) ------ - ⏩ [`gitea`](7b39c82587) Fix "oras" OCI client compatibility ([gitea#34666](https://github.com/go-gitea/gitea/pull/34666)) Already in forgejo - see https://codeberg.org/forgejo/forgejo/issues/8070 ------ - ⏩ [`gitea`](1fe652cd26) [skip ci] Updated translations via Crowdin ------ - ⏩ [`gitea`](a9a705f4db) Fix missed merge commit sha and time when migrating from codecommit ([gitea#34645](https://github.com/go-gitea/gitea/pull/34645)) Migration: Seems to be an important fix, but no tests. As I know @earl-warren worked hard on migration, is this still relevant to us? ------ - ⏩ [`gitea`](1e0758a9f1) [skip ci] Updated translations via Crowdin ------ - ⏩ [`gitea`](f6f6aedd4f) Update JS deps, regenerate SVGs ([gitea#34640](https://github.com/go-gitea/gitea/pull/34640)) ------ - ⏩ [`gitea`](aa2b3b2b1f) Misc CSS fixes ([gitea#34638](https://github.com/go-gitea/gitea/pull/34638)) - gitea UI specific specific ------ - ⏩ [`gitea`](b38f2d31fd) add codecommit to supported services in api docs ([gitea#34626](https://github.com/go-gitea/gitea/pull/34626)) ------ - ⏩ [`gitea`](74a0178c6a) add openssh-keygen to rootless image ([gitea#34625](https://github.com/go-gitea/gitea/pull/34625)) already in Forgejo - see https://codeberg.org/forgejo/forgejo/issues/6896 ------ - ⏩ [`gitea`](5b22af4373) bump to alpine 3.22 ([gitea#34613](https://github.com/go-gitea/gitea/pull/34613)) ------ - ⏩ [`gitea`](9e0e107d23) Fix notification count positioning for variable-width elements ([gitea#34597](https://github.com/go-gitea/gitea/pull/34597)) - gitea UI specific specific ------ - ⏩ [`gitea`](e5781cec75) Fix margin issue in markup paragraph rendering ([gitea#34599](https://github.com/go-gitea/gitea/pull/34599)) - gitea UI specific specific ------ - ⏩ [`gitea`](375dab1111) Make pull request and issue history more compact ([gitea#34588](https://github.com/go-gitea/gitea/pull/34588)) - gitea UI specific specific ------ - ⏩ [`gitea`](2a1585b32e) Refactor some tests ([gitea#34580](https://github.com/go-gitea/gitea/pull/34580)) ------ <details> <summary><h2>Stats</h2></summary> <br> Between [`gitea@d5bbaee64e`](d5bbaee64e) and [`gitea@6b8b580218`](6b8b580218), **55** commits have been reviewed. We picked **5**, skipped **28** (of which **3** were already in Forgejo!), and decided to port **22**. </details> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: NorthRealm <155140859+NorthRealm@users.noreply.github.com> Co-authored-by: TheFox0x7 <thefox0x7@gmail.com> Co-authored-by: endo0911engineer <161911062+endo0911engineer@users.noreply.github.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8198 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: Michael Jerger <michael.jerger@meissa-gmbh.de> Co-committed-by: Michael Jerger <michael.jerger@meissa-gmbh.de>
402 lines
12 KiB
Go
402 lines
12 KiB
Go
// Copyright 2015 The Gogs Authors. All rights reserved.
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
// Copyright 2023 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package user
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"net/http"
|
|
"path"
|
|
"strings"
|
|
|
|
activities_model "forgejo.org/models/activities"
|
|
"forgejo.org/models/db"
|
|
repo_model "forgejo.org/models/repo"
|
|
user_model "forgejo.org/models/user"
|
|
"forgejo.org/modules/base"
|
|
"forgejo.org/modules/git"
|
|
"forgejo.org/modules/log"
|
|
"forgejo.org/modules/markup"
|
|
"forgejo.org/modules/markup/markdown"
|
|
"forgejo.org/modules/optional"
|
|
"forgejo.org/modules/setting"
|
|
"forgejo.org/modules/util"
|
|
"forgejo.org/routers/web/feed"
|
|
"forgejo.org/routers/web/org"
|
|
shared_user "forgejo.org/routers/web/shared/user"
|
|
"forgejo.org/services/context"
|
|
user_service "forgejo.org/services/user"
|
|
)
|
|
|
|
const (
|
|
tplProfileBigAvatar base.TplName = "shared/user/profile_big_avatar"
|
|
tplFollowUnfollow base.TplName = "org/follow_unfollow"
|
|
)
|
|
|
|
// OwnerProfile render profile page for a user or a organization (aka, repo owner)
|
|
func OwnerProfile(ctx *context.Context) {
|
|
if strings.Contains(ctx.Req.Header.Get("Accept"), "application/rss+xml") {
|
|
feed.ShowUserFeedRSS(ctx)
|
|
return
|
|
}
|
|
if strings.Contains(ctx.Req.Header.Get("Accept"), "application/atom+xml") {
|
|
feed.ShowUserFeedAtom(ctx)
|
|
return
|
|
}
|
|
|
|
if ctx.ContextUser.IsOrganization() {
|
|
org.Home(ctx)
|
|
} else {
|
|
userProfile(ctx)
|
|
}
|
|
}
|
|
|
|
func userProfile(ctx *context.Context) {
|
|
// check view permissions
|
|
if !user_model.IsUserVisibleToViewer(ctx, ctx.ContextUser, ctx.Doer) {
|
|
ctx.NotFound("User not visible", nil)
|
|
return
|
|
}
|
|
|
|
ctx.Data["Title"] = ctx.ContextUser.DisplayName()
|
|
ctx.Data["PageIsUserProfile"] = true
|
|
|
|
ctx.Data["OpenGraphTitle"] = ctx.ContextUser.DisplayName()
|
|
ctx.Data["OpenGraphType"] = "profile"
|
|
ctx.Data["OpenGraphImageURL"] = ctx.ContextUser.AvatarLink(ctx)
|
|
ctx.Data["OpenGraphURL"] = ctx.ContextUser.HTMLURL()
|
|
ctx.Data["OpenGraphDescription"] = ctx.ContextUser.Description
|
|
|
|
profileDbRepo, profileGitRepo, profileReadmeBlob, profileClose := shared_user.FindUserProfileReadme(ctx, ctx.Doer)
|
|
defer profileClose()
|
|
|
|
showPrivate := ctx.IsSigned && (ctx.Doer.IsAdmin || ctx.Doer.ID == ctx.ContextUser.ID)
|
|
prepareUserProfileTabData(ctx, showPrivate, profileDbRepo, profileGitRepo, profileReadmeBlob)
|
|
// call PrepareContextForProfileBigAvatar later to avoid re-querying the NumFollowers & NumFollowing
|
|
shared_user.PrepareContextForProfileBigAvatar(ctx)
|
|
ctx.HTML(http.StatusOK, tplProfile)
|
|
}
|
|
|
|
func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDbRepo *repo_model.Repository, profileGitRepo *git.Repository, profileReadme *git.Blob) {
|
|
// if there is a profile readme, default to "overview" page, otherwise, default to "repositories" page
|
|
// if there is not a profile readme, the overview tab should be treated as the repositories tab
|
|
tab := ctx.FormString("tab")
|
|
if tab == "" || tab == "overview" {
|
|
if profileReadme != nil {
|
|
tab = "overview"
|
|
} else {
|
|
tab = "repositories"
|
|
}
|
|
}
|
|
ctx.Data["TabName"] = tab
|
|
ctx.Data["HasProfileReadme"] = profileReadme != nil
|
|
|
|
page := ctx.FormInt("page")
|
|
if page <= 0 {
|
|
page = 1
|
|
}
|
|
|
|
pagingNum := setting.UI.User.RepoPagingNum
|
|
topicOnly := ctx.FormBool("topic")
|
|
var (
|
|
repos []*repo_model.Repository
|
|
count int64
|
|
total int
|
|
orderBy db.SearchOrderBy
|
|
)
|
|
|
|
sortOrder := ctx.FormString("sort")
|
|
if _, ok := repo_model.OrderByFlatMap[sortOrder]; !ok {
|
|
sortOrder = setting.UI.ExploreDefaultSort // TODO: add new default sort order for user home?
|
|
}
|
|
ctx.Data["SortType"] = sortOrder
|
|
orderBy = repo_model.OrderByFlatMap[sortOrder]
|
|
|
|
keyword := ctx.FormTrim("q")
|
|
ctx.Data["Keyword"] = keyword
|
|
|
|
language := ctx.FormTrim("language")
|
|
ctx.Data["Language"] = language
|
|
|
|
followers, numFollowers, err := user_model.GetUserFollowers(ctx, ctx.ContextUser, ctx.Doer, db.ListOptions{
|
|
PageSize: pagingNum,
|
|
Page: page,
|
|
})
|
|
if err != nil {
|
|
ctx.ServerError("GetUserFollowers", err)
|
|
return
|
|
}
|
|
ctx.Data["NumFollowers"] = numFollowers
|
|
following, numFollowing, err := user_model.GetUserFollowing(ctx, ctx.ContextUser, ctx.Doer, db.ListOptions{
|
|
PageSize: pagingNum,
|
|
Page: page,
|
|
})
|
|
if err != nil {
|
|
ctx.ServerError("GetUserFollowing", err)
|
|
return
|
|
}
|
|
ctx.Data["NumFollowing"] = numFollowing
|
|
|
|
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
|
|
|
|
switch tab {
|
|
case "followers":
|
|
ctx.Data["Cards"] = followers
|
|
total = int(numFollowers)
|
|
ctx.Data["CardsTitle"] = ctx.TrN(total, "user.followers.title.one", "user.followers.title.few")
|
|
if ctx.IsSigned && ctx.ContextUser.ID == ctx.Doer.ID {
|
|
ctx.Data["CardsNoneMsg"] = ctx.Tr("followers.incoming.list.self.none")
|
|
} else {
|
|
ctx.Data["CardsNoneMsg"] = ctx.Tr("followers.incoming.list.none")
|
|
}
|
|
case "following":
|
|
ctx.Data["Cards"] = following
|
|
total = int(numFollowing)
|
|
ctx.Data["CardsTitle"] = ctx.TrN(total, "user.following.title.one", "user.following.title.few")
|
|
if ctx.IsSigned && ctx.ContextUser.ID == ctx.Doer.ID {
|
|
ctx.Data["CardsNoneMsg"] = ctx.Tr("followers.outgoing.list.self.none")
|
|
} else {
|
|
ctx.Data["CardsNoneMsg"] = ctx.Tr("followers.outgoing.list.none", ctx.ContextUser.Name)
|
|
}
|
|
case "activity":
|
|
// prepare heatmap data
|
|
if setting.Service.EnableUserHeatmap {
|
|
data, err := activities_model.GetUserHeatmapDataByUser(ctx, ctx.ContextUser, ctx.Doer)
|
|
if err != nil {
|
|
ctx.ServerError("GetUserHeatmapDataByUser", err)
|
|
return
|
|
}
|
|
ctx.Data["HeatmapData"] = data
|
|
ctx.Data["HeatmapTotalContributions"] = activities_model.GetTotalContributionsInHeatmap(data)
|
|
}
|
|
|
|
date := ctx.FormString("date")
|
|
pagingNum = setting.UI.FeedPagingNum
|
|
items, count, err := activities_model.GetFeeds(ctx, activities_model.GetFeedsOptions{
|
|
RequestedUser: ctx.ContextUser,
|
|
Actor: ctx.Doer,
|
|
IncludePrivate: showPrivate,
|
|
OnlyPerformedBy: true,
|
|
IncludeDeleted: false,
|
|
Date: date,
|
|
ListOptions: db.ListOptions{
|
|
PageSize: pagingNum,
|
|
Page: page,
|
|
},
|
|
})
|
|
if err != nil {
|
|
ctx.ServerError("GetFeeds", err)
|
|
return
|
|
}
|
|
ctx.Data["Feeds"] = items
|
|
ctx.Data["Date"] = date
|
|
|
|
total = int(count)
|
|
case "stars":
|
|
ctx.Data["PageIsProfileStarList"] = true
|
|
repos, count, err = repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
|
|
ListOptions: db.ListOptions{
|
|
PageSize: pagingNum,
|
|
Page: page,
|
|
},
|
|
Actor: ctx.Doer,
|
|
Keyword: keyword,
|
|
OrderBy: orderBy,
|
|
Private: ctx.IsSigned,
|
|
StarredByID: ctx.ContextUser.ID,
|
|
Collaborate: optional.Some(false),
|
|
TopicOnly: topicOnly,
|
|
Language: language,
|
|
IncludeDescription: setting.UI.SearchRepoDescription,
|
|
Archived: archived,
|
|
Fork: fork,
|
|
Mirror: mirror,
|
|
Template: template,
|
|
IsPrivate: private,
|
|
})
|
|
if err != nil {
|
|
ctx.ServerError("SearchRepository", err)
|
|
return
|
|
}
|
|
|
|
total = int(count)
|
|
case "watching":
|
|
repos, count, err = repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
|
|
ListOptions: db.ListOptions{
|
|
PageSize: pagingNum,
|
|
Page: page,
|
|
},
|
|
Actor: ctx.Doer,
|
|
Keyword: keyword,
|
|
OrderBy: orderBy,
|
|
Private: ctx.IsSigned,
|
|
WatchedByID: ctx.ContextUser.ID,
|
|
Collaborate: optional.Some(false),
|
|
TopicOnly: topicOnly,
|
|
Language: language,
|
|
IncludeDescription: setting.UI.SearchRepoDescription,
|
|
Archived: archived,
|
|
Fork: fork,
|
|
Mirror: mirror,
|
|
Template: template,
|
|
IsPrivate: private,
|
|
})
|
|
if err != nil {
|
|
ctx.ServerError("SearchRepository", err)
|
|
return
|
|
}
|
|
|
|
total = int(count)
|
|
case "overview":
|
|
if bytes, err := profileReadme.GetBlobContent(setting.UI.MaxDisplayFileSize); err != nil {
|
|
log.Error("failed to GetBlobContent: %v", err)
|
|
} else {
|
|
if profileContent, err := markdown.RenderString(&markup.RenderContext{
|
|
Ctx: ctx,
|
|
GitRepo: profileGitRepo,
|
|
Links: markup.Links{
|
|
// Give the repo link to the markdown render for the full link of media element.
|
|
// the media link usually be like /[user]/[repoName]/media/branch/[branchName],
|
|
// Eg. /Tom/.profile/media/branch/main
|
|
// The branch shown on the profile page is the default branch, this need to be in sync with doc, see:
|
|
// https://docs.gitea.com/usage/profile-readme
|
|
Base: profileDbRepo.Link(),
|
|
BranchPath: path.Join("branch", util.PathEscapeSegments(profileDbRepo.DefaultBranch)),
|
|
},
|
|
Metas: map[string]string{"mode": "document"},
|
|
}, bytes); err != nil {
|
|
log.Error("failed to RenderString: %v", err)
|
|
} else {
|
|
ctx.Data["ProfileReadme"] = profileContent
|
|
}
|
|
}
|
|
default: // default to "repositories"
|
|
repos, count, err = repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
|
|
ListOptions: db.ListOptions{
|
|
PageSize: pagingNum,
|
|
Page: page,
|
|
},
|
|
Actor: ctx.Doer,
|
|
Keyword: keyword,
|
|
OwnerID: ctx.ContextUser.ID,
|
|
OrderBy: orderBy,
|
|
Private: ctx.IsSigned,
|
|
Collaborate: optional.Some(false),
|
|
TopicOnly: topicOnly,
|
|
Language: language,
|
|
IncludeDescription: setting.UI.SearchRepoDescription,
|
|
Archived: archived,
|
|
Fork: fork,
|
|
Mirror: mirror,
|
|
Template: template,
|
|
IsPrivate: private,
|
|
})
|
|
if err != nil {
|
|
ctx.ServerError("SearchRepository", err)
|
|
return
|
|
}
|
|
|
|
total = int(count)
|
|
}
|
|
ctx.Data["Repos"] = repos
|
|
ctx.Data["Total"] = total
|
|
|
|
err = shared_user.LoadHeaderCount(ctx)
|
|
if err != nil {
|
|
ctx.ServerError("LoadHeaderCount", err)
|
|
return
|
|
}
|
|
|
|
pager := context.NewPagination(total, pagingNum, page, 5)
|
|
pager.SetDefaultParams(ctx)
|
|
pager.AddParam(ctx, "tab", "TabName")
|
|
if tab != "followers" && tab != "following" && tab != "activity" && tab != "projects" {
|
|
pager.AddParam(ctx, "language", "Language")
|
|
}
|
|
if tab == "activity" {
|
|
pager.AddParam(ctx, "date", "Date")
|
|
}
|
|
if archived.Has() {
|
|
pager.AddParamString("archived", fmt.Sprint(archived.Value()))
|
|
}
|
|
if fork.Has() {
|
|
pager.AddParamString("fork", fmt.Sprint(fork.Value()))
|
|
}
|
|
if mirror.Has() {
|
|
pager.AddParamString("mirror", fmt.Sprint(mirror.Value()))
|
|
}
|
|
if template.Has() {
|
|
pager.AddParamString("template", fmt.Sprint(template.Value()))
|
|
}
|
|
if private.Has() {
|
|
pager.AddParamString("private", fmt.Sprint(private.Value()))
|
|
}
|
|
ctx.Data["Page"] = pager
|
|
}
|
|
|
|
// Action response for follow/unfollow user request
|
|
func Action(ctx *context.Context) {
|
|
var err error
|
|
action := ctx.FormString("action")
|
|
|
|
if ctx.ContextUser.IsOrganization() && (action == "block" || action == "unblock") {
|
|
log.Error("Cannot perform this action on an organization %q", ctx.FormString("action"))
|
|
ctx.JSONError(fmt.Sprintf("Action %q failed", ctx.FormString("action")))
|
|
return
|
|
}
|
|
|
|
switch action {
|
|
case "follow":
|
|
err = user_model.FollowUser(ctx, ctx.Doer.ID, ctx.ContextUser.ID)
|
|
case "unfollow":
|
|
err = user_model.UnfollowUser(ctx, ctx.Doer.ID, ctx.ContextUser.ID)
|
|
case "block":
|
|
err = user_service.BlockUser(ctx, ctx.Doer.ID, ctx.ContextUser.ID)
|
|
case "unblock":
|
|
err = user_model.UnblockUser(ctx, ctx.Doer.ID, ctx.ContextUser.ID)
|
|
}
|
|
|
|
if err != nil {
|
|
if !errors.Is(err, user_model.ErrBlockedByUser) {
|
|
log.Error("Failed to apply action %q: %v", ctx.FormString("action"), err)
|
|
ctx.Error(http.StatusBadRequest, fmt.Sprintf("Action %q failed", ctx.FormString("action")))
|
|
return
|
|
}
|
|
|
|
if ctx.ContextUser.IsOrganization() {
|
|
ctx.Flash.Error(ctx.Tr("org.follow_blocked_user"), true)
|
|
} else {
|
|
ctx.Flash.Error(ctx.Tr("user.follow_blocked_user"), true)
|
|
}
|
|
}
|
|
|
|
if ctx.ContextUser.IsIndividual() {
|
|
shared_user.PrepareContextForProfileBigAvatar(ctx)
|
|
ctx.Data["IsHTMX"] = true
|
|
ctx.HTML(http.StatusOK, tplProfileBigAvatar)
|
|
return
|
|
} else if ctx.ContextUser.IsOrganization() {
|
|
ctx.Data["Org"] = ctx.ContextUser
|
|
ctx.Data["IsFollowing"] = ctx.Doer != nil && user_model.IsFollowing(ctx, ctx.Doer.ID, ctx.ContextUser.ID)
|
|
ctx.HTML(http.StatusOK, tplFollowUnfollow)
|
|
return
|
|
}
|
|
log.Error("Failed to apply action %q: unsupported context user type: %s", ctx.FormString("action"), ctx.ContextUser.Type)
|
|
ctx.Error(http.StatusBadRequest, fmt.Sprintf("Action %q failed", ctx.FormString("action")))
|
|
}
|