stffn / declarative_authorization

An unmaintained authorization plugin for Rails. Please fork to support current versions of Rails
MIT License
1.24k stars 233 forks source link

How to use without_access_control into a migration ? #182

Closed bluebird-communication closed 11 years ago

bluebird-communication commented 11 years ago

I need to add a column to an existing table (and model). So i created a migration but I end up with following error :

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

So I managed to put 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 still got the following error :

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

How can I have access to this public method ?

bluebird-communication commented 11 years ago

I posted the answer here : http://stackoverflow.com/questions/16983305/security-issue-with-migration-when-using-declarative-authorization-gem/17200592#17200592