authorized_persona 0.9.0 → 0.9.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: 3072dc5f8b435349401f93116e4b0b7e3b7186f575edc9b8445d8cb57b0dff5a
4
- data.tar.gz: b667896c39b2f9707949556f27bbaf38da5c98c59e0bdd2ef7fe201eb078f6b4
3
+ metadata.gz: 83c7b75e101248119260f84dc0cfabd9dc6db7a079cacf89de689d7863e12028
4
+ data.tar.gz: 9d1e4c231c66e743650ae5566192a5a5aa640974d616c3f508b0f08a981ed592
5
5
  SHA512:
6
- metadata.gz: 359023dc6e9a4a3404fba063afc428cab6054910c7f495acbd3e8eaac045d1a3e8145f57b9b2e3355b7518110b57dcf6977338d75981ef6e93e5d267a01ba9e7
7
- data.tar.gz: 6109174ab892f4585d4a6cec4300d29184d55db985b100aae70a299b0a1f5f555bf50b97f20065b34e282cec13a633047989e759d2141cbca578b571e7ac84da
6
+ metadata.gz: db6b39f1ca8cadb3e9180e17bf36eb33467c5d929144444ac9d17d2e949d13697c36a21241f4e168367c0013569699299e6322b2e85d1548ef2360c9377ff890
7
+ data.tar.gz: 6300f79ee516294b170acd149d555b80c23033a29513d667511ef447e8025abccff942faf9ab55823dedc3d871daa17326c691ef4ef969d544c2958451bd5794
@@ -0,0 +1,27 @@
1
+ name: CI
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ fail-fast: false
10
+ matrix:
11
+ ruby: ['2.7', '3.0']
12
+ gemfile:
13
+ - gemfiles/rails_6_0.gemfile
14
+ - gemfiles/rails_6_1.gemfile
15
+ - gemfiles/rails_7_0.gemfile
16
+ steps:
17
+ - uses: actions/checkout@v2
18
+ - uses: ruby/setup-ruby@v1
19
+ env:
20
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
21
+ with:
22
+ ruby-version: ${{ matrix.ruby }}
23
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
24
+ - name: Run tests and linter
25
+ env:
26
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
27
+ run: bundle exec rake
data/.gitignore CHANGED
@@ -11,3 +11,4 @@
11
11
  .rspec_status
12
12
 
13
13
  /Gemfile.lock
14
+ *.gemfile.lock
data/.rubocop.yml CHANGED
@@ -1,3 +1,5 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
1
3
  inherit_gem:
