@@ -232,8 +232,7 @@ def permit!(privilege, options = {})
232
232
else
233
233
puts "Rule has #{ rule . attributes . count } attributes, examining them:"
234
234
235
- all_attributes_matched = true
236
- any_attribute_matched = false
235
+ matching_attributes_count = 0
237
236
238
237
rule . attributes . each_with_index do |attribute , index |
239
238
puts "\n -- Attribute ##{ index + 1 } : #{ attribute . inspect } "
@@ -248,8 +247,9 @@ def permit!(privilege, options = {})
248
247
249
248
next unless conditions . is_a? ( Hash )
250
249
251
- puts " Checking conditions against current values:"
252
- current_attribute_matched = true
250
+ puts " Checking #{ conditions . count } conditions against current values:"
251
+ matching_conditions_count = 0
252
+ any_condition_failed = false
253
253
254
254
if conditions . key? ( :granular_permissions )
255
255
rule_requires = conditions [ :granular_permissions ] [ 1 ]
@@ -258,13 +258,14 @@ def permit!(privilege, options = {})
258
258
puts " Granular permissions - Rule requires: #{ rule_requires } , Actual: #{ actual_value } "
259
259
if rule_requires == actual_value
260
260
puts " ✓ Granular permissions condition matched!"
261
+ matching_conditions_count += 1
261
262
else
262
263
puts " ✗ Granular permissions condition did not match"
263
- current_attribute_matched = false
264
+ any_condition_failed = true
264
265
end
265
266
end
266
267
267
- if conditions . key? ( :is_renewal ) && current_attribute_matched
268
+ if conditions . key? ( :is_renewal ) && ! any_condition_failed
268
269
rule_requires = conditions [ :is_renewal ] [ 1 ]
269
270
# If options[:object] has is_renewal, we'll use that value instead of obtaining it from SpiceDB.
270
271
# This allows for Blue Moon leases and others to be checked without having to make a SpiceDB call for the value of is_renewal.
@@ -286,13 +287,14 @@ def permit!(privilege, options = {})
286
287
puts " Is renewal - Rule requires: #{ rule_requires } , Actual: #{ actual_value } "
287
288
if rule_requires == actual_value
288
289
puts " ✓ Is_renewal condition matched!"
290
+ matching_conditions_count += 1
289
291
else
290
292
puts " ✗ Is_renewal condition did not match"
291
- current_attribute_matched = false
293
+ any_condition_failed = true
292
294
end
293
295
end
294
296
295
- if conditions . key? ( :id ) && current_attribute_matched
297
+ if conditions . key? ( :id ) && ! any_condition_failed
296
298
condition_type = conditions [ :id ] [ 0 ]
297
299
condition_proc = conditions [ :id ] [ 1 ]
298
300
@@ -302,27 +304,27 @@ def permit!(privilege, options = {})
302
304
puts " User has access to occupancy? #{ user_has_access_to_occupancy } "
303
305
if user_has_access_to_occupancy
304
306
puts " ✓ This attribute matched conditions"
307
+ matching_conditions_count += 1
305
308
else
306
309
puts " ✗ This attribute did not match conditions"
307
- current_attribute_matched = false
310
+ any_condition_failed = true
308
311
end
309
312
end
310
313
end
311
314
312
- if current_attribute_matched
313
- any_attribute_matched = true
315
+ if matching_conditions_count == conditions . count
314
316
puts " ✓ All conditions matched for this attribute"
317
+ matching_attributes_count += 1
315
318
else
316
- all_attributes_matched = false
317
319
puts " ✗ Not all conditions matched for this attribute"
318
320
end
319
321
end
320
322
321
323
puts " Finished checking attributes, checking if rule is authorized"
322
324
323
325
if rule . respond_to? ( :join_operator ) && rule . join_operator == :and
324
- puts " Rule uses AND operator, checking if all attributes matched: #{ all_attributes_matched } "
325
- if all_attributes_matched
326
+ puts " Rule uses AND operator, checking if all attributes matched: #{ matching_attributes_count == rule . attributes . count } "
327
+ if matching_attributes_count == rule . attributes . count
326
328
puts " All attributes matched, checking SpiceDB permission"
327
329
authorized = @auth_service . check_permission (
328
330
resource : { type : "vhost" , id : vhost_id } ,
@@ -334,8 +336,8 @@ def permit!(privilege, options = {})
334
336
puts " Not all attributes matched, authorization denied for this rule"
335
337
end
336
338
else
337
- puts " Rule uses OR operator (default), checking if any attribute matched: #{ any_attribute_matched } "
338
- if any_attribute_matched
339
+ puts " Rule uses OR operator (default), checking if any attribute matched: #{ matching_attributes_count > 0 } "
340
+ if matching_attributes_count > 0
339
341
puts " At least one attribute matched, checking SpiceDB permission"
340
342
authorized = @auth_service . check_permission (
341
343
resource : { type : "vhost" , id : vhost_id } ,
0 commit comments