mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
FIX: manually blocking/whitelisting an IP address wasn't working
This commit is contained in:
parent
5eff3153e5
commit
1704a362ef
4 changed files with 83 additions and 84 deletions
|
@ -1,79 +0,0 @@
|
||||||
import ScreenedIpAddress from 'admin/models/screened-ip-address';
|
|
||||||
/**
|
|
||||||
A form to create an IP address that will be blocked or whitelisted.
|
|
||||||
Example usage:
|
|
||||||
|
|
||||||
{{screened-ip-address-form action="recordAdded"}}
|
|
||||||
|
|
||||||
where action is a callback on the controller or route that will get called after
|
|
||||||
the new record is successfully saved. It is called with the new ScreenedIpAddress record
|
|
||||||
as an argument.
|
|
||||||
|
|
||||||
@class ScreenedIpAddressFormComponent
|
|
||||||
@extends Ember.Component
|
|
||||||
@namespace Discourse
|
|
||||||
@module Discourse
|
|
||||||
**/
|
|
||||||
const ScreenedIpAddressFormComponent = Ember.Component.extend({
|
|
||||||
classNames: ['screened-ip-address-form'],
|
|
||||||
formSubmitted: false,
|
|
||||||
actionName: 'block',
|
|
||||||
|
|
||||||
adminWhitelistEnabled: function() {
|
|
||||||
return Discourse.SiteSettings.use_admin_ip_whitelist;
|
|
||||||
}.property(),
|
|
||||||
|
|
||||||
actionNames: function() {
|
|
||||||
if (this.get('adminWhitelistEnabled')) {
|
|
||||||
return [
|
|
||||||
{id: 'block', name: I18n.t('admin.logs.screened_ips.actions.block')},
|
|
||||||
{id: 'do_nothing', name: I18n.t('admin.logs.screened_ips.actions.do_nothing')},
|
|
||||||
{id: 'allow_admin', name: I18n.t('admin.logs.screened_ips.actions.allow_admin')}
|
|
||||||
];
|
|
||||||
} else {
|
|
||||||
return [
|
|
||||||
{id: 'block', name: I18n.t('admin.logs.screened_ips.actions.block')},
|
|
||||||
{id: 'do_nothing', name: I18n.t('admin.logs.screened_ips.actions.do_nothing')}
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}.property('adminWhitelistEnabled'),
|
|
||||||
|
|
||||||
actions: {
|
|
||||||
submit: function() {
|
|
||||||
if (!this.get('formSubmitted')) {
|
|
||||||
var self = this;
|
|
||||||
this.set('formSubmitted', true);
|
|
||||||
var screenedIpAddress = ScreenedIpAddress.create({ip_address: this.get('ip_address'), action_name: this.get('actionName')});
|
|
||||||
screenedIpAddress.save().then(function(result) {
|
|
||||||
self.set('ip_address', '');
|
|
||||||
self.set('formSubmitted', false);
|
|
||||||
self.sendAction('action', ScreenedIpAddress.create(result.screened_ip_address));
|
|
||||||
Em.run.schedule('afterRender', function() { self.$('.ip-address-input').focus(); });
|
|
||||||
}, function(e) {
|
|
||||||
self.set('formSubmitted', false);
|
|
||||||
var msg;
|
|
||||||
if (e.responseJSON && e.responseJSON.errors) {
|
|
||||||
msg = I18n.t("generic_error_with_reason", {error: e.responseJSON.errors.join('. ')});
|
|
||||||
} else {
|
|
||||||
msg = I18n.t("generic_error");
|
|
||||||
}
|
|
||||||
bootbox.alert(msg, function() { self.$('.ip-address-input').focus(); });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
didInsertElement: function() {
|
|
||||||
var self = this;
|
|
||||||
this._super();
|
|
||||||
Em.run.schedule('afterRender', function() {
|
|
||||||
self.$('.ip-address-input').keydown(function(e) {
|
|
||||||
if (e.keyCode === 13) { // enter key
|
|
||||||
self.send('submit');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export default ScreenedIpAddressFormComponent;
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
/**
|
||||||
|
A form to create an IP address that will be blocked or whitelisted.
|
||||||
|
Example usage:
|
||||||
|
|
||||||
|
{{screened-ip-address-form action="recordAdded"}}
|
||||||
|
|
||||||
|
where action is a callback on the controller or route that will get called after
|
||||||
|
the new record is successfully saved. It is called with the new ScreenedIpAddress record
|
||||||
|
as an argument.
|
||||||
|
**/
|
||||||
|
|
||||||
|
import ScreenedIpAddress from 'admin/models/screened-ip-address';
|
||||||
|
import computed from 'ember-addons/ember-computed-decorators';
|
||||||
|
import { on } from 'ember-addons/ember-computed-decorators';
|
||||||
|
|
||||||
|
export default Ember.Component.extend({
|
||||||
|
classNames: ['screened-ip-address-form'],
|
||||||
|
formSubmitted: false,
|
||||||
|
actionName: 'block',
|
||||||
|
|
||||||
|
@computed
|
||||||
|
adminWhitelistEnabled() {
|
||||||
|
return Discourse.SiteSettings.use_admin_ip_whitelist;
|
||||||
|
},
|
||||||
|
|
||||||
|
@computed("adminWhitelistEnabled")
|
||||||
|
actionNames(adminWhitelistEnabled) {
|
||||||
|
if (adminWhitelistEnabled) {
|
||||||
|
return [
|
||||||
|
{id: 'block', name: I18n.t('admin.logs.screened_ips.actions.block')},
|
||||||
|
{id: 'do_nothing', name: I18n.t('admin.logs.screened_ips.actions.do_nothing')},
|
||||||
|
{id: 'allow_admin', name: I18n.t('admin.logs.screened_ips.actions.allow_admin')}
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
return [
|
||||||
|
{id: 'block', name: I18n.t('admin.logs.screened_ips.actions.block')},
|
||||||
|
{id: 'do_nothing', name: I18n.t('admin.logs.screened_ips.actions.do_nothing')}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
submit() {
|
||||||
|
if (!this.get('formSubmitted')) {
|
||||||
|
this.set('formSubmitted', true);
|
||||||
|
const screenedIpAddress = ScreenedIpAddress.create({
|
||||||
|
ip_address: this.get('ip_address'),
|
||||||
|
action_name: this.get('actionName')
|
||||||
|
});
|
||||||
|
screenedIpAddress.save().then(result => {
|
||||||
|
this.setProperties({ ip_address: '', formSubmitted: false });
|
||||||
|
this.sendAction('action', ScreenedIpAddress.create(result.screened_ip_address));
|
||||||
|
Ember.run.schedule('afterRender', () => this.$('.ip-address-input').focus());
|
||||||
|
}).catch(e => {
|
||||||
|
this.set('formSubmitted', false);
|
||||||
|
const msg = (e.responseJSON && e.responseJSON.errors) ?
|
||||||
|
I18n.t("generic_error_with_reason", {error: e.responseJSON.errors.join('. ')}) :
|
||||||
|
I18n.t("generic_error");
|
||||||
|
bootbox.alert(msg, () => this.$('.ip-address-input').focus());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
@on("didInsertElement")
|
||||||
|
_init() {
|
||||||
|
Ember.run.schedule('afterRender', () => {
|
||||||
|
this.$('.ip-address-input').keydown(e => {
|
||||||
|
if (e.keyCode === 13) {
|
||||||
|
this.send('submit');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
|
@ -1,4 +1,4 @@
|
||||||
<b>{{i18n 'admin.logs.screened_ips.form.label'}}</b>
|
<b>{{i18n 'admin.logs.screened_ips.form.label'}}</b>
|
||||||
{{text-field value=ip_address disabled=formSubmitted class="ip-address-input" placeholderKey="admin.logs.screened_ips.form.ip_address" autocorrect="off" autocapitalize="off"}}
|
{{text-field value=ip_address disabled=formSubmitted class="ip-address-input" placeholderKey="admin.logs.screened_ips.form.ip_address" autocorrect="off" autocapitalize="off"}}
|
||||||
{{combo-box content=actionNames value=actionName}}
|
{{combo-box content=actionNames value=actionName}}
|
||||||
<button class="btn" {{action "submit" target="view"}} {{bind-attr disabled="formSubmitted"}}>{{i18n 'admin.logs.screened_ips.form.add'}}</button>
|
{{d-button action="submit" disabled=formSubmitted label="admin.logs.screened_ips.form.add"}}
|
|
@ -1,11 +1,14 @@
|
||||||
<p>{{i18n 'admin.logs.screened_ips.description'}}</p>
|
<p>{{i18n 'admin.logs.screened_ips.description'}}</p>
|
||||||
|
|
||||||
<div class="pull-right">
|
<div class="pull-right">
|
||||||
{{text-field value=filter class="ip-address-input" placeholderKey="admin.logs.screened_ips.form.filter" autocorrect="off" autocapitalize="off"}}
|
{{text-field value=filter class="ip-address-input" placeholderKey="admin.logs.screened_ips.form.filter" autocorrect="off" autocapitalize="off"}}
|
||||||
<button class="btn" {{action "rollUp"}} title="{{i18n 'admin.logs.screened_ips.roll_up.title'}}">{{i18n 'admin.logs.screened_ips.roll_up.text'}}</button>
|
{{d-button action="rollUp" title="admin.logs.screened_ips.roll_up.title" label="admin.logs.screened_ips.roll_up.text"}}
|
||||||
<button class="btn" {{action "exportScreenedIpList"}} title="{{i18n 'admin.export_csv.button_title.screened_ip'}}">{{fa-icon "download"}}{{i18n 'admin.export_csv.button_text'}}</button>
|
{{d-button action="exportScreenedIpList" icon="download" title="admin.export_csv.button_title.screened_ip" label="admin.export_csv.button_text"}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{{screened-ip-address-form action="recordAdded"}}
|
||||||
</div>
|
</div>
|
||||||
{{screened-ip-address-form action="recordAdded"}}
|
|
||||||
<br/>
|
|
||||||
|
|
||||||
{{#conditional-loading-spinner condition=loading}}
|
{{#conditional-loading-spinner condition=loading}}
|
||||||
{{#if model.length}}
|
{{#if model.length}}
|
||||||
|
|
Loading…
Reference in a new issue