2
- rubocop-betterment:
4
+ betterlint:
3
5
  - config/default.yml
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,100 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 99999`
3
+ # on 2023-05-09 13:01:46 UTC using RuboCop version 1.50.2.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 4
10
+ # Configuration parameters: EnforcedStyle, AllowedGems, Include.
11
+ # SupportedStyles: Gemfile, gems.rb, gemspec
12
+ # Include: **/*.gemspec, **/Gemfile, **/gems.rb
13
+ Gemspec/DevelopmentDependencies:
14
+ Exclude:
15
+ - 'authorized_persona.gemspec'
16
+
17
+ # Offense count: 1
18
+ # Configuration parameters: Severity, Include.
19
+ # Include: **/*.gemspec
20
+ Gemspec/RequiredRubyVersion:
21
+ Exclude:
22
+ - 'authorized_persona.gemspec'
23
+
24
+ # Offense count: 1
25
+ # This cop supports safe autocorrection (--autocorrect).
26
+ # Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
27
+ # URISchemes: http, https
28
+ Layout/LineLength:
29
+ Exclude:
30
+ - 'lib/authorized_persona/authorization.rb'
31
+
32
+ # Offense count: 2
33
+ Lint/MissingSuper:
34
+ Exclude:
35
+ - 'spec/authorized_persona/authorization_spec.rb'
36
+ - 'spec/authorized_persona/persona_spec.rb'
37
+
38
+ # Offense count: 2
39
+ # This cop supports safe autocorrection (--autocorrect).
40
+ Lint/RedundantCopDisableDirective:
41
+ Exclude:
42
+ - 'lib/authorized_persona/authorization.rb'
43
+
44
+ # Offense count: 1
45
+ # Configuration parameters: AllowedMethods, AllowedPatterns, Max.
46
+ Metrics/PerceivedComplexity:
47
+ Exclude:
48
+ - 'lib/authorized_persona/persona.rb'
49
+
50
+ # Offense count: 2
51
+ # This cop supports unsafe autocorrection (--autocorrect-all).
52
+ RSpec/BeEq:
53
+ Exclude:
54
+ - 'spec/authorized_persona/authorization_spec.rb'
55
+
56
+ # Offense count: 1
57
+ # This cop supports unsafe autocorrection (--autocorrect-all).
58
+ Rails/ActiveSupportOnLoad:
59
+ Exclude:
60
+ - 'lib/authorized_persona/railtie.rb'
61
+
62
+ # Offense count: 1
63
+ Rails/I18nLocaleTexts:
64
+ Exclude:
65
+ - 'lib/authorized_persona/authorization.rb'
66
+
67
+ # Offense count: 1
68
+ # This cop supports unsafe autocorrection (--autocorrect-all).
69
+ # Configuration parameters: Include.
70
+ # Include: **/Rakefile, **/*.rake
71
+ Rails/RakeEnvironment:
72
+ Exclude:
73
+ - 'Rakefile'
74
+
75
+ # Offense count: 1
76
+ # This cop supports safe autocorrection (--autocorrect).
77
+ Rake/Desc:
78
+ Exclude:
79
+ - 'Rakefile'
80
+
81
+ # Offense count: 2
82
+ # This cop supports unsafe autocorrection (--autocorrect-all).
83
+ # Configuration parameters: AllowedReceivers.
84
+ # AllowedReceivers: Thread.current
85
+ Style/HashEachMethods:
86
+ Exclude:
87
+ - 'lib/authorized_persona/persona.rb'
88
+
89
+ # Offense count: 1
90
+ # This cop supports unsafe autocorrection (--autocorrect-all).
91
+ Style/MapToHash:
92
+ Exclude:
93
+ - 'lib/authorized_persona/authorization.rb'
94
+
95
+ # Offense count: 1
96
+ # This cop supports unsafe autocorrection (--autocorrect-all).
97
+ # Configuration parameters: Mode.
98
+ Style/StringConcatenation:
99
+ Exclude:
100
+ - 'lib/authorized_persona/view_helpers.rb'
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.0.6
data/Appraisals ADDED
@@ -0,0 +1,14 @@
1
+ appraise 'rails-6-0' do
2
+ gem 'railties', '~> 6.0.0'
3
+ gem 'activemodel', '~>6.0.0'
4
+ end
5
+
6
+ appraise 'rails-6-1' do
7
+ gem 'railties', '~> 6.1.0'
8
+ gem 'activemodel', '~>6.1.0'
9
+ end
10
+
11
+ appraise 'rails-7-0' do
12
+ gem 'railties', '~> 7.0.0'
13
+ gem 'activemodel', '~>7.0.0'
14
+ end
data/README.md CHANGED
@@ -107,23 +107,24 @@ end
107
107
  class ApplicationController < ActionController::Base
108
108
  include AuthorizedPersona::Authorization
109
109
 
110
- # Any needed hooks your authentication library needs to ensure
110
+ # Any hooks your authentication library needs to ensure
111
111
  # `current_user` is set before # authorization, e.g.:
112
112
  #
113
- # before_filter :authenticate_user!
113
+ # before_action :authenticate_user!
114
114
 
115
115
  authorize_persona class_name: "User"
116
116
 
117
117
  # or optionally override the method name we use to fetch current_[class_name] e.g.:
118
118
  #
119
- # authorize_persona class_name: "User", current_user_method_name: :current_fancy_user
119
+ # authorize_persona class_name: "User", current_user_method: :current_fancy_user
120
120
 
121
121
  # Your code here...
122
122
  end
123
123
  ```
124
124
 
125
125
  At this point, no user is authorized to make a request to any descendent
126
- of `ApplicationController`.
126
+ of `ApplicationController`. Note that any unauthenticated controllers (e.g. authentication
127
+ controllers) will need to have authorization disabled via `skip_before_action :authorize!`.
127
128
 
128
129
  3. Grant privileges in your base controller or any subclass:
129
130
 
@@ -22,13 +22,15 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
24
 
25
- rails_version_range = [">= 5.1.6.2", "< 7"]
25
+ rails_version_range = [">= 5.1.6.2", "< 7.1"]
26
26
 
27
27
  spec.add_dependency "railties", *rails_version_range
28
28
 
29
29
  spec.add_development_dependency "activemodel", *rails_version_range
30
- spec.add_development_dependency "bundler", "~> 2.0"
31
- spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "appraisal"
31
+ spec.add_development_dependency "betterlint"
32
+ spec.add_development_dependency "bundler"
33
+ spec.add_development_dependency "rake"
32
34
  spec.add_development_dependency "rspec", "~> 3.0"
