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