regulator 0.1.0 → 0.1.1
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/.travis.yml +1 -2
- data/CHANGELOG.md +7 -0
- data/README.md +3 -1
- data/lib/regulator/policy_finder.rb +10 -7
- data/lib/regulator/version.rb +1 -1
- data/lib/regulator.rb +12 -11
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: debaf2d2834f1f40dfb69f5d16f20a8b0f887d7e
|
4
|
+
data.tar.gz: a894788600e922d6fca85ae7897a08f76d7fdbcd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10a08ae8dc44b46b4a3bde10f5802ea32543b3f9ae55668ceae101439dc594dd0ef11f25a548706a44e07e8928527198a7a5369f6f4742c4db80dde8e00c1178
|
7
|
+
data.tar.gz: fe9af60ae01fd42e0ce9ad509c4feff5c696d244bf57318603844f3908a35955f7760b7449a48fb17ce552fdc21715869d8bd0d77eca22461f8bac302de405b0
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
# Regulator
|
2
2
|
|
3
|
+
## 0.1.1 (2015-07-23)
|
4
|
+
- Regulator.authorize support for controller namespacing
|
5
|
+
- Regulator can accept a controller instance or an explicity modules name
|
6
|
+
- Regulator.policy!(user,resource, my_controller_instance)
|
7
|
+
- Regulator.policy!(user,resource, Api::V2)
|
8
|
+
|
3
9
|
## 0.1.0 (2015-07-23)
|
4
10
|
- initial release
|
5
11
|
- pundit compatible
|
6
12
|
- controller based policy namespacing
|
13
|
+
ActiveAdmin.application.regulator_policy_namespace
|
data/README.md
CHANGED
@@ -16,7 +16,9 @@ Why not contribute to pundit? [It's](https://github.com/elabs/pundit/issues/12)
|
|
16
16
|
## TODOs
|
17
17
|
* [ ] generators
|
18
18
|
* [ ] activeadmin-regulator-adapter gem or generator
|
19
|
-
* [ ] documentation
|
19
|
+
* [ ] documentation
|
20
|
+
* [ ] Usage section below, mock pundit's
|
21
|
+
* [ ] yard doc
|
20
22
|
* [ ] Lotus examples
|
21
23
|
* [ ] Grape examples
|
22
24
|
* [ ] ROM examples
|
@@ -2,10 +2,17 @@ module Regulator
|
|
2
2
|
class PolicyFinder
|
3
3
|
attr_reader :object
|
4
4
|
attr_reader :controller
|
5
|
+
attr_reader :namespace
|
5
6
|
|
6
|
-
def initialize(object,
|
7
|
+
def initialize(object, controller_or_namespace = nil)
|
7
8
|
@object = object
|
8
|
-
|
9
|
+
|
10
|
+
if controller_or_namespace.is_a?(Module)
|
11
|
+
@namespace = controller_or_namespace
|
12
|
+
elsif controller_or_namespace
|
13
|
+
@controller = controller_or_namespace
|
14
|
+
@namespace = @controller.policy_namespace
|
15
|
+
end
|
9
16
|
end
|
10
17
|
|
11
18
|
def scope
|
@@ -64,11 +71,7 @@ module Regulator
|
|
64
71
|
|
65
72
|
policy_name = "#{klass}#{SUFFIX}"
|
66
73
|
|
67
|
-
|
68
|
-
"#{controller.policy_namespace}::#{policy_name}"
|
69
|
-
else
|
70
|
-
policy_name
|
71
|
-
end
|
74
|
+
namespace ? "#{namespace}::#{policy_name}" : policy_name
|
72
75
|
end
|
73
76
|
end
|
74
77
|
|
data/lib/regulator/version.rb
CHANGED
data/lib/regulator.rb
CHANGED
@@ -20,6 +20,7 @@ module Regulator
|
|
20
20
|
@query = options[:query]
|
21
21
|
@record = options[:record]
|
22
22
|
@policy = options[:policy]
|
23
|
+
@controller_or_namespace = options[:controller_or_namespace]
|
23
24
|
|
24
25
|
message = options.fetch(:message) { "not allowed to #{query} this #{record.inspect}" }
|
25
26
|
end
|
@@ -34,32 +35,32 @@ module Regulator
|
|
34
35
|
extend ActiveSupport::Concern
|
35
36
|
|
36
37
|
class << self
|
37
|
-
def authorize(user, record, query)
|
38
|
-
policy = policy!(user, record)
|
38
|
+
def authorize(user, record, query, controller_or_namespace = nil)
|
39
|
+
policy = policy!(user, record, controller_or_namespace)
|
39
40
|
|
40
41
|
unless policy.public_send(query)
|
41
|
-
raise NotAuthorizedError.new(query: query, record: record, policy: policy)
|
42
|
+
raise NotAuthorizedError.new(query: query, record: record, policy: policy, controller_or_namespace: controller_or_namespace)
|
42
43
|
end
|
43
44
|
|
44
45
|
true
|
45
46
|
end
|
46
47
|
|
47
|
-
def policy_scope(user, scope,
|
48
|
-
policy_scope = PolicyFinder.new(scope,
|
48
|
+
def policy_scope(user, scope, controller_or_namespace = nil)
|
49
|
+
policy_scope = PolicyFinder.new(scope,controller_or_namespace).scope
|
49
50
|
policy_scope.new(user, scope).resolve if policy_scope
|
50
51
|
end
|
51
52
|
|
52
|
-
def policy_scope!(user, scope,
|
53
|
-
PolicyFinder.new(scope,
|
53
|
+
def policy_scope!(user, scope, controller_or_namespace = nil)
|
54
|
+
PolicyFinder.new(scope,controller_or_namespace).scope!.new(user, scope).resolve
|
54
55
|
end
|
55
56
|
|
56
|
-
def policy(user, record,
|
57
|
-
policy = PolicyFinder.new(record,
|
57
|
+
def policy(user, record, controller_or_namespace = nil)
|
58
|
+
policy = PolicyFinder.new(record,controller_or_namespace).policy
|
58
59
|
policy.new(user, record) if policy
|
59
60
|
end
|
60
61
|
|
61
|
-
def policy!(user, record,
|
62
|
-
PolicyFinder.new(record,
|
62
|
+
def policy!(user, record, controller_or_namespace = nil)
|
63
|
+
PolicyFinder.new(record,controller_or_namespace).policy!.new(user, record)
|
63
64
|
end
|
64
65
|
end
|
65
66
|
|