2019-11-08 14:13:35 -05:00
|
|
|
import EmberObject from "@ember/object";
|
2023-10-10 14:38:59 -04:00
|
|
|
import { equal } from "@ember/object/computed";
|
2016-06-30 13:55:44 -04:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2019-11-07 16:38:28 -05:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2023-10-18 06:07:09 -04:00
|
|
|
import I18n from "discourse-i18n";
|
2016-05-18 13:27:39 -04:00
|
|
|
|
2023-03-17 06:18:42 -04:00
|
|
|
export default class ScreenedIpAddress extends EmberObject {
|
|
|
|
static findAll(filter) {
|
|
|
|
return ajax("/admin/logs/screened_ip_addresses.json", {
|
|
|
|
data: { filter },
|
|
|
|
}).then((screened_ips) =>
|
|
|
|
screened_ips.map((b) => ScreenedIpAddress.create(b))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@equal("action_name", "block") isBlocked;
|
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}`);
|
2023-03-17 06:18:42 -04:00
|
|
|
}
|
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;
|
2023-03-17 06:18:42 -04:00
|
|
|
}
|
2013-10-22 16:30:30 -04:00
|
|
|
|
2016-05-18 13:27:39 -04:00
|
|
|
save() {
|
2016-06-30 13:55:44 -04:00
|
|
|
return ajax(
|
|
|
|
"/admin/logs/screened_ip_addresses" +
|
|
|
|
(this.id ? "/" + this.id : "") +
|
|
|
|
".json",
|
|
|
|
{
|
2013-10-24 17:18:10 -04:00
|
|
|
type: this.id ? "PUT" : "POST",
|
|
|
|
data: {
|
2019-05-27 04:15:39 -04:00
|
|
|
ip_address: this.ip_address,
|
|
|
|
action_name: this.action_name,
|
2013-10-22 16:30:30 -04:00
|
|
|
},
|
2018-06-15 11:03:24 -04:00
|
|
|
}
|
2013-10-22 16:30:30 -04:00
|
|
|
);
|
2023-03-17 06:18:42 -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",
|
|
|
|
});
|
2023-03-17 06:18:42 -04:00
|
|
|
}
|
|
|
|
}
|