2015-12-21 13:24:11 +01:00
|
|
|
// Copyright 2015 The Gogs Authors. All rights reserved.
|
2019-02-18 17:00:27 +01:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
2022-11-27 19:20:29 +01:00
|
|
|
// SPDX-License-Identifier: MIT
|
2015-12-21 13:24:11 +01:00
|
|
|
|
|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-04-05 17:30:52 +02:00
|
|
|
"net/http"
|
2024-01-15 09:49:24 +01:00
|
|
|
"path"
|
2015-12-21 13:24:11 +01:00
|
|
|
"strings"
|
|
|
|
|
2022-08-25 04:31:57 +02:00
|
|
|
activities_model "code.gitea.io/gitea/models/activities"
|
2021-09-24 13:32:56 +02:00
|
|
|
"code.gitea.io/gitea/models/db"
|
2021-12-10 02:27:50 +01:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-11 08:03:30 +01:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2024-01-30 15:45:54 +01:00
|
|
|
"code.gitea.io/gitea/modules/base"
|
2023-05-09 07:57:24 +02:00
|
|
|
"code.gitea.io/gitea/modules/git"
|
2023-07-06 20:59:24 +02:00
|
|
|
"code.gitea.io/gitea/modules/log"
|
2021-04-20 00:25:08 +02:00
|
|
|
"code.gitea.io/gitea/modules/markup"
|
2020-08-05 09:48:37 +02:00
|
|
|
"code.gitea.io/gitea/modules/markup/markdown"
|
2024-02-29 19:52:49 +01:00
|
|
|
"code.gitea.io/gitea/modules/optional"
|
2016-11-10 17:24:48 +01:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2017-10-26 23:16:13 +02:00
|
|
|
"code.gitea.io/gitea/modules/util"
|
2021-10-16 16:21:16 +02:00
|
|
|
"code.gitea.io/gitea/routers/web/feed"
|
2021-06-09 01:33:54 +02:00
|
|
|
"code.gitea.io/gitea/routers/web/org"
|
2023-07-06 20:59:24 +02:00
|
|
|
shared_user "code.gitea.io/gitea/routers/web/shared/user"
|
2024-02-27 08:12:22 +01:00
|
|
|
"code.gitea.io/gitea/services/context"
|
2015-12-21 13:24:11 +01:00
|
|
|
)
|
|
|
|
|
2024-01-30 15:45:54 +01:00
|
|
|
const (
|
|
|
|
tplProfileBigAvatar base.TplName = "shared/user/profile_big_avatar"
|
2024-02-17 14:42:52 +01:00
|
|
|
tplFollowUnfollow base.TplName = "org/follow_unfollow"
|
2024-01-30 15:45:54 +01:00
|
|
|
)
|
|
|
|
|
2023-07-06 20:59:24 +02:00
|
|
|
// OwnerProfile render profile page for a user or a organization (aka, repo owner)
|
|
|
|
func OwnerProfile(ctx *context.Context) {
|
2022-03-26 10:04:22 +01:00
|
|
|
if strings.Contains(ctx.Req.Header.Get("Accept"), "application/rss+xml") {
|
|
|
|
feed.ShowUserFeedRSS(ctx)
|
2015-12-21 13:24:11 +01:00
|
|
|
return
|
2021-04-28 14:35:06 +02:00
|
|
|
}
|
2022-03-26 10:04:22 +01:00
|
|
|
if strings.Contains(ctx.Req.Header.Get("Accept"), "application/atom+xml") {
|
|
|
|
feed.ShowUserFeedAtom(ctx)
|
2015-12-21 13:24:11 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-03-26 10:04:22 +01:00
|
|
|
if ctx.ContextUser.IsOrganization() {
|
2021-06-26 21:53:14 +02:00
|
|
|
org.Home(ctx)
|
2023-07-06 20:59:24 +02:00
|
|
|
} else {
|
|
|
|
userProfile(ctx)
|
2021-06-26 21:53:14 +02:00
|
|
|
}
|
2023-07-06 20:59:24 +02:00
|
|
|
}
|
2021-06-26 21:53:14 +02:00
|
|
|
|
2023-07-06 20:59:24 +02:00
|
|
|
func userProfile(ctx *context.Context) {
|
2021-06-26 21:53:14 +02:00
|
|
|
// check view permissions
|
2022-05-20 16:08:52 +02:00
|
|
|
if !user_model.IsUserVisibleToViewer(ctx, ctx.ContextUser, ctx.Doer) {
|
2022-03-26 10:04:22 +01:00
|
|
|
ctx.NotFound("user", fmt.Errorf(ctx.ContextUser.Name))
|
2021-10-16 16:21:16 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-03-26 10:04:22 +01:00
|
|
|
ctx.Data["Title"] = ctx.ContextUser.DisplayName()
|
2015-12-21 13:24:11 +01:00
|
|
|
ctx.Data["PageIsUserProfile"] = true
|
2020-11-18 23:00:16 +01:00
|
|
|
|
2023-07-06 20:59:24 +02:00
|
|
|
// prepare heatmap data
|
2021-03-04 23:59:13 +01:00
|
|
|
if setting.Service.EnableUserHeatmap {
|
2023-09-25 15:17:37 +02:00
|
|
|
data, err := activities_model.GetUserHeatmapDataByUser(ctx, ctx.ContextUser, ctx.Doer)
|
2020-11-18 23:00:16 +01:00
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("GetUserHeatmapDataByUser", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ctx.Data["HeatmapData"] = data
|
2023-04-17 20:26:01 +02:00
|
|
|
ctx.Data["HeatmapTotalContributions"] = activities_model.GetTotalContributionsInHeatmap(data)
|
2020-11-18 23:00:16 +01:00
|
|
|
}
|
|
|
|
|
2023-12-27 09:32:27 +01:00
|
|
|
profileDbRepo, profileGitRepo, profileReadmeBlob, profileClose := shared_user.FindUserProfileReadme(ctx, ctx.Doer)
|
2023-07-06 20:59:24 +02:00
|
|
|
defer profileClose()
|
2023-05-09 07:57:24 +02:00
|
|
|
|
2022-03-26 10:04:22 +01:00
|
|
|
showPrivate := ctx.IsSigned && (ctx.Doer.IsAdmin || ctx.Doer.ID == ctx.ContextUser.ID)
|
2023-12-27 09:32:27 +01:00
|
|
|
prepareUserProfileTabData(ctx, showPrivate, profileDbRepo, profileGitRepo, profileReadmeBlob)
|
2023-07-06 20:59:24 +02:00
|
|
|
// call PrepareContextForProfileBigAvatar later to avoid re-querying the NumFollowers & NumFollowing
|
|
|
|
shared_user.PrepareContextForProfileBigAvatar(ctx)
|
|
|
|
ctx.HTML(http.StatusOK, tplProfile)
|
|
|
|
}
|
2016-01-30 22:51:11 +01:00
|
|
|
|
2023-12-27 09:32:27 +01:00
|
|
|
func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDbRepo *repo_model.Repository, profileGitRepo *git.Repository, profileReadme *git.Blob) {
|
2023-07-06 20:59:24 +02:00
|
|
|
// if there is a profile readme, default to "overview" page, otherwise, default to "repositories" page
|
2023-09-20 03:48:44 +02:00
|
|
|
// if there is not a profile readme, the overview tab should be treated as the repositories tab
|
2021-08-11 02:31:13 +02:00
|
|
|
tab := ctx.FormString("tab")
|
2023-09-20 03:48:44 +02:00
|
|
|
if tab == "" || tab == "overview" {
|
2023-07-06 20:59:24 +02:00
|
|
|
if profileReadme != nil {
|
|
|
|
tab = "overview"
|
|
|
|
} else {
|
|
|
|
tab = "repositories"
|
|
|
|
}
|
|
|
|
}
|
2015-12-21 13:24:11 +01:00
|
|
|
ctx.Data["TabName"] = tab
|
2023-07-06 20:59:24 +02:00
|
|
|
ctx.Data["HasProfileReadme"] = profileReadme != nil
|
2017-02-14 08:28:22 +01:00
|
|
|
|
2021-07-29 03:42:15 +02:00
|
|
|
page := ctx.FormInt("page")
|
2017-02-14 08:28:22 +01:00
|
|
|
if page <= 0 {
|
|
|
|
page = 1
|
|
|
|
}
|
|
|
|
|
2023-02-24 22:15:10 +01:00
|
|
|
pagingNum := setting.UI.User.RepoPagingNum
|
2021-07-29 03:42:15 +02:00
|
|
|
topicOnly := ctx.FormBool("topic")
|
2017-02-14 08:28:22 +01:00
|
|
|
var (
|
2021-12-10 02:27:50 +01:00
|
|
|
repos []*repo_model.Repository
|
2017-02-14 08:28:22 +01:00
|
|
|
count int64
|
2019-04-20 06:15:19 +02:00
|
|
|
total int
|
2021-11-24 10:49:20 +01:00
|
|
|
orderBy db.SearchOrderBy
|
2017-02-14 08:28:22 +01:00
|
|
|
)
|
|
|
|
|
2021-08-11 02:31:13 +02:00
|
|
|
ctx.Data["SortType"] = ctx.FormString("sort")
|
|
|
|
switch ctx.FormString("sort") {
|
2017-02-14 08:28:22 +01:00
|
|
|
case "newest":
|
2021-11-24 10:49:20 +01:00
|
|
|
orderBy = db.SearchOrderByNewest
|
2017-02-14 08:28:22 +01:00
|
|
|
case "oldest":
|
2021-11-24 10:49:20 +01:00
|
|
|
orderBy = db.SearchOrderByOldest
|
2017-02-14 08:28:22 +01:00
|
|
|
case "recentupdate":
|
2021-11-24 10:49:20 +01:00
|
|
|
orderBy = db.SearchOrderByRecentUpdated
|
2017-02-14 08:28:22 +01:00
|
|
|
case "leastupdate":
|
2021-11-24 10:49:20 +01:00
|
|
|
orderBy = db.SearchOrderByLeastUpdated
|
2017-02-14 08:28:22 +01:00
|
|
|
case "reversealphabetically":
|
2021-11-24 10:49:20 +01:00
|
|
|
orderBy = db.SearchOrderByAlphabeticallyReverse
|
2017-02-14 08:28:22 +01:00
|
|
|
case "alphabetically":
|
2021-11-24 10:49:20 +01:00
|
|
|
orderBy = db.SearchOrderByAlphabetically
|
2018-05-24 03:03:42 +02:00
|
|
|
case "moststars":
|
2021-11-24 10:49:20 +01:00
|
|
|
orderBy = db.SearchOrderByStarsReverse
|
2018-05-24 03:03:42 +02:00
|
|
|
case "feweststars":
|
2021-11-24 10:49:20 +01:00
|
|
|
orderBy = db.SearchOrderByStars
|
2018-05-24 03:03:42 +02:00
|
|
|
case "mostforks":
|
2021-11-24 10:49:20 +01:00
|
|
|
orderBy = db.SearchOrderByForksReverse
|
2018-05-24 03:03:42 +02:00
|
|
|
case "fewestforks":
|
2021-11-24 10:49:20 +01:00
|
|
|
orderBy = db.SearchOrderByForks
|
2017-02-14 08:28:22 +01:00
|
|
|
default:
|
|
|
|
ctx.Data["SortType"] = "recentupdate"
|
2021-11-24 10:49:20 +01:00
|
|
|
orderBy = db.SearchOrderByRecentUpdated
|
2017-02-14 08:28:22 +01:00
|
|
|
}
|
|
|
|
|
2021-08-11 17:08:52 +02:00
|
|
|
keyword := ctx.FormTrim("q")
|
2017-02-14 08:28:22 +01:00
|
|
|
ctx.Data["Keyword"] = keyword
|
2022-01-28 12:29:04 +01:00
|
|
|
|
|
|
|
language := ctx.FormTrim("language")
|
|
|
|
ctx.Data["Language"] = language
|
|
|
|
|
2023-04-29 21:13:58 +02:00
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
2015-12-21 13:24:11 +01:00
|
|
|
switch tab {
|
2020-02-09 21:18:01 +01:00
|
|
|
case "followers":
|
2023-04-29 21:13:58 +02:00
|
|
|
ctx.Data["Cards"] = followers
|
2023-09-19 17:24:54 +02:00
|
|
|
total = int(numFollowers)
|
2020-02-09 21:18:01 +01:00
|
|
|
case "following":
|
2023-04-29 21:13:58 +02:00
|
|
|
ctx.Data["Cards"] = following
|
2023-09-19 17:24:54 +02:00
|
|
|
total = int(numFollowing)
|
2015-12-21 13:24:11 +01:00
|
|
|
case "activity":
|
2023-02-24 22:15:10 +01:00
|
|
|
date := ctx.FormString("date")
|
2023-07-06 20:59:24 +02:00
|
|
|
pagingNum = setting.UI.FeedPagingNum
|
2023-02-24 22:15:10 +01:00
|
|
|
items, count, err := activities_model.GetFeeds(ctx, activities_model.GetFeedsOptions{
|
2022-03-26 10:04:22 +01:00
|
|
|
RequestedUser: ctx.ContextUser,
|
2022-03-22 08:03:22 +01:00
|
|
|
Actor: ctx.Doer,
|
2017-08-23 03:30:54 +02:00
|
|
|
IncludePrivate: showPrivate,
|
|
|
|
OnlyPerformedBy: true,
|
|
|
|
IncludeDeleted: false,
|
2023-02-24 22:15:10 +01:00
|
|
|
Date: date,
|
|
|
|
ListOptions: db.ListOptions{
|
|
|
|
PageSize: pagingNum,
|
|
|
|
Page: page,
|
|
|
|
},
|
2017-08-23 03:30:54 +02:00
|
|
|
})
|
2022-03-13 17:40:47 +01:00
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("GetFeeds", err)
|
2015-12-21 13:24:11 +01:00
|
|
|
return
|
|
|
|
}
|
2023-02-24 22:15:10 +01:00
|
|
|
ctx.Data["Feeds"] = items
|
|
|
|
ctx.Data["Date"] = date
|
|
|
|
|
|
|
|
total = int(count)
|
2016-12-29 15:58:24 +01:00
|
|
|
case "stars":
|
2017-02-14 08:28:22 +01:00
|
|
|
ctx.Data["PageIsProfileStarList"] = true
|
2022-11-19 09:12:33 +01:00
|
|
|
repos, count, err = repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
|
2021-09-24 13:32:56 +02:00
|
|
|
ListOptions: db.ListOptions{
|
2023-02-24 22:15:10 +01:00
|
|
|
PageSize: pagingNum,
|
2020-01-24 20:00:29 +01:00
|
|
|
Page: page,
|
|
|
|
},
|
2022-03-22 08:03:22 +01:00
|
|
|
Actor: ctx.Doer,
|
2019-08-25 19:06:36 +02:00
|
|
|
Keyword: keyword,
|
|
|
|
OrderBy: orderBy,
|
|
|
|
Private: ctx.IsSigned,
|
2022-03-26 10:04:22 +01:00
|
|
|
StarredByID: ctx.ContextUser.ID,
|
2024-02-29 19:52:49 +01:00
|
|
|
Collaborate: optional.Some(false),
|
2019-08-25 19:06:36 +02:00
|
|
|
TopicOnly: topicOnly,
|
2022-01-28 12:29:04 +01:00
|
|
|
Language: language,
|
2019-08-25 19:06:36 +02:00
|
|
|
IncludeDescription: setting.UI.SearchRepoDescription,
|
2024-03-03 11:18:34 +01:00
|
|
|
Archived: archived,
|
|
|
|
Fork: fork,
|
|
|
|
Mirror: mirror,
|
|
|
|
Template: template,
|
|
|
|
IsPrivate: private,
|
2019-05-15 17:24:39 +02:00
|
|
|
})
|
|
|
|
if err != nil {
|
2019-08-25 19:06:36 +02:00
|
|
|
ctx.ServerError("SearchRepository", err)
|
2019-05-15 17:24:39 +02:00
|
|
|
return
|
2017-02-07 12:54:16 +01:00
|
|
|
}
|
|
|
|
|
2019-04-20 06:15:19 +02:00
|
|
|
total = int(count)
|
2021-04-15 18:53:57 +02:00
|
|
|
case "watching":
|
2022-11-19 09:12:33 +01:00
|
|
|
repos, count, err = repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
|
2021-09-24 13:32:56 +02:00
|
|
|
ListOptions: db.ListOptions{
|
2023-02-24 22:15:10 +01:00
|
|
|
PageSize: pagingNum,
|
2021-04-15 18:53:57 +02:00
|
|
|
Page: page,
|
|
|
|
},
|
2022-03-22 08:03:22 +01:00
|
|
|
Actor: ctx.Doer,
|
2021-04-15 18:53:57 +02:00
|
|
|
Keyword: keyword,
|
|
|
|
OrderBy: orderBy,
|
|
|
|
Private: ctx.IsSigned,
|
2022-03-26 10:04:22 +01:00
|
|
|
WatchedByID: ctx.ContextUser.ID,
|
2024-02-29 19:52:49 +01:00
|
|
|
Collaborate: optional.Some(false),
|
2021-04-15 18:53:57 +02:00
|
|
|
TopicOnly: topicOnly,
|
2022-01-28 12:29:04 +01:00
|
|
|
Language: language,
|
2021-04-15 18:53:57 +02:00
|
|
|
IncludeDescription: setting.UI.SearchRepoDescription,
|
2024-03-03 11:18:34 +01:00
|
|
|
Archived: archived,
|
|
|
|
Fork: fork,
|
|
|
|
Mirror: mirror,
|
|
|
|
Template: template,
|
|
|
|
IsPrivate: private,
|
2021-04-15 18:53:57 +02:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("SearchRepository", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
total = int(count)
|
2023-07-06 20:59:24 +02:00
|
|
|
case "overview":
|
|
|
|
if bytes, err := profileReadme.GetBlobContent(setting.UI.MaxDisplayFileSize); err != nil {
|
|
|
|
log.Error("failed to GetBlobContent: %v", err)
|
|
|
|
} else {
|
2023-07-20 00:22:32 +02:00
|
|
|
if profileContent, err := markdown.RenderString(&markup.RenderContext{
|
2024-01-15 09:49:24 +01:00
|
|
|
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"},
|
2023-07-20 00:22:32 +02:00
|
|
|
}, bytes); err != nil {
|
2023-07-06 20:59:24 +02:00
|
|
|
log.Error("failed to RenderString: %v", err)
|
|
|
|
} else {
|
|
|
|
ctx.Data["ProfileReadme"] = profileContent
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default: // default to "repositories"
|
2022-11-19 09:12:33 +01:00
|
|
|
repos, count, err = repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
|
2021-09-24 13:32:56 +02:00
|
|
|
ListOptions: db.ListOptions{
|
2023-02-24 22:15:10 +01:00
|
|
|
PageSize: pagingNum,
|
2020-01-24 20:00:29 +01:00
|
|
|
Page: page,
|
|
|
|
},
|
2022-03-22 08:03:22 +01:00
|
|
|
Actor: ctx.Doer,
|
2019-08-25 19:06:36 +02:00
|
|
|
Keyword: keyword,
|
2022-03-26 10:04:22 +01:00
|
|
|
OwnerID: ctx.ContextUser.ID,
|
2019-08-25 19:06:36 +02:00
|
|
|
OrderBy: orderBy,
|
|
|
|
Private: ctx.IsSigned,
|
2024-02-29 19:52:49 +01:00
|
|
|
Collaborate: optional.Some(false),
|
2019-08-25 19:06:36 +02:00
|
|
|
TopicOnly: topicOnly,
|
2022-01-28 12:29:04 +01:00
|
|
|
Language: language,
|
2019-08-25 19:06:36 +02:00
|
|
|
IncludeDescription: setting.UI.SearchRepoDescription,
|
2024-03-03 11:18:34 +01:00
|
|
|
Archived: archived,
|
|
|
|
Fork: fork,
|
|
|
|
Mirror: mirror,
|
|
|
|
Template: template,
|
|
|
|
IsPrivate: private,
|
2019-05-15 17:24:39 +02:00
|
|
|
})
|
|
|
|
if err != nil {
|
2019-08-25 19:06:36 +02:00
|
|
|
ctx.ServerError("SearchRepository", err)
|
2019-05-15 17:24:39 +02:00
|
|
|
return
|
2015-12-21 13:24:11 +01:00
|
|
|
}
|
2019-05-15 17:24:39 +02:00
|
|
|
|
|
|
|
total = int(count)
|
2015-12-21 13:24:11 +01:00
|
|
|
}
|
2019-04-20 06:15:19 +02:00
|
|
|
ctx.Data["Repos"] = repos
|
|
|
|
ctx.Data["Total"] = total
|
|
|
|
|
2023-08-11 19:08:05 +02:00
|
|
|
err = shared_user.LoadHeaderCount(ctx)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("LoadHeaderCount", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-02-24 22:15:10 +01:00
|
|
|
pager := context.NewPagination(total, pagingNum, page, 5)
|
2019-04-20 06:15:19 +02:00
|
|
|
pager.SetDefaultParams(ctx)
|
2022-06-15 17:05:32 +02:00
|
|
|
pager.AddParam(ctx, "tab", "TabName")
|
2022-01-28 12:29:04 +01:00
|
|
|
if tab != "followers" && tab != "following" && tab != "activity" && tab != "projects" {
|
|
|
|
pager.AddParam(ctx, "language", "Language")
|
|
|
|
}
|
2023-02-24 22:15:10 +01:00
|
|
|
if tab == "activity" {
|
|
|
|
pager.AddParam(ctx, "date", "Date")
|
|
|
|
}
|
2019-04-20 06:15:19 +02:00
|
|
|
ctx.Data["Page"] = pager
|
2015-12-21 13:24:11 +01:00
|
|
|
}
|
|
|
|
|
2016-11-18 04:03:03 +01:00
|
|
|
// Action response for follow/unfollow user request
|
2016-03-11 17:56:52 +01:00
|
|
|
func Action(ctx *context.Context) {
|
2015-12-21 13:24:11 +01:00
|
|
|
var err error
|
2021-12-20 18:18:26 +01:00
|
|
|
switch ctx.FormString("action") {
|
2015-12-21 13:24:11 +01:00
|
|
|
case "follow":
|
2024-03-04 09:16:03 +01:00
|
|
|
err = user_model.FollowUser(ctx, ctx.Doer, ctx.ContextUser)
|
2015-12-21 13:24:11 +01:00
|
|
|
case "unfollow":
|
2023-09-16 16:39:12 +02:00
|
|
|
err = user_model.UnfollowUser(ctx, ctx.Doer.ID, ctx.ContextUser.ID)
|
2015-12-21 13:24:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
2023-07-07 17:27:12 +02:00
|
|
|
log.Error("Failed to apply action %q: %v", ctx.FormString("action"), err)
|
2024-01-30 15:45:54 +01:00
|
|
|
ctx.Error(http.StatusBadRequest, fmt.Sprintf("Action %q failed", ctx.FormString("action")))
|
2015-12-21 13:24:11 +01:00
|
|
|
return
|
|
|
|
}
|
2024-01-30 15:45:54 +01:00
|
|
|
|
2024-02-17 06:13:37 +01:00
|
|
|
if ctx.ContextUser.IsIndividual() {
|
|
|
|
shared_user.PrepareContextForProfileBigAvatar(ctx)
|
|
|
|
ctx.HTML(http.StatusOK, tplProfileBigAvatar)
|
|
|
|
return
|
|
|
|
} else if ctx.ContextUser.IsOrganization() {
|
2024-02-23 01:24:57 +01:00
|
|
|
ctx.Data["Org"] = ctx.ContextUser
|
2024-02-17 06:13:37 +01:00
|
|
|
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: unsupport context user type: %s", ctx.FormString("action"), ctx.ContextUser.Type)
|
|
|
|
ctx.Error(http.StatusBadRequest, fmt.Sprintf("Action %q failed", ctx.FormString("action")))
|
2015-12-21 13:24:11 +01:00
|
|
|
}
|