rodauth-rails 1.3.0 → 1.3.1

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: b1f519c5d15eb6c70585c8cfa625106dec267b4e7f666daeeb9499ef61c656e7
4
- data.tar.gz: 1bc84d1dba6ab9ab884a56f47419e207655c90f1d71d32b009575ab169fc0b3d
3
+ metadata.gz: 4e268594e5890725cbba25ee24ab158df204ada3789aeebe428b737307128d9e
4
+ data.tar.gz: dca778863032dc428ac44b5feca48fe430ef55ea64f4e10050293d1c1a3d95c6
5
5
  SHA512:
6
- metadata.gz: 88ccdb974fe6b6dd0e797cf5307656c80d7038c820eab897b277b6c22bd1bc61cc00e7e39295d2a98fc313530ad658c6be80e043dde595d3514c3a51fa0572a4
7
- data.tar.gz: d17fc8142a16f18ff485446d94e68ed4672faa64edfa8aaac3b400e9060f9638575a577ff232b83a1360a58e8655199c1ab88972f77a3af0f45d76f3514b7df5
6
+ metadata.gz: 9008b2381959811820eca625f68c5df7ec2021319ceb2c7bdf6c75412f32ea51f01ffabd716da73f6565e263e0a74699c2c940a70296adf0b9c0b8576ef8e3de
7
+ data.tar.gz: 4b0d70d43ff624b610bcded93a528b089d103f11975b7fdec9c8bd38b1f81b5c003de2fa1e4068f2c2006841f91783044280fa575ec5951b2ae319f4836a49b7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.3.1 (2022-04-22)
2
+
3
+ * Ensure response status is logged when calling a halting rodauth method inside a controller (@janko)
4
+
1
5
  ## 1.3.0 (2022-04-01)
2
6
 
3
7
  * Store password hash on the `accounts` table in generated Rodauth migration and configuration (@janko)
@@ -5,17 +5,21 @@ module Rodauth
5
5
  module Rails
6
6
  # The superclass for creating a Rodauth middleware.
7
7
  class App < Roda
8
- require "rodauth/rails/app/middleware"
9
- plugin Middleware
8
+ plugin :middleware, forward_response_headers: true do |middleware|
9
+ middleware.class_eval do
10
+ def self.inspect
11
+ "#{superclass}::Middleware"
12
+ end
13
+
14
+ def inspect
15
+ "#<#{self.class.inspect} request=#{request.inspect} response=#{response.inspect}>"
16
+ end
17
+ end
18
+ end
10
19
 
11
20
  plugin :hooks
12
21
  plugin :render, layout: false
13
22
 
14
- unless Rodauth::Rails.api_only?
15
- require "rodauth/rails/app/flash"
16
- plugin Flash
17
- end
18
-
19
23
  def self.configure(*args, **options, &block)
20
24
  auth_class = args.shift if args[0].is_a?(Class)
21
25
  name = args.shift if args[0].is_a?(Symbol)
@@ -35,6 +39,14 @@ module Rodauth
35
39
  end
36
40
  end
37
41
 
42
+ after do
43
+ rails_request.commit_flash
44
+ end unless ActionPack.version < Gem::Version.new("5.0")
45
+
46
+ def flash
47
+ rails_request.flash
48
+ end
49
+
38
50
  def rails_routes
39
51
  ::Rails.application.routes.url_helpers
40
52
  end
@@ -18,6 +18,15 @@ module Rodauth
18
18
 
19
19
  private
20
20
 
21
+ # Adds response status to instrumentation payload for logging,
22
+ # when calling a halting rodauth method inside a controller.
23
+ def append_info_to_payload(payload)
24
+ super
25
+ if request.env["rodauth.rails.status"]
26
+ payload[:status] = request.env.delete("rodauth.rails.status")
27
+ end
28
+ end
29
+
21
30
  def rodauth_response
22
31
  res = catch(:halt) { return yield }
23
32
 
@@ -54,6 +54,16 @@ module Rodauth
54
54
 
55
55
  private
56
56
 
57
+ unless ActionPack.version < Gem::Version.new("5.0")
58
+ # When calling a Rodauth method that redirects inside the Rails
59
+ # router, Roda's after hook that commits the flash would never get
60
+ # called, so we make sure to commit the flash beforehand.
61
+ def redirect(*)
62
+ rails_request.commit_flash
63
+ super
64
+ end
65
+ end
66
+
57
67
  def instantiate_rails_account
