2023-03-17 18:18:42 +08:00
|
|
|
import { equal } from "@ember/object/computed";
|
2019-11-09 03:13:35 +08:00
|
|
|
import EmberObject from "@ember/object";
|
2020-05-14 04:23:41 +08:00
|
|
|
import I18n from "I18n";
|
2016-07-01 01:55:44 +08:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2019-11-08 05:38:28 +08:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2016-05-19 01:27:39 +08:00
|
|
|
|
2023-03-17 18:18:42 +08: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-08 05:38:28 +08:00
|
|
|
@discourseComputed("action_name")
|
2016-05-19 01:27:39 +08:00
|
|
|
actionName(actionName) {
|
|
|
|
return I18n.t(`admin.logs.screened_ips.actions.${actionName}`);
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2013-10-23 04:30:30 +08:00
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("ip_address")
|
2016-05-19 01:27:39 +08:00
|
|
|
isRange(ipAddress) {
|
|
|
|
return ipAddress.indexOf("/") > 0;
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2013-10-23 04:30:30 +08:00
|
|
|
|
2016-05-19 01:27:39 +08:00
|
|
|
save() {
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax(
|
|
|
|
"/admin/logs/screened_ip_addresses" +
|
|
|
|
(this.id ? "/" + this.id : "") +
|
|
|
|
".json",
|
|
|
|
{
|
2013-10-25 05:18:10 +08:00
|
|
|
type: this.id ? "PUT" : "POST",
|
|
|
|
data: {
|
2019-05-27 16:15:39 +08:00
|
|
|
ip_address: this.ip_address,
|
|
|
|
action_name: this.action_name,
|
2013-10-23 04:30:30 +08:00
|
|
|
},
|
2018-06-15 23:03:24 +08:00
|
|
|
}
|
2013-10-23 04:30:30 +08:00
|
|
|
);
|
2023-03-17 18:18:42 +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",
|
|
|
|
});
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
|
|
|
}
|