action_controller-stashed_redirects 0.2.0 → 0.2.2

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: 48ec4248e68dd1601b20102049942417dd5fb85a6411b3e23940457653cb7bf8
4
- data.tar.gz: 6e94e481bd7777dee9dc8f418aca0ffba90211058ac5c674585c582c5d133573
3
+ metadata.gz: cf64ad8ee2fb60526d8517bb26be521de7952bcfd87ed860bfe5ce2fe8a0deb0
4
+ data.tar.gz: ce4550656d8f30fc4629f72329229542c457403e95803177260fbe575e9ab51a
5
5
  SHA512:
6
- metadata.gz: d917ddb4a35845beb4b4dc57db8dc276e9017b0b5156c7dd3f321af6c17ecd050c468a6ad4cef51181a50c8c103a677d56762b328de5508862400f992b3519c2
7
- data.tar.gz: cda0947e46c98f256995b240cbd4aded5771e8ae34352e1f228e6b65010664dd408e23f080f587fad1df6ff0c71dd6022018a7f7a14c98f0e8ced4bc85c20f19
6
+ metadata.gz: f4188865c205f58bf080d879f50ad818716bac84145b568db85324ea5cbb1aa0f2afe1df87a8e9f2cb29be276ed66dfdceb9ca359e58292e7f11cfff5163c76e
7
+ data.tar.gz: 2ab7965676ca7d50f881f26ae8fb5bdac89624a02642303feeab5db5191065d73aa7af578533d98fa7b61eb72f8d34c33e8c2f6ad686aaf2a44d07ba32659f75
data/Gemfile.lock CHANGED
@@ -1,15 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- action_controller-stashed_redirects (0.2.0)
4
+ action_controller-stashed_redirects (0.2.2)
5
5
  actionpack (>= 7.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- actionpack (7.1.2)
11
- actionview (= 7.1.2)
12
- activesupport (= 7.1.2)
10
+ actionpack (7.1.3.4)
11
+ actionview (= 7.1.3.4)
12
+ activesupport (= 7.1.3.4)
13
13
  nokogiri (>= 1.8.5)
14
14
  racc
15
15
  rack (>= 2.2.4)
@@ -17,13 +17,13 @@ GEM
17
17
  rack-test (>= 0.6.3)
18
18
  rails-dom-testing (~> 2.2)
19
19
  rails-html-sanitizer (~> 1.6)
20
- actionview (7.1.2)
21
- activesupport (= 7.1.2)
20
+ actionview (7.1.3.4)
21
+ activesupport (= 7.1.3.4)
22
22
  builder (~> 3.1)
23
23
  erubi (~> 1.11)
24
24
  rails-dom-testing (~> 2.2)
25
25
  rails-html-sanitizer (~> 1.6)
26
- activesupport (7.1.2)
26
+ activesupport (7.1.3.4)
27
27
  base64
28
28
  bigdecimal
29
29
  concurrent-ruby (~> 1.0, >= 1.0.2)
@@ -34,42 +34,41 @@ GEM
34
34
  mutex_m
35
35
  tzinfo (~> 2.0)
36
36
  base64 (0.2.0)
37
- bigdecimal (3.1.5)
38
- builder (3.2.4)
39
- concurrent-ruby (1.2.2)
37
+ bigdecimal (3.1.8)
38
+ builder (3.3.0)
39
+ concurrent-ruby (1.3.3)
40
40
  connection_pool (2.4.1)
41
41
  crass (1.0.6)
42
- debug (1.9.1)
42
+ debug (1.9.2)
43
43
  irb (~> 1.10)
44
44
  reline (>= 0.3.8)
45
- drb (2.2.0)
46
- ruby2_keywords
47
- erubi (1.12.0)
48
- i18n (1.14.1)
45
+ drb (2.2.1)
46
+ erubi (1.13.0)
47
+ i18n (1.14.5)
49
48
  concurrent-ruby (~> 1.0)
50
- io-console (0.7.1)
51
- irb (1.11.0)
52
- rdoc
53
- reline (>= 0.3.8)
49
+ io-console (0.7.2)
50
+ irb (1.13.2)
51
+ rdoc (>= 4.0.0)
52
+ reline (>= 0.4.2)
54
53
  loofah (2.22.0)
55
54
  crass (~> 1.0.2)
56
55
  nokogiri (>= 1.12.0)
57
- minitest (5.20.0)
56
+ minitest (5.24.1)
58
57
  mutex_m (0.2.0)
59
- nokogiri (1.16.0-aarch64-linux)
58
+ nokogiri (1.16.6-aarch64-linux)
60
59
  racc (~> 1.4)
61
- nokogiri (1.16.0-arm-linux)
60
+ nokogiri (1.16.6-arm-linux)
62
61
  racc (~> 1.4)
63
- nokogiri (1.16.0-arm64-darwin)
62
+ nokogiri (1.16.6-arm64-darwin)
64
63
  racc (~> 1.4)
65
- nokogiri (1.16.0-x86-linux)
64
+ nokogiri (1.16.6-x86-linux)
66
65
  racc (~> 1.4)
67
- nokogiri (1.16.0-x86_64-linux)
66
+ nokogiri (1.16.6-x86_64-linux)
68
67
  racc (~> 1.4)
69
68
  psych (5.1.2)
70
69
  stringio
71
- racc (1.7.3)
72
- rack (3.0.8)
70
+ racc (1.8.0)
71
+ rack (3.1.6)
73
72
  rack-session (2.0.0)
74
73
  rack (>= 3.0.0)
75
74
  rack-test (2.1.0)
@@ -84,26 +83,25 @@ GEM
84
83
  rails-html-sanitizer (1.6.0)
85
84
  loofah (~> 2.21)
86
85
  nokogiri (~> 1.14)
87
- railties (7.1.2)
88
- actionpack (= 7.1.2)
89
- activesupport (= 7.1.2)
86
+ railties (7.1.3.4)
87
+ actionpack (= 7.1.3.4)
88
+ activesupport (= 7.1.3.4)
90
89
  irb
91
90
  rackup (>= 1.0.0)
92
91
  rake (>= 12.2)
93
92
  thor (~> 1.0, >= 1.2.2)
94
93
  zeitwerk (~> 2.6)
95
- rake (13.1.0)
96
- rdoc (6.6.2)
94
+ rake (13.2.1)
95
+ rdoc (6.7.0)
97
96
  psych (>= 4.0.0)
98
- reline (0.4.2)
97
+ reline (0.5.9)
99
98
  io-console (~> 0.5)
100
- ruby2_keywords (0.0.5)
101
- stringio (3.1.0)
102
- thor (1.3.0)
99
+ stringio (3.1.1)
100
+ thor (1.3.1)
103
101
  tzinfo (2.0.6)
104
102
  concurrent-ruby (~> 1.0)
105
103
  webrick (1.8.1)
106
- zeitwerk (2.6.12)
104
+ zeitwerk (2.6.16)
107
105
 
108
106
  PLATFORMS
109
107
  arm64-darwin-20
@@ -118,4 +116,4 @@ DEPENDENCIES
118
116
  rake (~> 13.0)
119
117
 
120
118
  BUNDLED WITH
121
- 2.5.4
119
+ 2.5.14
data/README.md CHANGED
@@ -65,10 +65,8 @@ end
65
65
  ```ruby
66
66
  # app/controllers/concerns/sudo/examination.rb
67
67
  module Sudo::Examination
68
- extend ActiveSupport::Concern
69
-
70
- class_methods do
71
- def require_sudo_on(*actions, **options) = require_sudo(only: *actions, **options)
68
+ def self.included(klass) = klass.singleton_class.class_eval do
69
+ def require_sudo_on(*actions, **) = require_sudo(only: *actions, **)
72
70
  def require_sudo(...) = before_action(:require_sudo, ...)
73
71
  end
74
72
 
@@ -76,7 +74,7 @@ module Sudo::Examination
76
74
  def require_sudo
77
75
  if sudo.exam_needed?
78
76
  raise "Non-get: can't redirect back here, make sure you do …something with an interstitial page?" unless request.get?
79
- redirect_to new_sudo_authentications_url(redirect_url: request.url)
77
+ redirect_to new_sudo_exams_url(redirect_url: request.url)
80
78
  end
81
79
  end
82
80
 
@@ -89,7 +87,7 @@ class ApplicationController < ActionController::Base
89
87
  end
90
88
  ```
91
89
 
92
- Notice how in `redirect_to new_sudo_authentications_url(redirect_url: request.original_url)` we're passing the `redirect_url:` along that `ActionController::StashedRedirects` will need.
90
+ Notice how in `redirect_to new_sudo_exams_url(redirect_url: request.url)` we're passing the `redirect_url:` along that `ActionController::StashedRedirects` will need.
93
91
  It's pointing back to the page we're on, which required sudo authentication, so we can redirect back to it after the sudo exam has been passed.
94
92
 
95
93
  Next up, we can add an in-memory PORO model to give the behavior some better names:
@@ -108,11 +106,11 @@ class Sudo < Data.define(:store)
108
106
  end
109
107
  ```
110
108
 
111
- Finally, we can add the authenticating sudo controller itself, where `stash_redirect_for` will use the `redirect_url:` from earlier:
109
+ Next, we can add the authenticating sudo controller itself, where `stash_redirect_for` will use the `redirect_url:` from earlier:
112
110
 
113
111
  ```ruby
114
- # app/controllers/sudo/authentications_controller.rb
115
- class Sudo::AuthenticationsController < ApplicationController
112
+ # app/controllers/sudo/exams_controller.rb
113
+ class Sudo::ExamsController < ApplicationController
116
114
  stash_redirect_for :sudo, on: :new
117
115
 
118
116
  def new
@@ -129,14 +127,18 @@ class Sudo::AuthenticationsController < ApplicationController
129
127
  end
130
128
  private def pass_sudo_exam? = Current.user.authenticate_password(params[:password])
131
129
  end
130
+ ```
132
131
 
132
+ Finally, we mount the routes for the controller:
133
+
134
+ ```ruby
133
135
  # config/routes.rb
134
136
  namespace :sudo do
135
- resources :authentications
137
+ resources :exams
136
138
  end
137
139
  ```
138
140
 
139
- Users can now fill-in their password, which will hit `sudo/authentications#create` and redirect them back to the edit form on the
141
+ Users can now fill-in their password, which will hit `sudo/exams#create` and redirect them back to the edit form on the
140
142
  credit cards flow if it's the correct password.
141
143
 
142
144
  ## Installation
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActionController
4
4
  module StashedRedirects
5
- VERSION = "0.2.0"
5
+ VERSION = "0.2.2"
6
6
  end
7
7
  end
@@ -83,12 +83,18 @@ module ActionController::StashedRedirects
83
83
  end
84
84
  end
85
85
 
86
- # Looks up a redirect URL from `params[:redirect_url]` using
87
- # `url_from` as the protection mechanism to ensure it's a valid internal redirect.
86
+ # Syntactic sugar for redirecting to `redirect_url` with a fallback.
88
87
  #
89
- # Can be passed to `redirect_to` with a fallback:
88
+ # redirect_forward_or_to root_url # => redirect_to redirect_url || root_url
89
+ def redirect_forward_or_to(fallback_url)
90
+ redirect_to redirect_url || fallback_url
91
+ end
92
+
93
+ # Looks up a redirect URL from `params[:redirect_url]` using
94
+ # Rails' `url_from` as the protection mechanism to ensure it's a valid internal redirect.
95
+ # See the `url_from` docs: https://api.rubyonrails.org/classes/ActionController/Redirecting.html#method-i-url_from
90
96
  #
91
- # redirect_to redirect_url || users_url
97
+ # You probably want to use `redirect_forward_or_to`.
92
98
  def redirect_url = url_from(params[:redirect_url])
93
99
 
94
100
  DEFAULT_URL = Object.new
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_controller-stashed_redirects
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kasper Timm Hansen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-08 00:00:00.000000000 Z
11
+ date: 2024-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack