Skip to content

A platform for community discussion. Free, open, simple.

UX: Allow admin to copy IP address details of a user. (#6270)

Misaka 0x4e211d913d320482
diff --git a/app/assets/javascripts/admin/components/ip-lookup.js.es6 b/app/assets/javascripts/admin/components/ip-lookup.js.es6
index 3f06ba38d67..f376007af00 100644
--- a/app/assets/javascripts/admin/components/ip-lookup.js.es6
+++ b/app/assets/javascripts/admin/components/ip-lookup.js.es6
@@ -1,5 +1,6 @@
import { ajax } from "discourse/lib/ajax";
import AdminUser from "admin/models/admin-user";
+import copyText from "discourse/lib/copy-text";
export default Ember.Component.extend({
classNames: ["ip-lookup"],
@@ -62,6 +63,38 @@ export default Ember.Component.extend({
this.set("show", false);
},
+ copy: function() {
+ let text = `IP: ${this.get("ip")}\n`;
+ const location = this.get("location");
+ if (location) {
+ if (location.hostname) {
+ text += `${I18n.t("ip_lookup.hostname")}: ${location.hostname}\n`;
+ }
+
+ text += I18n.t("ip_lookup.location");
+ if (location.loc) {
+ text += `: ${location.loc} ${this.get("city")}\n`;
+ } else {
+ text += `: ${I18n.t("ip_lookup.location_not_found")}\n`;
+ }
+
+ if (location.org) {
+ text += I18n.t("ip_lookup.organisation");
+ text += `: ${location.org}\n`;
+ }
+
+ if (location.phone) {
+ text += I18n.t("ip_lookup.phone");
+ text += `: ${location.phone}\n`;
+ }
+ }
+ const copyRange = $(`<textarea id="copy-range"></textarea>`);
+ copyRange.text(text);
+ $(document.body).append(copyRange);
+ copyText(text, copyRange[0]);
+ copyRange.remove();
+ },
+
deleteOtherAccounts: function() {
var self = this;
bootbox.confirm(
diff --git a/app/assets/javascripts/discourse/templates/components/ip-lookup.hbs b/app/assets/javascripts/discourse/templates/components/ip-lookup.hbs
index 7fc97aeb052..d63f71375c4 100644
--- a/app/assets/javascripts/discourse/templates/components/ip-lookup.hbs
+++ b/app/assets/javascripts/discourse/templates/components/ip-lookup.hbs
@@ -6,6 +6,7 @@
{{#if show}}
<div class="location-box">
<a class="close pull-right" {{action "hide"}}>{{d-icon "times"}}</a>
+ <a class="btn pull-right" {{action "copy"}}>{{d-icon "copy"}}</a>
<h4>{{i18n 'ip_lookup.title'}}</h4>
<p class='powered-by'>{{{i18n 'ip_lookup.powered_by'}}}</p>
<dl>