mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-23 09:30:50 +00:00
[refactor] Unify the export of user data via API (#15144)
* [refactor] unify how user data is exported via API * test time via unix timestamp
This commit is contained in:
parent
f4d27498bd
commit
290cf75f93
26 changed files with 117 additions and 97 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue