cancancan 2.3.0 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/cancancan.gemspec +6 -5
  3. data/init.rb +2 -0
  4. data/lib/cancan/ability/actions.rb +2 -0
  5. data/lib/cancan/ability/rules.rb +19 -8
  6. data/lib/cancan/ability/strong_parameter_support.rb +41 -0
  7. data/lib/cancan/ability.rb +54 -24
  8. data/lib/cancan/class_matcher.rb +26 -0
  9. data/lib/cancan/conditions_matcher.rb +25 -12
  10. data/lib/cancan/config.rb +74 -0
  11. data/lib/cancan/controller_additions.rb +4 -1
  12. data/lib/cancan/controller_resource.rb +6 -0
  13. data/lib/cancan/controller_resource_builder.rb +2 -0
  14. data/lib/cancan/controller_resource_finder.rb +2 -0
  15. data/lib/cancan/controller_resource_loader.rb +4 -0
  16. data/lib/cancan/controller_resource_name_finder.rb +2 -0
  17. data/lib/cancan/controller_resource_sanitizer.rb +2 -0
  18. data/lib/cancan/exceptions.rb +18 -2
  19. data/lib/cancan/matchers.rb +3 -0
  20. data/lib/cancan/model_adapters/abstract_adapter.rb +3 -1
  21. data/lib/cancan/model_adapters/active_record_4_adapter.rb +26 -25
  22. data/lib/cancan/model_adapters/active_record_5_adapter.rb +21 -26
  23. data/lib/cancan/model_adapters/active_record_adapter.rb +56 -14
  24. data/lib/cancan/model_adapters/conditions_extractor.rb +3 -3
  25. data/lib/cancan/model_adapters/conditions_normalizer.rb +49 -0
  26. data/lib/cancan/model_adapters/default_adapter.rb +2 -0
  27. data/lib/cancan/model_adapters/sti_normalizer.rb +39 -0
  28. data/lib/cancan/model_additions.rb +6 -2
  29. data/lib/cancan/parameter_validators.rb +9 -0
  30. data/lib/cancan/relevant.rb +29 -0
  31. data/lib/cancan/rule.rb +67 -23
  32. data/lib/cancan/rules_compressor.rb +3 -0
  33. data/lib/cancan/unauthorized_message_resolver.rb +24 -0
  34. data/lib/cancan/version.rb +3 -1
  35. data/lib/cancan.rb +6 -0
  36. data/lib/cancancan.rb +2 -0
  37. data/lib/generators/cancan/ability/ability_generator.rb +3 -1
  38. data/lib/generators/cancan/ability/templates/ability.rb +2 -0
  39. metadata +37 -30
  40. data/lib/cancan/model_adapters/can_can/model_adapters/active_record_adapter/joins.rb +0 -39
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CanCan
4
+ module UnauthorizedMessageResolver
5
+ def unauthorized_message(action, subject)
6
+ subject = subject.values.last if subject.is_a?(Hash)
7
+ keys = unauthorized_message_keys(action, subject)
8
+ variables = {}
9
+ variables[:action] = I18n.translate("actions.#{action}", default: action.to_s)
10
+ variables[:subject] = translate_subject(subject)
11
+ message = I18n.translate(keys.shift, **variables.merge(scope: :unauthorized, default: keys + ['']))
12
+ message.blank? ? nil : message
13
+ end
14
+
15
+ def translate_subject(subject)
16
+ klass = (subject.class == Class ? subject : subject.class)
17
+ if klass.respond_to?(:model_name)
18
+ klass.model_name.human
19
+ else
20
+ klass.to_s.underscore.humanize.downcase
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CanCan
2
- VERSION = '2.3.0'.freeze
4
+ VERSION = '3.3.0'.freeze
3
5
  end
data/lib/cancan.rb CHANGED
@@ -1,4 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cancan/version'
4
+ require 'cancan/config'
5
+ require 'cancan/parameter_validators'
2
6
  require 'cancan/ability'
3
7
  require 'cancan/rule'
4
8
  require 'cancan/controller_resource'
