cancan/cantango 在第一次请求后丢失用户/user_session 和/或角色

发布于 2024-12-03 13:54:43 字数 1055 浏览 0 评论 0原文

Vanilla authlogic/cantango 设置,在返回 [:user] 的测试期间使用硬编码的 roles_list 进行测试。测试 requests.yml 文件:

roles:
  user:
    can:
      manage:
      - User

在第一个请求中,user_can?(:manage, User) 执行了我所期望的操作。然而,在随后的请求中,情况不再如此,我的许可也随之消失。

current_usercurrent_user_session 变量在每次请求时都会发生变化;不确定这是否是因为我处于开发环境中并且正在重新加载某些内容,但它让我了解了一些。 Duh :/

ApplicationController 中的实现遵循默认的 authlogic 示例。

如果我加载控制台:

pry(main)> u = User.first
=> #<User id: 2, email: "[email protected]", [...]
pry(main)> a = CanTango::Ability.new u
=> [lots of stuff, available on request]
pry(main)> a.can?(:manage, User.new)
=> true
pry(main)> a.can?(:manage, User.new)
=> true

我尝试根据 cantango 的文档在 cantango.rb 中关闭 cantango 的缓存(以防万一)[...]>

任何提示/提示/指针/源/文档?

Vanilla authlogic/cantango setup, testing with a hard-coded roles_list during test that returns [:user]. Test permissions.yml file:

roles:
  user:
    can:
      manage:
      - User

On the first request, user_can?(:manage, User) does what I expect. On subsequent requests, however, it's no longer true, and my permission goes away.

The current_user and current_user_session vars change on each request; not sure if that's because I'm in dev environment and something's being reloaded, but it sketches me out a little bit. Duh :/

Implementation in ApplicationController follows default authlogic examples.

If I load up the console:

pry(main)> u = User.first
=> #<User id: 2, email: "[email protected]", [...]
pry(main)> a = CanTango::Ability.new u
=> [lots of stuff, available on request]
pry(main)> a.can?(:manage, User.new)
=> true
pry(main)> a.can?(:manage, User.new)
=> true

I attempted to turn cantango's caching off (just in case) in cantango.rb per cantango's docs [...]>

Any hints/tips/pointers/source/docs?

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

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

发布评论

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

评论(1

梦境 2024-12-10 13:54:43

如果我将 requests.yml 文件更改为以下内容(理论上,这些是角色,而不是用户,但没有来宾角色,我从未在代码中的任何地方引用它,它不起作用),那么大多数情况下都会起作用。

roles:
  user:
    can:
      manage:
      - User
  guest:
    cannot:
      manage:
      - User

到目前为止我仍然必须关闭缓存。

我暂时放弃cantango;虽然我有大量基于角色的权限需求,但由此造成的麻烦并不值得,而且到目前为止,使用一些相同元技术的更有针对性的解决方案似乎会更干净、更容易。

If I change the permissions.yml file to the following (these are roles, not users, in theory, but w/o the guest role, which I never reference anywhere in my code, it doesn't work) things mostly work.

roles:
  user:
    can:
      manage:
      - User
  guest:
    cannot:
      manage:
      - User

I still have to leave caching off so far.

I'm abandoning cantango for now; while I have significant role-based permissions needs, the amount of trouble this caused isn't worth it, and so far it seems like a more targeted solution using some of the same meta-techniques will be cleaner and easier.

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