开发者

Database help trying to get Functions from a group through users

I need to check whether a USER is a part of a group which has functions which give them access to a usermanagement page.. what i current have is

def user_managment
      # If they are in group 1              AND user has function id 1 (user management)
      if current_user.group_ids.include?(1) && current_user.function_ids.include?(1)#&& group.function_ids.include?(1)
      flash[:error] = "You have access to user management!"
      else
        flash[:er开发者_开发问答ror] = "You have DO NOT access to user management!"
      end

      if current_user.group_ids.include?(1) && group_ids(1).function_ids.include?(1)
        flash[:error] = "Test"
      end
    end

im unsure how do check if they have the string user management in the table from the userscontrollers can anyone help?


What you're talking about here is access control, please please please PLEASE, stop what you're doing and look at one of the many, excellent authorization/ACL gems out there. For example, using acl9 you could have some code that's much more comprehensible and expressive, such as:

access_control do
  allow :manager, :of => User, :to => :user_management
end

Rolling this stuff yourself is a bad move, and you'll end up with a lot of messy code intertwined through your app, very hard to maintain, and impossible to ensure it's always doing what you need it to.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