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
18 changes: 14 additions & 4 deletions assets/javascripts/discourse/initializers/location-edits.js.es6
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import I18n from "I18n";
export default {
name: "location-edits",
initialize(container) {
const currentUser = container.lookup("current-user:main");
const siteSettings = container.lookup("site-settings:main");
const site = container.lookup("site:main");

Expand Down Expand Up @@ -83,13 +82,24 @@ export default {
@observes("draftKey")
_setupDefaultLocation() {
if (this.draftKey === "new_topic") {
const topicDefaultLocation = siteSettings.location_topic_default;
const topicDefaultLocation =
this.siteSettings.location_topic_default;
// NB: we can't use the siteSettings, nor currentUser values set in the initialiser here
// because in QUnit they will not be defined as the initialiser only runs once
// so this will break all tests, even if in runtime it may work.
// so solution is to use the values provided by the Composer model under 'this'.
if (
topicDefaultLocation === "user" &&
currentUser.custom_fields.geo_location
this.user.custom_fields.geo_location &&
((typeof this.user.custom_fields.geo_location === "string" &&
this.user.custom_fields.geo_location.replaceAll(" ", "") !==
"{}") ||
(typeof this.user.custom_fields.geo_location === "object" &&
Object.keys(this.user.custom_fields.geo_location).length !==
0))
) {
this.set("location", {
geo_location: currentUser.custom_fields.geo_location,
geo_location: this.user.custom_fields.geo_location,
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ plugins:
client: false
location_topic_default:
type: enum
default: 'none'
default: none
client: true
choices:
- none
Expand Down
2 changes: 1 addition & 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.3.8
# version: 6.3.9
# authors: Angus McLeod, Robert Barrow
# contact_emails: development@pavilion.tech
# url: https://github.com/angusmcleod/discourse-locations
Expand Down
89 changes: 89 additions & 0 deletions test/javascripts/acceptance/composer-default-location-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { acceptance, query } from "discourse/tests/helpers/qunit-helpers";
import { click, visit } from "@ember/test-helpers";
import { test } from "qunit";
import siteFixtures from "../fixtures/site-fixtures";
import { cloneJSON } from "discourse-common/lib/object";

acceptance(
"Composer (locations) | don't show default location as user location when behaviour set",
function (needs) {
needs.user({
username: "demetria_gutmann",
id: 134,
custom_fields: {
geo_location: {
lat: "51.5073219",
lon: "-0.1276474",
address: "London, Greater London, England, United Kingdom",
countrycode: "gb",
city: "London",
state: "England",
country: "United Kingdom",
postalcode: "",
boundingbox: ["51.2867601", "51.6918741", "-0.5103751", "0.3340155"],
type: "city",
},
},
});
needs.site(cloneJSON(siteFixtures["site.json"]));
needs.settings({
location_enabled: true,
location_users_map: true,
hide_user_profiles_from_public: false,
location_topic_default: "none",
default_composer_category: 11,
});

test("composer doesn't contain default location", async function (assert) {
await visit("/");
await click("#create-topic");

assert.equal(
query(".composer-controls-location span.d-button-label").innerText,
"Add Location"
);
});
}
);

acceptance(
"Composer (locations) | - show default location as user location when behaviour set",
function (needs) {
needs.user({
username: "demetria_gutmann",
id: 134,
custom_fields: {
geo_location: {
lat: "51.5073219",
lon: "-0.1276474",
address: "London, Greater London, England, United Kingdom",
countrycode: "gb",
city: "London",
state: "England",
country: "United Kingdom",
postalcode: "",
boundingbox: ["51.2867601", "51.6918741", "-0.5103751", "0.3340155"],
type: "city",
},
},
});
needs.site(cloneJSON(siteFixtures["site.json"]));
needs.settings({
location_enabled: true,
location_users_map: true,
hide_user_profiles_from_public: false,
location_topic_default: "user",
default_composer_category: 11,
});

test("composer includes default location", async function (assert) {
await visit("/");
await click("#create-topic");

assert.equal(
query(".composer-controls-location span.d-button-label").innerText,
"London, Greater London, England, United Kingdom"
);
});
}
);