mirror of
https://github.com/discourse/discourse.git
synced 2024-12-16 23:13:53 +08:00
5ccf581e1e
- Removed trailing whitespaces caused by textarea. - Clicking the Copy button will show "copied" for 2 seconds.
131 lines
3.6 KiB
JavaScript
131 lines
3.6 KiB
JavaScript
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"],
|
|
|
|
city: function() {
|
|
return [
|
|
this.get("location.city"),
|
|
this.get("location.region"),
|
|
this.get("location.country")
|
|
]
|
|
.filter(Boolean)
|
|
.join(", ");
|
|
}.property("location.{city,region,country}"),
|
|
|
|
otherAccountsToDelete: function() {
|
|
// can only delete up to 50 accounts at a time
|
|
var total = Math.min(50, this.get("totalOthersWithSameIP") || 0);
|
|
var visible = Math.min(50, this.get("other_accounts.length") || 0);
|
|
return Math.max(visible, total);
|
|
}.property("other_accounts", "totalOthersWithSameIP"),
|
|
|
|
actions: {
|
|
lookup: function() {
|
|
var self = this;
|
|
this.set("show", true);
|
|
|
|
if (!this.get("location")) {
|
|
ajax("/admin/users/ip-info", {
|
|
data: { ip: this.get("ip") }
|
|
}).then(function(location) {
|
|
self.set("location", Em.Object.create(location));
|
|
});
|
|
}
|
|
|
|
if (!this.get("other_accounts")) {
|
|
this.set("otherAccountsLoading", true);
|
|
|
|
var data = {
|
|
ip: this.get("ip"),
|
|
exclude: this.get("userId"),
|
|
order: "trust_level DESC"
|
|
};
|
|
|
|
ajax("/admin/users/total-others-with-same-ip", { data }).then(function(
|
|
result
|
|
) {
|
|
self.set("totalOthersWithSameIP", result.total);
|
|
});
|
|
|
|
AdminUser.findAll("active", data).then(function(users) {
|
|
self.setProperties({
|
|
other_accounts: users,
|
|
otherAccountsLoading: false
|
|
});
|
|
});
|
|
}
|
|
},
|
|
|
|
hide: function() {
|
|
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 = $('<p id="copy-range"></p>');
|
|
copyRange.html(text.trim().replace("\n", "<br>"));
|
|
$(document.body).append(copyRange);
|
|
if (copyText(text, copyRange[0])) {
|
|
this.set("copied", true);
|
|
Ember.run.later(() => this.set("copied", false), 2000);
|
|
}
|
|
copyRange.remove();
|
|
},
|
|
|
|
deleteOtherAccounts: function() {
|
|
var self = this;
|
|
bootbox.confirm(
|
|
I18n.t("ip_lookup.confirm_delete_other_accounts"),
|
|
I18n.t("no_value"),
|
|
I18n.t("yes_value"),
|
|
function(confirmed) {
|
|
if (confirmed) {
|
|
self.setProperties({
|
|
other_accounts: null,
|
|
otherAccountsLoading: true,
|
|
totalOthersWithSameIP: null
|
|
});
|
|
|
|
ajax("/admin/users/delete-others-with-same-ip.json", {
|
|
type: "DELETE",
|
|
data: {
|
|
ip: self.get("ip"),
|
|
exclude: self.get("userId"),
|
|
order: "trust_level DESC"
|
|
}
|
|
}).then(function() {
|
|
self.send("lookup");
|
|
});
|
|
}
|
|
}
|
|
);
|
|
}
|
|
}
|
|
});
|