2015-08-10 17:11:27 -04:00
|
|
|
import debounce from 'discourse/lib/debounce';
|
2014-12-22 11:17:04 -05:00
|
|
|
import { outputExportResult } from 'discourse/lib/export-result';
|
2015-07-24 12:33:53 -04:00
|
|
|
import { exportEntity } from 'discourse/lib/export-csv';
|
2015-11-20 20:27:06 -05:00
|
|
|
import ScreenedIpAddress from 'admin/models/screened-ip-address';
|
2014-12-06 23:15:22 -05:00
|
|
|
|
2015-05-12 04:49:05 -04:00
|
|
|
export default Ember.ArrayController.extend({
|
2014-07-22 23:20:45 -04:00
|
|
|
loading: false,
|
2015-02-10 13:38:59 -05:00
|
|
|
filter: null,
|
2016-05-18 13:27:39 -04:00
|
|
|
savedIpAddress: null,
|
2014-07-22 23:20:45 -04:00
|
|
|
|
2015-08-10 17:11:27 -04:00
|
|
|
show: debounce(function() {
|
2016-05-18 13:27:39 -04:00
|
|
|
this.set('loading', true);
|
|
|
|
ScreenedIpAddress.findAll(this.get("filter"))
|
|
|
|
.then(result => {
|
|
|
|
this.set('model', result);
|
|
|
|
this.set('loading', false);
|
|
|
|
});
|
2015-02-10 13:38:59 -05:00
|
|
|
}, 250).observes("filter"),
|
2014-07-22 23:20:45 -04:00
|
|
|
|
|
|
|
actions: {
|
2016-05-18 13:27:39 -04:00
|
|
|
allow(record) {
|
|
|
|
record.set('action_name', 'do_nothing');
|
|
|
|
record.save();
|
|
|
|
},
|
|
|
|
|
|
|
|
block(record) {
|
|
|
|
record.set('action_name', 'block');
|
|
|
|
record.save();
|
|
|
|
},
|
|
|
|
|
|
|
|
edit(record) {
|
|
|
|
if (!record.get('editing')) {
|
|
|
|
this.set("savedIpAddress", record.get('ip_address'));
|
|
|
|
}
|
|
|
|
record.set('editing', true);
|
|
|
|
},
|
|
|
|
|
|
|
|
cancel(record) {
|
|
|
|
if (this.get('savedIpAddress') && record.get('editing')) {
|
|
|
|
record.set('ip_address', this.get('savedIpAddress'));
|
|
|
|
}
|
|
|
|
record.set('editing', false);
|
|
|
|
},
|
|
|
|
|
|
|
|
save(record) {
|
|
|
|
const wasEditing = record.get('editing');
|
|
|
|
record.set('editing', false);
|
|
|
|
record.save().then(saved => {
|
|
|
|
if (saved.success) {
|
|
|
|
this.set('savedIpAddress', null);
|
|
|
|
} else {
|
|
|
|
bootbox.alert(saved.errors);
|
|
|
|
if (wasEditing) record.set('editing', true);
|
|
|
|
}
|
|
|
|
}).catch(e => {
|
|
|
|
if (e.responseJSON && e.responseJSON.errors) {
|
|
|
|
bootbox.alert(I18n.t("generic_error_with_reason", {error: e.responseJSON.errors.join('. ')}));
|
|
|
|
} else {
|
|
|
|
bootbox.alert(I18n.t("generic_error"));
|
|
|
|
}
|
|
|
|
if (wasEditing) record.set('editing', true);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy(record) {
|
|
|
|
const self = this;
|
|
|
|
return bootbox.confirm(
|
|
|
|
I18n.t("admin.logs.screened_ips.delete_confirm", { ip_address: record.get('ip_address') }),
|
|
|
|
I18n.t("no_value"),
|
|
|
|
I18n.t("yes_value"),
|
|
|
|
function (result) {
|
|
|
|
if (result) {
|
|
|
|
record.destroy().then(deleted => {
|
|
|
|
if (deleted) {
|
|
|
|
self.get("content").removeObject(record);
|
|
|
|
} else {
|
|
|
|
bootbox.alert(I18n.t("generic_error"));
|
|
|
|
}
|
|
|
|
}).catch(e => {
|
|
|
|
bootbox.alert(I18n.t("generic_error_with_reason", {error: "http: " + e.status + " - " + e.body}));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2015-02-10 17:20:16 -05:00
|
|
|
recordAdded(arg) {
|
2014-10-31 17:35:27 -04:00
|
|
|
this.get("model").unshiftObject(arg);
|
2014-11-24 11:25:48 -05:00
|
|
|
},
|
|
|
|
|
2015-02-10 17:20:16 -05:00
|
|
|
rollUp() {
|
|
|
|
const self = this;
|
2014-11-24 13:38:47 -05:00
|
|
|
return bootbox.confirm(I18n.t("admin.logs.screened_ips.roll_up_confirm"), I18n.t("no_value"), I18n.t("yes_value"), function (confirmed) {
|
|
|
|
if (confirmed) {
|
2015-02-10 17:20:16 -05:00
|
|
|
self.set("loading", true);
|
2015-11-20 20:27:06 -05:00
|
|
|
return ScreenedIpAddress.rollUp().then(function(results) {
|
2014-11-27 13:29:30 -05:00
|
|
|
if (results && results.subnets) {
|
|
|
|
if (results.subnets.length > 0) {
|
|
|
|
self.send("show");
|
|
|
|
bootbox.alert(I18n.t("admin.logs.screened_ips.rolled_up_some_subnets", { subnets: results.subnets.join(", ") }));
|
|
|
|
} else {
|
|
|
|
self.set("loading", false);
|
|
|
|
bootbox.alert(I18n.t("admin.logs.screened_ips.rolled_up_no_subnet"));
|
|
|
|
}
|
|
|
|
}
|
2014-11-24 13:38:47 -05:00
|
|
|
});
|
|
|
|
}
|
2014-11-24 11:25:48 -05:00
|
|
|
});
|
2014-12-06 23:15:22 -05:00
|
|
|
},
|
|
|
|
|
2015-02-10 17:20:16 -05:00
|
|
|
exportScreenedIpList() {
|
2015-07-24 12:33:53 -04:00
|
|
|
exportEntity('screened_ip').then(outputExportResult);
|
2014-07-22 23:20:45 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|