33
- spec.add_development_dependency "rubocop-betterment"
35
+ spec.metadata['rubygems_mfa_required'] = 'true'
34
36
  end
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activemodel", "~>6.0.0"
6
+ gem "railties", "~> 6.0.0"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activemodel", "~>6.1.0"
6
+ gem "railties", "~> 6.1.0"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activemodel", "~>7.0.0"
6
+ gem "railties", "~> 7.0.0"
7
+
8
+ gemspec path: "../"
@@ -13,7 +13,7 @@ module AuthorizedPersona
13
13
 
14
14
  class_methods do
15
15
  # Configure authorization for an authorized persona class
16
- def authorize_persona(class_name:, current_user_method: nil) # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity, Metrics/MethodLength, Metrics/LineLength
16
+ def authorize_persona(class_name:, current_user_method: nil) # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity, Metrics/
17
17
  raise AuthorizedPersona::Error, "you can only configure authorization once" if authorization_persona_class_name.present?
18
18
  raise AuthorizedPersona::Error, "class_name must be a string" unless class_name.is_a?(String)
19
19
  raise AuthorizedPersona::Error, "current_user_method must be a symbol" if current_user_method && !current_user_method.is_a?(Symbol)
@@ -36,13 +36,13 @@ module AuthorizedPersona
36
36
 
37
37
  # Grants replace all previous grants to avoid privilege leakage
38
38
  def grant(privileges) # rubocop:disable Metrics/AbcSize
39
- self.authorized_actions = Hash[privileges.map { |auth_tier, actions| [auth_tier.to_s, [actions].flatten.map(&:to_sym)] }]
39
+ self.authorized_actions = privileges.map { |auth_tier, actions| [auth_tier.to_s, [actions].flatten.map(&:to_sym)] }.to_h
40
40
 
41
41
  tier_names = authorization_persona.authorization_tier_names
42
42
  extra_keys = authorized_actions.keys - authorization_persona.authorization_tier_names
43
43
  if extra_keys.present?
44
44
  raise AuthorizedPersona::Error, "invalid grant: #{authorization_persona_class_name} " \
45
- "has authorization tiers #{tier_names.join(', ')} but received extra keys: #{extra_keys.join(', ')}"
45
+ "has authorization tiers #{tier_names.join(', ')} but received extra keys: #{extra_keys.join(', ')}"
46
46
  end
47
47
  end
48
48
 
@@ -79,7 +79,7 @@ module AuthorizedPersona
79
79
  def authorization_current_user
80
80
  unless authorization_current_user_method.is_a?(Symbol)
81
81
  raise AuthorizedPersona::Error, "you must configure authorization with a valid current_user method name, " \
82
- "e.g. `authorize_persona class_name: 'User', current_user_method: :my_custom_current_user`"
82
+ "e.g. `authorize_persona class_name: 'User', current_user_method: :my_custom_current_user`"
83
83
  end
84
84
 
85
85
  send(self.class.authorization_current_user_method)
@@ -89,7 +89,7 @@ module AuthorizedPersona
89
89
  self.class.authorized_tier(action: params[:action])
90
90
  end
91
91
 
92
- def authorize! # rubocop:disable Metrics/MethodLength
92
+ def authorize!
93
93
  return if authorized?
94
94
 
95
95
  respond_to do |format|
@@ -34,7 +34,7 @@ module AuthorizedPersona
34
34
  end
35
35
 
36
36
  # Configure the authorization tiers in my_tier_slug: "My Tier Title And Description" form from lowest to highest privilege.
37
- def authorization_tiers(tiers) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
37
+ def authorization_tiers(tiers) # rubocop:disable Metrics/AbcSize
38
38
  raise AuthorizedPersona::Error, "you can only define authorization tiers once" if instance_variable_defined?(:@authorization_tiers)
39
39
 
40
40
  if !tiers.is_a?(Hash) || !tiers.all? { |k, v| k.is_a?(Symbol) && v.is_a?(String) }
@@ -1,7 +1,7 @@
1
1
  module AuthorizedPersona
2
2
  class Railtie < Rails::Railtie
3
3
  initializer "authorized_persona.view_helpers" do
4
- ActionView::Base.send :include, AuthorizedPersona::ViewHelpers
4
+ ActionView::Base.include AuthorizedPersona::ViewHelpers
5
5
  end
6
6
  end
7
7
  end
@@ -1,3 +1,3 @@
1
1
  module AuthorizedPersona
