From 8c8471e75464fa6253a44cdbb8f6ad233aae9067 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Sun, 2 May 2021 21:03:15 +0200 Subject: [PATCH] Addition to (Add Location, Website and Description to API #15675) (#15690) * Use same name as other structs. * Sync with normal forms. * Edit description with API. * Workaround for nil value. --- modules/structs/admin_user.go | 3 ++- modules/structs/org.go | 12 ++++++------ modules/structs/user.go | 4 ++-- routers/api/v1/admin/user.go | 3 +++ templates/swagger/v1_json.tmpl | 14 +++++++++----- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/modules/structs/admin_user.go b/modules/structs/admin_user.go index ee1738579..5da4e9608 100644 --- a/modules/structs/admin_user.go +++ b/modules/structs/admin_user.go @@ -32,8 +32,9 @@ type EditUserOption struct { FullName *string `json:"full_name" binding:"MaxSize(100)"` Password string `json:"password" binding:"MaxSize(255)"` MustChangePassword *bool `json:"must_change_password"` - Website *string `json:"website" binding:"MaxSize(50)"` + Website *string `json:"website" binding:"OmitEmpty;ValidUrl;MaxSize(255)"` Location *string `json:"location" binding:"MaxSize(50)"` + Description *string `json:"description" binding:"MaxSize(255)"` Active *bool `json:"active"` Admin *bool `json:"admin"` AllowGitHook *bool `json:"allow_git_hook"` diff --git a/modules/structs/org.go b/modules/structs/org.go index 4b79a4e70..483f5044a 100644 --- a/modules/structs/org.go +++ b/modules/structs/org.go @@ -22,9 +22,9 @@ type CreateOrgOption struct { // required: true UserName string `json:"username" binding:"Required"` FullName string `json:"full_name"` - Description string `json:"description"` - Website string `json:"website"` - Location string `json:"location"` + Description string `json:"description" binding:"MaxSize(255)"` + Website string `json:"website" binding:"ValidUrl;MaxSize(255)"` + Location string `json:"location" binding:"MaxSize(50)"` // possible values are `public` (default), `limited` or `private` // enum: public,limited,private Visibility string `json:"visibility" binding:"In(,public,limited,private)"` @@ -34,9 +34,9 @@ type CreateOrgOption struct { // EditOrgOption options for editing an organization type EditOrgOption struct { FullName string `json:"full_name"` - Description string `json:"description"` - Website string `json:"website"` - Location string `json:"location"` + Description string `json:"description" binding:"MaxSize(255)"` + Website string `json:"website" binding:"ValidUrl;MaxSize(255)"` + Location string `json:"location" binding:"MaxSize(50)"` // possible values are `public`, `limited` or `private` // enum: public,limited,private Visibility string `json:"visibility" binding:"In(,public,limited,private)"` diff --git a/modules/structs/user.go b/modules/structs/user.go index efd246e56..b5d5b9298 100644 --- a/modules/structs/user.go +++ b/modules/structs/user.go @@ -37,8 +37,8 @@ type User struct { Location string `json:"location"` // the user's website Website string `json:"website"` - // the user's biography - Description string `json:"bio"` + // the user's description + Description string `json:"description"` } // MarshalJSON implements the json.Marshaler interface for User, adding field(s) for backward compatibility diff --git a/routers/api/v1/admin/user.go b/routers/api/v1/admin/user.go index 5a74c6ccd..2d4a3815f 100644 --- a/routers/api/v1/admin/user.go +++ b/routers/api/v1/admin/user.go @@ -203,6 +203,9 @@ func EditUser(ctx *context.APIContext) { if form.Location != nil { u.Location = *form.Location } + if form.Description != nil { + u.Description = *form.Description + } if form.Active != nil { u.IsActive = *form.Active } diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 6d690ba27..8255ed6e6 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -13800,6 +13800,10 @@ "type": "boolean", "x-go-name": "AllowImportLocal" }, + "description": { + "type": "string", + "x-go-name": "Description" + }, "email": { "type": "string", "format": "email", @@ -16251,16 +16255,16 @@ "type": "string", "x-go-name": "AvatarURL" }, - "bio": { - "description": "the user's biography", - "type": "string", - "x-go-name": "Description" - }, "created": { "type": "string", "format": "date-time", "x-go-name": "Created" }, + "description": { + "description": "the user's description", + "type": "string", + "x-go-name": "Description" + }, "email": { "type": "string", "format": "email",