discourse/app/assets/javascripts/admin/components/ip-lookup.js.es6

86 lines
2.4 KiB
Plaintext
Raw Normal View History

2016-06-30 13:55:44 -04:00
import { ajax } from 'discourse/lib/ajax';
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")) {
2016-06-30 13:55:44 -04:00
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")) {
2014-11-17 12:17:24 -05:00
this.set("otherAccountsLoading", true);
var data = {
"ip": this.get("ip"),
2014-11-24 12:04:34 -05:00
"exclude": this.get("userId"),
"order": "trust_level DESC"
};
2016-06-30 13:55:44 -04:00
ajax("/admin/users/total-others-with-same-ip", { data }).then(function (result) {
self.set("totalOthersWithSameIP", result.total);
});
const AdminUser = require('admin/models/admin-user').default;
AdminUser.findAll("active", data).then(function (users) {
self.setProperties({
other_accounts: users,
2014-11-17 12:17:24 -05:00
otherAccountsLoading: false,
});
});
}
},
hide: function () {
this.set("show", false);
},
2014-11-24 12:04:34 -05:00
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
});
2016-06-30 13:55:44 -04:00
ajax("/admin/users/delete-others-with-same-ip.json", {
type: "DELETE",
data: {
"ip": self.get("ip"),
2014-11-24 12:04:34 -05:00
"exclude": self.get("userId"),
"order": "trust_level DESC"
}
}).then(function() {
self.send("lookup");
});
}
});
}
}
});