From 67e66ab40ef644be040a8bdab6f022fdafc10f80 Mon Sep 17 00:00:00 2001 From: "Panagiotis \"Ivory\" Vasilopoulos" Date: Wed, 19 Jul 2023 21:29:19 +0200 Subject: [PATCH] [GITEA] Add OpenStreetMap URL to Location field in profile Not too important, but I think that it'd be a pretty neat touch. (cherry picked from commit 64de4e02f9ed776bc751354d39fc652ea5c2ef19) Add placeholder text (cherry picked from commit 1396e2716b57c8cc3f635837696b6c65edda3ea2) Add test for OSM feature (doesn't work yet) (cherry picked from commit 2c94e6d56f6444946bcdff3f24776e4532903b8c) Lint tests (sorry, I'm a bit tired) (cherry picked from commit 5731fbb4a4f800e1f38eba34a9db98913287928e) It finally works, will add more tests later. (cherry picked from commit 4437292622e689ae7afbada9bcc84186560c1cf9) Improve testing (cherry picked from commit 56a028ec96e232cfec32956f7c9908f6a059513d) Introduce new button for OpenStreetMap URL (cherry picked from commit 852317b46734ca5c929b4b12fb067c14e51d0f1b) 16, "gt-mr-2" in *all* icons (cherry picked from commit c2c60a01eb0be9062000bc5b8cf7a4fdb534a2f0) Wait, I forgot about *that* icon (cherry picked from commit 9930f9b8f2b06d9593b256e4afee0109970a15f8) Alright, we just made all the icons in that submenu a bit bolder and more consistent. (cherry picked from commit d5c0009ad01fbf0486620b7c00351a6d1d01b6aa) Remove | Safe attribute, it does exactly the opposite of what I intended it to. (cherry picked from commit 1254f2aa9df3ba046d3067ffa49978cf053cdf39) Make OSM button configurable (cherry picked from commit ba3d76f5ba1621356390412a3767fc2daa6bfae7) Fix tests (tested) (cherry picked from commit 22983c65f8b143d26600d02b2615d4b36b02000f) Add more tests (cherry picked from commit 4bbcbd37e138c68d3b9329cb2dbcfd8aad430c79) Add tooltip (cherry picked from commit b906008ff1792f6e6e3acaa6e7c71be30c009dd2) Revert "16, "gt-mr-2" in *all* icons" This reverts commit c2c60a01eb0be9062000bc5b8cf7a4fdb534a2f0. (cherry picked from commit 02bb52617dbf93d96bb69183ea8879e7e2e28d50) Revert "Wait, I forgot about *that* icon" This reverts commit 9930f9b8f2b06d9593b256e4afee0109970a15f8. (cherry picked from commit a36d6575090124cac2b46b288cbb6f5c1df482ea) Revert "Alright, we just made all the icons in that submenu a bit bolder and more consistent." This reverts commit d5c0009ad01fbf0486620b7c00351a6d1d01b6aa. (cherry picked from commit 27d8d1c5fc6418cb55430fc3f093a2e02ffaeb93) --- custom/conf/app.example.ini | 3 ++ modules/setting/service.go | 2 + options/locale/locale_en-US.ini | 2 + routers/web/user/profile.go | 1 + templates/shared/user/profile_big_avatar.tmpl | 12 +++++- templates/user/settings/profile.tmpl | 2 +- tests/integration/user_test.go | 40 +++++++++++++++++++ 7 files changed, 60 insertions(+), 2 deletions(-) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index a63170a525..807919102c 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -832,6 +832,9 @@ LEVEL = Info ;; Dependencies can be added from any repository where the user is granted access or only from the current repository depending on this setting. ;ALLOW_CROSS_REPOSITORY_DEPENDENCIES = true ;; +;; Enable OpenStreetMap button in Location field on user profiles +;ENABLE_OSM_BUTTON = true +;; ;; Enable heatmap on users profiles. ;ENABLE_USER_HEATMAP = true ;; diff --git a/modules/setting/service.go b/modules/setting/service.go index b2cef8126e..aa6cba6134 100644 --- a/modules/setting/service.go +++ b/modules/setting/service.go @@ -74,6 +74,7 @@ var Service = struct { AllowCrossRepositoryDependencies bool DefaultAllowOnlyContributorsToTrackTime bool NoReplyAddress string + EnableOSMButton bool EnableUserHeatmap bool AutoWatchNewRepos bool AutoWatchOnChanges bool @@ -187,6 +188,7 @@ func loadServiceFrom(rootCfg ConfigProvider) { Service.AllowCrossRepositoryDependencies = sec.Key("ALLOW_CROSS_REPOSITORY_DEPENDENCIES").MustBool(true) Service.DefaultAllowOnlyContributorsToTrackTime = sec.Key("DEFAULT_ALLOW_ONLY_CONTRIBUTORS_TO_TRACK_TIME").MustBool(true) Service.NoReplyAddress = sec.Key("NO_REPLY_ADDRESS").MustString("noreply." + Domain) + Service.EnableOSMButton = sec.Key("ENABLE_OSM_BUTTON").MustBool(true) Service.EnableUserHeatmap = sec.Key("ENABLE_USER_HEATMAP").MustBool(true) Service.AutoWatchNewRepos = sec.Key("AUTO_WATCH_NEW_REPOS").MustBool(true) Service.AutoWatchOnChanges = sec.Key("AUTO_WATCH_ON_CHANGES").MustBool(false) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index fbb22eb2f6..8a1efab33c 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -603,6 +603,7 @@ user_bio = Biography disabled_public_activity = This user has disabled the public visibility of the activity. email_visibility.limited = Your email address is visible to all authenticated users email_visibility.private = Your email address is only visible to you and administrators +redirect_to_osm = View on OpenStreetMap form.name_reserved = The username "%s" is reserved. form.name_pattern_not_allowed = The pattern "%s" is not allowed in a username. @@ -629,6 +630,7 @@ webauthn = Security Keys public_profile = Public Profile biography_placeholder = Tell us a little bit about yourself +location_placeholder = Share your approximate location with others profile_desc = Your email address will be used for notifications and other operations. password_username_disabled = Non-local users are not allowed to change their username. Please contact your site administrator for more details. full_name = Full Name diff --git a/routers/web/user/profile.go b/routers/web/user/profile.go index 15a9197b98..b08e343ae1 100644 --- a/routers/web/user/profile.go +++ b/routers/web/user/profile.go @@ -52,6 +52,7 @@ func userProfile(ctx *context.Context) { ctx.Data["Title"] = ctx.ContextUser.DisplayName() ctx.Data["PageIsUserProfile"] = true + ctx.Data["EnableOSMButton"] = setting.Service.EnableOSMButton // prepare heatmap data if setting.Service.EnableUserHeatmap { diff --git a/templates/shared/user/profile_big_avatar.tmpl b/templates/shared/user/profile_big_avatar.tmpl index 5a1e43b88e..e04a1b512f 100644 --- a/templates/shared/user/profile_big_avatar.tmpl +++ b/templates/shared/user/profile_big_avatar.tmpl @@ -24,7 +24,17 @@
- +
diff --git a/tests/integration/user_test.go b/tests/integration/user_test.go index 3e4d967686..e02fdb62e4 100644 --- a/tests/integration/user_test.go +++ b/tests/integration/user_test.go @@ -4,6 +4,7 @@ package integration import ( + "fmt" "net/http" "testing" @@ -12,6 +13,7 @@ import ( repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/test" "code.gitea.io/gitea/modules/translation" @@ -276,3 +278,41 @@ func TestListStopWatches(t *testing.T) { assert.Greater(t, apiWatches[0].Seconds, int64(0)) } } + +func TestGetOpenStreetMapLink(t *testing.T) { + setting.Service.EnableOSMButton = true + defer tests.PrepareTestEnv(t)() + + testLocations := map[string]string{ + "Αθήνα": "%ce%91%ce%b8%ce%ae%ce%bd%ce%b1", + " Αθήνα": "%20%20%ce%91%ce%b8%ce%ae%ce%bd%ce%b1", + "Barbarossabrunnen, Düsseldorf": "Barbarossabrunnen%2c%20D%c3%bcsseldorf", + "39.91025,116.40753": "39.91025%2c116.40753", + "པེ་ཅིང་གྲོང་ཁྱེར།": "%e0%bd%94%e0%bd%ba%e0%bc%8b%e0%bd%85%e0%bd%b2%e0%bd%84%e0%bc%8b%e0%bd%82%e0%be%b2%e0%bd%bc%e0%bd%84%e0%bc%8b%e0%bd%81%e0%be%b1%e0%bd%ba%e0%bd%a2%e0%bc%8d", + "Internet Archive": "Internet%20Archive", + "Schönhauser Allee 2, Berlin, Deutschland": "Sch%c3%b6nhauser%20Allee%202%2c%20Berlin%2c%20Deutschland", + "Miestna knižnica Podunajské Biskupice": "Miestna%20kni%c5%benica%20Podunajsk%c3%a9%20Biskupice", + "東京タワー": "%e6%9d%b1%e4%ba%ac%e3%82%bf%e3%83%af%e3%83%bc", + "Carnarvon Space & Technology Centre": "Carnarvon%20Space%20%26%20Technology%20Centre", + } + + session := loginUser(t, "user2") + for location, encodedLocation := range testLocations { + t.Run(location, func(t *testing.T) { + req := NewRequestWithValues(t, "POST", "/user/settings", map[string]string{ + "_csrf": GetCSRF(t, session, "/user/settings"), + "name": "user2", + "email": "user@example.com", + "language": "en-US", + "location": location, + }) + session.MakeRequest(t, req, http.StatusSeeOther) + + req = NewRequest(t, "GET", "/user2/") + resp := session.MakeRequest(t, req, http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + + htmlDoc.AssertElement(t, fmt.Sprintf("a[href='https://www.openstreetmap.org/search?query=%s']", encodedLocation), true) + }) + } +}