mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-02-17 04:01:29 -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({
|
export default Ember.ArrayController.extend({
|
||||||
loading: false,
|
loading: false,
|
||||||
itemController: 'admin-log-screened-ip-address',
|
|
||||||
filter: null,
|
filter: null,
|
||||||
|
savedIpAddress: null,
|
||||||
|
|
||||||
show: debounce(function() {
|
show: debounce(function() {
|
||||||
var self = this;
|
this.set('loading', true);
|
||||||
self.set('loading', true);
|
ScreenedIpAddress.findAll(this.get("filter"))
|
||||||
ScreenedIpAddress.findAll(this.get("filter")).then(function(result) {
|
.then(result => {
|
||||||
self.set('model', result);
|
this.set('model', result);
|
||||||
self.set('loading', false);
|
this.set('loading', false);
|
||||||
});
|
});
|
||||||
}, 250).observes("filter"),
|
}, 250).observes("filter"),
|
||||||
|
|
||||||
actions: {
|
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) {
|
recordAdded(arg) {
|
||||||
this.get("model").unshiftObject(arg);
|
this.get("model").unshiftObject(arg);
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,38 +1,37 @@
|
||||||
|
import computed from 'ember-addons/ember-computed-decorators';
|
||||||
|
|
||||||
const ScreenedIpAddress = Discourse.Model.extend({
|
const ScreenedIpAddress = Discourse.Model.extend({
|
||||||
actionName: function() {
|
@computed("action_name")
|
||||||
return I18n.t("admin.logs.screened_ips.actions." + this.get('action_name'));
|
actionName(actionName) {
|
||||||
}.property('action_name'),
|
return I18n.t(`admin.logs.screened_ips.actions.${actionName}`);
|
||||||
|
},
|
||||||
|
|
||||||
isBlocked: function() {
|
isBlocked: Ember.computed.equal("action_name", "block"),
|
||||||
return (this.get('action_name') === 'block');
|
|
||||||
}.property('action_name'),
|
|
||||||
|
|
||||||
actionIcon: function() {
|
@computed("ip_address")
|
||||||
return (this.get('action_name') === 'block') ? 'ban' : 'check';
|
isRange(ipAddress) {
|
||||||
}.property('action_name'),
|
return ipAddress.indexOf("/") > 0;
|
||||||
|
},
|
||||||
|
|
||||||
save: function() {
|
save() {
|
||||||
return Discourse.ajax("/admin/logs/screened_ip_addresses" + (this.id ? '/' + this.id : '') + ".json", {
|
return Discourse.ajax("/admin/logs/screened_ip_addresses" + (this.id ? '/' + this.id : '') + ".json", {
|
||||||
type: this.id ? 'PUT' : 'POST',
|
type: this.id ? 'PUT' : 'POST',
|
||||||
data: {ip_address: this.get('ip_address'), action_name: this.get('action_name')}
|
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'});
|
return Discourse.ajax("/admin/logs/screened_ip_addresses/" + this.get('id') + ".json", {type: 'DELETE'});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ScreenedIpAddress.reopenClass({
|
ScreenedIpAddress.reopenClass({
|
||||||
findAll: function(filter) {
|
findAll(filter) {
|
||||||
return Discourse.ajax("/admin/logs/screened_ip_addresses.json", { data: { filter: filter } }).then(function(screened_ips) {
|
return Discourse.ajax("/admin/logs/screened_ip_addresses.json", { data: { filter: filter } })
|
||||||
return screened_ips.map(function(b) {
|
.then(screened_ips => screened_ips.map(b => ScreenedIpAddress.create(b)));
|
||||||
return ScreenedIpAddress.create(b);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
rollUp: function() {
|
rollUp() {
|
||||||
return Discourse.ajax("/admin/logs/screened_ip_addresses/roll_up", { type: "POST" });
|
return Discourse.ajax("/admin/logs/screened_ip_addresses/roll_up", { type: "POST" });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
export default Discourse.Route.extend({
|
export default Discourse.Route.extend({
|
||||||
renderTemplate: function() {
|
renderTemplate() {
|
||||||
this.render('admin/templates/logs/screened_ip_addresses', {into: 'adminLogs'});
|
this.render('admin/templates/logs/screened_ip_addresses', {into: 'adminLogs'});
|
||||||
},
|
},
|
||||||
|
|
||||||
setupController: function() {
|
setupController() {
|
||||||
return this.controllerFor('adminLogsScreenedIpAddresses').show();
|
return this.controllerFor('adminLogsScreenedIpAddresses').show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -12,7 +12,11 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
<div class="col action">
|
<div class="col action">
|
||||||
{{fa-icon actionIcon}}
|
{{#if isBlocked}}
|
||||||
|
{{fa-icon "ban"}}
|
||||||
|
{{else}}
|
||||||
|
{{fa-icon "check"}}
|
||||||
|
{{/if}}
|
||||||
{{actionName}}
|
{{actionName}}
|
||||||
</div>
|
</div>
|
||||||
<div class="col match_count">{{match_count}}</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 created_at">{{age-with-tooltip created_at}}</div>
|
||||||
<div class="col actions">
|
<div class="col actions">
|
||||||
{{#unless editing}}
|
{{#unless editing}}
|
||||||
<button class="btn btn-danger" {{action "destroy" this}}><i class="fa fa-trash-o"></i></button>
|
{{d-button action="destroy" actionParam=this icon="trash-o" class="btn-danger"}}
|
||||||
<button class="btn" {{action "edit" this}}><i class="fa fa-pencil"></i></button>
|
{{d-button action="edit" actionParam=this icon="pencil"}}
|
||||||
{{#if isBlocked}}
|
{{#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}}
|
{{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}}
|
{{/if}}
|
||||||
{{else}}
|
{{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>
|
<a {{action "cancel" this}}>{{i18n 'cancel'}}</a>
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue