isomorfeus-policy 1.0.0.zeta12 → 1.0.0.zeta13
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c63ae4ae31c0ad817bda88e549b6f4817bc765a6f3b0037d5efc9ce93bc51450
|
4
|
+
data.tar.gz: 9782919673392439306b660dfaac76e9500e3448cdc28513ef6c5ce8a90c7074
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f039e71996cbd054a6dede06ce19db862600c43bbca53ea6ca57a344b2bf06f909f16aa615dc6c47781dc4d69a9c805aa95956386795aafd4ca7cb9a2b72f47
|
7
|
+
data.tar.gz: 02ecbfcba74d3324c00698321797bfed96cdf36feffb22f4e99682f675a48fe957c6410fd63ea372175198e7ba424c3bd8bca382017f2d8d8865b5269c31c9ed
|
data/README.md
CHANGED
@@ -45,11 +45,11 @@ Example Policy:
|
|
45
45
|
# allow all
|
46
46
|
# deny all
|
47
47
|
|
48
|
-
with_condition do |user_instance, target_class, target_method,
|
48
|
+
with_condition do |user_instance, target_class, target_method, props|
|
49
49
|
user_instance.class == AdminRole
|
50
50
|
end
|
51
51
|
|
52
|
-
refine BlaGraph, :load, :count do |user_instance, target_class, target_method,
|
52
|
+
refine BlaGraph, :load, :count do |user_instance, target_class, target_method, props|
|
53
53
|
allow if user_instance.verified?
|
54
54
|
deny
|
55
55
|
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module Isomorfeus
|
2
|
+
class PropsProxy
|
3
|
+
def initialize(props_hash)
|
4
|
+
props_hash = {} unless props_hash
|
5
|
+
@props_hash = props_hash
|
6
|
+
end
|
7
|
+
|
8
|
+
def any?
|
9
|
+
@props_hash.keys.size > 0
|
10
|
+
end
|
11
|
+
|
12
|
+
if RUBY_ENGINE == 'opal'
|
13
|
+
def [](prop_name)
|
14
|
+
@props_hash[prop_name]
|
15
|
+
end
|
16
|
+
|
17
|
+
def []=(prop_name, value)
|
18
|
+
@props_hash[prop_name] = value
|
19
|
+
end
|
20
|
+
|
21
|
+
def key?(prop_name)
|
22
|
+
@props_hash.key?(prop_name)
|
23
|
+
end
|
24
|
+
|
25
|
+
def keys
|
26
|
+
@props_hash.keys
|
27
|
+
end
|
28
|
+
|
29
|
+
def method_missing(prop_name, *args, &block)
|
30
|
+
return @props_hash[prop_name] if @props_hash.key?(prop_name)
|
31
|
+
super(prop_name, *args, &block)
|
32
|
+
end
|
33
|
+
|
34
|
+
def set(prop_name, value)
|
35
|
+
@props_hash[prop_name] = value
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_json
|
39
|
+
JSON.dump(to_transport)
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_transport
|
43
|
+
transport_hash = {}.merge(@props_hash)
|
44
|
+
transport_hash
|
45
|
+
end
|
46
|
+
else # RUBY_ENGINE
|
47
|
+
def [](prop_name)
|
48
|
+
name = prop_name.to_sym
|
49
|
+
return @props_hash[name] if @props_hash.key?(name)
|
50
|
+
name = prop_name.to_s
|
51
|
+
return @props_hash[name] if @props_hash.key?(name)
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
|
55
|
+
def []=(prop_name, value)
|
56
|
+
@props_hash[prop_name.to_sym] = value
|
57
|
+
end
|
58
|
+
|
59
|
+
def key?(prop_name)
|
60
|
+
@props_hash.key?(prop_name.to_sym) || @props_hash.key?(prop_name.to_s)
|
61
|
+
end
|
62
|
+
|
63
|
+
def keys
|
64
|
+
@props_hash.keys.map(&:to_sym)
|
65
|
+
end
|
66
|
+
|
67
|
+
def method_missing(prop_name, *args, &block)
|
68
|
+
name = prop_name.to_sym
|
69
|
+
return @props_hash[name] if @props_hash.key?(name)
|
70
|
+
name = prop_name.to_s
|
71
|
+
return @props_hash[name] if @props_hash.key?(name)
|
72
|
+
super(prop_name, *args, &block)
|
73
|
+
end
|
74
|
+
|
75
|
+
def set(prop_name, value)
|
76
|
+
@props_hash[prop_name.to_sym] = value
|
77
|
+
end
|
78
|
+
|
79
|
+
def to_json
|
80
|
+
Oj.dump(to_transport, mode: :strict)
|
81
|
+
end
|
82
|
+
|
83
|
+
def to_transport
|
84
|
+
transport_hash = {}.merge(@props_hash)
|
85
|
+
transport_hash
|
86
|
+
end
|
87
|
+
end # RUBY_ENGINE
|
88
|
+
|
89
|
+
alias_method :has_key?, :key?
|
90
|
+
end
|
91
|
+
end
|
data/lib/isomorfeus-policy.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module LucidAuthorization
|
2
2
|
module Mixin
|
3
|
-
def authorized?(target_class, target_method = nil,
|
3
|
+
def authorized?(target_class, target_method = nil, props = nil)
|
4
4
|
begin
|
5
5
|
class_name = self.class.name
|
6
6
|
class_name = class_name.split('>::').last if class_name.start_with?('#<')
|
@@ -9,15 +9,15 @@ module LucidAuthorization
|
|
9
9
|
policy_class = nil
|
10
10
|
end
|
11
11
|
return false unless policy_class
|
12
|
-
policy_class.new(self).authorized?(target_class, target_method,
|
12
|
+
policy_class.new(self).authorized?(target_class, target_method, props = nil)
|
13
13
|
end
|
14
14
|
|
15
|
-
def authorized!(target_class, target_method = nil,
|
15
|
+
def authorized!(target_class, target_method = nil, props = nil)
|
16
16
|
class_name = self.class.name
|
17
17
|
class_name = class_name.split('>::').last if class_name.start_with?('#<')
|
18
18
|
policy_class = Isomorfeus.cached_policy_class("#{class_name}Policy")
|
19
|
-
|
20
|
-
policy_class.new(self).authorized!(target_class, target_method,
|
19
|
+
Isomorfeus.raise_error(error_class: LucidPolicy::Exception, message: "#{self}: policy class #{class_name}Policy not found!") unless policy_class
|
20
|
+
policy_class.new(self).authorized!(target_class, target_method, props = nil)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -43,7 +43,7 @@ module LucidPolicy
|
|
43
43
|
private
|
44
44
|
|
45
45
|
def _raise_allow_deny_first
|
46
|
-
|
46
|
+
Isomorfeus.raise_error(error_class: LucidPolicy::Exception, message: "#{self}: 'allow' or 'deny' must appear before 'refine'")
|
47
47
|
end
|
48
48
|
|
49
49
|
def _allow_or_deny(allow_or_deny, *classes_and_methods, &block)
|
@@ -85,15 +85,17 @@ module LucidPolicy
|
|
85
85
|
@object = object
|
86
86
|
end
|
87
87
|
|
88
|
-
def authorized?(target_class, target_method = nil,
|
89
|
-
|
88
|
+
def authorized?(target_class, target_method = nil, props = nil)
|
89
|
+
Isomorfeus.raise_error(error_class: LucidPolicy::Exception, message: "#{self}: At least the class must be given!") unless target_class
|
90
90
|
result = :deny
|
91
91
|
|
92
92
|
rules = self.class.authorization_rules
|
93
93
|
|
94
|
+
props = Isomorfeus::PropsProxy.new(props) unless props.class == Isomorfeus::PropsProxy
|
95
|
+
|
94
96
|
condition_result = true
|
95
97
|
rules[:conditions].each do |condition|
|
96
|
-
condition_result = condition.call(@object, target_class, target_method,
|
98
|
+
condition_result = condition.call(@object, target_class, target_method, props, &condition)
|
97
99
|
break unless condition_result == true
|
98
100
|
end
|
99
101
|
|
@@ -111,7 +113,7 @@ module LucidPolicy
|
|
111
113
|
|
112
114
|
if result.class == Proc
|
113
115
|
policy_helper = LucidPolicy::Helper.new
|
114
|
-
policy_helper.instance_exec(@object, target_class, target_method,
|
116
|
+
policy_helper.instance_exec(@object, target_class, target_method, props, &result)
|
115
117
|
result = policy_helper.result
|
116
118
|
end
|
117
119
|
end
|
@@ -119,9 +121,9 @@ module LucidPolicy
|
|
119
121
|
result == :allow ? true : false
|
120
122
|
end
|
121
123
|
|
122
|
-
def authorized!(target_class, target_method = nil,
|
123
|
-
return true if authorized?(target_class, target_method,
|
124
|
-
|
124
|
+
def authorized!(target_class, target_method = nil, props = nil)
|
125
|
+
return true if authorized?(target_class, target_method, props)
|
126
|
+
Isomorfeus.raise_error(error_class: LucidPolicy::Exception, message: "#{@object}: not authorized to call #{target_class}.#{target_method}(#{props})!")
|
125
127
|
end
|
126
128
|
end
|
127
129
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: isomorfeus-policy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.zeta13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Biedermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 16.12.
|
33
|
+
version: 16.12.14
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 16.12.
|
40
|
+
version: 16.12.14
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: isomorfeus-redux
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - '='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.0.0.
|
61
|
+
version: 1.0.0.zeta13
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - '='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 1.0.0.
|
68
|
+
version: 1.0.0.zeta13
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: opal-webpack-loader
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- lib/isomorfeus-policy.rb
|
120
120
|
- lib/isomorfeus/policy/config.rb
|
121
121
|
- lib/isomorfeus/policy/version.rb
|
122
|
+
- lib/isomorfeus/props_proxy.rb
|
122
123
|
- lib/isomorfeus_policy/anonymous.rb
|
123
124
|
- lib/isomorfeus_policy/lucid_authorization/base.rb
|
124
125
|
- lib/isomorfeus_policy/lucid_authorization/mixin.rb
|