simple_auth 3.1.1 → 3.1.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: 4c6838ee76a4171f9949a217cb1071c3e419ff11b1c0bbf577ea05239ae2abb9
4
- data.tar.gz: 84b753d0a73b218d694ec8cbce6159997a44d73c6c44f9b8338fdfbb67c8a734
3
+ metadata.gz: 3d766e5009401ad9ed59c71e123f83046e23ea750ed8cc1f0aa7d3d3953f4185
4
+ data.tar.gz: fefbd6744a260ded45f3cb53db8fb5d407b0b4c8ac1fac606a9d49ce3321379c
5
5
  SHA512:
6
- metadata.gz: 8f605bdc0caad8f2c605116a1e9c293dce9ff24fd45ef63abae8084b4cc7959d94a61691df43796fa14fb2e49efcddb519cf9f20ed3172511bc0062d3ed692f2
7
- data.tar.gz: b40738c8f921ffd2bbd0a865948f816e6cf5ae125e7810a443d37a5925101bf4d03e3b55f35ca9ade4ce7003cddd1cd3fb576299ff0b8314a337e609d6b740e6
6
+ metadata.gz: 2b07279571d5d771fe036f2102a4c9c0333aea5eb8c87816a37c5c1742fd365b60926dd59dfe5e9cd265019a99035b41d250a2d939d711836ce50d50dfcc1ba0
7
+ data.tar.gz: 896be7f120ffe8154a7b3cdf7b90b4782b9b2f5914454ed8745051c9b1e612180afd0929cb2cd6c5f1286a6179b92e766a697e77b17fab3905e470ec9589d5ab
data/.rubocop.yml CHANGED
@@ -4,3 +4,6 @@ inherit_gem:
4
4
 
5
5
  AllCops:
6
6
  TargetRubyVersion: 2.6
7
+
8
+ Metrics/AbcSize:
9
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # v3.1.2
2
+
3
+ - Make flash message key configurable via
4
+ `SimpleAuth::Config#flash_message_key`.
5
+
1
6
  # v3.1.1
2
7
 
3
8
  - Catch exceptions related to record not found when session tries to load a
@@ -18,7 +23,8 @@
18
23
 
19
24
  # v2.0.3
20
25
 
21
- - Assign the raw password/confirmation, so we can apply validations on the raw value.
26
+ - Assign the raw password/confirmation, so we can apply validations on the raw
27
+ value.
22
28
 
23
29
  # v2.0.2
24
30
 
data/README.md CHANGED
@@ -32,6 +32,7 @@ SimpleAuth.setup do |config|
32
32
  config.scopes = %i[user admin]
33
33
  config.login_url = proc { login_path }
34
34
  config.logged_url = proc { dashboard_path }
35
+ config.flash_message_key = :alert
35
36
 
36
37
  config.install_helpers!
37
38
  end
@@ -143,12 +144,26 @@ These are the translations you'll need:
143
144
  en:
144
145
  simple_auth:
145
146
  user:
146
- need_to_be_logged_in: "You need to be logged"
147
+ need_to_be_logged_in: "You need to be logged in"
147
148
  not_authorized: "You don't have permission to access this page"
148
149
  ```
149
150
 
150
151
  If you don't set these translations, a default message will be used.
151
152
 
153
+ To display the error message, use something like `<%= flash[:alert] %>`. If you
154
+ want to use a custom key, say `:error`, use the configuration file
155
+ `config/initializers/simple_auth.rb` to define the new key:
156
+
157
+ # config/initializers/simple_auth.rb
158
+ SimpleAuth.setup do |config|
159
+ # ...
160
+
161
+ config.flash_message_key = :error
162
+
163
+ # ...
164
+ end
165
+ ```
166
+
152
167
  ## Maintainer
153
168
 
