From 67e10397af909a6f6b36000e2e4b5e3a95641832 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Sat, 1 May 2021 11:05:55 +0200 Subject: [PATCH] Add Location, Website and Biography to API (#15675) --- modules/convert/user.go | 17 ++++++++++------- modules/structs/user.go | 6 ++++++ templates/swagger/v1_json.tmpl | 15 +++++++++++++++ 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/modules/convert/user.go b/modules/convert/user.go index f3a33aee41..364914f2ad 100644 --- a/modules/convert/user.go +++ b/modules/convert/user.go @@ -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) { diff --git a/modules/structs/user.go b/modules/structs/user.go index 9e021e40fe..efd246e566 100644 --- a/modules/structs/user.go +++ b/modules/structs/user.go @@ -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 diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 5aeed4a30f..6d690ba275 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -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"