Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Location, Website and Description to API #15675

Merged
merged 3 commits into from
May 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions modules/convert/user.go
Original file line number Diff line number Diff line change
@@ -38,13 +38,16 @@ func ToUserWithAccessMode(user *models.User, accessMode models.AccessMode) *api.
// 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,
FullName: markup.Sanitize(user.FullName),
Email: user.GetEmail(),
AvatarURL: user.AvatarLink(),
Created: user.CreatedUnix.AsTime(),
Restricted: user.IsRestricted,
ID: user.ID,
UserName: user.Name,
FullName: markup.Sanitize(user.FullName),
Email: user.GetEmail(),
AvatarURL: user.AvatarLink(),
Created: user.CreatedUnix.AsTime(),
Restricted: user.IsRestricted,
Location: user.Location,
Website: user.Website,
Description: user.Description,
}
// hide primary email if API caller is anonymous or user keep email private
if signed && (!user.KeepEmailPrivate || authed) {
6 changes: 6 additions & 0 deletions modules/structs/user.go
Original file line number Diff line number Diff line change
@@ -33,6 +33,12 @@ type User struct {
Created time.Time `json:"created,omitempty"`
// Is user restricted
Restricted bool `json:"restricted"`
// the user's location
Location string `json:"location"`
// the user's website
Website string `json:"website"`
// the user's biography
Description string `json:"bio"`
}

// MarshalJSON implements the json.Marshaler interface for User, adding field(s) for backward compatibility
15 changes: 15 additions & 0 deletions templates/swagger/v1_json.tmpl
Original file line number Diff line number Diff line change
@@ -16251,6 +16251,11 @@
"type": "string",
"x-go-name": "AvatarURL"
},
"bio": {
"description": "the user's biography",
"type": "string",
"x-go-name": "Description"
},
"created": {
"type": "string",
"format": "date-time",
@@ -16287,6 +16292,11 @@
"format": "date-time",
"x-go-name": "LastLogin"
},
"location": {
"description": "the user's location",
"type": "string",
"x-go-name": "Location"
},
"login": {
"description": "the user's username",
"type": "string",
@@ -16296,6 +16306,11 @@
"description": "Is user restricted",
"type": "boolean",
"x-go-name": "Restricted"
},
"website": {
"description": "the user's website",
"type": "string",
"x-go-name": "Website"
}
},
"x-go-package": "code.gitea.io/gitea/modules/structs"