154
169
  * Nando Vieira (<http://nandovieira.com>)
data/Rakefile CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "bundler/gem_tasks"
4
4
  require "rake/testtask"
5
+ require "rubocop/rake_task"
5
6
 
6
7
  Rake::TestTask.new(:test) do |t|
7
8
  t.libs << "test"
@@ -9,4 +10,6 @@ Rake::TestTask.new(:test) do |t|
9
10
  t.test_files = FileList["test/**/*_test.rb"]
10
11
  end
11
12
 
12
- task default: :test
13
+ RuboCop::RakeTask.new
14
+
15
+ task default: %i[test rubocop]
data/lib/simple_auth.rb CHANGED
@@ -22,6 +22,7 @@ module SimpleAuth
22
22
  end
23
23
 
24
24
  setup do |config|
25
+ config.flash_message_key = :alert
25
26
  config.scopes = %i[user]
26
27
  config.login_url = -> { login_path }
27
28
  config.logged_url = -> { dashboard_path }
@@ -55,10 +55,11 @@ module SimpleAuth
55
55
 
56
56
  private def simple_auth_require_logged_scope(scope)
57
57
  action = RequireLoginAction.new(self, scope)
58
+
58
59
  return if action.valid?
59
60
 
60
61
  reset_session
61
- flash[:alert] = action.message
62
+ flash[simple_auth.flash_message_key] = action.message
62
63
  session[:return_to] = request.fullpath if request.get?
63
64
  redirect_to instance_eval(&simple_auth.login_url)
64
65
  end
@@ -16,6 +16,10 @@ module SimpleAuth
16
16
  # Default to `dashboard_path`.
17
17
  attr_accessor :logged_url
18
18
 
19
+ # Set the flash message key.
20
+ # This will be used when setting messages for unlogged/unauthorized users.
21
+ attr_accessor :flash_message_key
22
+
19
23
  def install_helpers!
20
24
  ::ActionController::Base.include SimpleAuth::ActionController
21
25
  end
@@ -20,6 +20,10 @@ SimpleAuth.setup do |config|
20
20
  # when `before_action :redirect_logged_user` filter is used.
21
21
  config.logged_url = proc { dashboard_path }
22
22
 
23
+ # Set the flash message key.
24
+ # This will be used when setting messages for unlogged/unauthorized users.
25
+ config.flash_message_key = :alert
26
+
23
27
  # Install SimpleAuth helpers to the controllers.
24
28
  config.install_helpers!
25
29
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SimpleAuth
4
- VERSION = "3.1.1"
4
+ VERSION = "3.1.2"
5
5
  end
@@ -10,11 +10,22 @@ class PagesControllerTest < ActionController::TestCase
10
10
  User.delete_all
11
11
  end
12
12
 
13
+ teardown do
14
+ SimpleAuth.config.flash_message_key = :alert
15
+ end
16
+
13
17
  test "sets flash message while redirecting unlogged user" do
14
18
  get :index
15
19
  assert_equal "You must be logged in to access this page.", flash[:alert]
16
20
  end
17
21
 
22
+ test "sets flash message using custom key" do
23
+ SimpleAuth.config.flash_message_key = :error
24
+
25
+ get :index
26
+ assert_equal "You must be logged in to access this page.", flash[:error]
27
+ end
28
+
18
29
  test "redirects to login url" do
19
30
  get :index
20
31
 
data/test/test_helper.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "simplecov"
4
- SimpleCov.start
4
+ SimpleCov.start do
5
+ add_filter "/test/"
6
+ end
5
7
 
6
8
  require "bundler/setup"
7
9
  require "rack/test"
@@ -16,4 +18,4 @@ require "active_record"
16
18
  ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
17
19
  require "./test/support/schema"
18
20
 
19
- Dir["./test/support/**/*.rb"].each {|file| require file }
21
+ Dir["./test/support/**/*.rb"].sort.each {|file| require file }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-09 00:00:00.000000000 Z
11
+ date: 2020-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: globalid