2018-06-15 23:03:24 +08:00
|
|
|
import debounce from "discourse/lib/debounce";
|
|
|
|
import { outputExportResult } from "discourse/lib/export-result";
|
|
|
|
import { exportEntity } from "discourse/lib/export-csv";
|
|
|
|
import ScreenedIpAddress from "admin/models/screened-ip-address";
|
2014-12-07 12:15:22 +08:00
|
|
|
|
2016-10-21 01:26:41 +08:00
|
|
|
export default Ember.Controller.extend({
|
2014-07-23 11:20:45 +08:00
|
|
|
loading: false,
|
2015-02-11 02:38:59 +08:00
|
|
|
filter: null,
|
2016-05-19 01:27:39 +08:00
|
|
|
savedIpAddress: null,
|
2014-07-23 11:20:45 +08:00
|
|
|
|
2015-08-11 05:11:27 +08:00
|
|
|
show: debounce(function() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("loading", true);
|
|
|
|
ScreenedIpAddress.findAll(this.get("filter")).then(result => {
|
|
|
|
this.set("model", result);
|
|
|
|
this.set("loading", false);
|
|
|
|
});
|
2015-02-11 02:38:59 +08:00
|
|
|
}, 250).observes("filter"),
|
2014-07-23 11:20:45 +08:00
|
|
|
|
|
|
|
actions: {
|
2016-05-19 01:27:39 +08:00
|
|
|
allow(record) {
|
2018-06-15 23:03:24 +08:00
|
|
|
record.set("action_name", "do_nothing");
|
2016-05-19 01:27:39 +08:00
|
|
|
record.save();
|
|
|
|
},
|
|
|
|
|
|
|
|
block(record) {
|
2018-06-15 23:03:24 +08:00
|
|
|
record.set("action_name", "block");
|
2016-05-19 01:27:39 +08:00
|
|
|
record.save();
|
|
|
|
},
|
|
|
|
|
|
|
|
edit(record) {
|
2018-06-15 23:03:24 +08:00
|
|
|
if (!record.get("editing")) {
|
|
|
|
this.set("savedIpAddress", record.get("ip_address"));
|
2016-05-19 01:27:39 +08:00
|
|
|
}
|
2018-06-15 23:03:24 +08:00
|
|
|
record.set("editing", true);
|
2016-05-19 01:27:39 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
cancel(record) {
|
2018-06-15 23:03:24 +08:00
|
|
|
if (this.get("savedIpAddress") && record.get("editing")) {
|
|
|
|
record.set("ip_address", this.get("savedIpAddress"));
|
2016-05-19 01:27:39 +08:00
|
|
|
}
|
2018-06-15 23:03:24 +08:00
|
|
|
record.set("editing", false);
|
2016-05-19 01:27:39 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
save(record) {
|
2018-06-15 23:03:24 +08:00
|
|
|
const wasEditing = record.get("editing");
|
|
|
|
record.set("editing", false);
|
|
|
|
record
|
|
|
|
.save()
|
2018-08-20 23:37:30 +08:00
|
|
|
.then(() => {
|
|
|
|
this.set("savedIpAddress", null);
|
2018-06-15 23:03:24 +08:00
|
|
|
})
|
|
|
|
.catch(e => {
|
2018-08-20 23:37:30 +08:00
|
|
|
if (e.jqXHR.responseJSON && e.jqXHR.responseJSON.errors) {
|
2018-06-15 23:03:24 +08:00
|
|
|
bootbox.alert(
|
|
|
|
I18n.t("generic_error_with_reason", {
|
2018-08-20 23:37:30 +08:00
|
|
|
error: e.jqXHR.responseJSON.errors.join(". ")
|
2018-06-15 23:03:24 +08:00
|
|
|
})
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
bootbox.alert(I18n.t("generic_error"));
|
|
|
|
}
|
|
|
|
if (wasEditing) record.set("editing", true);
|
|
|
|
});
|
2016-05-19 01:27:39 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
destroy(record) {
|
|
|
|
return bootbox.confirm(
|
2018-06-15 23:03:24 +08:00
|
|
|
I18n.t("admin.logs.screened_ips.delete_confirm", {
|
|
|
|
ip_address: record.get("ip_address")
|
|
|
|
}),
|
2016-05-19 01:27:39 +08:00
|
|
|
I18n.t("no_value"),
|
|
|
|
I18n.t("yes_value"),
|
2016-10-21 01:26:41 +08:00
|
|
|
result => {
|
2016-05-19 01:27:39 +08:00
|
|
|
if (result) {
|
2018-06-15 23:03:24 +08:00
|
|
|
record
|
|
|
|
.destroy()
|
|
|
|
.then(deleted => {
|
|
|
|
if (deleted) {
|
|
|
|
this.get("model").removeObject(record);
|
|
|
|
} else {
|
|
|
|
bootbox.alert(I18n.t("generic_error"));
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
bootbox.alert(
|
|
|
|
I18n.t("generic_error_with_reason", {
|
|
|
|
error: "http: " + e.status + " - " + e.body
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
2016-05-19 01:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2015-02-11 06:20:16 +08:00
|
|
|
recordAdded(arg) {
|
2014-11-01 05:35:27 +08:00
|
|
|
this.get("model").unshiftObject(arg);
|
2014-11-25 00:25:48 +08:00
|
|
|
},
|
|
|
|
|
2015-02-11 06:20:16 +08:00
|
|
|
rollUp() {
|
|
|
|
const self = this;
|
2018-06-15 23:03:24 +08:00
|
|
|
return bootbox.confirm(
|
|
|
|
I18n.t("admin.logs.screened_ips.roll_up_confirm"),
|
|
|
|
I18n.t("no_value"),
|
|
|
|
I18n.t("yes_value"),
|
|
|
|
function(confirmed) {
|
|
|
|
if (confirmed) {
|
|
|
|
self.set("loading", true);
|
|
|
|
return ScreenedIpAddress.rollUp().then(function(results) {
|
|
|
|
if (results && results.subnets) {
|
|
|
|
if (results.subnets.length > 0) {
|
|
|
|
self.send("show");
|
|
|
|
bootbox.alert(
|
|
|
|
I18n.t("admin.logs.screened_ips.rolled_up_some_subnets", {
|
|
|
|
subnets: results.subnets.join(", ")
|
|
|
|
})
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
self.set("loading", false);
|
|
|
|
bootbox.alert(
|
|
|
|
I18n.t("admin.logs.screened_ips.rolled_up_no_subnet")
|
|
|
|
);
|
|
|
|
}
|
2014-11-28 02:29:30 +08:00
|
|
|
}
|
2018-06-15 23:03:24 +08:00
|
|
|
});
|
|
|
|
}
|
2014-11-25 02:38:47 +08:00
|
|
|
}
|
2018-06-15 23:03:24 +08:00
|
|
|
);
|
2014-12-07 12:15:22 +08:00
|
|
|
},
|
|
|
|
|
2015-02-11 06:20:16 +08:00
|
|
|
exportScreenedIpList() {
|
2018-06-15 23:03:24 +08:00
|
|
|
exportEntity("screened_ip").then(outputExportResult);
|
2014-07-23 11:20:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|