@@ -12,6 +16,8 @@ require 'cancan/rules_compressor'
12
16
 
13
17
  if defined? ActiveRecord
14
18
  require 'cancan/model_adapters/conditions_extractor'
19
+ require 'cancan/model_adapters/conditions_normalizer'
20
+ require 'cancan/model_adapters/sti_normalizer'
15
21
  require 'cancan/model_adapters/active_record_adapter'
16
22
  require 'cancan/model_adapters/active_record_4_adapter'
17
23
  require 'cancan/model_adapters/active_record_5_adapter'
data/lib/cancancan.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cancan'
2
4
 
3
5
  module CanCanCan
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Cancan
2
4
  module Generators
3
5
  class AbilityGenerator < Rails::Generators::Base
4
- source_root File.expand_path('../templates', __FILE__)
6
+ source_root File.expand_path('templates', __dir__)
5
7
 
6
8
  def generate_ability
7
9
  copy_file 'ability.rb', 'app/models/ability.rb'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Ability
2
4
  include CanCan::Ability
3
5
 
metadata CHANGED
@@ -1,46 +1,52 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cancancan
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Rodi (Renuo AG)
8
8
  - Bryan Rite
9
9
  - Ryan Bates
10
10
  - Richard Wilson
11
- autorequire:
11
+ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2018-09-16 00:00:00.000000000 Z
14
+ date: 2021-06-21 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
- name: bundler
17
+ name: appraisal
18
18
  requirement: !ruby/object:Gem::Requirement
19
19
  requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.0.0
20
23
  - - "~>"
21
24
  - !ruby/object:Gem::Version
22
- version: '1.3'
25
+ version: '2.0'
23
26
  type: :development
24
27
  prerelease: false
25
28
  version_requirements: !ruby/object:Gem::Requirement
26
29
  requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.0.0
27
33
  - - "~>"
28
34
  - !ruby/object:Gem::Version
29
- version: '1.3'
35
+ version: '2.0'
30
36
  - !ruby/object:Gem::Dependency
31
- name: rubocop
37
+ name: bundler
32
38
  requirement: !ruby/object:Gem::Requirement
33
39
  requirements:
34
40
  - - "~>"
35
41
  - !ruby/object:Gem::Version
36
- version: 0.48.1
42
+ version: '2.0'
37
43
  type: :development
38
44
  prerelease: false
39
45
  version_requirements: !ruby/object:Gem::Requirement
40
46
  requirements:
41
47
  - - "~>"
42
48
  - !ruby/object:Gem::Version
43
- version: 0.48.1
49
+ version: '2.0'
44
50
  - !ruby/object:Gem::Dependency
45
51
  name: rake
46
52
  requirement: !ruby/object:Gem::Requirement
@@ -65,42 +71,36 @@ dependencies:
65
71
  name: rspec
66
72
  requirement: !ruby/object:Gem::Requirement
67
73
  requirements:
68
- - - "~>"
69
- - !ruby/object:Gem::Version
70
- version: '3.2'
71
74
  - - ">="
72
75
  - !ruby/object:Gem::Version
73
76
  version: 3.2.0
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '3.2'
74
80
  type: :development
75
81
  prerelease: false
76
82
  version_requirements: !ruby/object:Gem::Requirement
77
83
  requirements:
78
- - - "~>"
79
- - !ruby/object:Gem::Version
80
- version: '3.2'
81
84
  - - ">="
82
85
  - !ruby/object:Gem::Version
83
86
  version: 3.2.0
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.2'
84
90
  - !ruby/object:Gem::Dependency
85
- name: appraisal
91
+ name: rubocop
86
92
  requirement: !ruby/object:Gem::Requirement
87
93
  requirements:
88
94
  - - "~>"
89
95
  - !ruby/object:Gem::Version
90
- version: '2.0'
91
- - - ">="
92
- - !ruby/object:Gem::Version
93
- version: 2.0.0
96
+ version: 0.63.1
94
97
  type: :development
95
98
  prerelease: false
96
99
  version_requirements: !ruby/object:Gem::Requirement
97
100
  requirements:
98
101
  - - "~>"
