safety_cone 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +111 -7
- data/app/helpers/safety_cone/cones_helper.rb +1 -1
- data/app/models/safety_cone/cone.rb +4 -4
- data/app/views/safety_cone/cones/edit.html.erb +6 -6
- data/lib/safety_cone/configuration.rb +2 -5
- data/lib/safety_cone/filter.rb +14 -8
- data/lib/safety_cone/version.rb +1 -1
- data/lib/safety_cone/view_helper.rb +15 -0
- data/lib/safety_cone.rb +1 -0
- metadata +6 -6
- data/lib/tasks/safety_cone_tasks.rake +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1a84c4f47818100346deb5406a5e31349fbe369
|
4
|
+
data.tar.gz: 1300636c1ce0920c16f9ecb14e727e373fc0fcaf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 391806f295ceb89632b0f65bf3b82be0a0230993c2a0fdf579176d4efd2265c9f3d9dcf352bc2dddefe22c8eb43f11b4333172486b204ae592fd7184609e76ee
|
7
|
+
data.tar.gz: 72411e11648c4774b0579870172235acd163db7d3cfbf740ffecb3e0dce14fb33b4ed20c428d24ebfddbde70da4af4ad2b79c75085bdfa7bc2ae8e7b980a86da
|
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
![safety cone logo](https://raw.githubusercontent.com/boost/safety_cone/master/app/assets/images/safety_cone/logo.png)
|
2
|
+
# SafetyCone [![Gem Version](https://badge.fury.io/rb/safety_cone.svg)](https://badge.fury.io/rb/safety_cone)
|
3
3
|
|
4
|
-
|
5
|
-
How to use my plugin.
|
4
|
+
Safety Cone is a Rails gem that allows you to temporarily add warnings or block requests to specific pages through a simple interface. It's intended use case is primarily for maintenance.
|
6
5
|
|
7
6
|
## Installation
|
8
7
|
Add this line to your application's Gemfile:
|
@@ -16,10 +15,115 @@ And then execute:
|
|
16
15
|
$ bundle
|
17
16
|
```
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
Create a safety_cone.rb file in config/initializers. The routes that needs to be managed can be added to this config file.
|
21
|
+
|
22
|
+
```
|
23
|
+
$redis = Redis::Namespace.new("app_name", :redis => Redis.new)
|
24
|
+
|
25
|
+
SafetyCone.configure do |config|
|
26
|
+
# Redis connection for safety_cone
|
27
|
+
config.redis = $redis
|
28
|
+
|
29
|
+
# Http auth username and password for Safety Cone admin page
|
30
|
+
config.auth = { username: 'admin', password: 'admin-password' }
|
31
|
+
|
32
|
+
# To allow Safety Cone to manage a single controller action
|
33
|
+
config.add(
|
34
|
+
controller: :registrations,
|
35
|
+
action: :new,
|
36
|
+
name: 'User Registration'
|
37
|
+
)
|
38
|
+
|
39
|
+
# To allow Safety Cone to manage all POST requests
|
40
|
+
config.add(
|
41
|
+
method: 'POST',
|
42
|
+
name: 'All POST requests'
|
43
|
+
)
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
In routes add
|
48
|
+
|
49
|
+
```
|
50
|
+
mount SafetyCone::Engine, :at => '/safety_cone'
|
51
|
+
```
|
52
|
+
|
53
|
+
In ApplicationController
|
54
|
+
|
22
55
|
```
|
56
|
+
class ApplicationController < ActionController::Base
|
57
|
+
protect_from_forgery
|
58
|
+
|
59
|
+
# Add this line
|
60
|
+
include SafetyCone::Filter
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
64
|
+
In View
|
65
|
+
|
66
|
+
```html
|
67
|
+
<div class="container">
|
68
|
+
<% if safetycone_notice %>
|
69
|
+
<div class="notice"><%= safetycone_notice %></div>
|
70
|
+
<% end %>
|
71
|
+
|
72
|
+
<% if safetycone_alert %>
|
73
|
+
<div class="alert"><%= safetycone_alert %></div>
|
74
|
+
<% end %>
|
75
|
+
</div>
|
76
|
+
```
|
77
|
+
|
78
|
+
Now you should be able to go to http://localhost:3000/safety_cone and manage your routes.
|
79
|
+
|
80
|
+
## For version 0.1.0 users
|
81
|
+
|
82
|
+
This earlier version is not a mountable engine and it does not provide an admin interface. The configuration is as follows:
|
83
|
+
|
84
|
+
```
|
85
|
+
SafetyCone.configure do |config|
|
86
|
+
# disables Safety Cone. By default this value is true
|
87
|
+
config.enabled = false
|
88
|
+
|
89
|
+
# This config will block all POST requests and display this message.
|
90
|
+
config.add(
|
91
|
+
method: :POST,
|
92
|
+
message: 'We are unable to write any data to database now.',
|
93
|
+
type: :block
|
94
|
+
)
|
95
|
+
|
96
|
+
# This is a controller action specific warning. But with no measures to prevent this action
|
97
|
+
config.add(
|
98
|
+
controller: :users,
|
99
|
+
action: :new,
|
100
|
+
message: 'We are unable to register any user now. Please try after sometime.'
|
101
|
+
type: :notice
|
102
|
+
)
|
103
|
+
|
104
|
+
# This is a controller action specific block. This config will let the application
|
105
|
+
# to raise an alert message and block the request from hitting the controller action.
|
106
|
+
config.add(
|
107
|
+
controller: 'users',
|
108
|
+
action: 'create',
|
109
|
+
message: 'We are unable to register any user now. Please try after sometime.',
|
110
|
+
type: :block
|
111
|
+
)
|
112
|
+
|
113
|
+
# This is a controller action specific block with a redirect configured.
|
114
|
+
config.add(
|
115
|
+
controller: 'users',
|
116
|
+
action: 'create',
|
117
|
+
message: 'We are unable to register any user now. Please try after sometime.',
|
118
|
+
type: :block,
|
119
|
+
redirect: '/page/more_info'
|
120
|
+
)
|
121
|
+
|
122
|
+
# For :block flash message is an alert
|
123
|
+
# For :notice flash message is a notice
|
124
|
+
end
|
125
|
+
```
|
126
|
+
|
23
127
|
|
24
128
|
## Contributing
|
25
129
|
Contribution directions go here.
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module SafetyCone
|
2
2
|
class Cone
|
3
3
|
attr_accessor :name, :controller, :action,
|
4
|
-
:method, :message, :
|
4
|
+
:method, :message, :type,
|
5
5
|
:key, :redis
|
6
6
|
|
7
7
|
def initialize(key, params)
|
@@ -11,12 +11,12 @@ module SafetyCone
|
|
11
11
|
@method = params[:action]
|
12
12
|
@method = params[:method]
|
13
13
|
@message = params[:message]
|
14
|
-
@
|
14
|
+
@type = params[:type] || 'disabled'
|
15
15
|
@redis = SafetyCone.redis
|
16
16
|
end
|
17
17
|
|
18
18
|
def save
|
19
|
-
data = { message: @message,
|
19
|
+
data = { message: @message, type: @type }.to_json
|
20
20
|
@redis.set(redis_key, data)
|
21
21
|
end
|
22
22
|
|
@@ -26,7 +26,7 @@ module SafetyCone
|
|
26
26
|
if stored_data
|
27
27
|
data = JSON.parse(stored_data)
|
28
28
|
@message = data['message']
|
29
|
-
@
|
29
|
+
@type = data['type']
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -11,14 +11,14 @@
|
|
11
11
|
</div>
|
12
12
|
|
13
13
|
<div class="input-field col s12">
|
14
|
-
<%= form.radio_button :
|
15
|
-
<%= form.label :
|
14
|
+
<%= form.radio_button :type, 'notice' %>
|
15
|
+
<%= form.label :type_notice, 'Notice' %>
|
16
16
|
|
17
|
-
<%= form.radio_button :
|
18
|
-
<%= form.label :
|
17
|
+
<%= form.radio_button :type, 'block' %>
|
18
|
+
<%= form.label :type_block, 'Block' %>
|
19
19
|
|
20
|
-
<%= form.radio_button :
|
21
|
-
<%= form.label :
|
20
|
+
<%= form.radio_button :type, 'disabled' %>
|
21
|
+
<%= form.label :type_disabled, 'Disable this Cone' %>
|
22
22
|
</div>
|
23
23
|
|
24
24
|
<div class="input-field col s12">
|
@@ -1,10 +1,7 @@
|
|
1
1
|
module SafetyCone
|
2
2
|
# Module for configuring safety measures
|
3
3
|
module Configuration
|
4
|
-
VALID_OPTION_KEYS = [
|
5
|
-
:method, :controller,
|
6
|
-
:action, :name
|
7
|
-
].freeze
|
4
|
+
VALID_OPTION_KEYS = %i[method controller action name].freeze
|
8
5
|
|
9
6
|
attr_accessor :cones, :options, :redis, :auth
|
10
7
|
|
@@ -32,7 +29,7 @@ module SafetyCone
|
|
32
29
|
# Configuration method for Rails initializer
|
33
30
|
def configure
|
34
31
|
self.cones = {}
|
35
|
-
self.auth = { username: nil, password: nil}
|
32
|
+
self.auth = { username: nil, password: nil }
|
36
33
|
|
37
34
|
yield self
|
38
35
|
end
|
data/lib/safety_cone/filter.rb
CHANGED
@@ -12,12 +12,18 @@ module SafetyCone
|
|
12
12
|
# based on the configuration.
|
13
13
|
def safety_cone_filter
|
14
14
|
if cone = fetch_cone
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
if cone.type == 'notice'
|
16
|
+
flash.now["safetycone_#{notice_type(cone.type)}"] = cone.message
|
17
|
+
else
|
18
|
+
flash["safetycone_#{notice_type(cone.type)}"] = cone.message
|
19
|
+
end
|
20
|
+
|
21
|
+
redirect_to safety_redirect if cone.type == 'block'
|
18
22
|
end
|
19
23
|
end
|
20
24
|
|
25
|
+
private
|
26
|
+
|
21
27
|
# Fetches a configuration based on current request
|
22
28
|
def fetch_cone
|
23
29
|
cones = SafetyCone.cones
|
@@ -32,18 +38,18 @@ module SafetyCone
|
|
32
38
|
|
33
39
|
cone = Cone.new(key, cone)
|
34
40
|
cone.fetch
|
35
|
-
|
36
|
-
%w
|
41
|
+
|
42
|
+
%w[notice block].include?(cone.type) ? cone : false
|
37
43
|
end
|
38
44
|
|
39
45
|
# Method to redirect a request
|
40
46
|
def safety_redirect
|
41
|
-
request.env['HTTP_REFERER']
|
47
|
+
request.env['HTTP_REFERER'] || root_path
|
42
48
|
end
|
43
49
|
|
44
50
|
# Returns type of notice
|
45
|
-
def notice_type(
|
46
|
-
|
51
|
+
def notice_type(type)
|
52
|
+
type == 'notice' ? 'notice' : 'alert'
|
47
53
|
end
|
48
54
|
|
49
55
|
# Returns the current request action as a symbol
|
data/lib/safety_cone/version.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
module SafetyCone
|
2
|
+
# Module for Filtering requests and raise notices
|
3
|
+
# and take measures
|
4
|
+
module Helper
|
5
|
+
def safetycone_notice
|
6
|
+
flash[:safetycone_notice]
|
7
|
+
end
|
8
|
+
|
9
|
+
def safetycone_alert
|
10
|
+
flash[:safetycone_alert]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
ActionView::Base.send :include, SafetyCone::Helper
|
data/lib/safety_cone.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: safety_cone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edwin Rozario
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-10-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "<="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 5.
|
20
|
+
version: '5.1'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "<="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 5.
|
27
|
+
version: '5.1'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: redis
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -203,7 +203,7 @@ files:
|
|
203
203
|
- lib/safety_cone/engine.rb
|
204
204
|
- lib/safety_cone/filter.rb
|
205
205
|
- lib/safety_cone/version.rb
|
206
|
-
- lib/
|
206
|
+
- lib/safety_cone/view_helper.rb
|
207
207
|
homepage: https://github.com/boost/safety_cone
|
208
208
|
licenses:
|
209
209
|
- MIT
|
@@ -224,7 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
224
224
|
version: '0'
|
225
225
|
requirements: []
|
226
226
|
rubyforge_project:
|
227
|
-
rubygems_version: 2.
|
227
|
+
rubygems_version: 2.6.11
|
228
228
|
signing_key:
|
229
229
|
specification_version: 4
|
230
230
|
summary: Blocks or warns requests as cofigured by the admin
|