-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 664a80a
Showing
27 changed files
with
3,773 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
< 3.3.0.beta1-dev: f1c7ada2637c52f4239420ebce8ac2e880d8de30 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require("@discourse/lint-configs/eslint"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
name: Discourse Plugin | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
jobs: | ||
ci: | ||
uses: discourse/.github/.github/workflows/discourse-plugin.yml@v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
/gems | ||
/auto_generated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require("@discourse/lint-configs/prettier"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
inherit_gem: | ||
rubocop-discourse: stree-compat.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--print-width=100 | ||
--plugins=plugin/trailing_comma,plugin/disable_auto_ternary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require("@discourse/lint-configs/template-lint"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
source "https://rubygems.org" | ||
|
||
group :development do | ||
gem "rubocop-discourse" | ||
gem "syntax_tree" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) Civilized Discourse Construction Kit, Inc. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# **Geo Customization** Plugin | ||
|
||
**Adds geo location to current_user serializer** | ||
|
||
If `SiteSetting.geo_include_country_code` is enabled, the ISO country code (as returned by Maxmind) | ||
will be added to the `<body>` class like "country-US". You can then use this class to hide/display | ||
text on the site. | ||
|
||
`SiteSetting.geo_include_city` similarly adds something like | ||
|
||
Here is a trival example of using this plugin | ||
|
||
Create a theme compnent and add this to the CSS: | ||
``` | ||
/* Hide both divs by default */ | ||
.location-us-content, | ||
.location-default-content { | ||
display: none; | ||
} | ||
/* Show the US div when the "location-US" class is on the body */ | ||
body.country-US .location-us-content { | ||
display: block; | ||
} | ||
/* Show the default div when the "location-US" class is NOT on the body */ | ||
body:not(.country-US) .location-default-content { | ||
display: block; | ||
} | ||
``` | ||
|
||
Add this to the `After Header`: | ||
``` | ||
<body class="location-US"> | ||
<div class="location-us-content"> | ||
This is text for the US | ||
</div> | ||
<div class="location-default-content"> | ||
This is everyone else's text | ||
</div> | ||
</body> | ||
``` | ||
## Testing | ||
|
||
To facilitate testing, `SiteSetting.geo_enable_admin_override` and `SiteSetting.geo_admin_ip_address` can | ||
be used to override the actual user IP address. Three examples are included. Anything after a `-` in the ip address setting will be ignored (making it easier to tell what to expect from the sample IP addresses). |
Empty file.
Empty file.
Empty file.
5 changes: 5 additions & 0 deletions
5
assets/javascripts/discourse/connectors/above-main-container/add-location.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import User from "discourse/models/user"; | ||
|
||
export default { | ||
currentUser: User.current() | ||
}; |
19 changes: 19 additions & 0 deletions
19
assets/javascripts/discourse/initializers/add-location-to-body.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { withPluginApi } from "discourse/lib/plugin-api"; | ||
|
||
export default { | ||
initialize(container) { | ||
const siteSettings = container.lookup("service:site-settings"); | ||
withPluginApi("0.11.4", (api) => { | ||
const user = api.getCurrentUser(); | ||
const body = document.querySelector('body'); | ||
if (user) { | ||
if (siteSettings.geo_include_country_code){ | ||
body.classList.add(`country-${user.geo_location.country_code}`) | ||
} | ||
if (siteSettings.geo_include_city) { | ||
body.classList.add(`city-${user.geo_location.city}`) | ||
}; | ||
} | ||
}) | ||
} | ||
} | ||
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
en: | ||
site_settings: | ||
geo_customization_enabled: "Enable Geo Customization Plugin" | ||
geo_include_city: "Include City in <body> tag" | ||
geo_include_country_code: "Include Country Code in <body> tag" | ||
geo_include_country: "Include Country in <body> tag" | ||
geo_admin_ip_address: "Use first of these for Admin IP Address Geo Customization" | ||
geo_enable_admin_override: "Use Admin IP Address for admin users" | ||
admin_js: | ||
admin: | ||
site_settings: | ||
geo_customization_enabled: "Enable Geo Customization" | ||
geo_include_city: "Include City" | ||
geo_include_country_code: "Include Country Code" | ||
geo_include_country: "Include Country" | ||
categories: | ||
geo_customization: "Geo Customization" | ||
js: | ||
discourse_geo_customization: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
en: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
geo_customization: | ||
geo_customization_enabled: | ||
default: true | ||
client: true | ||
geo_enable_admin_override: | ||
default: false | ||
client: false | ||
geo_admin_ip_address: | ||
# default: "174.50.213.1" | ||
type: list | ||
default: '173.32.159.123' # canada | ||
client: true | ||
allow_any: true | ||
choices: | ||
- 174.50.213.1 - USA | ||
- 175.156.235.1 - Singapore | ||
- 173.32.159.1 - Canada | ||
geo_include_city: | ||
type: bool | ||
default: false | ||
client: true | ||
geo_include_country_code: | ||
type: bool | ||
default: true | ||
client: true |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
module ::GeoCustomizationModule | ||
class Engine < ::Rails::Engine | ||
engine_name PLUGIN_NAME | ||
isolate_namespace GeoCustomizationModule | ||
config.autoload_paths << File.join(config.root, "lib") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"private": true, | ||
"devDependencies": { | ||
"@discourse/lint-configs": "^1.3.5", | ||
"ember-template-lint": "^5.13.0", | ||
"eslint": "^8.56.0", | ||
"prettier": "^2.8.8" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
# name: discourse-geo-customization | ||
# about: add geo location to current_user | ||
# meta_topic_id: TODO | ||
# version: 0.0.1 | ||
# authors: Jay Pfaffman | ||
# url: GPL | ||
# required_version: 3.1.0 | ||
|
||
enabled_site_setting :geo_customization_enabled | ||
|
||
module ::GeoCustomizationModule | ||
PLUGIN_NAME = "discourse-geo-customization" | ||
end | ||
|
||
require_relative "lib/geo_customization_module/engine" | ||
|
||
after_initialize do | ||
add_to_serializer(:current_user, :geo_location) do | ||
begin | ||
if SiteSetting.geo_enable_admin_override && object.admin || | ||
object.ip_address == '127.0.0.1' || object.ip_address == '::1' | ||
object.ip_address = SiteSetting.geo_admin_ip_address.split("|").first.split("-").first.strip | ||
end | ||
rescue => e | ||
Rails.logger.error("Error in geo_customization IP override: #{e}") | ||
end | ||
begin | ||
DiscourseIpInfo.get(object.ip_address) | ||
rescue => e | ||
Rails.logger.error("Error in geo_customization getting IP address: #{e}") | ||
nil | ||
end | ||
end | ||
end |
Empty file.
Empty file.
Oops, something went wrong.