2019-11-07 16:38:28 -05:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2019-10-30 16:28:29 -04:00
|
|
|
import { equal } from "@ember/object/computed";
|
2018-06-15 11:03:24 -04:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2019-11-08 14:13:35 -05:00
|
|
|
import EmberObject from "@ember/object";
|
2016-05-18 13:27:39 -04:00
|
|
|
|
2019-11-08 14:13:35 -05:00
|
|
|
const ScreenedIpAddress = EmberObject.extend({
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("action_name")
|
2016-05-18 13:27:39 -04:00
|
|
|
actionName(actionName) {
|
|
|
|
return I18n.t(`admin.logs.screened_ips.actions.${actionName}`);
|
|
|
|
},
|
2013-10-22 16:30:30 -04:00
|
|
|
|
2019-10-30 16:28:29 -04:00
|
|
|
isBlocked: equal("action_name", "block"),
|
2013-10-22 16:30:30 -04:00
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("ip_address")
|
2016-05-18 13:27:39 -04:00
|
|
|
isRange(ipAddress) {
|
|
|
|
return ipAddress.indexOf("/") > 0;
|
|
|
|
},
|
2013-10-22 16:30:30 -04:00
|
|
|
|
2016-05-18 13:27:39 -04:00
|
|
|
save() {
|
2018-06-15 11:03:24 -04:00
|
|
|
return ajax(
|
|
|
|
"/admin/logs/screened_ip_addresses" +
|
|
|
|
(this.id ? "/" + this.id : "") +
|
|
|
|
".json",
|
|
|
|
{
|
|
|
|
type: this.id ? "PUT" : "POST",
|
|
|
|
data: {
|
2019-05-27 04:15:39 -04:00
|
|
|
ip_address: this.ip_address,
|
|
|
|
action_name: this.action_name
|
2018-06-15 11:03:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2013-10-22 16:30:30 -04:00
|
|
|
},
|
|
|
|
|
2016-05-18 13:27:39 -04:00
|
|
|
destroy() {
|
2019-05-27 04:42:53 -04:00
|
|
|
return ajax("/admin/logs/screened_ip_addresses/" + this.id + ".json", {
|
|
|
|
type: "DELETE"
|
|
|
|
});
|
2013-10-22 16:30:30 -04:00
|
|
|
}
|
2013-10-21 14:49:51 -04:00
|
|
|
});
|
|
|
|
|
2015-11-20 20:27:06 -05:00
|
|
|
ScreenedIpAddress.reopenClass({
|
2016-05-18 13:27:39 -04:00
|
|
|
findAll(filter) {
|
2018-06-15 11:03:24 -04:00
|
|
|
return ajax("/admin/logs/screened_ip_addresses.json", {
|
|
|
|
data: { filter: filter }
|
|
|
|
}).then(screened_ips => screened_ips.map(b => ScreenedIpAddress.create(b)));
|
2014-11-24 11:25:48 -05:00
|
|
|
},
|
|
|
|
|
2016-05-18 13:27:39 -04:00
|
|
|
rollUp() {
|
2016-06-30 13:55:44 -04:00
|
|
|
return ajax("/admin/logs/screened_ip_addresses/roll_up", { type: "POST" });
|
2013-10-21 14:49:51 -04:00
|
|
|
}
|
|
|
|
});
|
2015-11-20 20:27:06 -05:00
|
|
|
|
|
|
|
export default ScreenedIpAddress;
|