#933 ✓duplicate
Tim Griffin

acting_user not valid in :available_to parameter of 'create' transition

Reported by Tim Griffin | March 16th, 2011 @ 06:17 PM

With help from Bryan Larsen, a problem has been identified with 'acting_user' not evaluating to a valid object in the context of <transition-buttons>, thereby causing a

"undefined method `administrator?' for nil:NilClass" 

error.

The example we were working with extended a default Hobo 1.3pre30 app User model with two new transitions as follows:

 lifecycle do

    state :invited, :default => true
    state :active
    state :suspended

    create :invite,
           :available_to => "acting_user if acting_user.administrator?",
           :subsite => "admin",
           :params => [:name, :email_address],
           :new_key => true,
           :become => :invited do
       UserMailer.invite(self, lifecycle.key).deliver
    end
  
    transition :accept_invitation, { :invited => :active }, 
        :available_to => :key_holder,
        :params => [ :password, :password_confirmation ]
                                    
    transition :request_password_reset, { :active => :active }, :new_key => true do
      UserMailer.forgot_password(self, lifecycle.key).deliver
    end

    transition :reset_password, { :active => :active }, 
        :available_to => :key_holder,
        :params => [ :password, :password_confirmation ]

    transition :suspend, { :active => :suspended }, 
        :available_to => "acting_user if acting_user.administrator?"

    transition :reactivate, { :suspended => :active }, 
        :available_to => "acting_user if acting_user.administrator?"

  end              

and added <transition-buttons> to the User#index view:

<old-index-page merge>

<collection: replace>
  <table-plus fields="id, this, email_address, created_at, state, administrator, officer" param>
    <controls:>
      <transition-buttons/>
    </controls:>
  </table-plus>
</collection:>

</old-index-page>

The two additional transitions would not evaluate acting_user properly, and had to be rewritten as:

   transition :suspend, { :active => :suspended }, :available_to => "User.administrator"

   transition :reactivate, { :suspended => :active }, :available_to => "User.administrator"

It also doesn't seem possible to OR conditions as in this example:

   transition :suspend, { :active => :suspended }, 
    :available_to => "User.administrator || User.officer"

This does not evaluate properly: if the user IS an officer, the expression does NOT evaluate to 'true', and the officer cannot perform the transition.

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

People watching this ticket

Referenced by

Pages