Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion plugin.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
# name: discourse-locations
# about: Tools for handling locations in Discourse
# version: 6.9.3
# version: 6.9.4
# authors: Robert Barrow, Angus McLeod
# contact_emails: [email protected]
# url: https://github.com/merefield/discourse-locations
Expand Down Expand Up @@ -147,6 +147,23 @@ class SiteSettings::TypeSupervisor
end
) { Locations.parse_geo_location(object.custom_fields["geo_location"]) }

add_to_serializer(
:post,
:user_custom_fields,
respect_plugin_enabled: false
) do
public_keys = SiteSetting.public_user_custom_fields.split("|")
user_fields = object.user&.custom_fields || {}

out = {}
public_keys.each do |k|
v = user_fields[k]
out[k] = (k == "geo_location" ? Locations.parse_geo_location(v) : v)
end

out
end

require_dependency "directory_item_serializer"
class ::DirectoryItemSerializer::UserSerializer
attributes :geo_location
Expand Down
35 changes: 30 additions & 5 deletions spec/system/user_location_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@

RSpec.describe "User can manage their location" do
fab!(:user)
let(:user_preferences_profile_page) { PageObjects::Pages::UserPreferencesProfile.new }
fab!(:topic) { Fabricate(:topic, user: user) }
fab!(:post) { Fabricate(:post, topic: topic, user: user) }
let(:user_preferences_profile_page) do
PageObjects::Pages::UserPreferencesProfile.new
end
let(:topic_page) { PageObjects::Pages::Topic.new }
let(:location_selector) do
PageObjects::Components::LocationSelector.new ".location-selector-wrapper"
end
Expand All @@ -13,7 +18,8 @@
let(:location) do
{
"place_id" => 256_934_900,
"licence" => "Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright",
"licence" =>
"Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright",
"osm_type" => "way",
"osm_id" => 4_086_265,
"lat" => "53.4011822",
Expand All @@ -24,23 +30,42 @@
"importance" => 0.30430544025715084,
"addresstype" => "road",
"name" => "Hope Street",
"country" => "United Kingdom",
"countrycode" => "gb",
"city" => "Liverpool",
"address" => address_string,
"boundingbox" => %w[53.3986907 53.4034963 -2.9714089 -2.9693595],
"boundingbox" => %w[53.3986907 53.4034963 -2.9714089 -2.9693595]
}
end

context "browsing the users preferences" do
before(:each) do
SiteSetting.location_enabled = true
SiteSetting.location_users_map = true
SiteSetting.location_user_post_format = "city|countrycode"
SiteSetting.location_user_post = true
sign_in(user)
UserCustomField.create!(user_id: user.id, name: "geo_location", value: location.to_json)
UserCustomField.create!(
user_id: user.id,
name: "geo_location",
value: location.to_json
)
end

it "allows user to view and update their location preferences" do
user_preferences_profile_page.visit(user)
expect(page).to have_css(".location-selector-wrapper")
expect(location_selector).to have_selected_location_with_string(address_string)
expect(location_selector).to have_selected_location_with_string(
address_string
)

topic_page.visit_topic(topic)
expect(page).to have_css(
".user-location",
text: "Liverpool, United Kingdom"
)

user_preferences_profile_page.visit(user)
location_selector.remove_location(address_string)
expect(location_selector).to have_no_selected_locations
user_preferences_profile_page.save
Expand Down
Loading