Security issue with Migration when using declarative authorization gem

199 Views Asked by At

I'm trying to run a migration (just adding a column and initializing it actually), but declarative authorization (gem) deny me access because she is using a "guest" user.

This is the error message i got :

No matching rules found for update for #<Authorization::AnonymousUser:0xaf100b8 @role_symbols=[:guest]>

Of course, the "guest" user has no access at all defined in config/authorization.rb Moreover, I enforced model security with "using_access_control" option of declarative authorization

How could I run my migration as "admin" declarative-authorization's user ?

I've already bee facing such issue in the past and found a solution in stackoferflow answers, but I'm unable to find it back again.

Thanks fo any help

=== UPDATE ===

I found a possible solution with puting my migration block into a "without_access_control" method block from the declarative authorization gem :

class AddDateToProjMesure < ActiveRecord::Migration

  def change
    add_column :proj_mesures, :date_reference, :date

    Authorization::Maintenance::without_access_control do
      ProjMesure.all.each do |proj_mesure|
        proj_mesure.update_attributes! :date_reference => Time.zone.today
      end # ProjMesure.all.each
    end # Authorization::Maintenance::without_access_control

  end
end

but I got the following error :

uninitialized constant Authorization::Maintenance/var/www-opf/opf/db/migrate/20130607103809_add_date_to_proj_mesure.rb:41:in `change'

any idea why ? and if i need to use a require statement what should it point to ? ( vendor/plugins/ folder is empty !!!! )

1

There are 1 best solutions below

0
Douglas On

The documentation says to add the following, but it is wrong as Rails 3 vendor folder doesn't exist anymore in rails 3 and 4 :

require "vendor/plugins/declarative_authorization/lib/maintenance"

I asked in the google group and they give me the correct line :

require 'declarative_authorization/maintenance'

It works for me !