I am encountering an issue in my Ruby application where authorisation failures occur intermittently when attempting to create multiple records using a loop. This behavior arises despite having defined authorisation rules that should allow the operation. The application uses a custom authorisation setup and raises specific exceptions when permissions are not met.
Environment
- Ruby Version: 2.3.1
- Framework: Sinatra
- Database: MySQL
- Authorisation Library: Declarative Authorization
Authorization::NotAuthorized: No matching rules found for create for #<User id: 14, name: "Foo", surname: "Bar", email:....> (roles [:delegate, :guest ], privileges [:create, :manage], context :schedule_groups).
Example:
i = 0
75.times do
i += 1
begin
event = Something.create({})
puts "Successfully created record number #{i}"
rescue Authorization::NotAuthorized => e
puts "Authorization failed for record number #{i}: #{e.message}"
end
end
model:
class Something < ActiveRecord::Base
using_access_control
end
This above code creates 50 – 59 records out of 75 and later on breaks with the Authorization::NotAuthorized:
error.
Not sure why it is breaking after creating few records?
please advice,
Thanks in advance.