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