Remove unnecessary attributes of User struct (#17745)

* Remove unnecessary functions of User struct

* Move more database methods out of user struct

* Move more database methods out of user struct

* Fix template failure

* Fix bug

* Remove finished FIXME

* remove unnecessary code
This commit is contained in:
Lunny Xiao 2021-11-22 23:21:55 +08:00 committed by GitHub
parent c2ab19888f
commit baed01f247
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 279 additions and 451 deletions

View file

@ -107,7 +107,7 @@ func Profile(ctx *context.Context) {
}
// check view permissions
if !ctxUser.IsVisibleToUser(ctx.User) {
if !models.IsUserVisibleToViewer(ctxUser, ctx.User) {
ctx.NotFound("user", fmt.Errorf(uname))
return
}
@ -137,10 +137,16 @@ func Profile(ctx *context.Context) {
return
}
var isFollowing bool
if ctx.User != nil && ctxUser != nil {
isFollowing = user_model.IsFollowing(ctx.User.ID, ctxUser.ID)
}
ctx.Data["Title"] = ctxUser.DisplayName()
ctx.Data["PageIsUserProfile"] = true
ctx.Data["Owner"] = ctxUser
ctx.Data["OpenIDs"] = openIDs
ctx.Data["IsFollowing"] = isFollowing
if setting.Service.EnableUserHeatmap {
data, err := models.GetUserHeatmapDataByUser(ctxUser, ctx.User)
@ -227,24 +233,24 @@ func Profile(ctx *context.Context) {
ctx.Data["Keyword"] = keyword
switch tab {
case "followers":
items, err := ctxUser.GetFollowers(db.ListOptions{
items, err := models.GetUserFollowers(ctxUser, db.ListOptions{
PageSize: setting.UI.User.RepoPagingNum,
Page: page,
})
if err != nil {
ctx.ServerError("GetFollowers", err)
ctx.ServerError("GetUserFollowers", err)
return
}
ctx.Data["Cards"] = items
total = ctxUser.NumFollowers
case "following":
items, err := ctxUser.GetFollowing(db.ListOptions{
items, err := models.GetUserFollowing(ctxUser, db.ListOptions{
PageSize: setting.UI.User.RepoPagingNum,
Page: page,
})
if err != nil {
ctx.ServerError("GetFollowing", err)
ctx.ServerError("GetUserFollowing", err)
return
}
ctx.Data["Cards"] = items