2016-05-18 13:27:39 -04:00
|
|
|
import computed from 'ember-addons/ember-computed-decorators';
|
|
|
|
|
2015-11-20 20:27:06 -05:00
|
|
|
const ScreenedIpAddress = Discourse.Model.extend({
|
2016-05-18 13:27:39 -04:00
|
|
|
@computed("action_name")
|
|
|
|
actionName(actionName) {
|
|
|
|
return I18n.t(`admin.logs.screened_ips.actions.${actionName}`);
|
|
|
|
},
|
2013-10-22 16:30:30 -04:00
|
|
|
|
2016-05-18 13:27:39 -04:00
|
|
|
isBlocked: Ember.computed.equal("action_name", "block"),
|
2013-10-22 16:30:30 -04:00
|
|
|
|
2016-05-18 13:27:39 -04:00
|
|
|
@computed("ip_address")
|
|
|
|
isRange(ipAddress) {
|
|
|
|
return ipAddress.indexOf("/") > 0;
|
|
|
|
},
|
2013-10-22 16:30:30 -04:00
|
|
|
|
2016-05-18 13:27:39 -04:00
|
|
|
save() {
|
2013-10-24 17:18:10 -04:00
|
|
|
return Discourse.ajax("/admin/logs/screened_ip_addresses" + (this.id ? '/' + this.id : '') + ".json", {
|
|
|
|
type: this.id ? 'PUT' : 'POST',
|
|
|
|
data: {ip_address: this.get('ip_address'), action_name: this.get('action_name')}
|
2013-10-22 16:30:30 -04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-05-18 13:27:39 -04:00
|
|
|
destroy() {
|
2013-10-22 16:30:30 -04:00
|
|
|
return Discourse.ajax("/admin/logs/screened_ip_addresses/" + this.get('id') + ".json", {type: 'DELETE'});
|
|
|
|
}
|
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) {
|
|
|
|
return Discourse.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() {
|
2014-11-24 11:25:48 -05:00
|
|
|
return Discourse.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;
|