pundit 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +19 -46
- data/.travis.yml +8 -8
- data/CHANGELOG.md +28 -3
- data/Gemfile +2 -11
- data/LICENSE.txt +1 -1
- data/README.md +8 -0
- data/Rakefile +2 -0
- data/lib/generators/rspec/templates/policy_spec.rb +1 -1
- data/lib/pundit/policy_finder.rb +2 -0
- data/lib/pundit/rspec.rb +2 -0
- data/lib/pundit/version.rb +1 -1
- data/lib/pundit.rb +26 -12
- data/pundit.gemspec +12 -2
- data/spec/policies/post_policy_spec.rb +2 -0
- data/spec/policy_finder_spec.rb +2 -0
- data/spec/pundit_spec.rb +40 -23
- data/spec/spec_helper.rb +14 -0
- metadata +116 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 371516754ff155f90b2093a0ce80aacf097ab555027b19ea22b7c823de72a66a
|
|
4
|
+
data.tar.gz: 41e69a7d6a317b46ad35d1d1485d2119b443b8a430e5c78e62935ec502c7d08f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c77a792bec5d87f487fd3ee419d00745dcab754bd1bd38504d9987b71d80be3bd32fb1aab8419a8e63ef3c3718e1bd8a255ff0117be8f8a5c743c221d87fccdd
|
|
7
|
+
data.tar.gz: 3086b4036cdbafb499f462f22405f185c83d12c8d8175136531dd053733320574b3d5d05c8379895940d854d54d7abb59d6a0958a9d0e6fdfc03f7691883c3ab
|
data/.rubocop.yml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
AllCops:
|
|
2
2
|
DisplayCopNames: true
|
|
3
|
-
TargetRubyVersion: 2.
|
|
3
|
+
TargetRubyVersion: 2.2
|
|
4
4
|
Exclude:
|
|
5
5
|
- "gemfiles/**/*"
|
|
6
6
|
- "vendor/**/*"
|
|
@@ -30,33 +30,9 @@ Metrics/CyclomaticComplexity:
|
|
|
30
30
|
Metrics/PerceivedComplexity:
|
|
31
31
|
Enabled: false
|
|
32
32
|
|
|
33
|
-
Style/StructInheritance:
|
|
34
|
-
Enabled: false
|
|
35
|
-
|
|
36
33
|
Layout/AlignParameters:
|
|
37
34
|
EnforcedStyle: with_fixed_indentation
|
|
38
35
|
|
|
39
|
-
Style/StringLiterals:
|
|
40
|
-
EnforcedStyle: double_quotes
|
|
41
|
-
|
|
42
|
-
Style/StringLiteralsInInterpolation:
|
|
43
|
-
EnforcedStyle: double_quotes
|
|
44
|
-
|
|
45
|
-
Layout/ClosingParenthesisIndentation:
|
|
46
|
-
Enabled: false
|
|
47
|
-
|
|
48
|
-
Style/OneLineConditional:
|
|
49
|
-
Enabled: false
|
|
50
|
-
|
|
51
|
-
Style/AndOr:
|
|
52
|
-
Enabled: false
|
|
53
|
-
|
|
54
|
-
Style/Not:
|
|
55
|
-
Enabled: false
|
|
56
|
-
|
|
57
|
-
Documentation:
|
|
58
|
-
Enabled: false # TODO: Enable again once we have more docs
|
|
59
|
-
|
|
60
36
|
Layout/CaseIndentation:
|
|
61
37
|
EnforcedStyle: case
|
|
62
38
|
SupportedStyles:
|
|
@@ -64,40 +40,37 @@ Layout/CaseIndentation:
|
|
|
64
40
|
- end
|
|
65
41
|
IndentOneStep: true
|
|
66
42
|
|
|
67
|
-
Style/PercentLiteralDelimiters:
|
|
68
|
-
PreferredDelimiters:
|
|
69
|
-
'%w': "[]"
|
|
70
|
-
'%W': "[]"
|
|
71
|
-
|
|
72
43
|
Layout/AccessModifierIndentation:
|
|
73
44
|
EnforcedStyle: outdent
|
|
74
45
|
|
|
75
|
-
Style/SignalException:
|
|
76
|
-
Enabled: false
|
|
77
|
-
|
|
78
|
-
Layout/IndentationWidth:
|
|
79
|
-
Enabled: false
|
|
80
|
-
|
|
81
|
-
Style/TrivialAccessors:
|
|
82
|
-
ExactNameMatch: true
|
|
83
|
-
|
|
84
46
|
Layout/EndAlignment:
|
|
85
47
|
EnforcedStyleAlignWith: variable
|
|
86
48
|
|
|
87
|
-
|
|
88
|
-
Enabled:
|
|
49
|
+
Style/FrozenStringLiteralComment:
|
|
50
|
+
Enabled: true
|
|
89
51
|
|
|
90
|
-
|
|
91
|
-
|
|
52
|
+
Style/PercentLiteralDelimiters:
|
|
53
|
+
PreferredDelimiters:
|
|
54
|
+
'%w': "[]"
|
|
55
|
+
'%W': "[]"
|
|
92
56
|
|
|
93
|
-
Style/
|
|
57
|
+
Style/StringLiterals:
|
|
58
|
+
EnforcedStyle: double_quotes
|
|
59
|
+
|
|
60
|
+
Style/StringLiteralsInInterpolation:
|
|
61
|
+
EnforcedStyle: double_quotes
|
|
62
|
+
|
|
63
|
+
Style/StructInheritance:
|
|
94
64
|
Enabled: false
|
|
95
65
|
|
|
96
|
-
Style/
|
|
66
|
+
Style/AndOr:
|
|
97
67
|
Enabled: false
|
|
98
68
|
|
|
99
|
-
|
|
69
|
+
Style/Not:
|
|
100
70
|
Enabled: false
|
|
101
71
|
|
|
102
72
|
Style/DoubleNegation:
|
|
103
73
|
Enabled: false
|
|
74
|
+
|
|
75
|
+
Documentation:
|
|
76
|
+
Enabled: false # TODO: Enable again once we have more docs
|
data/.travis.yml
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
language: ruby
|
|
2
|
-
sudo: false
|
|
3
2
|
before_install:
|
|
4
|
-
- gem
|
|
5
|
-
- gem install bundler
|
|
3
|
+
- gem install bundler -v 1.17.3
|
|
6
4
|
|
|
7
5
|
matrix:
|
|
8
6
|
include:
|
|
9
|
-
- rvm: 2.5.1
|
|
7
|
+
- rvm: 2.5.1 # Pre-installed Ruby version
|
|
10
8
|
script: bundle exec rake rubocop # ONLY lint once, first
|
|
11
9
|
- rvm: 2.1
|
|
12
|
-
- rvm: 2.2
|
|
10
|
+
- rvm: 2.2
|
|
13
11
|
- rvm: 2.3.5
|
|
14
|
-
- rvm: 2.4.
|
|
15
|
-
- rvm: 2.5.
|
|
12
|
+
- rvm: 2.4.6
|
|
13
|
+
- rvm: 2.5.5
|
|
14
|
+
- rvm: 2.6.3
|
|
16
15
|
- rvm: jruby-9.1.8.0
|
|
17
16
|
env:
|
|
18
17
|
- JRUBY_OPTS="--debug"
|
|
19
|
-
|
|
18
|
+
jdk: openjdk8
|
|
19
|
+
- rvm: jruby-9.2.8.0
|
|
20
20
|
env:
|
|
21
21
|
- JRUBY_OPTS="--debug"
|
data/CHANGELOG.md
CHANGED
|
@@ -1,21 +1,46 @@
|
|
|
1
1
|
# Pundit
|
|
2
2
|
|
|
3
|
+
### Fixed
|
|
4
|
+
|
|
5
|
+
- Avoid name clashes with the Error class. (#590)
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
|
|
9
|
+
- Return a safer default NotAuthorizedError message. (#583)
|
|
10
|
+
|
|
11
|
+
## 2.0.1 (2019-01-18)
|
|
12
|
+
|
|
13
|
+
### Breaking changes
|
|
14
|
+
|
|
15
|
+
None
|
|
16
|
+
|
|
17
|
+
### Other changes
|
|
18
|
+
|
|
19
|
+
- Improve exception handling for `#policy_scope` and `#policy_scope!`. (#550)
|
|
20
|
+
- Add `:policy` metadata to RSpec template. (#566)
|
|
21
|
+
|
|
3
22
|
## 2.0.0 (2018-07-21)
|
|
4
23
|
|
|
5
24
|
No changes since beta1
|
|
6
25
|
|
|
7
26
|
## 2.0.0.beta1 (2018-07-04)
|
|
8
27
|
|
|
28
|
+
### Breaking changes
|
|
29
|
+
|
|
30
|
+
- Only pass last element of "namespace array" to policy and scope. (#529)
|
|
31
|
+
- Raise `InvalidConstructorError` if a policy or policy scope with an invalid constructor is called. (#462)
|
|
32
|
+
- Return passed object from `#authorize` method to make chaining possible. (#385)
|
|
33
|
+
|
|
34
|
+
### Other changes
|
|
35
|
+
|
|
9
36
|
- Add `policy_class` option to `authorize` to be able to override the policy. (#441)
|
|
10
37
|
- Add `policy_scope_class` option to `authorize` to be able to override the policy scope. (#441)
|
|
11
38
|
- Fix `param_key` issue when passed an array. (#529)
|
|
12
|
-
- Only pass last element of "namespace array" to policy and scope. (#529)
|
|
13
39
|
- Allow specification of a `NilClassPolicy`. (#525)
|
|
14
40
|
- Make sure `policy_class` override is called when passed an array. (#475)
|
|
15
|
-
|
|
41
|
+
|
|
16
42
|
- Use `action_name` instead of `params[:action]`. (#419)
|
|
17
43
|
- Add `pundit_params_for` method to make it easy to customize params fetching. (#502)
|
|
18
|
-
- Return passed object from `#authorize` method to make chaining possible. (#385)
|
|
19
44
|
|
|
20
45
|
## 1.1.0 (2016-01-14)
|
|
21
46
|
|
data/Gemfile
CHANGED
|
@@ -1,16 +1,7 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
source "https://rubygems.org"
|
|
2
4
|
|
|
3
5
|
ruby RUBY_VERSION
|
|
4
6
|
|
|
5
7
|
gemspec
|
|
6
|
-
|
|
7
|
-
group :development, :test do
|
|
8
|
-
gem "actionpack"
|
|
9
|
-
gem "activemodel"
|
|
10
|
-
gem "bundler"
|
|
11
|
-
gem "pry"
|
|
12
|
-
gem "rake"
|
|
13
|
-
gem "rspec"
|
|
14
|
-
gem "rubocop"
|
|
15
|
-
gem "yard"
|
|
16
|
-
end
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
|
@@ -195,6 +195,10 @@ class DashboardPolicy < Struct.new(:user, :dashboard)
|
|
|
195
195
|
end
|
|
196
196
|
```
|
|
197
197
|
|
|
198
|
+
Note that the headless policy still needs to accept two arguments. The
|
|
199
|
+
second argument will just be the symbol `:dashboard` in this case which
|
|
200
|
+
is what is passed as the record to `authorize` below.
|
|
201
|
+
|
|
198
202
|
```ruby
|
|
199
203
|
# In controllers
|
|
200
204
|
authorize :dashboard, :show?
|
|
@@ -781,6 +785,10 @@ Pundit does not provide a DSL for testing scopes. Just test it like a regular Ru
|
|
|
781
785
|
- [Using Pundit outside of a Rails controller](https://github.com/varvet/pundit/pull/136)
|
|
782
786
|
- [Straightforward Rails Authorization with Pundit](http://www.sitepoint.com/straightforward-rails-authorization-with-pundit/)
|
|
783
787
|
|
|
788
|
+
## Other implementations
|
|
789
|
+
|
|
790
|
+
- [Flask-Pundit](https://github.com/anurag90x/flask-pundit) (Python) is a [Flask](http://flask.pocoo.org/) extension "heavily inspired by" Pundit
|
|
791
|
+
|
|
784
792
|
# License
|
|
785
793
|
|
|
786
794
|
Licensed under the MIT license, see the separate LICENSE.txt file.
|
data/Rakefile
CHANGED
data/lib/pundit/policy_finder.rb
CHANGED
data/lib/pundit/rspec.rb
CHANGED
data/lib/pundit/version.rb
CHANGED
data/lib/pundit.rb
CHANGED
|
@@ -8,6 +8,11 @@ require "active_support/core_ext/object/blank"
|
|
|
8
8
|
require "active_support/core_ext/module/introspection"
|
|
9
9
|
require "active_support/dependencies/autoload"
|
|
10
10
|
|
|
11
|
+
# @api private
|
|
12
|
+
# To avoid name clashes with common Error naming when mixing in Pundit,
|
|
13
|
+
# keep it here with compact class style definition.
|
|
14
|
+
class Pundit::Error < StandardError; end # rubocop:disable Style/ClassAndModuleChildren
|
|
15
|
+
|
|
11
16
|
# @api public
|
|
12
17
|
module Pundit
|
|
13
18
|
SUFFIX = "Policy".freeze
|
|
@@ -15,9 +20,6 @@ module Pundit
|
|
|
15
20
|
# @api private
|
|
16
21
|
module Generators; end
|
|
17
22
|
|
|
18
|
-
# @api private
|
|
19
|
-
class Error < StandardError; end
|
|
20
|
-
|
|
21
23
|
# Error that will be raised when authorization has failed
|
|
22
24
|
class NotAuthorizedError < Error
|
|
23
25
|
attr_reader :query, :record, :policy
|
|
@@ -30,7 +32,7 @@ module Pundit
|
|
|
30
32
|
@record = options[:record]
|
|
31
33
|
@policy = options[:policy]
|
|
32
34
|
|
|
33
|
-
message = options.fetch(:message) { "not allowed to #{query} this #{record.
|
|
35
|
+
message = options.fetch(:message) { "not allowed to #{query} this #{record.class}" }
|
|
34
36
|
end
|
|
35
37
|
|
|
36
38
|
super(message)
|
|
@@ -80,10 +82,16 @@ module Pundit
|
|
|
80
82
|
# @raise [InvalidConstructorError] if the policy constructor called incorrectly
|
|
81
83
|
# @return [Scope{#resolve}, nil] instance of scope class which can resolve to a scope
|
|
82
84
|
def policy_scope(user, scope)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
policy_scope_class = PolicyFinder.new(scope).scope
|
|
86
|
+
return unless policy_scope_class
|
|
87
|
+
|
|
88
|
+
begin
|
|
89
|
+
policy_scope = policy_scope_class.new(user, pundit_model(scope))
|
|
90
|
+
rescue ArgumentError
|
|
91
|
+
raise InvalidConstructorError, "Invalid #<#{policy_scope_class}> constructor is called"
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
policy_scope.resolve
|
|
87
95
|
end
|
|
88
96
|
|
|
89
97
|
# Retrieves the policy scope for the given record.
|
|
@@ -95,10 +103,16 @@ module Pundit
|
|
|
95
103
|
# @raise [InvalidConstructorError] if the policy constructor called incorrectly
|
|
96
104
|
# @return [Scope{#resolve}] instance of scope class which can resolve to a scope
|
|
97
105
|
def policy_scope!(user, scope)
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
106
|
+
policy_scope_class = PolicyFinder.new(scope).scope!
|
|
107
|
+
return unless policy_scope_class
|
|
108
|
+
|
|
109
|
+
begin
|
|
110
|
+
policy_scope = policy_scope_class.new(user, pundit_model(scope))
|
|
111
|
+
rescue ArgumentError
|
|
112
|
+
raise InvalidConstructorError, "Invalid #<#{policy_scope_class}> constructor is called"
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
policy_scope.resolve
|
|
102
116
|
end
|
|
103
117
|
|
|
104
118
|
# Retrieves the policy for the given record.
|
data/pundit.gemspec
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
lib = File.expand_path("lib", __dir__)
|
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
5
|
require "pundit/version"
|
|
@@ -5,17 +7,25 @@ require "pundit/version"
|
|
|
5
7
|
Gem::Specification.new do |gem|
|
|
6
8
|
gem.name = "pundit"
|
|
7
9
|
gem.version = Pundit::VERSION
|
|
8
|
-
gem.authors = ["Jonas Nicklas", "
|
|
10
|
+
gem.authors = ["Jonas Nicklas", "Varvet AB"]
|
|
9
11
|
gem.email = ["jonas.nicklas@gmail.com", "dev@elabs.se"]
|
|
10
12
|
gem.description = "Object oriented authorization for Rails applications"
|
|
11
13
|
gem.summary = "OO authorization for Rails"
|
|
12
14
|
gem.homepage = "https://github.com/varvet/pundit"
|
|
13
15
|
gem.license = "MIT"
|
|
14
16
|
|
|
15
|
-
gem.files = `git ls-files`.split(
|
|
17
|
+
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
|
16
18
|
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
|
17
19
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
18
20
|
gem.require_paths = ["lib"]
|
|
19
21
|
|
|
20
22
|
gem.add_dependency "activesupport", ">= 3.0.0"
|
|
23
|
+
gem.add_development_dependency "actionpack", ">= 3.0.0"
|
|
24
|
+
gem.add_development_dependency "activemodel", ">= 3.0.0"
|
|
25
|
+
gem.add_development_dependency "bundler"
|
|
26
|
+
gem.add_development_dependency "pry"
|
|
27
|
+
gem.add_development_dependency "rake"
|
|
28
|
+
gem.add_development_dependency "rspec", ">= 2.0.0"
|
|
29
|
+
gem.add_development_dependency "rubocop", "0.57.2"
|
|
30
|
+
gem.add_development_dependency "yard"
|
|
21
31
|
end
|
data/spec/policy_finder_spec.rb
CHANGED
data/spec/pundit_spec.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "spec_helper"
|
|
2
4
|
|
|
3
5
|
describe Pundit do
|
|
@@ -16,6 +18,7 @@ describe Pundit do
|
|
|
16
18
|
let(:tag_four_five_six) { ProjectOneTwoThree::TagFourFiveSix.new(user) }
|
|
17
19
|
let(:avatar_four_five_six) { ProjectOneTwoThree::AvatarFourFiveSix.new }
|
|
18
20
|
let(:wiki) { Wiki.new }
|
|
21
|
+
let(:thread) { Thread.new }
|
|
19
22
|
|
|
20
23
|
describe ".authorize" do
|
|
21
24
|
it "infers the policy and authorizes based on it" do
|
|
@@ -35,7 +38,7 @@ describe Pundit do
|
|
|
35
38
|
# rubocop:disable Style/MultilineBlockChain
|
|
36
39
|
expect do
|
|
37
40
|
Pundit.authorize(user, post, :destroy?)
|
|
38
|
-
end.to raise_error(Pundit::NotAuthorizedError, "not allowed to destroy? this
|
|
41
|
+
end.to raise_error(Pundit::NotAuthorizedError, "not allowed to destroy? this Post") do |error|
|
|
39
42
|
expect(error.query).to eq :destroy?
|
|
40
43
|
expect(error.record).to eq post
|
|
41
44
|
expect(error.policy).to eq Pundit.policy(user, post)
|
|
@@ -88,6 +91,12 @@ describe Pundit do
|
|
|
88
91
|
Pundit.policy_scope(user, Wiki)
|
|
89
92
|
end.to raise_error(Pundit::InvalidConstructorError, "Invalid #<WikiPolicy::Scope> constructor is called")
|
|
90
93
|
end
|
|
94
|
+
|
|
95
|
+
it "raises an original error with a policy scope that contains error" do
|
|
96
|
+
expect do
|
|
97
|
+
Pundit.policy_scope(user, Thread)
|
|
98
|
+
end.to raise_error(ArgumentError)
|
|
99
|
+
end
|
|
91
100
|
end
|
|
92
101
|
|
|
93
102
|
describe ".policy_scope!" do
|
|
@@ -511,11 +520,13 @@ describe Pundit do
|
|
|
511
520
|
|
|
512
521
|
describe "#permitted_attributes" do
|
|
513
522
|
it "checks policy for permitted attributes" do
|
|
514
|
-
params = ActionController::Parameters.new(
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
523
|
+
params = ActionController::Parameters.new(
|
|
524
|
+
post: {
|
|
525
|
+
title: "Hello",
|
|
526
|
+
votes: 5,
|
|
527
|
+
admin: true
|
|
528
|
+
}
|
|
529
|
+
)
|
|
519
530
|
|
|
520
531
|
action = "update"
|
|
521
532
|
|
|
@@ -527,11 +538,13 @@ describe Pundit do
|
|
|
527
538
|
end
|
|
528
539
|
|
|
529
540
|
it "checks policy for permitted attributes for record of a ActiveModel type" do
|
|
530
|
-
params = ActionController::Parameters.new(
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
541
|
+
params = ActionController::Parameters.new(
|
|
542
|
+
customer_post: {
|
|
543
|
+
title: "Hello",
|
|
544
|
+
votes: 5,
|
|
545
|
+
admin: true
|
|
546
|
+
}
|
|
547
|
+
)
|
|
535
548
|
|
|
536
549
|
action = "update"
|
|
537
550
|
|
|
@@ -547,24 +560,28 @@ describe Pundit do
|
|
|
547
560
|
|
|
548
561
|
describe "#permitted_attributes_for_action" do
|
|
549
562
|
it "is checked if it is defined in the policy" do
|
|
550
|
-
params = ActionController::Parameters.new(
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
563
|
+
params = ActionController::Parameters.new(
|
|
564
|
+
post: {
|
|
565
|
+
title: "Hello",
|
|
566
|
+
body: "blah",
|
|
567
|
+
votes: 5,
|
|
568
|
+
admin: true
|
|
569
|
+
}
|
|
570
|
+
)
|
|
556
571
|
|
|
557
572
|
action = "revise"
|
|
558
573
|
expect(Controller.new(user, action, params).permitted_attributes(post).to_h).to eq("body" => "blah")
|
|
559
574
|
end
|
|
560
575
|
|
|
561
576
|
it "can be explicitly set" do
|
|
562
|
-
params = ActionController::Parameters.new(
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
577
|
+
params = ActionController::Parameters.new(
|
|
578
|
+
post: {
|
|
579
|
+
title: "Hello",
|
|
580
|
+
body: "blah",
|
|
581
|
+
votes: 5,
|
|
582
|
+
admin: true
|
|
583
|
+
}
|
|
584
|
+
)
|
|
568
585
|
|
|
569
586
|
action = "update"
|
|
570
587
|
expect(Controller.new(user, action, params).permitted_attributes(post, :revise).to_h).to eq("body" => "blah")
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "pundit"
|
|
2
4
|
require "pundit/rspec"
|
|
3
5
|
|
|
@@ -236,6 +238,18 @@ class WikiPolicy
|
|
|
236
238
|
end
|
|
237
239
|
end
|
|
238
240
|
|
|
241
|
+
class Thread
|
|
242
|
+
def self.all; end
|
|
243
|
+
end
|
|
244
|
+
class ThreadPolicy < Struct.new(:user, :thread)
|
|
245
|
+
class Scope < Struct.new(:user, :scope)
|
|
246
|
+
def resolve
|
|
247
|
+
# deliberate wrong useage of the method
|
|
248
|
+
scope.all(:unvalid, :parameters)
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
end
|
|
252
|
+
|
|
239
253
|
class PostFourFiveSix < Struct.new(:user); end
|
|
240
254
|
|
|
241
255
|
class CommentFourFiveSix; extend ActiveModel::Naming; end
|
metadata
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pundit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jonas Nicklas
|
|
8
|
-
-
|
|
8
|
+
- Varvet AB
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2019-08-14 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: activesupport
|
|
@@ -25,6 +25,118 @@ dependencies:
|
|
|
25
25
|
- - ">="
|
|
26
26
|
- !ruby/object:Gem::Version
|
|
27
27
|
version: 3.0.0
|
|
28
|
+
- !ruby/object:Gem::Dependency
|
|
29
|
+
name: actionpack
|
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
|
31
|
+
requirements:
|
|
32
|
+
- - ">="
|
|
33
|
+
- !ruby/object:Gem::Version
|
|
34
|
+
version: 3.0.0
|
|
35
|
+
type: :development
|
|
36
|
+
prerelease: false
|
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - ">="
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: 3.0.0
|
|
42
|
+
- !ruby/object:Gem::Dependency
|
|
43
|
+
name: activemodel
|
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - ">="
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: 3.0.0
|
|
49
|
+
type: :development
|
|
50
|
+
prerelease: false
|
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
52
|
+
requirements:
|
|
53
|
+
- - ">="
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: 3.0.0
|
|
56
|
+
- !ruby/object:Gem::Dependency
|
|
57
|
+
name: bundler
|
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
|
59
|
+
requirements:
|
|
60
|
+
- - ">="
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: '0'
|
|
63
|
+
type: :development
|
|
64
|
+
prerelease: false
|
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
66
|
+
requirements:
|
|
67
|
+
- - ">="
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '0'
|
|
70
|
+
- !ruby/object:Gem::Dependency
|
|
71
|
+
name: pry
|
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
|
73
|
+
requirements:
|
|
74
|
+
- - ">="
|
|
75
|
+
- !ruby/object:Gem::Version
|
|
76
|
+
version: '0'
|
|
77
|
+
type: :development
|
|
78
|
+
prerelease: false
|
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
80
|
+
requirements:
|
|
81
|
+
- - ">="
|
|
82
|
+
- !ruby/object:Gem::Version
|
|
83
|
+
version: '0'
|
|
84
|
+
- !ruby/object:Gem::Dependency
|
|
85
|
+
name: rake
|
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
|
87
|
+
requirements:
|
|
88
|
+
- - ">="
|
|
89
|
+
- !ruby/object:Gem::Version
|
|
90
|
+
version: '0'
|
|
91
|
+
type: :development
|
|
92
|
+
prerelease: false
|
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
94
|
+
requirements:
|
|
95
|
+
- - ">="
|
|
96
|
+
- !ruby/object:Gem::Version
|
|
97
|
+
version: '0'
|
|
98
|
+
- !ruby/object:Gem::Dependency
|
|
99
|
+
name: rspec
|
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
|
101
|
+
requirements:
|
|
102
|
+
- - ">="
|
|
103
|
+
- !ruby/object:Gem::Version
|
|
104
|
+
version: 2.0.0
|
|
105
|
+
type: :development
|
|
106
|
+
prerelease: false
|
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
108
|
+
requirements:
|
|
109
|
+
- - ">="
|
|
110
|
+
- !ruby/object:Gem::Version
|
|
111
|
+
version: 2.0.0
|
|
112
|
+
- !ruby/object:Gem::Dependency
|
|
113
|
+
name: rubocop
|
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
|
115
|
+
requirements:
|
|
116
|
+
- - '='
|
|
117
|
+
- !ruby/object:Gem::Version
|
|
118
|
+
version: 0.57.2
|
|
119
|
+
type: :development
|
|
120
|
+
prerelease: false
|
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
122
|
+
requirements:
|
|
123
|
+
- - '='
|
|
124
|
+
- !ruby/object:Gem::Version
|
|
125
|
+
version: 0.57.2
|
|
126
|
+
- !ruby/object:Gem::Dependency
|
|
127
|
+
name: yard
|
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
|
129
|
+
requirements:
|
|
130
|
+
- - ">="
|
|
131
|
+
- !ruby/object:Gem::Version
|
|
132
|
+
version: '0'
|
|
133
|
+
type: :development
|
|
134
|
+
prerelease: false
|
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
136
|
+
requirements:
|
|
137
|
+
- - ">="
|
|
138
|
+
- !ruby/object:Gem::Version
|
|
139
|
+
version: '0'
|
|
28
140
|
description: Object oriented authorization for Rails applications
|
|
29
141
|
email:
|
|
30
142
|
- jonas.nicklas@gmail.com
|
|
@@ -82,8 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
82
194
|
- !ruby/object:Gem::Version
|
|
83
195
|
version: '0'
|
|
84
196
|
requirements: []
|
|
85
|
-
|
|
86
|
-
rubygems_version: 2.7.6
|
|
197
|
+
rubygems_version: 3.0.3
|
|
87
198
|
signing_key:
|
|
88
199
|
specification_version: 4
|
|
89
200
|
summary: OO authorization for Rails
|