mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-29 06:47:41 +01:00
Merge pull request '[FEAT] Add OpenStreetMap URL to Location field in profile' (#1076) from n0toose/forgejo:osm-urls-in-profiles into forgejo-development
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/1076
This commit is contained in:
commit
e2c6c1dbd0
7 changed files with 60 additions and 2 deletions
|
@ -827,6 +827,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
|
||||
;;
|
||||
|
|
|
@ -73,6 +73,7 @@ var Service = struct {
|
|||
AllowCrossRepositoryDependencies bool
|
||||
DefaultAllowOnlyContributorsToTrackTime bool
|
||||
NoReplyAddress string
|
||||
EnableOSMButton bool
|
||||
EnableUserHeatmap bool
|
||||
AutoWatchNewRepos bool
|
||||
AutoWatchOnChanges bool
|
||||
|
@ -185,6 +186,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)
|
||||
|
|
|
@ -601,6 +601,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.
|
||||
|
@ -627,6 +628,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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -24,7 +24,17 @@
|
|||
<div class="extra content gt-word-break">
|
||||
<ul>
|
||||
{{if .ContextUser.Location}}
|
||||
<li>{{svg "octicon-location"}} {{.ContextUser.Location}}</li>
|
||||
<li>
|
||||
{{svg "octicon-location"}}
|
||||
{{.ContextUser.Location}}
|
||||
{{if .EnableOSMButton}}
|
||||
<a href="https://www.openstreetmap.org/search?query={{.ContextUser.Location}}" rel="nofollow noreferrer">
|
||||
<i class="ui right" data-tooltip-content="{{.locale.Tr "user.redirect_to_osm"}}">
|
||||
{{svg "octicon-link-external"}}
|
||||
</i>
|
||||
</a>
|
||||
{{end}}
|
||||
</li>
|
||||
{{end}}
|
||||
{{if (eq .SignedUserID .ContextUser.ID)}}
|
||||
<li>
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
</div>
|
||||
<div class="field">
|
||||
<label for="location">{{.locale.Tr "settings.location"}}</label>
|
||||
<input id="location" name="location" value="{{.SignedUser.Location}}" maxlength="50">
|
||||
<input id="location" name="location" placeholder="{{.locale.Tr "settings.location_placeholder"}}" value="{{.SignedUser.Location}}" maxlength="50">
|
||||
</div>
|
||||
|
||||
<div class="divider"></div>
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue