diff options
Diffstat (limited to 'modules/convert/user.go')
-rw-r--r-- | modules/convert/user.go | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/modules/convert/user.go b/modules/convert/user.go index f5d853fd4d..f3a33aee41 100644 --- a/modules/convert/user.go +++ b/modules/convert/user.go @@ -11,11 +11,32 @@ import ( ) // ToUser convert models.User to api.User -// signed shall only be set if requester is logged in. authed shall only be set if user is site admin or user himself -func ToUser(user *models.User, signed, authed bool) *api.User { +// if doer is set, private information is added if the doer has the permission to see it +func ToUser(user, doer *models.User) *api.User { + if user == nil { + return nil + } + authed := false + signed := false + if doer != nil { + signed = true + authed = doer.ID == user.ID || doer.IsAdmin + } + return toUser(user, signed, authed) +} + +// ToUserWithAccessMode convert models.User to api.User +// AccessMode is not none show add some more information +func ToUserWithAccessMode(user *models.User, accessMode models.AccessMode) *api.User { if user == nil { return nil } + return toUser(user, accessMode != models.AccessModeNone, false) +} + +// toUser convert models.User to api.User +// signed shall only be set if requester is logged in. authed shall only be set if user is site admin or user himself +func toUser(user *models.User, signed, authed bool) *api.User { result := &api.User{ ID: user.ID, UserName: user.Name, |