ii_policy 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +4 -19
- data/ii_policy.gemspec +1 -0
- data/lib/ii_policy/base.rb +2 -2
- data/lib/ii_policy/coactors.rb +29 -0
- data/lib/ii_policy/version.rb +1 -1
- data/lib/ii_policy.rb +1 -0
- metadata +18 -4
- data/lib/ii_policy/chain.rb +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12f75fa515f57c1d7cb21138025c5fea4f8202ecfdde800abec38451c54c9604
|
4
|
+
data.tar.gz: 5b52a7b58ed0eb07e3ff42165518e3be2b79f41846a6d34c92a0c4090c90b51a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0933c5f001415a5c54ab3a89d3485d62579f0a7c0cb4a4519934dc68a17843eed920feeb44356c7f4d0e04203fd8e28f8541211ce448aa7c468de51fda0a13d8'
|
7
|
+
data.tar.gz: 73b0729f99bfd3ed83a13fa4ffda3ec091934b03b834f6a522667dacd822ffac4294ad11ea332cc40f5de53dabd58cd61e6726dcc1a62619fa80aaf9c131e67d
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -175,9 +175,9 @@ class ItemPolicy < IIPolicy::Base
|
|
175
175
|
end
|
176
176
|
```
|
177
177
|
|
178
|
-
####
|
178
|
+
#### Coactors
|
179
179
|
|
180
|
-
You can
|
180
|
+
You can define multiple coactors by using `coact` as follows:
|
181
181
|
|
182
182
|
```ruby
|
183
183
|
# shared policy
|
@@ -189,7 +189,7 @@ end
|
|
189
189
|
|
190
190
|
# base policy
|
191
191
|
class ItemPolicy < IIPolicy::Base
|
192
|
-
|
192
|
+
coact SharedPolicy
|
193
193
|
|
194
194
|
def show?
|
195
195
|
@item.status != 'deleted'
|
@@ -203,22 +203,7 @@ policy.allowed(:show?)
|
|
203
203
|
|
204
204
|
In this example, `policy.allowed(:show?)` is evaluated by `SharedPolicy#show? && ItemPolicy#show?`.
|
205
205
|
|
206
|
-
|
207
|
-
|
208
|
-
```ruby
|
209
|
-
class ItemPolicy < IIPolicy::Base
|
210
|
-
chain -> { SharedPolicy }
|
211
|
-
end
|
212
|
-
|
213
|
-
class ItemPolicy < IIPolicy::Base
|
214
|
-
chain :chain_policy
|
215
|
-
|
216
|
-
def chain_policy
|
217
|
-
SharedPolicy
|
218
|
-
end
|
219
|
-
end
|
220
|
-
```
|
221
|
-
|
206
|
+
See [coactive](https://github.com/kanety/coactive) for more `coact` examples:
|
222
207
|
|
223
208
|
### Lookup for policy
|
224
209
|
|
data/ii_policy.gemspec
CHANGED
data/lib/ii_policy/base.rb
CHANGED
@@ -5,7 +5,7 @@ require_relative 'core'
|
|
5
5
|
require_relative 'callbacks'
|
6
6
|
require_relative 'instrumentation'
|
7
7
|
require_relative 'lookup'
|
8
|
-
require_relative '
|
8
|
+
require_relative 'coactors'
|
9
9
|
|
10
10
|
module IIPolicy
|
11
11
|
class Base
|
@@ -13,6 +13,6 @@ module IIPolicy
|
|
13
13
|
include Callbacks
|
14
14
|
include Instrumentation
|
15
15
|
include Lookup
|
16
|
-
include
|
16
|
+
include Coactors
|
17
17
|
end
|
18
18
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module IIPolicy
|
4
|
+
module Coactors
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
include Coactive::Base
|
9
|
+
|
10
|
+
configure_coactive do |config|
|
11
|
+
config.load_paths = ['app/policies']
|
12
|
+
config.class_suffix = 'Policy'
|
13
|
+
config.use_cache = true
|
14
|
+
config.lookup_superclass_until = ['ActiveRecord::Base', 'ActiveModel::Base']
|
15
|
+
end
|
16
|
+
|
17
|
+
class << self
|
18
|
+
alias_method :chain, :coact
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def call(action)
|
23
|
+
coactors.each do |policy|
|
24
|
+
return false unless policy.new(@context).call(action)
|
25
|
+
end
|
26
|
+
super
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/ii_policy/version.rb
CHANGED
data/lib/ii_policy.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ii_policy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yoshikazu Kaneta
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '5.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: coactive
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.1'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rails
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,7 +134,7 @@ files:
|
|
120
134
|
- lib/ii_policy.rb
|
121
135
|
- lib/ii_policy/base.rb
|
122
136
|
- lib/ii_policy/callbacks.rb
|
123
|
-
- lib/ii_policy/
|
137
|
+
- lib/ii_policy/coactors.rb
|
124
138
|
- lib/ii_policy/config.rb
|
125
139
|
- lib/ii_policy/context.rb
|
126
140
|
- lib/ii_policy/controller.rb
|
@@ -150,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
164
|
- !ruby/object:Gem::Version
|
151
165
|
version: '0'
|
152
166
|
requirements: []
|
153
|
-
rubygems_version: 3.
|
167
|
+
rubygems_version: 3.0.3
|
154
168
|
signing_key:
|
155
169
|
specification_version: 4
|
156
170
|
summary: A base policy to support management of authorization logic
|
data/lib/ii_policy/chain.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module IIPolicy
|
4
|
-
module Chain
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
|
7
|
-
included do
|
8
|
-
class_attribute :_chains
|
9
|
-
self._chains = []
|
10
|
-
end
|
11
|
-
|
12
|
-
def call(action)
|
13
|
-
lookup.each do |policy|
|
14
|
-
return false unless policy.new(@context).call(action)
|
15
|
-
end
|
16
|
-
super
|
17
|
-
end
|
18
|
-
|
19
|
-
def lookup
|
20
|
-
self.class._chains.map do |policy|
|
21
|
-
if policy.is_a?(Symbol) && respond_to?(policy, true)
|
22
|
-
send(policy)
|
23
|
-
elsif policy.is_a?(Proc)
|
24
|
-
instance_exec(&policy)
|
25
|
-
else
|
26
|
-
policy
|
27
|
-
end
|
28
|
-
end.flatten.compact
|
29
|
-
end
|
30
|
-
|
31
|
-
class_methods do
|
32
|
-
def chain(*policies, &block)
|
33
|
-
self._chains = _chains + policies
|
34
|
-
self._chains << block if block
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|