2
- VERSION = "0.9.0".freeze
2
+ VERSION = "0.9.1".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authorized_persona
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mileham
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-08 00:00:00.000000000 Z
11
+ date: 2023-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: 5.1.6.2
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '7'
22
+ version: '7.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: 5.1.6.2
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '7'
32
+ version: '7.1'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: activemodel
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -39,7 +39,7 @@ dependencies:
39
39
  version: 5.1.6.2
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
- version: '7'
42
+ version: '7.1'
43
43
  type: :development
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
@@ -49,51 +49,51 @@ dependencies:
49
49
  version: 5.1.6.2
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
- version: '7'
52
+ version: '7.1'
53
53
  - !ruby/object:Gem::Dependency
54
- name: bundler
54
+ name: appraisal
55
55
  requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
- - - "~>"
57
+ - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: '2.0'
59
+ version: '0'
60
60
  type: :development
61
61
  prerelease: false
62
62
  version_requirements: !ruby/object:Gem::Requirement
63
63
  requirements:
64
- - - "~>"
64
+ - - ">="
65
65
  - !ruby/object:Gem::Version
66
- version: '2.0'
66
+ version: '0'
67
67
  - !ruby/object:Gem::Dependency
68
- name: rake
68
+ name: betterlint
69
69
  requirement: !ruby/object:Gem::Requirement
70
70
  requirements:
71
- - - "~>"
71
+ - - ">="
72
72
  - !ruby/object:Gem::Version
73
- version: '10.0'
73
+ version: '0'
74
74
  type: :development
75
75
  prerelease: false
76
76
  version_requirements: !ruby/object:Gem::Requirement
77
77
  requirements:
78
- - - "~>"
78
+ - - ">="
79
79
  - !ruby/object:Gem::Version
80
- version: '10.0'
80
+ version: '0'
81
81
  - !ruby/object:Gem::Dependency
82
- name: rspec
82
+ name: bundler
83
83
  requirement: !ruby/object:Gem::Requirement
84
84
  requirements:
85
- - - "~>"
85
+ - - ">="
86
86
  - !ruby/object:Gem::Version
87
- version: '3.0'
87
+ version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
90
  version_requirements: !ruby/object:Gem::Requirement
91
91
  requirements:
92
- - - "~>"
92
+ - - ">="
93
93
  - !ruby/object:Gem::Version
94
- version: '3.0'
94
+ version: '0'
95
95
  - !ruby/object:Gem::Dependency
96
- name: rubocop-betterment
96
+ name: rake
97
97
  requirement: !ruby/object:Gem::Requirement
98
98
  requirements:
99
99
  - - ">="
@@ -106,6 +106,20 @@ dependencies:
106
106
  - - ">="
107
107
  - !ruby/object:Gem::Version
108
108
  version: '0'
109
+ - !ruby/object:Gem::Dependency
110
+ name: rspec
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: '3.0'
116
+ type: :development
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: '3.0'
109
123
  description: AuthorizedPersona is a rails implementation of Betterment's Persona Centric
110
124
  Authorization pattern
111
125
  email:
@@ -114,10 +128,13 @@ executables: []
114
128
  extensions: []
115
129
  extra_rdoc_files: []
116
130
  files:
131
+ - ".github/workflows/ci.yml"
117
132
  - ".gitignore"
118
133
  - ".rspec"
119
134
  - ".rubocop.yml"
120
- - ".travis.yml"
135
+ - ".rubocop_todo.yml"
136
+ - ".ruby-version"
137
+ - Appraisals
121
138
  - CODE_OF_CONDUCT.md
122
139
  - Gemfile
123
140
  - LICENSE.txt
@@ -126,6 +143,9 @@ files:
126
143
  - authorized_persona.gemspec
127
144
  - bin/console
128
145
  - bin/setup
146
+ - gemfiles/rails_6_0.gemfile
147
+ - gemfiles/rails_6_1.gemfile
148
+ - gemfiles/rails_7_0.gemfile
129
149
  - lib/authorized_persona.rb
130
150
  - lib/authorized_persona/authorization.rb
131
151
  - lib/authorized_persona/persona.rb
@@ -135,8 +155,9 @@ files:
135
155
  homepage: https://github.com/Betterment/authorized_persona
136
156
  licenses:
137
157
  - MIT
138
- metadata: {}
139
- post_install_message:
158
+ metadata:
159
+ rubygems_mfa_required: 'true'
160
+ post_install_message:
140
161
  rdoc_options: []
141
162
  require_paths:
142
163
  - lib
@@ -151,8 +172,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
172
  - !ruby/object:Gem::Version
152
173
  version: '0'
153
174
  requirements: []
154
- rubygems_version: 3.0.3
155
- signing_key:
175
+ rubygems_version: 3.4.12
176
+ signing_key:
156
177
  specification_version: 4
157
178
  summary: the simplest authorization library you will ever love
158
179
  test_files: []
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.6.1
7
- before_install: gem install bundler -v 2.0.1