diff --git a/app/assets/javascripts/admin/components/ip-lookup.js.es6 b/app/assets/javascripts/admin/components/ip-lookup.js.es6
new file mode 100644
index 00000000000..d93d44c9051
--- /dev/null
+++ b/app/assets/javascripts/admin/components/ip-lookup.js.es6
@@ -0,0 +1,43 @@
+export default Ember.Component.extend({
+ classNames: ["ip-lookup"],
+
+ city: function () {
+ return [
+ this.get("location.city"),
+ this.get("location.region"),
+ this.get("location.country")
+ ].filter(Boolean).join(", ");
+ }.property("location.@{city,region,country}"),
+
+ actions: {
+ lookup: function () {
+ var self = this;
+ this.set("show", true);
+
+ if (!this.get("location")) {
+ Discourse.ajax("/admin/users/ip-info.json", {
+ data: { ip: this.get("ip") }
+ }).then(function (location) {
+ self.set("location", Em.Object.create(location));
+ });
+ }
+
+ if (!this.get("other_accounts")) {
+ this.set("other_accounts_loading", true);
+ Discourse.AdminUser.findAll("active", {
+ "ip": this.get("ip"),
+ "exclude": this.get("user_id")
+ }).then(function (users) {
+ self.setProperties({
+ other_accounts: users,
+ other_accounts_loading: false,
+ });
+ });
+ }
+ },
+
+ hide: function () {
+ this.set("show", false);
+ }
+ }
+});
diff --git a/app/assets/javascripts/admin/controllers/admin_users_list_controller.js b/app/assets/javascripts/admin/controllers/admin_users_list_controller.js
index 7322aa2d9c3..5239056e108 100644
--- a/app/assets/javascripts/admin/controllers/admin_users_list_controller.js
+++ b/app/assets/javascripts/admin/controllers/admin_users_list_controller.js
@@ -91,7 +91,7 @@ Discourse.AdminUsersListController = Ember.ArrayController.extend(Discourse.Pres
var adminUsersListController = this;
adminUsersListController.set('loading', true);
- Discourse.AdminUser.findAll(this.get('query'), this.get('username')).then(function (result) {
+ Discourse.AdminUser.findAll(this.get('query'), { filter: this.get('username') }).then(function (result) {
adminUsersListController.set('content', result);
adminUsersListController.set('loading', false);
});
diff --git a/app/assets/javascripts/admin/models/admin_user.js b/app/assets/javascripts/admin/models/admin_user.js
index f84cc9a3bd4..981e1be3674 100644
--- a/app/assets/javascripts/admin/models/admin_user.js
+++ b/app/assets/javascripts/admin/models/admin_user.js
@@ -431,7 +431,7 @@ Discourse.AdminUser.reopenClass({
findAll: function(query, filter) {
return Discourse.ajax("/admin/users/list/" + query + ".json", {
- data: { filter: filter }
+ data: filter
}).then(function(users) {
return users.map(function(u) {
return Discourse.AdminUser.create(u);
diff --git a/app/assets/javascripts/admin/templates/ip_locator.js.handlebars b/app/assets/javascripts/admin/templates/ip_locator.js.handlebars
deleted file mode 100644
index 379e61fe7de..00000000000
--- a/app/assets/javascripts/admin/templates/ip_locator.js.handlebars
+++ /dev/null
@@ -1,54 +0,0 @@
-{{#if view.ip}}
-
- {{i18n admin.user.ip_lookup}}
-
-{{/if}}
-{{#if view.showBox }}
-
-
{{i18n ip_info.title}}
-
- {{#if view.location}}
- {{#if view.location.hostname}}
- {{i18n ip_info.hostname}}
- {{view.location.hostname}}
- {{/if}}
-
- {{i18n ip_info.location}}
-
- {{#if view.location.loc}}
- {{view.location.loc}}
- {{view.location.city}}, {{view.location.region}}, {{view.location.country}}
- {{else}}
- {{i18n ip_info.location_not_found}}
- {{/if}}
-
-
- {{#if view.location.org}}
- {{i18n ip_info.organisation}}
- {{view.location.org}}
- {{/if}}
-
- {{#if view.location.phone}}
- {{i18n ip_info.phone}}
- {{view.location.phone}}
- {{/if}}
- {{else}}
- {{i18n loading}}
- {{/if}}
-
- {{i18n ip_info.other_accounts}}
-
- {{#if view.other_accounts_loading}}
- {{i18n loading}}
- {{else}}
- {{#each view.other_accounts}}
- {{#link-to 'adminUser' this}}{{avatar this usernamePath="user.username" imageSize="small"}}{{/link-to}}
- {{else}}
- {{i18n ip_info.no_other_accounts}}
- {{/each}}
- {{/if}}
-
-
-
{{i18n close}}
-
-{{/if}}
\ No newline at end of file
diff --git a/app/assets/javascripts/admin/templates/user_index.js.handlebars b/app/assets/javascripts/admin/templates/user_index.js.handlebars
index e3a8d41ef9e..b7f7cd69d71 100644
--- a/app/assets/javascripts/admin/templates/user_index.js.handlebars
+++ b/app/assets/javascripts/admin/templates/user_index.js.handlebars
@@ -76,10 +76,10 @@
{{ip_address}}
{{#if currentUser.admin}}
-
- {{i18n admin.user.refresh_browsers}}
-
- {{view Discourse.AdminIpLocatorView ipBinding="ip_address"}}
+
+ {{i18n admin.user.refresh_browsers}}
+
+ {{ip-lookup ip=ip_address user_id=id}}
{{/if}}
@@ -89,7 +89,7 @@
{{registration_ip_address}}
{{#if currentUser.admin}}
- {{view Discourse.AdminIpLocatorView ipBinding="registration_ip_address"}}
+ {{ip-lookup ip=registration_ip_address user_id=id}}
{{/if}}
diff --git a/app/assets/javascripts/discourse/templates/components/ip-lookup.js.handlebars b/app/assets/javascripts/discourse/templates/components/ip-lookup.js.handlebars
new file mode 100644
index 00000000000..30dec03a34b
--- /dev/null
+++ b/app/assets/javascripts/discourse/templates/components/ip-lookup.js.handlebars
@@ -0,0 +1,54 @@
+{{#if ip}}
+
+ {{i18n admin.user.ip_lookup}}
+
+{{/if}}
+{{#if show}}
+
+
{{i18n ip_lookup.title}}
+
+ {{#if location}}
+ {{#if location.hostname}}
+ {{i18n ip_lookup.hostname}}
+ {{location.hostname}}
+ {{/if}}
+
+ {{i18n ip_lookup.location}}
+
+ {{#if location.loc}}
+ {{location.loc}}
+ {{city}}
+ {{else}}
+ {{i18n ip_lookup.location_not_found}}
+ {{/if}}
+
+
+ {{#if location.org}}
+ {{i18n ip_lookup.organisation}}
+ {{location.org}}
+ {{/if}}
+
+ {{#if location.phone}}
+ {{i18n ip_lookup.phone}}
+ {{location.phone}}
+ {{/if}}
+ {{else}}
+ {{i18n loading}}
+ {{/if}}
+
+ {{i18n ip_lookup.other_accounts}}
+
+ {{#if other_accounts_loading}}
+ {{i18n loading}}
+ {{else}}
+ {{#each other_accounts}}
+ {{#link-to "adminUser" this}}{{avatar this usernamePath="user.username" imageSize="small"}}{{/link-to}}
+ {{else}}
+ {{i18n ip_lookup.no_other_accounts}}
+ {{/each}}
+ {{/if}}
+
+
+
{{i18n close}}
+
+{{/if}}
diff --git a/app/assets/stylesheets/common/admin/admin_base.scss b/app/assets/stylesheets/common/admin/admin_base.scss
index d92c4a27500..0d719b29950 100644
--- a/app/assets/stylesheets/common/admin/admin_base.scss
+++ b/app/assets/stylesheets/common/admin/admin_base.scss
@@ -86,7 +86,7 @@ td.flaggers td {
};
}
-.iplocator {
+.ip-lookup {
position: relative;
display: inline-block;
diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb
index f4ab08ed95d..e5fd6d1ae8f 100644
--- a/app/controllers/admin/users_controller.rb
+++ b/app/controllers/admin/users_controller.rb
@@ -183,6 +183,15 @@ class Admin::UsersController < Admin::AdminController
def leader_requirements
end
+ def ip_info
+ params.require(:ip)
+ ip = params[:ip]
+
+ # should we cache results in redis?
+ location = Excon.get("http://ipinfo.io/#{ip}/json", read_timeout: 30, connect_timeout: 30).body rescue nil
+
+ render json: location
+ end
private
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index f756cd57662..14b8eaf4dd6 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -240,7 +240,7 @@ en:
one: "%{count} new post in the past %{unit}."
other: "%{count} new posts in the past %{unit}."
- ip_info:
+ ip_lookup:
title: IP Address Lookup
hostname: Hostname
location: Location
diff --git a/config/routes.rb b/config/routes.rb
index 34d929fc0b8..8d968fb7f92 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -48,6 +48,7 @@ Discourse::Application.routes.draw do
resources :users, id: USERNAME_ROUTE_FORMAT do
collection do
get "list/:query" => "users#index"
+ get "ip-info" => "users#ip_info"
put "approve-bulk" => "users#approve_bulk"
delete "reject-bulk" => "users#reject_bulk"
end
diff --git a/lib/admin_user_index_query.rb b/lib/admin_user_index_query.rb
index d59ab466c5b..2b07fb20960 100644
--- a/lib/admin_user_index_query.rb
+++ b/lib/admin_user_index_query.rb
@@ -40,7 +40,6 @@ class AdminUserIndexQuery
end
end
-
def filter_by_ip
if params[:ip].present?
@query.where('ip_address = :ip or registration_ip_address = :ip', ip: params[:ip])
diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb
index b974dbc6390..ba4dcc65fe8 100644
--- a/spec/controllers/admin/users_controller_spec.rb
+++ b/spec/controllers/admin/users_controller_spec.rb
@@ -371,6 +371,15 @@ describe Admin::UsersController do
end
end
+ context 'ip-info' do
+
+ it "uses ipinfo.io webservice to retrieve the info" do
+ Excon.expects(:get).with("http://ipinfo.io/123.123.123.123/json", read_timeout: 30, connect_timeout: 30)
+ xhr :get, :ip_info, ip: "123.123.123.123"
+ end
+
+ end
+
end
end