2019-10-24 01:06:54 +08:00
|
|
|
import Controller from "@ember/controller";
|
2020-05-14 04:23:41 +08:00
|
|
|
import I18n from "I18n";
|
2020-03-11 22:28:16 +08:00
|
|
|
import { INPUT_DELAY } from "discourse-common/config/environment";
|
2015-11-21 09:27:06 +08:00
|
|
|
import ScreenedIpAddress from "admin/models/screened-ip-address";
|
2020-08-27 00:57:13 +08:00
|
|
|
import bootbox from "bootbox";
|
2020-12-18 21:18:52 +08:00
|
|
|
import discourseDebounce from "discourse-common/lib/debounce";
|
2015-07-25 00:33:53 +08:00
|
|
|
import { exportEntity } from "discourse/lib/export-csv";
|
2020-01-17 01:56:53 +08:00
|
|
|
import { observes } from "discourse-common/utils/decorators";
|
2020-03-11 22:28:16 +08:00
|
|
|
import { outputExportResult } from "discourse/lib/export-result";
|
2014-12-07 12:15:22 +08:00
|
|
|
|
2019-10-24 01:06:54 +08:00
|
|
|
export default 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
|
|
|
|
2020-12-18 21:18:52 +08:00
|
|
|
_debouncedShow() {
|
2016-05-19 01:27:39 +08:00
|
|
|
this.set("loading", true);
|
2019-05-27 16:15:39 +08:00
|
|
|
ScreenedIpAddress.findAll(this.filter).then((result) => {
|
2019-01-24 00:40:37 +08:00
|
|
|
this.setProperties({ model: result, loading: false });
|
2016-05-19 01:27:39 +08:00
|
|
|
});
|
2020-12-18 21:18:52 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
@observes("filter")
|
|
|
|
show() {
|
|
|
|
discourseDebounce(this, this._debouncedShow, INPUT_DELAY);
|
|
|
|
},
|
2014-07-23 11:20:45 +08:00
|
|
|
|
|
|
|
actions: {
|
2016-05-19 01:27:39 +08:00
|
|
|
allow(record) {
|
|
|
|
record.set("action_name", "do_nothing");
|
|
|
|
record.save();
|
|
|
|
},
|
|
|
|
|
|
|
|
block(record) {
|
|
|
|
record.set("action_name", "block");
|
|
|
|
record.save();
|
|
|
|
},
|
|
|
|
|
|
|
|
edit(record) {
|
|
|
|
if (!record.get("editing")) {
|
|
|
|
this.set("savedIpAddress", record.get("ip_address"));
|
|
|
|
}
|
|
|
|
record.set("editing", true);
|
|
|
|
},
|
|
|
|
|
|
|
|
cancel(record) {
|
2019-05-27 16:15:39 +08:00
|
|
|
const savedIpAddress = this.savedIpAddress;
|
2019-01-24 00:40:37 +08:00
|
|
|
if (savedIpAddress && record.get("editing")) {
|
|
|
|
record.set("ip_address", savedIpAddress);
|
2016-05-19 01:27:39 +08:00
|
|
|
}
|
|
|
|
record.set("editing", false);
|
|
|
|
},
|
|
|
|
|
|
|
|
save(record) {
|
|
|
|
const wasEditing = record.get("editing");
|
|
|
|
record.set("editing", false);
|
|
|
|
record
|
|
|
|
.save()
|
2019-01-24 00:40:37 +08:00
|
|
|
.then(() => this.set("savedIpAddress", null))
|
2016-05-19 01:27:39 +08:00
|
|
|
.catch((e) => {
|
2018-08-20 23:37:30 +08:00
|
|
|
if (e.jqXHR.responseJSON && e.jqXHR.responseJSON.errors) {
|
2016-05-19 01:27:39 +08:00
|
|
|
bootbox.alert(
|
|
|
|
I18n.t("generic_error_with_reason", {
|
2018-08-20 23:37:30 +08:00
|
|
|
error: e.jqXHR.responseJSON.errors.join(". "),
|
2016-05-19 01:27:39 +08:00
|
|
|
})
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
bootbox.alert(I18n.t("generic_error"));
|
|
|
|
}
|
2020-09-22 22:28:28 +08:00
|
|
|
if (wasEditing) {
|
|
|
|
record.set("editing", true);
|
|
|
|
}
|
2016-05-19 01:27:39 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy(record) {
|
|
|
|
return bootbox.confirm(
|
|
|
|
I18n.t("admin.logs.screened_ips.delete_confirm", {
|
|
|
|
ip_address: record.get("ip_address"),
|
|
|
|
}),
|
|
|
|
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) {
|
|
|
|
record
|
|
|
|
.destroy()
|
|
|
|
.then((deleted) => {
|
|
|
|
if (deleted) {
|
2019-05-27 16:15:39 +08:00
|
|
|
this.model.removeObject(record);
|
2016-05-19 01:27:39 +08:00
|
|
|
} else {
|
|
|
|
bootbox.alert(I18n.t("generic_error"));
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch((e) => {
|
|
|
|
bootbox.alert(
|
|
|
|
I18n.t("generic_error_with_reason", {
|
2019-01-24 00:40:37 +08:00
|
|
|
error: `http: ${e.status} - ${e.body}`,
|
2016-05-19 01:27:39 +08:00
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2015-02-11 06:20:16 +08:00
|
|
|
recordAdded(arg) {
|
2019-05-27 16:15:39 +08:00
|
|
|
this.model.unshiftObject(arg);
|
2014-11-25 00:25:48 +08:00
|
|
|
},
|
|
|
|
|
2015-02-11 06:20:16 +08:00
|
|
|
rollUp() {
|
2014-11-25 02:38:47 +08:00
|
|
|
return bootbox.confirm(
|
|
|
|
I18n.t("admin.logs.screened_ips.roll_up_confirm"),
|
|
|
|
I18n.t("no_value"),
|
|
|
|
I18n.t("yes_value"),
|
2019-01-24 00:40:37 +08:00
|
|
|
(confirmed) => {
|
2014-11-25 02:38:47 +08:00
|
|
|
if (confirmed) {
|
2019-01-24 00:40:37 +08:00
|
|
|
this.set("loading", true);
|
|
|
|
return ScreenedIpAddress.rollUp().then((results) => {
|
2014-11-28 02:29:30 +08:00
|
|
|
if (results && results.subnets) {
|
|
|
|
if (results.subnets.length > 0) {
|
2019-01-24 00:40:37 +08:00
|
|
|
this.send("show");
|
2014-11-28 02:29:30 +08:00
|
|
|
bootbox.alert(
|
|
|
|
I18n.t("admin.logs.screened_ips.rolled_up_some_subnets", {
|
|
|
|
subnets: results.subnets.join(", "),
|
|
|
|
})
|
|
|
|
);
|
|
|
|
} else {
|
2019-01-24 00:40:37 +08:00
|
|
|
this.set("loading", false);
|
2014-11-28 02:29:30 +08:00
|
|
|
bootbox.alert(
|
|
|
|
I18n.t("admin.logs.screened_ips.rolled_up_no_subnet")
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
}
|
2014-11-28 02:29:30 +08:00
|
|
|
}
|
2014-11-25 02:38:47 +08:00
|
|
|
});
|
2018-06-15 23:03:24 +08:00
|
|
|
}
|
2014-11-25 02:38:47 +08:00
|
|
|
}
|
2014-11-25 00:25:48 +08:00
|
|
|
);
|
2014-12-07 12:15:22 +08:00
|
|
|
},
|
|
|
|
|
2015-02-11 06:20:16 +08:00
|
|
|
exportScreenedIpList() {
|
2015-07-25 00:33:53 +08:00
|
|
|
exportEntity("screened_ip").then(outputExportResult);
|
2014-07-23 11:20:45 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|