mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
FIX: screened IP addresses list wasn't working anymore - TAKE 2
This commit is contained in:
parent
d2e0ee6222
commit
d6ab54378c
5 changed files with 102 additions and 105 deletions
|
@ -1,72 +0,0 @@
|
|||
export default Ember.Controller.extend({
|
||||
editing: false,
|
||||
savedIpAddress: null,
|
||||
|
||||
isRange: function() {
|
||||
return this.get("model.ip_address").indexOf("/") > 0;
|
||||
}.property("model.ip_address"),
|
||||
|
||||
actions: {
|
||||
allow: function(record) {
|
||||
record.set('action_name', 'do_nothing');
|
||||
this.send('save', record);
|
||||
},
|
||||
|
||||
block: function(record) {
|
||||
record.set('action_name', 'block');
|
||||
this.send('save', record);
|
||||
},
|
||||
|
||||
edit: function() {
|
||||
if (!this.get('editing')) {
|
||||
this.savedIpAddress = this.get('model.ip_address');
|
||||
}
|
||||
this.set('editing', true);
|
||||
},
|
||||
|
||||
cancel: function() {
|
||||
if (this.get('savedIpAddress') && this.get('editing')) {
|
||||
this.set('model.ip_address', this.get('savedIpAddress'));
|
||||
}
|
||||
this.set('editing', false);
|
||||
},
|
||||
|
||||
save: function(record) {
|
||||
var self = this;
|
||||
var wasEditing = this.get('editing');
|
||||
this.set('editing', false);
|
||||
record.save().then(function(saved){
|
||||
if (saved.success) {
|
||||
self.set('savedIpAddress', null);
|
||||
} else {
|
||||
bootbox.alert(saved.errors);
|
||||
if (wasEditing) self.set('editing', true);
|
||||
}
|
||||
}, function(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) self.set('editing', true);
|
||||
});
|
||||
},
|
||||
|
||||
destroy: function(record) {
|
||||
var 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(function(deleted) {
|
||||
if (deleted) {
|
||||
self.get("parentController.content").removeObject(record);
|
||||
} else {
|
||||
bootbox.alert(I18n.t("generic_error"));
|
||||
}
|
||||
}, function(e){
|
||||
bootbox.alert(I18n.t("generic_error_with_reason", {error: "http: " + e.status + " - " + e.body}));
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
|
@ -5,19 +5,85 @@ import ScreenedIpAddress from 'admin/models/screened-ip-address';
|
|||
|
||||
export default Ember.ArrayController.extend({
|
||||
loading: false,
|
||||
itemController: 'admin-log-screened-ip-address',
|
||||
filter: null,
|
||||
savedIpAddress: null,
|
||||
|
||||
show: debounce(function() {
|
||||
var self = this;
|
||||
self.set('loading', true);
|
||||
ScreenedIpAddress.findAll(this.get("filter")).then(function(result) {
|
||||
self.set('model', result);
|
||||
self.set('loading', false);
|
||||
});
|
||||
this.set('loading', true);
|
||||
ScreenedIpAddress.findAll(this.get("filter"))
|
||||
.then(result => {
|
||||
this.set('model', result);
|
||||
this.set('loading', false);
|
||||
});
|
||||
}, 250).observes("filter"),
|
||||
|
||||
actions: {
|
||||
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}));
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
recordAdded(arg) {
|
||||
this.get("model").unshiftObject(arg);
|
||||
},
|
||||
|
|
|
@ -1,38 +1,37 @@
|
|||
import computed from 'ember-addons/ember-computed-decorators';
|
||||
|
||||
const ScreenedIpAddress = Discourse.Model.extend({
|
||||
actionName: function() {
|
||||
return I18n.t("admin.logs.screened_ips.actions." + this.get('action_name'));
|
||||
}.property('action_name'),
|
||||
@computed("action_name")
|
||||
actionName(actionName) {
|
||||
return I18n.t(`admin.logs.screened_ips.actions.${actionName}`);
|
||||
},
|
||||
|
||||
isBlocked: function() {
|
||||
return (this.get('action_name') === 'block');
|
||||
}.property('action_name'),
|
||||
isBlocked: Ember.computed.equal("action_name", "block"),
|
||||
|
||||
actionIcon: function() {
|
||||
return (this.get('action_name') === 'block') ? 'ban' : 'check';
|
||||
}.property('action_name'),
|
||||
@computed("ip_address")
|
||||
isRange(ipAddress) {
|
||||
return ipAddress.indexOf("/") > 0;
|
||||
},
|
||||
|
||||
save: function() {
|
||||
save() {
|
||||
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')}
|
||||
});
|
||||
},
|
||||
|
||||
destroy: function() {
|
||||
destroy() {
|
||||
return Discourse.ajax("/admin/logs/screened_ip_addresses/" + this.get('id') + ".json", {type: 'DELETE'});
|
||||
}
|
||||
});
|
||||
|
||||
ScreenedIpAddress.reopenClass({
|
||||
findAll: function(filter) {
|
||||
return Discourse.ajax("/admin/logs/screened_ip_addresses.json", { data: { filter: filter } }).then(function(screened_ips) {
|
||||
return screened_ips.map(function(b) {
|
||||
return ScreenedIpAddress.create(b);
|
||||
});
|
||||
});
|
||||
findAll(filter) {
|
||||
return Discourse.ajax("/admin/logs/screened_ip_addresses.json", { data: { filter: filter } })
|
||||
.then(screened_ips => screened_ips.map(b => ScreenedIpAddress.create(b)));
|
||||
},
|
||||
|
||||
rollUp: function() {
|
||||
rollUp() {
|
||||
return Discourse.ajax("/admin/logs/screened_ip_addresses/roll_up", { type: "POST" });
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
export default Discourse.Route.extend({
|
||||
renderTemplate: function() {
|
||||
renderTemplate() {
|
||||
this.render('admin/templates/logs/screened_ip_addresses', {into: 'adminLogs'});
|
||||
},
|
||||
|
||||
setupController: function() {
|
||||
setupController() {
|
||||
return this.controllerFor('adminLogsScreenedIpAddresses').show();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -12,7 +12,11 @@
|
|||
{{/if}}
|
||||
</div>
|
||||
<div class="col action">
|
||||
{{fa-icon actionIcon}}
|
||||
{{#if isBlocked}}
|
||||
{{fa-icon "ban"}}
|
||||
{{else}}
|
||||
{{fa-icon "check"}}
|
||||
{{/if}}
|
||||
{{actionName}}
|
||||
</div>
|
||||
<div class="col match_count">{{match_count}}</div>
|
||||
|
@ -24,15 +28,15 @@
|
|||
<div class="col created_at">{{age-with-tooltip created_at}}</div>
|
||||
<div class="col actions">
|
||||
{{#unless editing}}
|
||||
<button class="btn btn-danger" {{action "destroy" this}}><i class="fa fa-trash-o"></i></button>
|
||||
<button class="btn" {{action "edit" this}}><i class="fa fa-pencil"></i></button>
|
||||
{{d-button action="destroy" actionParam=this icon="trash-o" class="btn-danger"}}
|
||||
{{d-button action="edit" actionParam=this icon="pencil"}}
|
||||
{{#if isBlocked}}
|
||||
<button class="btn" {{action "allow" this}}>{{fa-icon "check"}} {{i18n 'admin.logs.screened_ips.actions.do_nothing'}}</button>
|
||||
{{d-button action="allow" actionParam=this icon="check" label="admin.logs.screened_ips.actions.do_nothing"}}
|
||||
{{else}}
|
||||
<button class="btn" {{action "block" this}}>{{fa-icon "ban"}} {{i18n 'admin.logs.screened_ips.actions.block'}}</button>
|
||||
{{d-button action="block" actionParam=this icon="ban" label="admin.logs.screened_ips.actions.block"}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
<button class="btn" {{action "save" this}}>{{i18n 'admin.logs.save'}}</button>
|
||||
{{d-button action="save" actionParam=this label="admin.logs.save"}}
|
||||
<a {{action "cancel" this}}>{{i18n 'cancel'}}</a>
|
||||
{{/unless}}
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue