action_policy 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -1
- data/config/rubocop-rspec.yml +17 -0
- data/lib/action_policy/lookup_chain.rb +10 -26
- data/lib/action_policy/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 911b1f7b929d458ae0bb95eb22fa11ff2a17925d9c797b626664bdad82b7abbc
|
4
|
+
data.tar.gz: 69bc6ead609db7cbcdc3d31455e7e17b88bf9037a51a8b1722e414a7e50c41e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3cf8e4bd9347f052a34cee11fad004030ee80d9281c6bbbb9fe99b8f6665b0c611661d6ce3be8578345ef3171ad35d2c38fff8936bdd47efef48bb137a5a415
|
7
|
+
data.tar.gz: 63c4444667971ee445b60e2d9ffee89402021151ac730f00063f2066984c1ca75c15ae40b45fbce60ce9c4201826116bb417f6e62dbfd91f96a3f3974e26a458
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 0.5.4 (2020-12-09)
|
6
|
+
|
7
|
+
- Add support for RSpec aliases detection when linting policy specs with `rubocop-rspec` 2.0 ([@pirj][])
|
8
|
+
|
9
|
+
- Fix `strict_namespace: true` lookup option not finding policies in global namespace ([@Be-ngt-oH][])
|
10
|
+
|
5
11
|
## 0.5.0 (2020-09-29)
|
6
12
|
|
7
13
|
- Move `deny!` / `allow!` to core. ([@palkan][])
|
@@ -37,7 +43,7 @@ This method is similar to `allowed_to?` but returns an authorization result obje
|
|
37
43
|
|
38
44
|
Fixes [#122](https://github.com/palkan/action_policy/issues/122).
|
39
45
|
|
40
|
-
- Separated `#classify`-based and `#camelize`-based symbol lookups. ([Be-ngt-oH][])
|
46
|
+
- Separated `#classify`-based and `#camelize`-based symbol lookups. ([@Be-ngt-oH][])
|
41
47
|
|
42
48
|
Only affects Rails apps. Now lookup for `:users` tries to find `UsersPolicy` first (camelize),
|
43
49
|
and only then search for `UserPolicy` (classify).
|
@@ -429,3 +435,4 @@ This value is now stored in a cache (if any) instead of just the call result (`t
|
|
429
435
|
[@nicolas-brousse]: https://github.com/nicolas-brousse
|
430
436
|
[@somenugget]: https://github.com/somenugget
|
431
437
|
[@Be-ngt-oH]: https://github.com/Be-ngt-oH
|
438
|
+
[@pirj]: https://github.com/pirj
|
@@ -36,8 +36,7 @@ module ActionPolicy
|
|
36
36
|
if strict
|
37
37
|
put_if_absent(:strict, namespace, policy, &block)
|
38
38
|
else
|
39
|
-
|
40
|
-
put_if_absent(:flexible, namespace, policy) { cached_policy }
|
39
|
+
put_if_absent(:flexible, namespace, policy, &block)
|
41
40
|
end
|
42
41
|
end
|
43
42
|
|
@@ -66,22 +65,17 @@ module ActionPolicy
|
|
66
65
|
private
|
67
66
|
|
68
67
|
def lookup_within_namespace(policy_name, namespace, strict: false)
|
69
|
-
|
70
|
-
NamespaceCache.fetch(namespace.name, policy_name, strict: strict) do
|
68
|
+
NamespaceCache.fetch(namespace&.name || "Kernel", policy_name, strict: strict) do
|
71
69
|
mod = namespace
|
72
70
|
loop do
|
73
|
-
policy =
|
74
|
-
break policy
|
71
|
+
policy = [mod&.name, policy_name].compact.join("::").safe_constantize
|
72
|
+
break policy if policy || mod.nil? || strict
|
73
|
+
|
75
74
|
mod = mod.namespace
|
76
|
-
break if mod.nil? || strict
|
77
75
|
end
|
78
76
|
end
|
79
77
|
end
|
80
78
|
|
81
|
-
def objectify_policy(policy_name, strict: false)
|
82
|
-
policy_name.safe_constantize unless strict
|
83
|
-
end
|
84
|
-
|
85
79
|
def policy_class_name_for(record)
|
86
80
|
return record.policy_name.to_s if record.respond_to?(:policy_name)
|
87
81
|
|
@@ -110,17 +104,10 @@ module ActionPolicy
|
|
110
104
|
record.class.policy_class if record.class.respond_to?(:policy_class)
|
111
105
|
}
|
112
106
|
|
113
|
-
# Lookup within namespace when provided
|
114
|
-
NAMESPACE_LOOKUP = ->(record, namespace: nil, **) {
|
115
|
-
next if namespace.nil?
|
116
|
-
|
117
|
-
policy_name = policy_class_name_for(record)
|
118
|
-
lookup_within_namespace(policy_name, namespace)
|
119
|
-
}
|
120
|
-
|
121
107
|
# Infer from class name
|
122
|
-
INFER_FROM_CLASS = ->(record, **) {
|
123
|
-
policy_class_name_for(record)
|
108
|
+
INFER_FROM_CLASS = ->(record, namespace: nil, strict_namespace: false, **) {
|
109
|
+
policy_name = policy_class_name_for(record)
|
110
|
+
lookup_within_namespace(policy_name, namespace, strict: strict_namespace)
|
124
111
|
}
|
125
112
|
|
126
113
|
# Infer from passed symbol
|
@@ -128,8 +115,7 @@ module ActionPolicy
|
|
128
115
|
next unless record.is_a?(Symbol)
|
129
116
|
|
130
117
|
policy_name = "#{record.camelize}Policy"
|
131
|
-
lookup_within_namespace(policy_name, namespace, strict: strict_namespace)
|
132
|
-
objectify_policy(policy_name, strict: strict_namespace)
|
118
|
+
lookup_within_namespace(policy_name, namespace, strict: strict_namespace)
|
133
119
|
}
|
134
120
|
|
135
121
|
# (Optional) Infer using String#classify if available
|
@@ -137,8 +123,7 @@ module ActionPolicy
|
|
137
123
|
next unless record.is_a?(Symbol)
|
138
124
|
|
139
125
|
policy_name = "#{record.to_s.classify}Policy"
|
140
|
-
lookup_within_namespace(policy_name, namespace, strict: strict_namespace)
|
141
|
-
objectify_policy(policy_name, strict: strict_namespace)
|
126
|
+
lookup_within_namespace(policy_name, namespace, strict: strict_namespace)
|
142
127
|
}
|
143
128
|
|
144
129
|
self.chain = [
|
@@ -146,7 +131,6 @@ module ActionPolicy
|
|
146
131
|
(CLASSIFY_SYMBOL_LOOKUP if String.method_defined?(:classify)),
|
147
132
|
INSTANCE_POLICY_CLASS,
|
148
133
|
CLASS_POLICY_CLASS,
|
149
|
-
NAMESPACE_LOOKUP,
|
150
134
|
INFER_FROM_CLASS
|
151
135
|
].compact
|
152
136
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_policy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Dementyev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-next-core
|
@@ -132,6 +132,7 @@ files:
|
|
132
132
|
- CHANGELOG.md
|
133
133
|
- LICENSE.txt
|
134
134
|
- README.md
|
135
|
+
- config/rubocop-rspec.yml
|
135
136
|
- lib/.rbnext/2.7/action_policy/behaviours/policy_for.rb
|
136
137
|
- lib/.rbnext/2.7/action_policy/i18n.rb
|
137
138
|
- lib/.rbnext/2.7/action_policy/policy/cache.rb
|