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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6f4da324f740e09486d891362c4ccca59293f1e6
4
- data.tar.gz: 8e81b842251b29657c0d853d1c30b686006dcba4
3
+ metadata.gz: b09c15051b80319c301293ec37ab69543724ca83
4
+ data.tar.gz: 3af871d40e05440ee846689d45bc479914bf26cb
5
5
  SHA512:
6
- metadata.gz: bb720596c9c935a5d5f9f2d0483b67c09de67cd8572569322acecf9c487031a54aeb3cf46810333bfb2502e729922ff304ccca177c415972bfe25b2774a1854f
7
- data.tar.gz: 27b4a65a2a1f986488f35e39f6b543079927fa8ec5efd6f4aeb0b62676e90e04654834696b8cf8433ccd114b88213e6e65277abc73d32c44075e3f6953321945
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
- check_role.respond_to?(:resource?) && check_role.resource?(required_resource)
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 = {})
@@ -1,3 +1,3 @@
1
1
  module Rolypoly
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
@@ -119,41 +119,75 @@ module Rolypoly
119
119
 
120
120
  subject { described_class.new roles, actions, :resource }
121
121
 
122
- describe "resource does not match" do
123
- before do
124
- allow(scorekeeper_role).to receive(:resource?).with(nil).and_return false
125
- allow(scorekeeper_role).to receive(:to_role_string).and_return 'scorekeeper'
126
- end
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
- it { expect(subject.allow?(nil, nil)).to be false }
129
- it { expect(subject.allow?(scorekeeper_role, :index)).to be false }
130
- it { expect(subject.allow?(scorekeeper_role, :edit)).to be false }
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
- describe "resource does not match" do
134
- let(:resource) { { resource: ['Organization', 123] } }
135
+ context 'with resource' do
136
+ describe "resource does not match" do
137
+ let(:resource) { { resource: ['Organization', 123] } }
135
138
 
136
- before do
137
- allow(scorekeeper_role).to receive(:resource?).with(resource[:resource]).and_return false
138
- allow(scorekeeper_role).to receive(:to_role_string).and_return "scorekeeper"
139
- end
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
- it { expect(subject.allow?(nil, nil, resource)).to be false }
142
- it { expect(subject.allow?([scorekeeper_role], "index", resource)).to be false }
143
- it { expect(subject.allow?([scorekeeper_role], "edit", resource)).to be false }
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
- describe "resource matches" do
147
- let(:resource) { { resource: ['Organization', 123] } }
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
- before do
150
- allow(scorekeeper_role).to receive(:resource?).with(resource[:resource]).and_return true
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
- it { expect(subject.allow?(nil, nil, resource)).to be false }
154
- it { expect(subject.allow?([scorekeeper_role], "index", resource)).to be true }
155
- it { expect(subject.allow?([scorekeeper_role], "edit", resource)).to be false }
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.2
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-07-25 00:00:00.000000000 Z
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.6
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