From f8e48e066af107225c7bdcae6ed16b067e175e2b Mon Sep 17 00:00:00 2001 From: hazycora Date: Mon, 25 Sep 2023 21:39:12 -0500 Subject: [PATCH 01/24] add pronoun field to user profiles --- models/user/user.go | 1 + modules/structs/admin_user.go | 1 + modules/structs/user.go | 1 + options/locale/locale_en-US.ini | 1 + routers/api/v1/admin/user.go | 1 + routers/api/v1/user/settings.go | 1 + routers/web/user/setting/profile.go | 1 + services/forms/user_form.go | 1 + services/user/update.go | 6 ++++++ templates/shared/user/profile_big_avatar.tmpl | 2 +- templates/user/settings/profile.tmpl | 4 ++++ 11 files changed, 19 insertions(+), 1 deletion(-) diff --git a/models/user/user.go b/models/user/user.go index 4aef30ca56..ff85c2cfa0 100644 --- a/models/user/user.go +++ b/models/user/user.go @@ -95,6 +95,7 @@ type User struct { Type UserType Location string Website string + Pronouns string Rands string `xorm:"VARCHAR(32)"` Salt string `xorm:"VARCHAR(32)"` Language string `xorm:"VARCHAR(5)"` diff --git a/modules/structs/admin_user.go b/modules/structs/admin_user.go index f7c6d10ba0..ad86f4ca03 100644 --- a/modules/structs/admin_user.go +++ b/modules/structs/admin_user.go @@ -41,6 +41,7 @@ type EditUserOption struct { MustChangePassword *bool `json:"must_change_password"` Website *string `json:"website" binding:"OmitEmpty;ValidUrl;MaxSize(255)"` Location *string `json:"location" binding:"MaxSize(50)"` + Pronouns *string `json:"pronouns" binding:"MaxSize(50)"` Description *string `json:"description" binding:"MaxSize(255)"` Active *bool `json:"active"` Admin *bool `json:"admin"` diff --git a/modules/structs/user.go b/modules/structs/user.go index 4e13669ad2..9e4858115c 100644 --- a/modules/structs/user.go +++ b/modules/structs/user.go @@ -87,6 +87,7 @@ type UserSettingsOptions struct { Website *string `json:"website" binding:"OmitEmpty;ValidUrl;MaxSize(255)"` Description *string `json:"description" binding:"MaxSize(255)"` Location *string `json:"location" binding:"MaxSize(50)"` + Pronouns *string `json:"pronouns" binding:"MaxSize(50)"` Language *string `json:"language"` Theme *string `json:"theme"` DiffViewStyle *string `json:"diff_view_style"` diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 3a871b2eb8..d099e78207 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -701,6 +701,7 @@ password_username_disabled = Non-local users are not allowed to change their use full_name = Full name website = Website location = Location +pronouns = Pronouns update_theme = Change theme update_profile = Update profile update_language = Change language diff --git a/routers/api/v1/admin/user.go b/routers/api/v1/admin/user.go index 87a5b28fad..12da8a9597 100644 --- a/routers/api/v1/admin/user.go +++ b/routers/api/v1/admin/user.go @@ -236,6 +236,7 @@ func EditUser(ctx *context.APIContext) { Website: optional.FromPtr(form.Website), Location: optional.FromPtr(form.Location), Description: optional.FromPtr(form.Description), + Pronouns: optional.FromPtr(form.Pronouns), IsActive: optional.FromPtr(form.Active), IsAdmin: optional.FromPtr(form.Admin), Visibility: optional.FromNonDefault(api.VisibilityModes[form.Visibility]), diff --git a/routers/api/v1/user/settings.go b/routers/api/v1/user/settings.go index f594eb211c..bfd24013db 100644 --- a/routers/api/v1/user/settings.go +++ b/routers/api/v1/user/settings.go @@ -48,6 +48,7 @@ func UpdateUserSettings(ctx *context.APIContext) { opts := &user_service.UpdateOptions{ FullName: optional.FromPtr(form.FullName), Description: optional.FromPtr(form.Description), + Pronouns: optional.FromPtr(form.Pronouns), Website: optional.FromPtr(form.Website), Location: optional.FromPtr(form.Location), Language: optional.FromPtr(form.Language), diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go index 4e5c380ed9..b5d916b78f 100644 --- a/routers/web/user/setting/profile.go +++ b/routers/web/user/setting/profile.go @@ -90,6 +90,7 @@ func ProfilePost(ctx *context.Context) { FullName: optional.Some(form.FullName), KeepEmailPrivate: optional.Some(form.KeepEmailPrivate), Description: optional.Some(form.Description), + Pronouns: optional.Some(form.Pronouns), Website: optional.Some(form.Website), Location: optional.Some(form.Location), Visibility: optional.Some(form.Visibility), diff --git a/services/forms/user_form.go b/services/forms/user_form.go index 3290179092..196b092990 100644 --- a/services/forms/user_form.go +++ b/services/forms/user_form.go @@ -218,6 +218,7 @@ type UpdateProfileForm struct { KeepEmailPrivate bool Website string `binding:"ValidSiteUrl;MaxSize(255)"` Location string `binding:"MaxSize(50)"` + Pronouns string `binding:"MaxSize(50)"` Description string `binding:"MaxSize(255)"` Visibility structs.VisibleType KeepActivityPrivate bool diff --git a/services/user/update.go b/services/user/update.go index e96ab4274a..1bdbf13f0d 100644 --- a/services/user/update.go +++ b/services/user/update.go @@ -22,6 +22,7 @@ type UpdateOptions struct { Website optional.Option[string] Location optional.Option[string] Description optional.Option[string] + Pronouns optional.Option[string] AllowGitHook optional.Option[bool] AllowImportLocal optional.Option[bool] MaxRepoCreation optional.Option[int] @@ -54,6 +55,11 @@ func UpdateUser(ctx context.Context, u *user_model.User, opts *UpdateOptions) er cols = append(cols, "full_name") } + if opts.Pronouns.Has() { + u.Pronouns = opts.Pronouns.Value() + + cols = append(cols, "pronouns") + } if opts.Website.Has() { u.Website = opts.Website.Value() diff --git a/templates/shared/user/profile_big_avatar.tmpl b/templates/shared/user/profile_big_avatar.tmpl index bc7785629e..329a06d84d 100644 --- a/templates/shared/user/profile_big_avatar.tmpl +++ b/templates/shared/user/profile_big_avatar.tmpl @@ -13,7 +13,7 @@
{{if .ContextUser.FullName}}{{.ContextUser.FullName}}{{end}} - {{.ContextUser.Name}} {{if .IsAdmin}} + {{.ContextUser.Name}}{{if .ContextUser.Pronouns}} ยท {{.ContextUser.Pronouns}}{{end}} {{if .IsAdmin}} {{svg "octicon-gear" 18}} diff --git a/templates/user/settings/profile.tmpl b/templates/user/settings/profile.tmpl index aaaf8f30db..ac82606134 100644 --- a/templates/user/settings/profile.tmpl +++ b/templates/user/settings/profile.tmpl @@ -37,6 +37,10 @@
+
+ + +
From a6f068a93bda0ad501d793ad36448301941a1fa3 Mon Sep 17 00:00:00 2001 From: hazycora Date: Tue, 26 Sep 2023 00:34:09 -0500 Subject: [PATCH 02/24] use dropdown for pronoun input --- options/locale/locale_en-US.ini | 1 + routers/web/user/setting/profile.go | 2 ++ templates/user/settings/profile.tmpl | 52 ++++++++++++++++++++++++++-- 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index d099e78207..b7237711de 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -702,6 +702,7 @@ full_name = Full name website = Website location = Location pronouns = Pronouns +pronouns_custom = Custom update_theme = Change theme update_profile = Update profile update_language = Change language diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go index b5d916b78f..6843340fec 100644 --- a/routers/web/user/setting/profile.go +++ b/routers/web/user/setting/profile.go @@ -46,6 +46,7 @@ func Profile(ctx *context.Context) { ctx.Data["PageIsSettingsProfile"] = true ctx.Data["AllowedUserVisibilityModes"] = setting.Service.AllowedUserVisibilityModesSlice.ToVisibleTypeSlice() ctx.Data["DisableGravatar"] = setting.Config().Picture.DisableGravatar.Value(ctx) + ctx.Data["PronounsAreCustom"] = ctx.Doer.Pronouns != "he/him" && ctx.Doer.Pronouns != "she/her" && ctx.Doer.Pronouns != "they/them" && ctx.Doer.Pronouns != "it/its" ctx.HTML(http.StatusOK, tplSettingsProfile) } @@ -56,6 +57,7 @@ func ProfilePost(ctx *context.Context) { ctx.Data["PageIsSettingsProfile"] = true ctx.Data["AllowedUserVisibilityModes"] = setting.Service.AllowedUserVisibilityModesSlice.ToVisibleTypeSlice() ctx.Data["DisableGravatar"] = setting.Config().Picture.DisableGravatar.Value(ctx) + ctx.Data["PronounsAreCustom"] = ctx.Doer.Pronouns != "he/him" && ctx.Doer.Pronouns != "she/her" && ctx.Doer.Pronouns != "they/them" && ctx.Doer.Pronouns != "it/its" if ctx.HasError() { ctx.HTML(http.StatusOK, tplSettingsProfile) diff --git a/templates/user/settings/profile.tmpl b/templates/user/settings/profile.tmpl index ac82606134..7638727e8c 100644 --- a/templates/user/settings/profile.tmpl +++ b/templates/user/settings/profile.tmpl @@ -37,9 +37,55 @@ -
- - +
+ + + +
From 994c6d3cde77278badc6dd74d9c1e54129e8c7e5 Mon Sep 17 00:00:00 2001 From: hazycora Date: Tue, 26 Sep 2023 00:56:20 -0500 Subject: [PATCH 03/24] move pronouns JS --- templates/user/settings/profile.tmpl | 24 --------------------- web_src/js/features/user-settings.js | 31 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/templates/user/settings/profile.tmpl b/templates/user/settings/profile.tmpl index 7638727e8c..822651a9db 100644 --- a/templates/user/settings/profile.tmpl +++ b/templates/user/settings/profile.tmpl @@ -62,30 +62,6 @@
-
diff --git a/web_src/js/features/user-settings.js b/web_src/js/features/user-settings.js index 2d8c53e457..d2617dda6a 100644 --- a/web_src/js/features/user-settings.js +++ b/web_src/js/features/user-settings.js @@ -1,5 +1,27 @@ import {hideElem, showElem} from '../utils/dom.js'; +function onPronounsDropdownUpdate() { + const pronounsCustom = document.getElementById('pronouns-custom'); + const pronounsInput = document.querySelector('#pronouns-dropdown input'); + const isCustom = !( + pronounsInput.value === 'he/him' || + pronounsInput.value === 'she/her' || + pronounsInput.value === 'they/them' || + pronounsInput.value === 'it/its' + ); + if (isCustom) { + pronounsCustom.value = pronounsInput.value; + pronounsCustom.style.display = ''; + } else { + pronounsCustom.style.display = 'none'; + } +} +function onPronounsCustomUpdate() { + const pronounsCustom = document.getElementById('pronouns-custom'); + const pronounsInput = document.querySelector('#pronouns-dropdown input'); + pronounsInput.value = pronounsCustom.value; +} + export function initUserSettings() { if (!document.querySelectorAll('.user.settings.profile').length) return; @@ -16,4 +38,13 @@ export function initUserSettings() { hideElem(promptRedirect); } }); + + const pronounsDropdown = document.getElementById('pronouns-dropdown'); + const pronounsCustom = document.getElementById('pronouns-custom'); + const pronounsInput = pronounsDropdown.querySelector('input'); + pronounsCustom.removeAttribute('name'); + pronounsDropdown.style.display = ''; + onPronounsDropdownUpdate(); + pronounsInput.addEventListener('change', onPronounsDropdownUpdate); + pronounsCustom.addEventListener('input', onPronounsCustomUpdate); } From 563e8b49e86785112ec440f2e82a3ed387089433 Mon Sep 17 00:00:00 2001 From: hazycora Date: Tue, 26 Sep 2023 01:21:52 -0500 Subject: [PATCH 04/24] Add "Unspecified" option to pronouns dropdown --- options/locale/locale_en-US.ini | 1 + routers/web/user/setting/profile.go | 4 ++-- templates/user/settings/profile.tmpl | 5 ++++- web_src/js/features/user-settings.js | 10 ++++++++-- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index b7237711de..6fa4e6d78f 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -703,6 +703,7 @@ website = Website location = Location pronouns = Pronouns pronouns_custom = Custom +pronouns_unspecified = Unspecified update_theme = Change theme update_profile = Update profile update_language = Change language diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go index 6843340fec..1b1cdb54d4 100644 --- a/routers/web/user/setting/profile.go +++ b/routers/web/user/setting/profile.go @@ -46,7 +46,7 @@ func Profile(ctx *context.Context) { ctx.Data["PageIsSettingsProfile"] = true ctx.Data["AllowedUserVisibilityModes"] = setting.Service.AllowedUserVisibilityModesSlice.ToVisibleTypeSlice() ctx.Data["DisableGravatar"] = setting.Config().Picture.DisableGravatar.Value(ctx) - ctx.Data["PronounsAreCustom"] = ctx.Doer.Pronouns != "he/him" && ctx.Doer.Pronouns != "she/her" && ctx.Doer.Pronouns != "they/them" && ctx.Doer.Pronouns != "it/its" + ctx.Data["PronounsAreCustom"] = ctx.Doer.Pronouns != "" && ctx.Doer.Pronouns != "he/him" && ctx.Doer.Pronouns != "she/her" && ctx.Doer.Pronouns != "they/them" && ctx.Doer.Pronouns != "it/its" ctx.HTML(http.StatusOK, tplSettingsProfile) } @@ -57,7 +57,7 @@ func ProfilePost(ctx *context.Context) { ctx.Data["PageIsSettingsProfile"] = true ctx.Data["AllowedUserVisibilityModes"] = setting.Service.AllowedUserVisibilityModesSlice.ToVisibleTypeSlice() ctx.Data["DisableGravatar"] = setting.Config().Picture.DisableGravatar.Value(ctx) - ctx.Data["PronounsAreCustom"] = ctx.Doer.Pronouns != "he/him" && ctx.Doer.Pronouns != "she/her" && ctx.Doer.Pronouns != "they/them" && ctx.Doer.Pronouns != "it/its" + ctx.Data["PronounsAreCustom"] = ctx.Doer.Pronouns != "" && ctx.Doer.Pronouns != "he/him" && ctx.Doer.Pronouns != "she/her" && ctx.Doer.Pronouns != "they/them" && ctx.Doer.Pronouns != "it/its" if ctx.HasError() { ctx.HTML(http.StatusOK, tplSettingsProfile) diff --git a/templates/user/settings/profile.tmpl b/templates/user/settings/profile.tmpl index 822651a9db..9d279f23a2 100644 --- a/templates/user/settings/profile.tmpl +++ b/templates/user/settings/profile.tmpl @@ -44,12 +44,15 @@
{{if .PronounsAreCustom}} {{.locale.Tr "settings.pronouns_custom"}} + {{else if eq "" .SignedUser.Pronouns}} + {{.locale.Tr "settings.pronouns_unspecified"}} {{else}} {{.SignedUser.Pronouns}} {{end}}
{{svg "octicon-triangle-down" 14 "dropdown icon"}} diff --git a/web_src/js/features/user-settings.js b/web_src/js/features/user-settings.js index d2617dda6a..ec99f168fe 100644 --- a/web_src/js/features/user-settings.js +++ b/web_src/js/features/user-settings.js @@ -2,15 +2,21 @@ import {hideElem, showElem} from '../utils/dom.js'; function onPronounsDropdownUpdate() { const pronounsCustom = document.getElementById('pronouns-custom'); - const pronounsInput = document.querySelector('#pronouns-dropdown input'); + const pronounsDropdown = document.getElementById('pronouns-dropdown'); + const pronounsInput = pronounsDropdown.querySelector('input'); const isCustom = !( + pronounsInput.value === '' || pronounsInput.value === 'he/him' || pronounsInput.value === 'she/her' || pronounsInput.value === 'they/them' || pronounsInput.value === 'it/its' ); if (isCustom) { - pronounsCustom.value = pronounsInput.value; + if (pronounsInput.value === '!') { + pronounsCustom.value = ''; + } else { + pronounsCustom.value = pronounsInput.value; + } pronounsCustom.style.display = ''; } else { pronounsCustom.style.display = 'none'; From 864a4332df4dafd3b1acd1fad1b5d912b9f86d3a Mon Sep 17 00:00:00 2001 From: hazycora Date: Tue, 26 Sep 2023 01:22:05 -0500 Subject: [PATCH 05/24] Make "Custom" pronoun option italic --- templates/user/settings/profile.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/user/settings/profile.tmpl b/templates/user/settings/profile.tmpl index 9d279f23a2..0a576f9d3b 100644 --- a/templates/user/settings/profile.tmpl +++ b/templates/user/settings/profile.tmpl @@ -58,9 +58,9 @@
they/them
it/its
{{if .PronounsAreCustom}} -
{{.locale.Tr "settings.pronouns_custom"}}
+
{{.locale.Tr "settings.pronouns_custom"}}
{{else}} -
{{.locale.Tr "settings.pronouns_custom"}}
+
{{.locale.Tr "settings.pronouns_custom"}}
{{end}} From 708327a548bce16a122c5f39999d14ba562330ab Mon Sep 17 00:00:00 2001 From: hazycora Date: Tue, 26 Sep 2023 12:51:30 -0500 Subject: [PATCH 06/24] set width on pronoun dropdown and custom input --- web_src/css/user.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/web_src/css/user.css b/web_src/css/user.css index 33ffa1eabc..e96598768b 100644 --- a/web_src/css/user.css +++ b/web_src/css/user.css @@ -157,3 +157,7 @@ .notifications-item:hover .notifications-updated { display: none; } + +#pronouns-dropdown, #pronouns-custom { + width: 140px; +} \ No newline at end of file From 12e00abe29b7fbc091658897a711e659a67fbc7a Mon Sep 17 00:00:00 2001 From: hazycora Date: Tue, 26 Sep 2023 12:54:18 -0500 Subject: [PATCH 07/24] add any/all pronoun option to dropdown --- routers/web/user/setting/profile.go | 4 ++-- templates/user/settings/profile.tmpl | 1 + web_src/js/features/user-settings.js | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go index 1b1cdb54d4..7a2f6ba46d 100644 --- a/routers/web/user/setting/profile.go +++ b/routers/web/user/setting/profile.go @@ -46,7 +46,7 @@ func Profile(ctx *context.Context) { ctx.Data["PageIsSettingsProfile"] = true ctx.Data["AllowedUserVisibilityModes"] = setting.Service.AllowedUserVisibilityModesSlice.ToVisibleTypeSlice() ctx.Data["DisableGravatar"] = setting.Config().Picture.DisableGravatar.Value(ctx) - ctx.Data["PronounsAreCustom"] = ctx.Doer.Pronouns != "" && ctx.Doer.Pronouns != "he/him" && ctx.Doer.Pronouns != "she/her" && ctx.Doer.Pronouns != "they/them" && ctx.Doer.Pronouns != "it/its" + ctx.Data["PronounsAreCustom"] = ctx.Doer.Pronouns != "" && ctx.Doer.Pronouns != "he/him" && ctx.Doer.Pronouns != "she/her" && ctx.Doer.Pronouns != "they/them" && ctx.Doer.Pronouns != "it/its" && ctx.Doer.Pronouns != "any/all" ctx.HTML(http.StatusOK, tplSettingsProfile) } @@ -57,7 +57,7 @@ func ProfilePost(ctx *context.Context) { ctx.Data["PageIsSettingsProfile"] = true ctx.Data["AllowedUserVisibilityModes"] = setting.Service.AllowedUserVisibilityModesSlice.ToVisibleTypeSlice() ctx.Data["DisableGravatar"] = setting.Config().Picture.DisableGravatar.Value(ctx) - ctx.Data["PronounsAreCustom"] = ctx.Doer.Pronouns != "" && ctx.Doer.Pronouns != "he/him" && ctx.Doer.Pronouns != "she/her" && ctx.Doer.Pronouns != "they/them" && ctx.Doer.Pronouns != "it/its" + ctx.Data["PronounsAreCustom"] = ctx.Doer.Pronouns != "" && ctx.Doer.Pronouns != "he/him" && ctx.Doer.Pronouns != "she/her" && ctx.Doer.Pronouns != "they/them" && ctx.Doer.Pronouns != "it/its" && ctx.Doer.Pronouns != "any/all" if ctx.HasError() { ctx.HTML(http.StatusOK, tplSettingsProfile) diff --git a/templates/user/settings/profile.tmpl b/templates/user/settings/profile.tmpl index 0a576f9d3b..4a9074eb4d 100644 --- a/templates/user/settings/profile.tmpl +++ b/templates/user/settings/profile.tmpl @@ -57,6 +57,7 @@
she/her
they/them
it/its
+
any/all
{{if .PronounsAreCustom}}
{{.locale.Tr "settings.pronouns_custom"}}
{{else}} diff --git a/web_src/js/features/user-settings.js b/web_src/js/features/user-settings.js index ec99f168fe..5ad8bd94d4 100644 --- a/web_src/js/features/user-settings.js +++ b/web_src/js/features/user-settings.js @@ -9,7 +9,8 @@ function onPronounsDropdownUpdate() { pronounsInput.value === 'he/him' || pronounsInput.value === 'she/her' || pronounsInput.value === 'they/them' || - pronounsInput.value === 'it/its' + pronounsInput.value === 'it/its' || + pronounsInput.value === 'any/all' ); if (isCustom) { if (pronounsInput.value === '!') { From 74da95df67fc1579cb61fe1c2331a18f64903050 Mon Sep 17 00:00:00 2001 From: hazycora Date: Tue, 26 Sep 2023 12:57:01 -0500 Subject: [PATCH 08/24] move pronouns below full name in user profile settings --- templates/user/settings/profile.tmpl | 32 ++++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/templates/user/settings/profile.tmpl b/templates/user/settings/profile.tmpl index 4a9074eb4d..b8028a7007 100644 --- a/templates/user/settings/profile.tmpl +++ b/templates/user/settings/profile.tmpl @@ -21,22 +21,6 @@ -
- -

{{.SignedUser.Email}}

-
-
- - -
-
- - -
-
- - -
+
+ +

{{.SignedUser.Email}}

+
+
+ + +
+
+ + +
+
+ + +
From 21c8c0943028c02c234e346a8ad897bab125c83d Mon Sep 17 00:00:00 2001 From: hazycora Date: Wed, 27 Dec 2023 00:08:43 -0600 Subject: [PATCH 09/24] generate swagger --- templates/swagger/v1_json.tmpl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 181c564f4a..44aac59583 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -20331,6 +20331,10 @@ "type": "boolean", "x-go-name": "ProhibitLogin" }, + "pronouns": { + "type": "string", + "x-go-name": "Pronouns" + }, "restricted": { "type": "boolean", "x-go-name": "Restricted" @@ -23953,6 +23957,10 @@ "type": "string", "x-go-name": "Location" }, + "pronouns": { + "type": "string", + "x-go-name": "Pronouns" + }, "theme": { "type": "string", "x-go-name": "Theme" From bbf906eccc109c8bdc4656d4002a51e8a76b19c3 Mon Sep 17 00:00:00 2001 From: hazycora Date: Wed, 27 Dec 2023 01:18:19 -0600 Subject: [PATCH 10/24] fix locale function in profile settings --- templates/user/settings/profile.tmpl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/templates/user/settings/profile.tmpl b/templates/user/settings/profile.tmpl index b8028a7007..a4b64da39b 100644 --- a/templates/user/settings/profile.tmpl +++ b/templates/user/settings/profile.tmpl @@ -22,30 +22,30 @@
- + From 204dd9e30035cb8f975705cbc1c46862145dccbe Mon Sep 17 00:00:00 2001 From: hazycora Date: Fri, 23 Feb 2024 16:33:02 -0600 Subject: [PATCH 11/24] Add migration for pronouns --- models/forgejo_migrations/migrate.go | 2 ++ models/forgejo_migrations/v1_22/v10.go | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 models/forgejo_migrations/v1_22/v10.go diff --git a/models/forgejo_migrations/migrate.go b/models/forgejo_migrations/migrate.go index 965b748ac9..7c295247c0 100644 --- a/models/forgejo_migrations/migrate.go +++ b/models/forgejo_migrations/migrate.go @@ -56,6 +56,8 @@ var migrations = []*Migration{ NewMigration("Modify the `release`.`note` content to remove SSH signatures", forgejo_v1_22.RemoveSSHSignaturesFromReleaseNotes), // v8 -> v9 NewMigration("Add the `apply_to_admins` column to the `protected_branch` table", forgejo_v1_22.AddApplyToAdminsSetting), + // v9 -> v10 + NewMigration("Add pronouns to user", forgejo_v1_22.AddPronounsToUser), } // GetCurrentDBVersion returns the current Forgejo database version. diff --git a/models/forgejo_migrations/v1_22/v10.go b/models/forgejo_migrations/v1_22/v10.go new file mode 100644 index 0000000000..bf1639eeeb --- /dev/null +++ b/models/forgejo_migrations/v1_22/v10.go @@ -0,0 +1,16 @@ +// Copyright 2024 The Forgejo Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_22 //nolint + +import ( + "xorm.io/xorm" +) + +func AddPronounsToUser(x *xorm.Engine) error { + type User struct { + Pronouns string + } + + return x.Sync(&User{}) +} From 20f96796d785603b01d173ef39a732d38790096a Mon Sep 17 00:00:00 2001 From: hazycora Date: Sat, 24 Feb 2024 12:13:49 -0600 Subject: [PATCH 12/24] use recognisedPronouns variable --- routers/web/user/setting/profile.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go index 7a2f6ba46d..e5750e724d 100644 --- a/routers/web/user/setting/profile.go +++ b/routers/web/user/setting/profile.go @@ -12,6 +12,7 @@ import ( "net/http" "os" "path/filepath" + "slices" "strings" "code.gitea.io/gitea/models/avatars" @@ -40,13 +41,17 @@ const ( tplSettingsRepositories base.TplName = "user/settings/repos" ) +var ( + recognisedPronouns = []string{"", "he/him", "she/her", "they/them", "it/its", "any/all"} +) + // Profile render user's profile page func Profile(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("settings.profile") ctx.Data["PageIsSettingsProfile"] = true ctx.Data["AllowedUserVisibilityModes"] = setting.Service.AllowedUserVisibilityModesSlice.ToVisibleTypeSlice() ctx.Data["DisableGravatar"] = setting.Config().Picture.DisableGravatar.Value(ctx) - ctx.Data["PronounsAreCustom"] = ctx.Doer.Pronouns != "" && ctx.Doer.Pronouns != "he/him" && ctx.Doer.Pronouns != "she/her" && ctx.Doer.Pronouns != "they/them" && ctx.Doer.Pronouns != "it/its" && ctx.Doer.Pronouns != "any/all" + ctx.Data["PronounsAreCustom"] = !slices.Contains(recognisedPronouns, ctx.Doer.Pronouns) ctx.HTML(http.StatusOK, tplSettingsProfile) } @@ -57,7 +62,7 @@ func ProfilePost(ctx *context.Context) { ctx.Data["PageIsSettingsProfile"] = true ctx.Data["AllowedUserVisibilityModes"] = setting.Service.AllowedUserVisibilityModesSlice.ToVisibleTypeSlice() ctx.Data["DisableGravatar"] = setting.Config().Picture.DisableGravatar.Value(ctx) - ctx.Data["PronounsAreCustom"] = ctx.Doer.Pronouns != "" && ctx.Doer.Pronouns != "he/him" && ctx.Doer.Pronouns != "she/her" && ctx.Doer.Pronouns != "they/them" && ctx.Doer.Pronouns != "it/its" && ctx.Doer.Pronouns != "any/all" + ctx.Data["PronounsAreCustom"] = !slices.Contains(recognisedPronouns, ctx.Doer.Pronouns) if ctx.HasError() { ctx.HTML(http.StatusOK, tplSettingsProfile) From 8d086ad91c4ef5c0236bdb72cc3becd1356e8b78 Mon Sep 17 00:00:00 2001 From: hazycora Date: Sat, 24 Feb 2024 12:24:12 -0600 Subject: [PATCH 13/24] change "any/all" to "any pronouns" --- routers/web/user/setting/profile.go | 2 +- templates/user/settings/profile.tmpl | 2 +- web_src/js/features/user-settings.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go index e5750e724d..5bbc497db8 100644 --- a/routers/web/user/setting/profile.go +++ b/routers/web/user/setting/profile.go @@ -42,7 +42,7 @@ const ( ) var ( - recognisedPronouns = []string{"", "he/him", "she/her", "they/them", "it/its", "any/all"} + recognisedPronouns = []string{"", "he/him", "she/her", "they/them", "it/its", "any pronouns"} ) // Profile render user's profile page diff --git a/templates/user/settings/profile.tmpl b/templates/user/settings/profile.tmpl index a4b64da39b..15eedc5056 100644 --- a/templates/user/settings/profile.tmpl +++ b/templates/user/settings/profile.tmpl @@ -41,7 +41,7 @@
she/her
they/them
it/its
-
any/all
+
any pronouns
{{if .PronounsAreCustom}}
{{ctx.Locale.Tr "settings.pronouns_custom"}}
{{else}} diff --git a/web_src/js/features/user-settings.js b/web_src/js/features/user-settings.js index 5ad8bd94d4..8f68b03b29 100644 --- a/web_src/js/features/user-settings.js +++ b/web_src/js/features/user-settings.js @@ -10,7 +10,7 @@ function onPronounsDropdownUpdate() { pronounsInput.value === 'she/her' || pronounsInput.value === 'they/them' || pronounsInput.value === 'it/its' || - pronounsInput.value === 'any/all' + pronounsInput.value === 'any pronouns' ); if (isCustom) { if (pronounsInput.value === '!') { From 75890e8f375da8e17c5b3c098ff0371a7f282a8b Mon Sep 17 00:00:00 2001 From: hazycora Date: Sat, 24 Feb 2024 12:24:20 -0600 Subject: [PATCH 14/24] gofumpt --- routers/web/user/setting/profile.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go index 5bbc497db8..24c2147a03 100644 --- a/routers/web/user/setting/profile.go +++ b/routers/web/user/setting/profile.go @@ -41,9 +41,7 @@ const ( tplSettingsRepositories base.TplName = "user/settings/repos" ) -var ( - recognisedPronouns = []string{"", "he/him", "she/her", "they/them", "it/its", "any pronouns"} -) +var recognisedPronouns = []string{"", "he/him", "she/her", "they/them", "it/its", "any pronouns"} // Profile render user's profile page func Profile(ctx *context.Context) { From 8cbacf850ad3e17ea3677bc39920fa832d68e695 Mon Sep 17 00:00:00 2001 From: hazycora Date: Sat, 24 Feb 2024 15:26:18 -0600 Subject: [PATCH 15/24] Add back ID field to pronouns migration looks unnecessary, but not doing this seems to cause failed tests. Other previous migrations follow this pattern as well. --- models/forgejo_migrations/v1_22/v10.go | 1 + 1 file changed, 1 insertion(+) diff --git a/models/forgejo_migrations/v1_22/v10.go b/models/forgejo_migrations/v1_22/v10.go index bf1639eeeb..819800ae71 100644 --- a/models/forgejo_migrations/v1_22/v10.go +++ b/models/forgejo_migrations/v1_22/v10.go @@ -9,6 +9,7 @@ import ( func AddPronounsToUser(x *xorm.Engine) error { type User struct { + ID int64 `xorm:"pk autoincr"` Pronouns string } From 454ceb2ada2678ecadd0bb6641e19cc6d05edcea Mon Sep 17 00:00:00 2001 From: hazycora Date: Mon, 26 Feb 2024 13:43:04 -0600 Subject: [PATCH 16/24] add some comments --- routers/web/user/setting/profile.go | 1 + web_src/js/features/user-settings.js | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go index 24c2147a03..a39c118ddd 100644 --- a/routers/web/user/setting/profile.go +++ b/routers/web/user/setting/profile.go @@ -41,6 +41,7 @@ const ( tplSettingsRepositories base.TplName = "user/settings/repos" ) +// must be kept in sync with `web_src/js/features/user-settings.js` var recognisedPronouns = []string{"", "he/him", "she/her", "they/them", "it/its", "any pronouns"} // Profile render user's profile page diff --git a/web_src/js/features/user-settings.js b/web_src/js/features/user-settings.js index 8f68b03b29..111bfc4465 100644 --- a/web_src/js/features/user-settings.js +++ b/web_src/js/features/user-settings.js @@ -4,6 +4,7 @@ function onPronounsDropdownUpdate() { const pronounsCustom = document.getElementById('pronouns-custom'); const pronounsDropdown = document.getElementById('pronouns-dropdown'); const pronounsInput = pronounsDropdown.querySelector('input'); + // must be kept in sync with `routers/web/user/setting/profile.go` const isCustom = !( pronounsInput.value === '' || pronounsInput.value === 'he/him' || @@ -49,8 +50,12 @@ export function initUserSettings() { const pronounsDropdown = document.getElementById('pronouns-dropdown'); const pronounsCustom = document.getElementById('pronouns-custom'); const pronounsInput = pronounsDropdown.querySelector('input'); + + // If JS is disabled, the page will show the custom input, as the dropdown requires JS to work. + // JS progressively enhances the input by adding a dropdown, but it works regardless. pronounsCustom.removeAttribute('name'); pronounsDropdown.style.display = ''; + onPronounsDropdownUpdate(); pronounsInput.addEventListener('change', onPronounsDropdownUpdate); pronounsCustom.addEventListener('input', onPronounsCustomUpdate); From 1c551f923b01292206f030bd0b533e671a238eeb Mon Sep 17 00:00:00 2001 From: hazycora Date: Mon, 26 Feb 2024 13:47:05 -0600 Subject: [PATCH 17/24] only add name attribute to pronouns input in JS, to ensure fallback works --- templates/user/settings/profile.tmpl | 2 +- web_src/js/features/user-settings.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/templates/user/settings/profile.tmpl b/templates/user/settings/profile.tmpl index 15eedc5056..e596fa3496 100644 --- a/templates/user/settings/profile.tmpl +++ b/templates/user/settings/profile.tmpl @@ -24,7 +24,7 @@