diff options
Diffstat (limited to 'routers/api/v1/convert/convert.go')
-rw-r--r-- | routers/api/v1/convert/convert.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/routers/api/v1/convert/convert.go b/routers/api/v1/convert/convert.go index 14344e581c..d9cc2da7a5 100644 --- a/routers/api/v1/convert/convert.go +++ b/routers/api/v1/convert/convert.go @@ -10,6 +10,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/util" api "code.gitea.io/sdk/gitea" @@ -216,3 +217,18 @@ func ToTeam(team *models.Team) *api.Team { Units: team.GetUnitNames(), } } + +// ToUser convert models.User to api.User +func ToUser(user *models.User, signed, admin bool) *api.User { + result := &api.User{ + ID: user.ID, + UserName: user.Name, + AvatarURL: user.AvatarLink(), + FullName: markup.Sanitize(user.FullName), + IsAdmin: user.IsAdmin, + } + if signed && (!user.KeepEmailPrivate || admin) { + result.Email = user.Email + } + return result +} |