rolypoly 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rolypoly/role_gatekeeper.rb +12 -1
- data/lib/rolypoly/version.rb +1 -1
- data/spec/lib/rolypoly/role_gatekeeper_spec.rb +58 -24
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b09c15051b80319c301293ec37ab69543724ca83
|
4
|
+
data.tar.gz: 3af871d40e05440ee846689d45bc479914bf26cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74757c303d7c9f040d8685a3baa9e0401584a3bea4ba6e241d883387e3089ee9db3c05e8644a8978b1efa70f91341a0d6a97bfa15909a43458d2be86a1cafb01
|
7
|
+
data.tar.gz: 01b232b80eeb8d65569fdc28a03348fedeb98bf50ca4b0ba003e068c1ed14afb6b478dca1d2b0d7f94d132353cd66dd7d2827f9bc9cdd997ef403f3c9a504cae
|
@@ -84,8 +84,19 @@ module Rolypoly
|
|
84
84
|
|
85
85
|
private def allowed_resource?(check_role, required_resource)
|
86
86
|
return true unless require_resource?
|
87
|
+
return false unless check_role.respond_to?(:resource?)
|
88
|
+
|
89
|
+
if resources?(required_resource)
|
90
|
+
required_resource.any? do |r|
|
91
|
+
check_role.resource?(r)
|
92
|
+
end
|
93
|
+
else
|
94
|
+
check_role.resource?(required_resource)
|
95
|
+
end
|
96
|
+
end
|
87
97
|
|
88
|
-
|
98
|
+
private def resources?(resources)
|
99
|
+
resources.is_a?(Array) && !%w(String Symbol).include?(resources.first.class.name)
|
89
100
|
end
|
90
101
|
|
91
102
|
private def find_required_resource(options = {})
|
data/lib/rolypoly/version.rb
CHANGED
@@ -119,41 +119,75 @@ module Rolypoly
|
|
119
119
|
|
120
120
|
subject { described_class.new roles, actions, :resource }
|
121
121
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
122
|
+
context 'with no resource' do
|
123
|
+
describe "resource does not match" do
|
124
|
+
before do
|
125
|
+
allow(scorekeeper_role).to receive(:resource?).with(nil).and_return false
|
126
|
+
allow(scorekeeper_role).to receive(:to_role_string).and_return 'scorekeeper'
|
127
|
+
end
|
127
128
|
|
128
|
-
|
129
|
-
|
130
|
-
|
129
|
+
it { expect(subject.allow?(nil, nil)).to be false }
|
130
|
+
it { expect(subject.allow?(scorekeeper_role, :index)).to be false }
|
131
|
+
it { expect(subject.allow?(scorekeeper_role, :edit)).to be false }
|
132
|
+
end
|
131
133
|
end
|
132
134
|
|
133
|
-
|
134
|
-
|
135
|
+
context 'with resource' do
|
136
|
+
describe "resource does not match" do
|
137
|
+
let(:resource) { { resource: ['Organization', 123] } }
|
135
138
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
139
|
+
before do
|
140
|
+
allow(scorekeeper_role).to receive(:resource?).with(resource[:resource]).and_return false
|
141
|
+
allow(scorekeeper_role).to receive(:to_role_string).and_return "scorekeeper"
|
142
|
+
end
|
143
|
+
|
144
|
+
it { expect(subject.allow?(nil, nil, resource)).to be false }
|
145
|
+
it { expect(subject.allow?([scorekeeper_role], "index", resource)).to be false }
|
146
|
+
it { expect(subject.allow?([scorekeeper_role], "edit", resource)).to be false }
|
147
|
+
end
|
148
|
+
|
149
|
+
describe "resource matches" do
|
150
|
+
let(:resource) { { resource: ['Organization', 123] } }
|
151
|
+
|
152
|
+
before do
|
153
|
+
allow(scorekeeper_role).to receive(:resource?).with(resource[:resource]).and_return true
|
154
|
+
end
|
140
155
|
|
141
|
-
|
142
|
-
|
143
|
-
|
156
|
+
it { expect(subject.allow?(nil, nil, resource)).to be false }
|
157
|
+
it { expect(subject.allow?([scorekeeper_role], "index", resource)).to be true }
|
158
|
+
it { expect(subject.allow?([scorekeeper_role], "edit", resource)).to be false }
|
159
|
+
end
|
144
160
|
end
|
145
161
|
|
146
|
-
|
147
|
-
let(:
|
162
|
+
context 'with resources' do
|
163
|
+
let(:first_resource) { ['Organization', 1] }
|
164
|
+
let(:second_resource) { ['Organization', 123] }
|
165
|
+
let(:resource) { { resource: [first_resource, second_resource] } }
|
148
166
|
|
149
|
-
|
150
|
-
|
167
|
+
describe 'none of the resources match' do
|
168
|
+
before do
|
169
|
+
allow(scorekeeper_role).to receive(:resource?).with(first_resource).and_return false
|
170
|
+
allow(scorekeeper_role).to receive(:resource?).with(second_resource).and_return false
|
171
|
+
allow(scorekeeper_role).to receive(:to_role_string).and_return "scorekeeper"
|
172
|
+
end
|
173
|
+
|
174
|
+
it { expect(subject.allow?(nil, nil, resource)).to be false }
|
175
|
+
it { expect(subject.allow?([scorekeeper_role], "index", resource)).to be false }
|
176
|
+
it { expect(subject.allow?([scorekeeper_role], "edit", resource)).to be false }
|
151
177
|
end
|
152
178
|
|
153
|
-
|
154
|
-
|
155
|
-
|
179
|
+
describe 'one of the resources match' do
|
180
|
+
before do
|
181
|
+
allow(scorekeeper_role).to receive(:resource?).with(first_resource).and_return false
|
182
|
+
allow(scorekeeper_role).to receive(:resource?).with(second_resource).and_return true
|
183
|
+
end
|
184
|
+
|
185
|
+
it { expect(subject.allow?(nil, nil, resource)).to be false }
|
186
|
+
it { expect(subject.allow?([scorekeeper_role], "index", resource)).to be true }
|
187
|
+
it { expect(subject.allow?([scorekeeper_role], "edit", resource)).to be false }
|
188
|
+
end
|
156
189
|
end
|
190
|
+
|
157
191
|
end
|
158
192
|
end
|
159
193
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rolypoly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Phenow
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-10-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
101
|
version: '0'
|
102
102
|
requirements: []
|
103
103
|
rubyforge_project:
|
104
|
-
rubygems_version: 2.4.
|
104
|
+
rubygems_version: 2.4.8
|
105
105
|
signing_key:
|
106
106
|
specification_version: 4
|
107
107
|
summary: Tools for handling per-action and per-app Role authorization
|