sudo_rails 0.4.3 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +13 -5
- data/app/controllers/sudo_rails/application_controller.rb +4 -3
- data/app/views/layouts/sudo_rails/application.html.erb +5 -3
- data/app/views/sudo_rails/_flash_alert.html.erb +5 -0
- data/app/views/sudo_rails/_stylesheet.html.erb +93 -0
- data/app/views/sudo_rails/confirm_form.html.erb +7 -4
- data/config/locales/en.yml +1 -0
- data/lib/sudo_rails.rb +1 -1
- data/lib/sudo_rails/engine.rb +1 -5
- data/lib/sudo_rails/styling.rb +1 -6
- data/lib/sudo_rails/version.rb +1 -1
- metadata +5 -20
- data/app/assets/stylesheets/sudo_rails/application.scss +0 -57
- data/app/views/sudo_rails/_inject_custom_styles.html.erb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b83893c9eec976687c8c2025317dc0e3b0b3174cc128868a0d4cdb079c83bfc
|
4
|
+
data.tar.gz: cf24b4e05521fc40d24e31e061c5fc71efb0b63af7eacfcff0164d35d60ac0e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 650c2237a64d202041e45f50b3831362af5077d5f1b35e56482d7c93326482c1b022896cd39a215e199c8a52aaf638db7db0b6a90bf7d5bbbb3e37dddf8e32fb
|
7
|
+
data.tar.gz: 25f83106ff3762ff132b442f186f2f82966595a82ee7390fef99a9b3a415b87a6cf882adadf14fb6e283a2f35c2b786673f0ff50bd8230cba7e329cff1bd803c
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Sudo Rails
|
2
2
|
|
3
3
|
[![Gem](https://img.shields.io/gem/v/sudo_rails.svg?style=flat-square)](https://rubygems.org/gems/sudo_rails)
|
4
|
-
[![Build Status](https://travis-ci.
|
4
|
+
[![Build Status](https://travis-ci.com/markets/sudo_rails.svg?branch=master)](https://travis-ci.com/markets/sudo_rails)
|
5
5
|
[![Maintainability](https://api.codeclimate.com/v1/badges/322350adc7ab052beccb/maintainability)](https://codeclimate.com/github/markets/sudo_rails/maintainability)
|
6
6
|
|
7
7
|
> Sudo mode for your Rails controllers
|
@@ -55,9 +55,9 @@ SudoRails.setup do |config|
|
|
55
55
|
config.sudo_session_duration = 10.minutes
|
56
56
|
|
57
57
|
# Confirmation page styling
|
58
|
-
config.custom_logo = '
|
59
|
-
config.primary_color = '#
|
60
|
-
config.background_color = '#
|
58
|
+
config.custom_logo = '/images/logo_medium.png'
|
59
|
+
config.primary_color = '#1a7191'
|
60
|
+
config.background_color = '#1a1a1a'
|
61
61
|
config.layout = 'admin'
|
62
62
|
|
63
63
|
# Confirmation strategy implementation
|
@@ -71,11 +71,19 @@ SudoRails.setup do |config|
|
|
71
71
|
end
|
72
72
|
```
|
73
73
|
|
74
|
+
### Sudo sessions
|
75
|
+
|
76
|
+
Using the `sudo_session_duration` option you are able to configure the `sudo` session duration (30 minutes by default).
|
77
|
+
|
78
|
+
If you set it to `nil`, your `sudo` session won't expire automatically and you will have to do it manually by using the `reset_sudo_session!` helper.
|
79
|
+
|
74
80
|
### Styling
|
75
81
|
|
76
82
|
Using the `custom_logo`, `primary_color` and `background_color` options, you can customize the confirmation page. In case you want full control of the styles, you can use your own layout (and consequently your own styles too) using the `layout` option.
|
77
83
|
|
78
|
-
See some [examples here](support/images/).
|
84
|
+
See some :camera: [examples here](support/images/).
|
85
|
+
|
86
|
+
**NOTE** If you are using your own layout, don't forget to render the flash messages in that layout. You can do something like [this](app/views/sudo_rails/_flash_alert.html.erb).
|
79
87
|
|
80
88
|
### Confirmation strategy
|
81
89
|
|
@@ -3,12 +3,13 @@ module SudoRails
|
|
3
3
|
before_action :sudo_enabled?
|
4
4
|
|
5
5
|
def confirm
|
6
|
-
if
|
6
|
+
if SudoRails.confirm?(self, params[:password])
|
7
7
|
session[:sudo_session] = Time.zone.now.to_s
|
8
|
-
redirect_to params[:target_path]
|
9
8
|
else
|
10
|
-
|
9
|
+
flash[:alert] = I18n.t('sudo_rails.invalid_pass', locale: params[:locale])
|
11
10
|
end
|
11
|
+
|
12
|
+
redirect_to params[:target_path]
|
12
13
|
end
|
13
14
|
|
14
15
|
private
|
@@ -3,10 +3,12 @@
|
|
3
3
|
<head>
|
4
4
|
<title><%= t('sudo_rails.page_header') %></title>
|
5
5
|
<%= csrf_meta_tags %>
|
6
|
-
<%=
|
7
|
-
<%= render 'sudo_rails/inject_custom_styles' if SudoRails.custom_styles? %>
|
6
|
+
<%= render 'sudo_rails/stylesheet' %>
|
8
7
|
</head>
|
9
8
|
<body>
|
10
|
-
<%=
|
9
|
+
<%= render 'sudo_rails/flash_alert' %>
|
10
|
+
<div class="sudo-container">
|
11
|
+
<%= yield %>
|
12
|
+
</div>
|
11
13
|
</body>
|
12
14
|
</html>
|
@@ -0,0 +1,93 @@
|
|
1
|
+
<style type="text/css">
|
2
|
+
body {
|
3
|
+
text-align: center;
|
4
|
+
font-family: Helvetica, Arial, sans-serif;
|
5
|
+
background-color: #ececec;
|
6
|
+
margin: 0 auto;
|
7
|
+
}
|
8
|
+
|
9
|
+
a {
|
10
|
+
color: #000;
|
11
|
+
}
|
12
|
+
|
13
|
+
input {
|
14
|
+
-webkit-appearance: none;
|
15
|
+
}
|
16
|
+
|
17
|
+
.sudo-container {
|
18
|
+
transform: translateY(25%);
|
19
|
+
}
|
20
|
+
|
21
|
+
.sudo-header {
|
22
|
+
margin: 2em auto;
|
23
|
+
}
|
24
|
+
|
25
|
+
.sudo-header img {
|
26
|
+
margin-top: -60px;
|
27
|
+
max-width: 280px;
|
28
|
+
}
|
29
|
+
|
30
|
+
.sudo-form {
|
31
|
+
background-color: #fff;
|
32
|
+
border-radius: 5px;
|
33
|
+
padding: 2em;
|
34
|
+
margin: 0 auto;
|
35
|
+
max-width: 340px;
|
36
|
+
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.2);
|
37
|
+
}
|
38
|
+
|
39
|
+
.sudo-form input {
|
40
|
+
display: block;
|
41
|
+
width: 100%;
|
42
|
+
font-size: 16px;
|
43
|
+
line-height: 2em;
|
44
|
+
padding: 4px;
|
45
|
+
border-radius: 5px;
|
46
|
+
border: 1px solid #ececec;
|
47
|
+
}
|
48
|
+
|
49
|
+
.sudo-form input[type="submit"] {
|
50
|
+
cursor: pointer;
|
51
|
+
margin: 1em auto;
|
52
|
+
width: 60%;
|
53
|
+
padding: 4px;
|
54
|
+
background-color: #ececec;
|
55
|
+
border-radius: 25px;
|
56
|
+
border: none;
|
57
|
+
}
|
58
|
+
|
59
|
+
.sudo-tip {
|
60
|
+
margin-top: 2em;
|
61
|
+
font-size: 14px;
|
62
|
+
}
|
63
|
+
|
64
|
+
.sudo-alert {
|
65
|
+
background: #000;
|
66
|
+
color: #fff;
|
67
|
+
padding: 10px;
|
68
|
+
font-weight: bold;
|
69
|
+
}
|
70
|
+
|
71
|
+
<% if SudoRails.background_color.present? %>
|
72
|
+
body {
|
73
|
+
background-color: <%= SudoRails.background_color %>;
|
74
|
+
color: <%= SudoRails.color_contrast(SudoRails.background_color) %>;
|
75
|
+
}
|
76
|
+
|
77
|
+
.sudo-alert {
|
78
|
+
background-color: <%= SudoRails.color_contrast(SudoRails.background_color) %>;
|
79
|
+
color: <%= SudoRails.background_color %>;
|
80
|
+
}
|
81
|
+
<% end %>
|
82
|
+
|
83
|
+
<% if SudoRails.primary_color.present? %>
|
84
|
+
a {
|
85
|
+
color: <%= SudoRails.primary_color %>;
|
86
|
+
}
|
87
|
+
|
88
|
+
.sudo-form input[type="submit"] {
|
89
|
+
background-color: <%= SudoRails.primary_color %>;
|
90
|
+
color: <%= SudoRails.color_contrast(SudoRails.primary_color) %>;
|
91
|
+
}
|
92
|
+
<% end %>
|
93
|
+
</style>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<div class='sudo-header'>
|
2
2
|
<% if SudoRails.custom_logo %>
|
3
|
-
<%=
|
3
|
+
<img src="<%= SudoRails.custom_logo %>">
|
4
4
|
<% end %>
|
5
5
|
|
6
6
|
<h2><%= t('sudo_rails.page_header') %></h2>
|
@@ -8,6 +8,7 @@
|
|
8
8
|
|
9
9
|
<div class='sudo-form'>
|
10
10
|
<%= form_tag '/sudo_rails/confirm' do |f| %>
|
11
|
+
<%= hidden_field_tag :locale, I18n.locale %>
|
11
12
|
<%= hidden_field_tag :target_path, params[:target_path] || request.url %>
|
12
13
|
<%= password_field_tag :password, nil, required: true, placeholder: t('sudo_rails.password') %>
|
13
14
|
<%= submit_tag t('sudo_rails.button') %>
|
@@ -18,6 +19,8 @@
|
|
18
19
|
<% end %>
|
19
20
|
</div>
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
<% unless SudoRails.sudo_session_duration.nil? %>
|
23
|
+
<div class='sudo-tip'>
|
24
|
+
<%= t('sudo_rails.tip', session_duration: time_ago_in_words(SudoRails.sudo_session_duration.ago)).html_safe %>
|
25
|
+
</div>
|
26
|
+
<% end %>
|
data/config/locales/en.yml
CHANGED
data/lib/sudo_rails.rb
CHANGED
@@ -2,7 +2,6 @@ require "sudo_rails/version"
|
|
2
2
|
require "sudo_rails/controller_ext"
|
3
3
|
require "sudo_rails/styling"
|
4
4
|
require "sudo_rails/engine"
|
5
|
-
require "sassc-rails"
|
6
5
|
|
7
6
|
module SudoRails
|
8
7
|
class << self
|
@@ -30,6 +29,7 @@ module SudoRails
|
|
30
29
|
|
31
30
|
def valid_sudo_session?(started_at)
|
32
31
|
return false unless started_at
|
32
|
+
return true if sudo_session_duration.nil?
|
33
33
|
|
34
34
|
DateTime.parse(started_at) + sudo_session_duration > Time.zone.now
|
35
35
|
end
|
data/lib/sudo_rails/engine.rb
CHANGED
@@ -10,12 +10,8 @@ module SudoRails
|
|
10
10
|
|
11
11
|
initializer 'sudo_rails.routes' do |app|
|
12
12
|
app.routes.append do
|
13
|
-
|
13
|
+
post '/sudo_rails/confirm' => 'sudo_rails/application#confirm'
|
14
14
|
end
|
15
15
|
end
|
16
|
-
|
17
|
-
config.assets.precompile << %w(
|
18
|
-
sudo_rails/application.css
|
19
|
-
)
|
20
16
|
end
|
21
17
|
end
|
data/lib/sudo_rails/styling.rb
CHANGED
@@ -4,15 +4,10 @@ module SudoRails
|
|
4
4
|
SudoRails.layout || 'sudo_rails/application'
|
5
5
|
end
|
6
6
|
|
7
|
-
def custom_styles?
|
8
|
-
SudoRails.primary_color.present? || SudoRails.background_color.present?
|
9
|
-
end
|
10
|
-
|
11
|
-
# Ref: https://gist.github.com/charliepark/480358
|
12
7
|
def color_contrast(hex_color)
|
13
8
|
return nil unless hex_color.include?('#')
|
14
9
|
|
15
|
-
hex_color.delete('#').scan(/../).sum { |color| color.hex } > 382.5 ? '#000' : '#
|
10
|
+
hex_color.delete('#').scan(/../).sum { |color| color.hex } > 382.5 ? '#000' : '#fff'
|
16
11
|
end
|
17
12
|
end
|
18
13
|
end
|
data/lib/sudo_rails/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sudo_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- markets
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '4.2'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: sassc-rails
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: rspec-rails
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -62,10 +48,10 @@ files:
|
|
62
48
|
- LICENSE
|
63
49
|
- README.md
|
64
50
|
- Rakefile
|
65
|
-
- app/assets/stylesheets/sudo_rails/application.scss
|
66
51
|
- app/controllers/sudo_rails/application_controller.rb
|
67
52
|
- app/views/layouts/sudo_rails/application.html.erb
|
68
|
-
- app/views/sudo_rails/
|
53
|
+
- app/views/sudo_rails/_flash_alert.html.erb
|
54
|
+
- app/views/sudo_rails/_stylesheet.html.erb
|
69
55
|
- app/views/sudo_rails/confirm_form.html.erb
|
70
56
|
- config/locales/en.yml
|
71
57
|
- lib/sudo_rails.rb
|
@@ -94,8 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
80
|
- !ruby/object:Gem::Version
|
95
81
|
version: '0'
|
96
82
|
requirements: []
|
97
|
-
|
98
|
-
rubygems_version: 2.7.6
|
83
|
+
rubygems_version: 3.0.3
|
99
84
|
signing_key:
|
100
85
|
specification_version: 4
|
101
86
|
summary: Sudo mode for Rails
|
@@ -1,57 +0,0 @@
|
|
1
|
-
body {
|
2
|
-
text-align: center;
|
3
|
-
font-family: Helvetica, Arial, sans-serif;
|
4
|
-
background-color: #ececec;
|
5
|
-
transform: translateY(20%);
|
6
|
-
}
|
7
|
-
|
8
|
-
a {
|
9
|
-
color: #000;
|
10
|
-
}
|
11
|
-
|
12
|
-
input {
|
13
|
-
-webkit-appearance: none;
|
14
|
-
}
|
15
|
-
|
16
|
-
.sudo-header {
|
17
|
-
margin: 2em auto;
|
18
|
-
|
19
|
-
img {
|
20
|
-
margin-top: -60px;
|
21
|
-
max-width: 280px;
|
22
|
-
}
|
23
|
-
}
|
24
|
-
|
25
|
-
.sudo-form {
|
26
|
-
background-color: #fff;
|
27
|
-
border-radius: 5px;
|
28
|
-
padding: 2em;
|
29
|
-
margin: 0 auto;
|
30
|
-
max-width: 340px;
|
31
|
-
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.2);
|
32
|
-
|
33
|
-
input {
|
34
|
-
display: block;
|
35
|
-
width: 100%;
|
36
|
-
font-size: 16px;
|
37
|
-
line-height: 2em;
|
38
|
-
padding: 4px;
|
39
|
-
border-radius: 5px;
|
40
|
-
border: 1px solid #ececec;
|
41
|
-
}
|
42
|
-
|
43
|
-
input[type="submit"] {
|
44
|
-
cursor: pointer;
|
45
|
-
margin: 1em auto;
|
46
|
-
width: 60%;
|
47
|
-
padding: 4px;
|
48
|
-
background-color: #ececec;
|
49
|
-
border-radius: 25px;
|
50
|
-
border: none;
|
51
|
-
}
|
52
|
-
}
|
53
|
-
|
54
|
-
.sudo-tip {
|
55
|
-
margin-top: 2em;
|
56
|
-
font-size: 14px;
|
57
|
-
}
|
@@ -1,19 +0,0 @@
|
|
1
|
-
<style type="text/css">
|
2
|
-
<% if SudoRails.background_color.present? %>
|
3
|
-
body {
|
4
|
-
background-color: <%= SudoRails.background_color %>;
|
5
|
-
color: <%= SudoRails.color_contrast(SudoRails.background_color) %>;
|
6
|
-
}
|
7
|
-
<% end %>
|
8
|
-
|
9
|
-
<% if SudoRails.primary_color.present? %>
|
10
|
-
a {
|
11
|
-
color: <%= SudoRails.primary_color %>;
|
12
|
-
}
|
13
|
-
|
14
|
-
.sudo-form input[type="submit"] {
|
15
|
-
background-color: <%= SudoRails.primary_color %>;
|
16
|
-
color: <%= SudoRails.color_contrast(SudoRails.primary_color) %>;
|
17
|
-
}
|
18
|
-
<% end %>
|
19
|
-
</style>
|