mirror of
https://github.com/discourse/discourse.git
synced 2025-02-05 19:11:13 +00:00
A form to add ip addresses to be blocked or whitelisted
This commit is contained in:
parent
61468f6f27
commit
017efdece5
@ -0,0 +1,64 @@
|
|||||||
|
/**
|
||||||
|
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
|
||||||
|
**/
|
||||||
|
Discourse.ScreenedIpAddressFormComponent = Ember.Component.extend({
|
||||||
|
classNames: ['screened-ip-address-form'],
|
||||||
|
formSubmitted: false,
|
||||||
|
actionName: 'block',
|
||||||
|
|
||||||
|
actionNames: function() {
|
||||||
|
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(),
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
submit: function() {
|
||||||
|
if (!this.get('formSubmitted')) {
|
||||||
|
var self = this;
|
||||||
|
this.set('formSubmitted', true);
|
||||||
|
var screenedIpAddress = Discourse.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', Discourse.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(e) {
|
||||||
|
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');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
@ -18,6 +18,12 @@ Discourse.AdminLogsScreenedIpAddressesController = Ember.ArrayController.extend(
|
|||||||
self.set('content', result);
|
self.set('content', result);
|
||||||
self.set('loading', false);
|
self.set('loading', false);
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
recordAdded: function(arg) {
|
||||||
|
this.get("content").unshiftObject(arg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -27,12 +33,12 @@ Discourse.AdminLogsScreenedIpAddressController = Ember.ObjectController.extend({
|
|||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
allow: function(record) {
|
allow: function(record) {
|
||||||
record.set('action', 'do_nothing');
|
record.set('action_name', 'do_nothing');
|
||||||
this.send('save', record);
|
this.send('save', record);
|
||||||
},
|
},
|
||||||
|
|
||||||
block: function(record) {
|
block: function(record) {
|
||||||
record.set('action', 'block');
|
record.set('action_name', 'block');
|
||||||
this.send('save', record);
|
this.send('save', record);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -9,20 +9,20 @@
|
|||||||
**/
|
**/
|
||||||
Discourse.ScreenedIpAddress = Discourse.Model.extend({
|
Discourse.ScreenedIpAddress = Discourse.Model.extend({
|
||||||
actionName: function() {
|
actionName: function() {
|
||||||
return I18n.t("admin.logs.screened_ips.actions." + this.get('action'));
|
return I18n.t("admin.logs.screened_ips.actions." + this.get('action_name'));
|
||||||
}.property('action'),
|
}.property('action_name'),
|
||||||
|
|
||||||
isBlocked: function() {
|
isBlocked: function() {
|
||||||
return (this.get('action') === 'block');
|
return (this.get('action_name') === 'block');
|
||||||
}.property('action'),
|
}.property('action_name'),
|
||||||
|
|
||||||
actionIcon: function() {
|
actionIcon: function() {
|
||||||
if (this.get('action') === 'block') {
|
if (this.get('action_name') === 'block') {
|
||||||
return this.get('blockIcon');
|
return this.get('blockIcon');
|
||||||
} else {
|
} else {
|
||||||
return this.get('doNothingIcon');
|
return this.get('doNothingIcon');
|
||||||
}
|
}
|
||||||
}.property('action'),
|
}.property('action_name'),
|
||||||
|
|
||||||
blockIcon: function() {
|
blockIcon: function() {
|
||||||
return 'icon-ban-circle';
|
return 'icon-ban-circle';
|
||||||
@ -33,9 +33,9 @@ Discourse.ScreenedIpAddress = Discourse.Model.extend({
|
|||||||
}.property(),
|
}.property(),
|
||||||
|
|
||||||
save: function() {
|
save: function() {
|
||||||
return Discourse.ajax("/admin/logs/screened_ip_addresses/" + this.get('id') + ".json", {
|
return Discourse.ajax("/admin/logs/screened_ip_addresses" + (this.id ? '/' + this.id : '') + ".json", {
|
||||||
type: 'PUT',
|
type: this.id ? 'PUT' : 'POST',
|
||||||
data: {ip_address: this.get('ip_address'), action_name: this.get('action')}
|
data: {ip_address: this.get('ip_address'), action_name: this.get('action_name')}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
<p>{{i18n admin.logs.screened_ips.description}}</p>
|
<p>{{i18n admin.logs.screened_ips.description}}</p>
|
||||||
|
|
||||||
|
{{screened-ip-address-form action="recordAdded"}}
|
||||||
|
<br/>
|
||||||
|
|
||||||
{{#if loading}}
|
{{#if loading}}
|
||||||
<div class='admin-loading'>{{i18n loading}}</div>
|
<div class='admin-loading'>{{i18n loading}}</div>
|
||||||
{{else}}
|
{{else}}
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
<b>{{i18n admin.logs.screened_ips.form.label}}</b>
|
||||||
|
{{textField value=ip_address disabled=formSubmitted class="ip-address-input" placeholderKey="admin.logs.screened_ips.form.ip_address" autocorrect="off" autocapitalize="off"}}
|
||||||
|
{{combobox content=actionNames value=actionName}}
|
||||||
|
<button class="btn btn-small" {{action submit target="view"}} {{bindAttr disabled="formSubmitted"}}>{{i18n admin.logs.screened_ips.form.add}}</button>
|
@ -752,6 +752,14 @@ table.api-keys {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.screened-ip-address-form {
|
||||||
|
margin-left: 6px;
|
||||||
|
.combobox {
|
||||||
|
width: 130px;
|
||||||
|
top: 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.screened-emails, .screened-urls {
|
.screened-emails, .screened-urls {
|
||||||
.ip_address {
|
.ip_address {
|
||||||
width: 110px;
|
width: 110px;
|
||||||
|
@ -7,6 +7,15 @@ class Admin::ScreenedIpAddressesController < Admin::AdminController
|
|||||||
render_serialized(screened_ip_addresses, ScreenedIpAddressSerializer)
|
render_serialized(screened_ip_addresses, ScreenedIpAddressSerializer)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
screened_ip_address = ScreenedIpAddress.new(allowed_params)
|
||||||
|
if screened_ip_address.save
|
||||||
|
render_serialized(screened_ip_address, ScreenedIpAddressSerializer)
|
||||||
|
else
|
||||||
|
render_json_error(screened_ip_address)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
if @screened_ip_address.update_attributes(allowed_params)
|
if @screened_ip_address.update_attributes(allowed_params)
|
||||||
render json: success_json
|
render json: success_json
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
class ScreenedIpAddressSerializer < ApplicationSerializer
|
class ScreenedIpAddressSerializer < ApplicationSerializer
|
||||||
attributes :id,
|
attributes :id,
|
||||||
:ip_address,
|
:ip_address,
|
||||||
:action,
|
:action_name,
|
||||||
:match_count,
|
:match_count,
|
||||||
:last_match_at,
|
:last_match_at,
|
||||||
:created_at
|
:created_at
|
||||||
|
|
||||||
def action
|
def action_name
|
||||||
ScreenedIpAddress.actions.key(object.action_type).to_s
|
ScreenedIpAddress.actions.key(object.action_type).to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1268,11 +1268,15 @@ en:
|
|||||||
url: "URL"
|
url: "URL"
|
||||||
screened_ips:
|
screened_ips:
|
||||||
title: "Screened IPs"
|
title: "Screened IPs"
|
||||||
description: "IP addresses that are being watched."
|
description: 'IP addresses that are being watched. Use "Allow" to whitelist IP addresses.'
|
||||||
delete_confirm: "Are you sure you want to remove the rule for %{ip_address}?"
|
delete_confirm: "Are you sure you want to remove the rule for %{ip_address}?"
|
||||||
actions:
|
actions:
|
||||||
block: "Block"
|
block: "Block"
|
||||||
do_nothing: "Allow"
|
do_nothing: "Allow"
|
||||||
|
form:
|
||||||
|
label: "New:"
|
||||||
|
ip_address: "IP address"
|
||||||
|
add: "Add"
|
||||||
|
|
||||||
impersonate:
|
impersonate:
|
||||||
title: "Impersonate User"
|
title: "Impersonate User"
|
||||||
|
@ -69,7 +69,7 @@ Discourse::Application.routes.draw do
|
|||||||
scope '/logs' do
|
scope '/logs' do
|
||||||
resources :staff_action_logs, only: [:index]
|
resources :staff_action_logs, only: [:index]
|
||||||
resources :screened_emails, only: [:index]
|
resources :screened_emails, only: [:index]
|
||||||
resources :screened_ip_addresses, only: [:index, :update, :destroy]
|
resources :screened_ip_addresses, only: [:index, :create, :update, :destroy]
|
||||||
resources :screened_urls, only: [:index]
|
resources :screened_urls, only: [:index]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user