isomorfeus-policy 1.0.0.delta12 → 1.0.0.epsilon1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/isomorfeus/policy/version.rb +1 -1
- data/lib/lucid_policy/base.rb +0 -6
- data/lib/lucid_policy/mixin.rb +34 -59
- metadata +31 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a2f26a5f58b1c8dce4bb0439587288e5bf5b38cd48174a25abe6bf24479148d
|
4
|
+
data.tar.gz: badb0fdc82dd47c5660d737c798f81f8544a640b91e65ceb638c07f43383c290
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d778f99cea46d15f2c21e75e80d11e4877d89908012c9610aad44da71af7873109cc965c49be7be372fc9ff5239d35ed02c69529c6e7828269eaf0945577eb5c
|
7
|
+
data.tar.gz: 59c041bb5980a783f77ecb5332b4b7e82024ef4be35dd15f0bed4f2c524485c686a2bcf4a809debbbd9c607fdf70407ee642ad93de04562efeecaf56bb5b7347
|
data/lib/lucid_policy/base.rb
CHANGED
data/lib/lucid_policy/mixin.rb
CHANGED
@@ -1,38 +1,13 @@
|
|
1
1
|
module LucidPolicy
|
2
2
|
module Mixin
|
3
3
|
def self.included(base)
|
4
|
-
if RUBY_ENGINE != 'opal'
|
5
|
-
Isomorfeus.add_valid_policy_class(base) unless base == LucidPolicy::Base
|
6
|
-
end
|
7
|
-
|
8
|
-
# DSL
|
9
|
-
# class MySimplePolicy < LucidPolicy::Base
|
10
|
-
#
|
11
|
-
# policy_for UserOrRoleClass
|
12
|
-
#
|
13
|
-
# allow BlaBlaGraph, :load
|
14
|
-
#
|
15
|
-
# deny BlaGraph, SuperOperation
|
16
|
-
#
|
17
|
-
# deny others # or: allow others
|
18
|
-
#
|
19
|
-
# with_condition do |user_or_role_instance, target_class, target_method, *props|
|
20
|
-
# role.class == AdminRole
|
21
|
-
# end
|
22
|
-
#
|
23
|
-
# refine BlaGraph, :load, :count do |user_or_role_instance, target_class, target_method, *props|
|
24
|
-
# allow if role.verified?
|
25
|
-
# deny
|
26
|
-
# end
|
27
|
-
# end
|
28
|
-
#
|
29
4
|
base.instance_exec do
|
30
5
|
def policy_for(a_class)
|
31
6
|
raise LucidPolicy::Exception, "policy_for #{a_class} can only be used once within #{self}!" if @the_class
|
32
7
|
@the_class = a_class
|
33
8
|
unless a_class.methods.include?(:authorization_rules)
|
34
9
|
a_class.define_singleton_method(:authorization_rules) do
|
35
|
-
@authorization_rules ||= {
|
10
|
+
@authorization_rules ||= {}
|
36
11
|
end
|
37
12
|
end
|
38
13
|
unless a_class.method_defined?(:authorized?)
|
@@ -42,35 +17,35 @@ module LucidPolicy
|
|
42
17
|
target_method = class_method_props[1]
|
43
18
|
props = class_method_props[2..-1]
|
44
19
|
|
45
|
-
|
46
|
-
self.class.authorization_rules
|
47
|
-
condition_result =
|
48
|
-
|
49
|
-
|
20
|
+
result = :deny
|
21
|
+
self.class.authorization_rules.each_value do |rules|
|
22
|
+
condition_result = true
|
23
|
+
rules[:conditions].each do |condition|
|
24
|
+
condition_result = condition.call(self, target_class, target_method, *props, &condition)
|
25
|
+
break unless condition_result == true
|
26
|
+
end
|
50
27
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
28
|
+
if condition_result == true
|
29
|
+
result = if rules[:classes].key?(target_class)
|
30
|
+
if target_method && rules[:classes][target_class].key?(:methods) &&
|
31
|
+
rules[:classes][target_class][:methods].key?(target_method)
|
32
|
+
rules[:classes][target_class][:methods][target_method]
|
33
|
+
else
|
34
|
+
rules[:classes][target_class][:default]
|
35
|
+
end
|
57
36
|
else
|
58
|
-
|
37
|
+
rules[:others]
|
59
38
|
end
|
60
|
-
else
|
61
|
-
self.class.authorization_rules[:others]
|
62
|
-
end
|
63
|
-
|
64
|
-
if result.class == Proc
|
65
|
-
policy_helper = Isomorfeus::Policy::Helper.new
|
66
|
-
policy_helper.instance_exec(self, target_class, target_method, *props, &result)
|
67
|
-
result = policy_helper.result
|
68
|
-
end
|
69
39
|
|
70
|
-
|
71
|
-
|
72
|
-
|
40
|
+
if result.class == Proc
|
41
|
+
policy_helper = Isomorfeus::Policy::Helper.new
|
42
|
+
policy_helper.instance_exec(self, target_class, target_method, *props, &result)
|
43
|
+
result = policy_helper.result
|
44
|
+
end
|
45
|
+
end
|
46
|
+
break if result == :allow
|
73
47
|
end
|
48
|
+
result == :allow ? true : false
|
74
49
|
end
|
75
50
|
end
|
76
51
|
unless a_class.method_defined?(:authorized!)
|
@@ -79,7 +54,7 @@ module LucidPolicy
|
|
79
54
|
raise LucidPolicy::Exception, "#{self} not authorized to call #{class_method_props}"
|
80
55
|
end
|
81
56
|
end
|
82
|
-
@the_class.authorization_rules[:
|
57
|
+
@the_class.authorization_rules[self.to_s] = { classes: {}, conditions: [], others: :deny }
|
83
58
|
end
|
84
59
|
|
85
60
|
def allow(*classes_and_methods)
|
@@ -103,7 +78,7 @@ module LucidPolicy
|
|
103
78
|
|
104
79
|
def with_condition(&block)
|
105
80
|
_raise_policy_first unless @the_class
|
106
|
-
@the_class.authorization_rules[:conditions] << block
|
81
|
+
@the_class.authorization_rules[self.to_s][:conditions] << block
|
107
82
|
end
|
108
83
|
|
109
84
|
private
|
@@ -118,14 +93,14 @@ module LucidPolicy
|
|
118
93
|
|
119
94
|
def _allow_or_deny(allow_or_deny, *classes_and_methods, &block)
|
120
95
|
_raise_policy_first unless @the_class
|
121
|
-
|
96
|
+
rule_hash = @the_class.authorization_rules[self.to_s]
|
122
97
|
allow_or_deny_or_block = block_given? ? block : allow_or_deny.to_sym
|
123
98
|
|
124
99
|
target_classes = []
|
125
100
|
target_methods = []
|
126
101
|
|
127
102
|
if classes_and_methods.first == :others
|
128
|
-
|
103
|
+
rule_hash[:others] = allow_or_deny_or_block
|
129
104
|
return
|
130
105
|
end
|
131
106
|
|
@@ -138,14 +113,14 @@ module LucidPolicy
|
|
138
113
|
end
|
139
114
|
|
140
115
|
target_classes.each do |target_class|
|
141
|
-
|
116
|
+
rule_hash[:classes][target_class] = {} unless rule_hash[:classes].key?(target_class)
|
142
117
|
if allow_or_deny && target_methods.empty?
|
143
|
-
|
118
|
+
rule_hash[:classes][target_class][:default] = allow_or_deny_or_block
|
144
119
|
else
|
145
|
-
|
146
|
-
|
120
|
+
rule_hash[:classes][target_class][:default] = :deny unless rule_hash[:classes][target_class].key?(:default)
|
121
|
+
rule_hash[:classes][target_class][:methods] = {} unless rule_hash[:classes][target_class].key?(:methods)
|
147
122
|
target_methods.each do |target_method|
|
148
|
-
|
123
|
+
rule_hash[:classes][target_class][:methods][target_method] = allow_or_deny_or_block
|
149
124
|
end
|
150
125
|
end
|
151
126
|
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.epsilon1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Biedermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal
|
@@ -66,6 +66,34 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 4.0.11
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.8.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 3.8.0
|
69
97
|
description: Policies for Isomorfeus.
|
70
98
|
email: jan@kursator.de
|
71
99
|
executables: []
|
@@ -100,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
128
|
- !ruby/object:Gem::Version
|
101
129
|
version: 1.3.1
|
102
130
|
requirements: []
|
103
|
-
rubygems_version: 3.0.
|
131
|
+
rubygems_version: 3.0.6
|
104
132
|
signing_key:
|
105
133
|
specification_version: 4
|
106
134
|
summary: Policies for Isomorfeus.
|