数据库帮助尝试通过用户从组中获取功能

发布于 2024-11-19 18:58:10 字数 663 浏览 2 评论 0原文

我需要检查用户是否是一个组的一部分,该组具有使他们能够访问用户管理页面的功能。我当前所拥有的是

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[:error] = "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

我不确定如何检查他们是否在用户控制器的表中具有字符串用户管理可以有人帮忙吗?

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[:error] = "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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回心转意 2024-11-26 18:58:10

你在这里谈论的是访问控制,请停止你正在做的事情并查看众多优秀的授权/ACL 精华之一。例如,使用 acl9 你可以得到一些更容易理解和更具表现力的代码,例如:

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

Rolling this stuff你自己是一个糟糕的举动,你最终会在你的应用程序中交织出大量混乱的代码,非常难以维护,并且不可能确保它始终执行你需要的操作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文