:available_to is more flexible than just a list of users.
http://cookbook.hobocentral.net/manual/lifecycles#the__option

for a string it should evaluate it but this is something that'd be
better to encompass in a method and call that.  perhaps a can_set_won?
method in User.
from the manual:
The value returned is then used to determine if the acting_user  has
access or not. The value is expected to be:
      A class – access is granted if the acting_user is a kind_of?
that class.
      A collection – if the value responds to :include?, access is
granted if include?(acting_user) is true. e.g.
      A record – if the value is neither a class or a collection,
access is granted if the value is the acting_user

So, for it to work you need that method to return either User for
access to all records, the owner of the quote for just owner access or
false/nil etc if no access period.  the problem is I'm not sure if you
have access to acting_user in the string eval or not.  if you didn't
get an exception you probably do.


On May 13, 7:00 am, Henry Baragar <[email protected]>
wrote:
> The :available_to expects a list of users, not a Boolean.  You can use :if for
> Boolean tests.
>
> Henry
>
> On May 13, 2010 08:35:12 am paulo wrote:
>
>
>
> > Hi folks,
>
> > I'm struggling to put together a permission system required for
> > transitions on one of my models.
>
> > The app needs to allow users to create quotes, and then change the
> > state of a quote, if they have access to do this.
> > Access is determined from a integer value in the 'acl_group' Model,
> > which each user belongs to. This is loosely based on the linux
> > permission system i.e.
> > 0=no access,
> > 1=create quotes + read/update quotes they own,
> > 2= create quotes + read/update ALL quotes
> > 3 = same as level 2 but can delete quotes
>
> > My simplified models are below:
>
> > Model User
> > belongs_to :acl_group
> > has_many :quote
>
> > Model acl_group
> > quote  :integer
> > has_many :user
>
> > Model quote
> > belongs_to :user
> > lifecycle do
> >     state :quoted, :default => true
> >     state :won
>
> >     create :make_quote, :become => :quoted do end
>
> >     transition :won, {:quoted => :won}, :available_to =>
> > "acting_user.administrator ||  acting_user.acl_group.quote > 1 ||
> > acting_user.acl_group.quote = 1 && acting_user == user"
> >   end
>
> > I've tried using the String option, which never grants access and also
> > tried a code-block which didn't appear to work (I couldn't get past a
> > 'ERROR NameError: undefined local variable or method' error, putting
> > the code block either in the controller or model (within lifecycle
> > block and outside).
>
> > I trust that I am probably missing something very obvious here, or
> > maybe just approaching this in the wrong way?
>
> > Thanks in advance,
>
> > Paul
>
> --
> Henry Baragar
> Instantiated Software
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Hobo Users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group 
> athttp://groups.google.com/group/hobousers?hl=en.

-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en.

Reply via email to