From 044ce3778ece04ede8eb85056bf9c2f563e5f61c Mon Sep 17 00:00:00 2001 From: Baekjun Kim Date: Thu, 7 Jul 2022 12:24:23 -0700 Subject: [PATCH 1/7] Include login_name in adminCreateUser response --- modules/convert/user.go | 1 + modules/structs/user.go | 2 ++ 2 files changed, 3 insertions(+) diff --git a/modules/convert/user.go b/modules/convert/user.go index 2b07d21838d71..e4c80c023d415 100644 --- a/modules/convert/user.go +++ b/modules/convert/user.go @@ -50,6 +50,7 @@ func toUser(user *user_model.User, signed, authed bool) *api.User { ID: user.ID, UserName: user.Name, FullName: user.FullName, + LoginName: user.LoginName, Email: user.GetEmail(), AvatarURL: user.AvatarLink(), Created: user.CreatedUnix.AsTime(), diff --git a/modules/structs/user.go b/modules/structs/user.go index 431e230fac038..b91bb877bfdcb 100644 --- a/modules/structs/user.go +++ b/modules/structs/user.go @@ -17,6 +17,8 @@ type User struct { ID int64 `json:"id"` // the user's username UserName string `json:"login"` + // the user's login name + LoginName string `json:"login_name"` // the user's full name FullName string `json:"full_name"` // swagger:strfmt email From 2820ac3b75373da8c85425546fa4da95dbdc2e8f Mon Sep 17 00:00:00 2001 From: Baekjun Kim Date: Thu, 7 Jul 2022 13:28:57 -0700 Subject: [PATCH 2/7] generate swagger --- templates/swagger/v1_json.tmpl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index f3f9a33672253..aa4b3cae53ead 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -18575,6 +18575,11 @@ "type": "string", "x-go-name": "UserName" }, + "login_name": { + "description": "the user's login name", + "type": "string", + "x-go-name": "LoginName" + }, "prohibit_login": { "description": "Is user login prohibited", "type": "boolean", @@ -19732,4 +19737,4 @@ "TOTPHeader": [] } ] -} +} \ No newline at end of file From 9347835749b4ad52c56d353154cbc8db0d9b753d Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Fri, 8 Jul 2022 18:03:20 +0800 Subject: [PATCH 3/7] Update v1_json.tmpl --- templates/swagger/v1_json.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index aa4b3cae53ead..ed8398718ea04 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -19737,4 +19737,4 @@ "TOTPHeader": [] } ] -} \ No newline at end of file +} From 23cdfc94c9f1da2f2d9039f70f0c813e8b01d305 Mon Sep 17 00:00:00 2001 From: Baekjun Kim Date: Tue, 12 Jul 2022 19:54:02 -0700 Subject: [PATCH 4/7] expose login_name to admin and user itself only --- modules/convert/user.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/convert/user.go b/modules/convert/user.go index e4c80c023d415..6d1148916c0e0 100644 --- a/modules/convert/user.go +++ b/modules/convert/user.go @@ -50,7 +50,6 @@ func toUser(user *user_model.User, signed, authed bool) *api.User { ID: user.ID, UserName: user.Name, FullName: user.FullName, - LoginName: user.LoginName, Email: user.GetEmail(), AvatarURL: user.AvatarLink(), Created: user.CreatedUnix.AsTime(), @@ -64,6 +63,10 @@ func toUser(user *user_model.User, signed, authed bool) *api.User { StarredRepos: user.NumStars, } + if authed { + result.LoginName = user.LoginName + } + result.Visibility = user.Visibility.String() // hide primary email if API caller is anonymous or user keep email private From f4efad8297d4b4e2be545ddd92775805106c16aa Mon Sep 17 00:00:00 2001 From: Baekjun Kim Date: Tue, 12 Jul 2022 19:57:28 -0700 Subject: [PATCH 5/7] add missing case --- modules/convert/user.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/convert/user.go b/modules/convert/user.go index 6d1148916c0e0..61e006730c336 100644 --- a/modules/convert/user.go +++ b/modules/convert/user.go @@ -65,6 +65,8 @@ func toUser(user *user_model.User, signed, authed bool) *api.User { if authed { result.LoginName = user.LoginName + } else { + result.LoginName = "" } result.Visibility = user.Visibility.String() From ecdf8eab068a25f54cfc731d1c9d7285013a5140 Mon Sep 17 00:00:00 2001 From: Baekjun Kim Date: Thu, 14 Jul 2022 09:40:46 -0700 Subject: [PATCH 6/7] Fix structure and comment --- modules/convert/user.go | 7 +------ modules/structs/user.go | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/modules/convert/user.go b/modules/convert/user.go index 61e006730c336..093994856cae7 100644 --- a/modules/convert/user.go +++ b/modules/convert/user.go @@ -63,12 +63,6 @@ func toUser(user *user_model.User, signed, authed bool) *api.User { StarredRepos: user.NumStars, } - if authed { - result.LoginName = user.LoginName - } else { - result.LoginName = "" - } - result.Visibility = user.Visibility.String() // hide primary email if API caller is anonymous or user keep email private @@ -79,6 +73,7 @@ func toUser(user *user_model.User, signed, authed bool) *api.User { // only site admin will get these information and possibly user himself if authed { result.IsAdmin = user.IsAdmin + result.LoginName = user.LoginName result.LastLogin = user.LastLoginUnix.AsTime() result.Language = user.Language result.IsActive = user.IsActive diff --git a/modules/structs/user.go b/modules/structs/user.go index b91bb877bfdcb..75341c28daebc 100644 --- a/modules/structs/user.go +++ b/modules/structs/user.go @@ -17,7 +17,7 @@ type User struct { ID int64 `json:"id"` // the user's username UserName string `json:"login"` - // the user's login name + // the user's authentication sign-in name. default: empty LoginName string `json:"login_name"` // the user's full name FullName string `json:"full_name"` From 96c4c9c6993826f37db1fc2aa0364f36cbd9073b Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 14 Jul 2022 18:46:29 +0200 Subject: [PATCH 7/7] modules/structs/user.go --- modules/structs/user.go | 3 ++- templates/swagger/v1_json.tmpl | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/structs/user.go b/modules/structs/user.go index 75341c28daebc..81516894a58f9 100644 --- a/modules/structs/user.go +++ b/modules/structs/user.go @@ -17,7 +17,8 @@ type User struct { ID int64 `json:"id"` // the user's username UserName string `json:"login"` - // the user's authentication sign-in name. default: empty + // the user's authentication sign-in name. + // default: empty LoginName string `json:"login_name"` // the user's full name FullName string `json:"full_name"` diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 3623b058d663a..7ef547b676c82 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -18480,8 +18480,9 @@ "x-go-name": "UserName" }, "login_name": { - "description": "the user's login name", + "description": "the user's authentication sign-in name.", "type": "string", + "default": "empty", "x-go-name": "LoginName" }, "prohibit_login": {