sudo_rails 0.6.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ed6d190a51d927747f58d7ce61af01b6dd8ab0edff663969773ebbbebd21b37
4
- data.tar.gz: 85f9dc0920bdc8226b36053b06c4304b45b55f90a4735b22faed4334a7a87ad1
3
+ metadata.gz: 13a5abdefd6191deed91535f4401bf0def14a6e502b6d4b191d7129e7fb2c754
4
+ data.tar.gz: 1166792b0ff651665d8dba513e56af064decf4b97c6d68c5302eddc3a194ac04
5
5
  SHA512:
6
- metadata.gz: ef19bd450721d754b582ebe425dcdf30e91758089593743ed16fadd2400ac4cb2e898e336000a840fed37ac69124138cf5105953ff2342cdf3b37b45c6295196
7
- data.tar.gz: 76a63a6de298a85130286495533149325a752c772bcf0a4d3d33ccb20e9645563397c9dca75f0c9174f46e9924b02d58b89a4de5919067ffd2f00cd2cd540bf7
6
+ metadata.gz: cb284469c871a0f3bd17213d2c316835b4a1c3ea2ed82d3fda416066e1a89128f0d2b0c4848b3068eb1298109993ece6fec8941b119ca8cb1cf591d32998d2c8
7
+ data.tar.gz: 6154b8cdda0c06b4c6afc7d19d751131fb1cfe33d93e6e090afd8f8070c52197c62d0f65d0928001281f5f489d6965dd9c2f229232308ae1d297af378ab3821a
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2019-2020 Marc Anguera Insa @markets
1
+ Copyright 2019 Marc Anguera Insa @markets
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
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.com/markets/sudo_rails.svg?branch=master)](https://travis-ci.com/markets/sudo_rails)
4
+ [![Build Status](https://github.com/markets/sudo_rails/workflows/CI/badge.svg)](https://github.com/markets/sudo_rails/actions)
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
@@ -16,6 +16,8 @@ end
16
16
 
17
17
  *Inspired by [Unix `sudo` command](https://en.wikipedia.org/wiki/Sudo) and [GitHub Sudo mode](https://help.github.com/en/articles/sudo-mode).*
18
18
 
19
+ ![](support/images/cover.png)
20
+
19
21
  ## Installation
20
22
 
21
23
  Add this line to your Gemfile and then execute `bundle install`:
@@ -55,9 +57,9 @@ SudoRails.setup do |config|
55
57
  config.sudo_session_duration = 10.minutes
56
58
 
57
59
  # Confirmation page styling
58
- config.custom_logo = 'logos/medium_dark.png'
59
- config.primary_color = '#1A7191'
60
- config.background_color = '#1A7191'
60
+ config.custom_logo = '/images/logo_medium.png'
61
+ config.primary_color = '#1a7191'
62
+ config.background_color = '#1a1a1a'
61
63
  config.layout = 'admin'
62
64
 
63
65
  # Confirmation strategy implementation
@@ -71,6 +73,8 @@ SudoRails.setup do |config|
71
73
  end
72
74
  ```
73
75
 
76
+ Use the provided `sudo_rails:config` generator to create a default config file under your *initializers* folder.
77
+
74
78
  ### Sudo sessions
75
79
 
76
80
  Using the `sudo_session_duration` option you are able to configure the `sudo` session duration (30 minutes by default).
@@ -81,9 +85,11 @@ If you set it to `nil`, your `sudo` session won't expire automatically and you w
81
85
 
82
86
  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.
83
87
 
84
- See some [examples here](support/images/).
88
+ See some :camera: [examples here](support/images/examples/).
85
89
 
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).
90
+ > ℹ️ 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).
91
+
92
+ You can also override the view by calling the `sudo_rails:view` generator. This will create a copy of the view file at `app/views/sudo_rails/confirm_form.html.erb` which can be later modified as per your requirements.
87
93
 
88
94
  ### Confirmation strategy
89
95
 
@@ -91,6 +97,8 @@ You should define how to validate the password using the `confirm_strategy` opti
91
97
 
92
98
  By default, the gem ships with `Devise` and `Clearance` integration. Check it [here](lib/sudo_rails/integrations/).
93
99
 
100
+ > ℹ️ In order to autoload `Devise` or `Clearance` strategy properly, you should place the `sudo_rails` gem after them in the Gemfile.
101
+
94
102
  Implementation examples:
95
103
 
96
104
  ```ruby
data/Rakefile CHANGED
@@ -1,6 +1 @@
1
1
  require "bundler/gem_tasks"
2
-
3
- require 'rspec/core/rake_task'
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
@@ -3,8 +3,7 @@
3
3
  <head>
4
4
  <title><%= t('sudo_rails.page_header') %></title>
5
5
  <%= csrf_meta_tags %>
6
- <%= stylesheet_link_tag "sudo_rails/application", media: "all" %>
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' %>
@@ -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,13 +1,13 @@
1
1
  <div class='sudo-header'>
2
2
  <% if SudoRails.custom_logo %>
3
- <%= image_tag SudoRails.custom_logo %>
3
+ <img src="<%= SudoRails.custom_logo %>">
4
4
  <% end %>
5
5
 
6
6
  <h2><%= t('sudo_rails.page_header') %></h2>
7
7
  </div>
8
8
 
9
9
  <div class='sudo-form'>
10
- <%= form_tag '/sudo_rails/confirm' do |f| %>
10
+ <%= form_tag sudo_rails_confirm_path do |f| %>
11
11
  <%= hidden_field_tag :locale, I18n.locale %>
12
12
  <%= hidden_field_tag :target_path, params[:target_path] || request.url %>
13
13
  <%= password_field_tag :password, nil, required: true, placeholder: t('sudo_rails.password') %>
@@ -0,0 +1,28 @@
1
+ class SudoRails::ConfigGenerator < Rails::Generators::Base
2
+ def create_config_file
3
+ create_file "config/initializers/sudo_rails.rb", <<~RUBY
4
+ SudoRails.setup do |config|
5
+ ### On/off engine
6
+ # config.enabled = true
7
+
8
+ ### Sudo mode sessions duration, default is 30 minutes
9
+ # config.sudo_session_duration = 10.minutes
10
+
11
+ ### Confirmation page styling
12
+ # config.custom_logo = '/images/logo_medium.png'
13
+ # config.primary_color = '#1a7191'
14
+ # config.background_color = '#1a1a1a'
15
+ # config.layout = 'admin'
16
+
17
+ ### Confirmation strategy implementation
18
+ # config.confirm_strategy = -> (context, password) {
19
+ # user = context.current_user
20
+ # user.valid_password?(password)
21
+ # }
22
+
23
+ ### Reset password link
24
+ # config.reset_pass_link = '/users/password/new'
25
+ end
26
+ RUBY
27
+ end
28
+ end
@@ -0,0 +1,7 @@
1
+ class SudoRails::ViewGenerator < Rails::Generators::Base
2
+ source_root File.expand_path("../../../app/views/sudo_rails/", __dir__)
3
+
4
+ def copy_view_file
5
+ copy_file "confirm_form.html.erb", "app/views/sudo_rails/confirm_form.html.erb"
6
+ end
7
+ end
@@ -3,19 +3,15 @@ module SudoRails
3
3
  isolate_namespace SudoRails
4
4
 
5
5
  initializer "sudo_rails.controller_ext" do
6
- ActiveSupport.on_load(:action_controller) do
6
+ ActiveSupport.on_load(:action_controller_base) do
7
7
  include SudoRails::ControllerExt
8
8
  end
9
9
  end
10
10
 
11
11
  initializer 'sudo_rails.routes' do |app|
12
12
  app.routes.append do
13
- post '/sudo_rails/confirm' => 'sudo_rails/application#confirm'
13
+ post '/sudo_rails/confirm' => 'sudo_rails/application#confirm', as: :sudo_rails_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
@@ -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' : '#FFF'
10
+ hex_color.delete('#').scan(/../).sum { |color| color.hex } > 382.5 ? '#000' : '#fff'
16
11
  end
17
12
  end
18
13
  end
@@ -1,3 +1,3 @@
1
1
  module SudoRails
2
- VERSION = "0.6.1"
2
+ VERSION = "0.8.0"
3
3
  end
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
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.6.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - markets
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-14 00:00:00.000000000 Z
11
+ date: 2024-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,28 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
19
+ version: '5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
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'
26
+ version: '5'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rspec-rails
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -62,13 +48,14 @@ 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
53
  - app/views/sudo_rails/_flash_alert.html.erb
69
- - app/views/sudo_rails/_inject_custom_styles.html.erb
54
+ - app/views/sudo_rails/_stylesheet.html.erb
70
55
  - app/views/sudo_rails/confirm_form.html.erb
71
56
  - config/locales/en.yml
57
+ - lib/generators/sudo_rails/config_generator.rb
58
+ - lib/generators/sudo_rails/view_generator.rb
72
59
  - lib/sudo_rails.rb
73
60
  - lib/sudo_rails/controller_ext.rb
74
61
  - lib/sudo_rails/engine.rb
@@ -80,7 +67,7 @@ homepage: https://github.com/markets/sudo_rails
80
67
  licenses:
81
68
  - MIT
82
69
  metadata: {}
83
- post_install_message:
70
+ post_install_message:
84
71
  rdoc_options: []
85
72
  require_paths:
86
73
  - lib
@@ -95,8 +82,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
82
  - !ruby/object:Gem::Version
96
83
  version: '0'
97
84
  requirements: []
98
- rubygems_version: 3.0.3
99
- signing_key:
85
+ rubygems_version: 3.4.10
86
+ signing_key:
100
87
  specification_version: 4
101
88
  summary: Sudo mode for Rails
102
89
  test_files: []
@@ -1,68 +0,0 @@
1
- body {
2
- text-align: center;
3
- font-family: Helvetica, Arial, sans-serif;
4
- background-color: #ececec;
5
- margin: 0 auto;
6
- }
7
-
8
- a {
9
- color: #000;
10
- }
11
-
12
- input {
13
- -webkit-appearance: none;
14
- }
15
-
16
- .sudo-container {
17
- transform: translateY(25%);
18
- }
19
-
20
- .sudo-header {
21
- margin: 2em auto;
22
-
23
- img {
24
- margin-top: -60px;
25
- max-width: 280px;
26
- }
27
- }
28
-
29
- .sudo-form {
30
- background-color: #fff;
31
- border-radius: 5px;
32
- padding: 2em;
33
- margin: 0 auto;
34
- max-width: 340px;
35
- box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.2);
36
-
37
- input {
38
- display: block;
39
- width: 100%;
40
- font-size: 16px;
41
- line-height: 2em;
42
- padding: 4px;
43
- border-radius: 5px;
44
- border: 1px solid #ececec;
45
- }
46
-
47
- input[type="submit"] {
48
- cursor: pointer;
49
- margin: 1em auto;
50
- width: 60%;
51
- padding: 4px;
52
- background-color: #ececec;
53
- border-radius: 25px;
54
- border: none;
55
- }
56
- }
57
-
58
- .sudo-tip {
59
- margin-top: 2em;
60
- font-size: 14px;
61
- }
62
-
63
- .sudo-alert {
64
- background: #000;
65
- color: #fff;
66
- padding: 10px;
67
- font-weight: bold;
68
- }
@@ -1,24 +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
-
8
- .sudo-alert {
9
- background-color: <%= SudoRails.color_contrast(SudoRails.background_color) %>;
10
- color: <%= SudoRails.background_color %>;
11
- }
12
- <% end %>
13
-
14
- <% if SudoRails.primary_color.present? %>
15
- a {
16
- color: <%= SudoRails.primary_color %>;
17
- }
18
-
19
- .sudo-form input[type="submit"] {
20
- background-color: <%= SudoRails.primary_color %>;
21
- color: <%= SudoRails.color_contrast(SudoRails.primary_color) %>;
22
- }
23
- <% end %>
24
- </style>