authorization on group...

1 view
Skip to first unread message

phil

unread,
Jul 10, 2009, 8:59:37 AM7/10/09
to Rails Authorization Plugin
Sorry - I am new to this plugin and hitting a learning curve.

I have an item and an item_group (to which it belongs).

I want a user to be able to administer the item if they are authorized
on the item OR on the item group to which it belongs.

so, I've done something like
user.is_admin_of item
and then of course user.is_admin_of? item returns true.
But how can I extend this behaving so I can have user.is_admin_of?
item return true when the user has just be admin'd on the item group?
I assume I have to override something and put it on the shop model (or
that is what would make sense to me)... but I can't figure out what!

Thanks in advance!

Donald Ball

unread,
Jul 10, 2009, 2:18:20 PM7/10/09
to Rails Authorization Plugin
On Fri, Jul 10, 2009 at 7:59 AM, phil<ph...@philsmy.com> wrote:
>
> Sorry - I am new to this plugin and hitting a learning curve.
>
> I have an item and an item_group (to which it belongs).
>
> I want a user to be able to administer the item if they are authorized
> on the item OR on the item group to which it belongs.

If the item, and the item_group, belong_to a :user, and you're using
"hard-wired" roles, you probably want something like:

class Item
def accepts_role?(role, user)
role == 'admin' && (user == self.user ||
item_group.accepts_role(role, user))
end
end

If you're using the object_roles data models, I'm afraid I can't offer any help.

- donald

Reply all
Reply to author
Forward
0 new messages