99
102
  - !ruby/object:Gem::Version
100
- version: '2.0'
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: 2.0.0
103
+ version: 0.63.1
104
104
  description: Simple authorization solution for Rails. All permissions are stored in
105
105
  a single location.
106
106
  email: alessandro.rodi@renuo.ch
@@ -114,7 +114,10 @@ files:
114
114
  - lib/cancan/ability.rb
115
115
  - lib/cancan/ability/actions.rb
116
116
  - lib/cancan/ability/rules.rb
117
+ - lib/cancan/ability/strong_parameter_support.rb
118
+ - lib/cancan/class_matcher.rb
117
119
  - lib/cancan/conditions_matcher.rb
120
+ - lib/cancan/config.rb
118
121
  - lib/cancan/controller_additions.rb
119
122
  - lib/cancan/controller_resource.rb
120
123
  - lib/cancan/controller_resource_builder.rb
@@ -128,12 +131,16 @@ files:
128
131
  - lib/cancan/model_adapters/active_record_4_adapter.rb
129
132
  - lib/cancan/model_adapters/active_record_5_adapter.rb
130
133
  - lib/cancan/model_adapters/active_record_adapter.rb
131
- - lib/cancan/model_adapters/can_can/model_adapters/active_record_adapter/joins.rb
132
134
  - lib/cancan/model_adapters/conditions_extractor.rb
135
+ - lib/cancan/model_adapters/conditions_normalizer.rb
133
136
  - lib/cancan/model_adapters/default_adapter.rb
137
+ - lib/cancan/model_adapters/sti_normalizer.rb
134
138
  - lib/cancan/model_additions.rb
139
+ - lib/cancan/parameter_validators.rb
140
+ - lib/cancan/relevant.rb
135
141
  - lib/cancan/rule.rb
136
142
  - lib/cancan/rules_compressor.rb
143
+ - lib/cancan/unauthorized_message_resolver.rb
137
144
  - lib/cancan/version.rb
138
145
  - lib/cancancan.rb
139
146
  - lib/generators/cancan/ability/USAGE
@@ -142,8 +149,9 @@ files:
142
149
  homepage: https://github.com/CanCanCommunity/cancancan
143
150
  licenses:
144
151
  - MIT
145
- metadata: {}
146
- post_install_message:
152
+ metadata:
153
+ funding_uri: https://github.com/sponsors/coorasse
154
+ post_install_message:
147
155
  rdoc_options: []
148
156
  require_paths:
149
157
  - lib
@@ -158,9 +166,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
166
  - !ruby/object:Gem::Version
159
167
  version: '0'
160
168
  requirements: []
161
- rubyforge_project:
162
- rubygems_version: 2.7.4
163
- signing_key:
169
+ rubygems_version: 3.0.6
170
+ signing_key:
164
171
  specification_version: 4
165
172
  summary: Simple authorization solution for Rails.
166
173
  test_files: []
@@ -1,39 +0,0 @@
1
- module CanCan
2
- module ModelAdapters
3
- module ActiveRecordAdapter
4
- module Joins
5
- # Returns the associations used in conditions for the :joins option of a search.
6
- # See ModelAdditions#accessible_by
7
- def joins
8
- joins_hash = {}
9
- @rules.reverse.each do |rule|
10
- merge_joins(joins_hash, rule.associations_hash)
11
- end
12
- clean_joins(joins_hash) unless joins_hash.empty?
13
- end
14
-
15
- private
16
-
17
- # Removes empty hashes and moves everything into arrays.
18
- def clean_joins(joins_hash)
19
- joins = []
20
- joins_hash.each do |name, nested|
21
- joins << (nested.empty? ? name : { name => clean_joins(nested) })
22
- end
23
- joins
24
- end
25
-
26
- # Takes two hashes and does a deep merge.
27
- def merge_joins(base, add)
28
- add.each do |name, nested|
29
- if base[name].is_a?(Hash)
30
- merge_joins(base[name], nested) unless nested.empty?
31
- else
32
- base[name] = nested
33
- end
34
- end
35
- end
36
- end
37
- end
38
- end
39
- end