rails-authorization-pugin issue

1 view
Skip to first unread message

Jason Patrick Agujo

unread,
Nov 26, 2009, 6:04:48 AM11/26/09
to ruby...@googlegroups.com
i setup my rails project yesterday (thanks crigor) but i noticed something wierd at the back end.

here are the steps taken:

user = User.find(3)
role = Role.find(1)
user.has_role role.name

what i expected to see was the that only the roles_user will be updated but when i checked it out the back end there were duplicate records being made on the back. has anyone used this plugin before or anyone encountered this same issue before?

Erol Fornoles

unread,
Nov 26, 2009, 8:33:56 AM11/26/09
to Philippine Ruby Users Group (PRUG/PhRUG)
Can you elaborate on what you mean by "duplicate records being made"?

Richard Gonzales

unread,
Nov 26, 2009, 11:56:49 PM11/26/09
to ruby...@googlegroups.com
if you are using role_requirement, here's how to set the role:
@user = User.find(3)
@user.role_ids = ["1"]

your roles_users table should have a record with id = 1 and the name of the role (name = "member").
take note that its an array, so a user could have multiple roles, such as, @user.role_ids = ["1", "3"].

if you are using RESTful Authentication with role_requirement, you can evaluate by:

if @user.has_role?("member")

has_role does not add any record, it just evaluates the role in question:
def has_role?(role_in_question)
    @_list ||= self.roles.collect(&:name)
    # return true if @_list.include?("admin")
    (@_list.include?(role_in_question.to_s) )
  end

Please paste more of your code so we can check it out.
Hope that helps?!

--

You received this message because you are subscribed to the Google Groups "Philippine Ruby Users Group (PRUG/PhRUG)" group.
To post to this group, send email to ruby...@googlegroups.com.
To unsubscribe from this group, send email to ruby-phil+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ruby-phil?hl=en.

Jason Patrick Agujo

unread,
Nov 27, 2009, 12:16:00 AM11/27/09
to ruby...@googlegroups.com
thanks for the all the info guys, i somewhat got it late last night.

im using restful_authentication and rails-authorization-plugin. inside the role table i set up 3 different roles:

Ex:
id: 1
name: Admin
authorizable_type: Admin

when i created a new user and performed the

@user.has_role role.name

i noticed that a new record was created:

Ex:
id: 4
name: Admin
authorizable_type:

thats when i realized that somehow rails-authorization-plugin is making a new record without anyother fields except id and name. so i modified the 3 roles that i had inside so only the ID and Name were filled out. then i noticed that the "bug" wasnt repeating.

it was odd for me though, i guess im the only one that experienced that. il just present this as is (because its working already) and go deeper into this after.

thank  you so much for all the input/insights

Richard Gonzales

unread,
Nov 27, 2009, 12:25:15 AM11/27/09
to ruby...@googlegroups.com
Geez! Did not notice the subject. My bad!

Erol Fornoles

unread,
Nov 27, 2009, 1:19:35 AM11/27/09
to Philippine Ruby Users Group (PRUG/PhRUG)
Hmmm, seems like your "bug" isn't a bug at all. By specifying an
authorizable_type in your example record, you are basically telling
the authorization-plugin to authorize the role "Admin" ONLY with your
"Admin" model. The plugin treats the global "Admin" role as being
different to the "Admin of Admin" role, and therefore, it creates a
new record when you tried to create a global "Admin" by calling
#has_role with only a symbol or string parameter.
Reply all
Reply to author
Forward
0 new messages