58
68
  if defined?(ActiveRecord::Base) && rails_account_model < ActiveRecord::Base
59
69
  rails_account_model.instantiate(account.stringify_keys)
@@ -10,6 +10,14 @@ module Rodauth
10
10
 
11
11
  def redirect(*)
12
12
  rails_instrument_redirection { super }
13
+ ensure
14
+ request.env["rodauth.rails.status"] = response.status
15
+ end
16
+
17
+ def return_response(*)
18
+ super
19
+ ensure
20
+ request.env["rodauth.rails.status"] = response.status
13
21
  end
14
22
 
15
23
  def rails_render(*)
@@ -1,5 +1,5 @@
1
1
  module Rodauth
2
2
  module Rails
3
- VERSION = "1.3.0"
3
+ VERSION = "1.3.1"
4
4
  end
5
5
  end
@@ -17,7 +17,8 @@ Gem::Specification.new do |spec|
17
17
  spec.require_paths = ["lib"]
18
18
 
19
19
  spec.add_dependency "railties", ">= 4.2", "< 8"
20
- spec.add_dependency "rodauth", "~> 2.19"
20
+ spec.add_dependency "rodauth", "~> 2.23"
21
+ spec.add_dependency "roda", "~> 3.55"
21
22
  spec.add_dependency "sequel-activerecord_connection", "~> 1.1"
22
23
  spec.add_dependency "tilt"
23
24
  spec.add_dependency "bcrypt"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rodauth-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janko Marohnić
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-01 00:00:00.000000000 Z
11
+ date: 2022-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -36,14 +36,28 @@ dependencies:
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '2.19'
39
+ version: '2.23'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '2.19'
46
+ version: '2.23'
47
+ - !ruby/object:Gem::Dependency
48
+ name: roda
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.55'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.55'
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: sequel-activerecord_connection
49
63
  requirement: !ruby/object:Gem::Requirement
@@ -230,8 +244,6 @@ files:
230
244
  - lib/rodauth-rails.rb
231
245
  - lib/rodauth/rails.rb
232
246
  - lib/rodauth/rails/app.rb
233
- - lib/rodauth/rails/app/flash.rb
234
- - lib/rodauth/rails/app/middleware.rb
235
247
  - lib/rodauth/rails/auth.rb
236
248
  - lib/rodauth/rails/controller_methods.rb
237
249
  - lib/rodauth/rails/feature.rb
@@ -1,45 +0,0 @@
1
- module Rodauth
2
- module Rails
3
- class App
4
- # Roda plugin that sets up Rails flash integration.
5
- module Flash
6
- def self.load_dependencies(app)
7
- app.plugin :hooks
8
- end
9
-
10
- def self.configure(app)
11
- app.after { request.commit_flash }
12
- end
13
-
14
- module InstanceMethods
15
- def flash
16
- request.flash
17
- end
18
- end
19
-
20
- module RequestMethods
21
- # If the redirect would bubble up outside of the Roda app, the after
22
- # hook would never get called, so we make sure to commit the flash.
23
- def redirect(*)
24
- commit_flash
25
- super
26
- end
27
-
28
- def flash
29
- scope.rails_request.flash
30
- end
31
-
32
- if ActionPack.version >= Gem::Version.new("5.0")
33
- def commit_flash
34
- scope.rails_request.commit_flash
35
- end
36
- else
37
- def commit_flash
38
- # ActionPack 4.2 automatically commits flash
39
- end
40
- end
41
- end
42
- end
43
- end
44
- end
45
- end
@@ -1,36 +0,0 @@
1
- module Rodauth
2
- module Rails
3
- class App
4
- # Roda plugin that extends middleware plugin by propagating response headers.
5
- module Middleware
6
- def self.configure(app)
7
- handle_result = -> (env, res) do
8
- if headers = env.delete("rodauth.rails.headers")
9
- res[1] = headers.merge(res[1])
10
- end
11
- end
12
-
13
- app.plugin :middleware, handle_result: handle_result do |middleware|
14
- middleware.plugin :hooks
15
-
16
- middleware.after do
17
- if response.empty? && response.headers.any?
18
- env["rodauth.rails.headers"] = response.headers
19
- end
20
- end
21
-
22
- middleware.class_eval do
23
- def self.inspect
24
- "#{superclass}::Middleware"
25
- end
26
-
27
- def inspect
28
- "#<#{self.class.inspect} request=#{request.inspect} response=#{response.inspect}>"
29
- end
30
- end
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end