crewd_policies 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/crewd_policies/model.rb +3 -3
- data/lib/crewd_policies/policy.rb +4 -3
- data/lib/crewd_policies/version.rb +1 -1
- 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: da58fbf9df8d461a914137bab938033f4efee6a0
|
4
|
+
data.tar.gz: b553dbabc6208daa598cabb5b727e9bfec5080b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 638f046880f1001e59df48d61dba5300d4fcdaf2a5d8e2c0d3a5d14c832519afd69ec939d2e66e2aafd0fefe808fe1cdfce4c2a742fbb3ca2ca3473133326c0b
|
7
|
+
data.tar.gz: 02aa2ac5d8dc3f9aaf3df456a0ed96a75ec37121cecb2713ac67ae2c0b4a6886b3c521a4b6e6caa7bf197c830ff1ea7526453e40b6b51c64285813927ffd4662
|
data/lib/crewd_policies/model.rb
CHANGED
@@ -21,9 +21,9 @@ module CrewdPolicies::Model
|
|
21
21
|
aRole.each {|r| allow(r,aAbilities.dup) }
|
22
22
|
return
|
23
23
|
end
|
24
|
-
raise "aRole must be a string or a symbol" unless aRole.is_a?(String) or aRole.is_a?(Symbol)
|
24
|
+
raise ::StandardExceptions::Http::InternalServerError.new "aRole must be a string or a symbol" unless aRole.is_a?(String) or aRole.is_a?(Symbol)
|
25
25
|
aRole = aRole.to_s
|
26
|
-
raise "aAbilities must be a Hash" unless aAbilities.is_a? Hash # eg. :write => [:name,:address]
|
26
|
+
raise ::StandardExceptions::Http::InternalServerError.new "aAbilities must be a Hash" unless aAbilities.is_a? Hash # eg. :write => [:name,:address]
|
27
27
|
|
28
28
|
role_rules = (self.roles_rules[aRole] ||= [])
|
29
29
|
conditions = {}
|
@@ -42,7 +42,7 @@ module CrewdPolicies::Model
|
|
42
42
|
if fields==true # special "field" value to mean the record or class
|
43
43
|
rule[:allowed] = true
|
44
44
|
else
|
45
|
-
raise "create, destroy and index must have true as a value, not an array of fields" if a=='create' or a=='destroy' or a=='index'
|
45
|
+
raise ::StandardExceptions::Http::InternalServerError.new "create, destroy and index must have true as a value, not an array of fields" if a=='create' or a=='destroy' or a=='index'
|
46
46
|
rule[:fields] = fields
|
47
47
|
end
|
48
48
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'active_support/core_ext/class/attribute'
|
2
2
|
require 'active_support/core_ext/string/inflections'
|
3
|
+
require 'pundit'
|
3
4
|
require 'standard_exceptions'
|
4
5
|
|
5
6
|
module CrewdPolicies
|
@@ -141,7 +142,7 @@ module CrewdPolicies
|
|
141
142
|
def inner_query_fields(aAbility)
|
142
143
|
internal_server_error! "roles_rules not found on #{record_class.name}, make sure it has \"include CrewdPolicies::Model\"" unless ra = record_class.roles_rules rescue nil
|
143
144
|
unauthorized! "identity not given" if !identity
|
144
|
-
internal_server_error! "identity must implement has_role?" if !identity.
|
145
|
+
internal_server_error! "identity must implement has_role?" if !identity.respond_to? :has_role?
|
145
146
|
|
146
147
|
ability = coalesce_field_ability(aAbility)
|
147
148
|
|
@@ -209,7 +210,7 @@ module CrewdPolicies
|
|
209
210
|
|
210
211
|
# does the identity have this ability on the record/resource at all?
|
211
212
|
def inner_query_ability(aAbility)
|
212
|
-
|
213
|
+
internal_server_error! "aAbility must be a string or a symbol" unless aAbility.is_a?(String) or aAbility.is_a?(Symbol)
|
213
214
|
aAbility = aAbility.to_s
|
214
215
|
|
215
216
|
case aAbility
|
@@ -218,7 +219,7 @@ module CrewdPolicies
|
|
218
219
|
when 'create','destroy','index'
|
219
220
|
inner_query_resource(aAbility)
|
220
221
|
else
|
221
|
-
|
222
|
+
internal_server_error! 'this ability is unknown'
|
222
223
|
end
|
223
224
|
end
|
224
225
|
end
|