【问题标题】:Does granting cancan ability to create automatically imply access to new action?授予 cancan 自动创建的能力是否意味着可以访问新操作?
【发布时间】:2021-02-09 07:19:45
【问题描述】:

我有一个 cancan 能力,说用户可以 createMessage 如果它是他们的

can [:create], [Message] do |message|
  message.user_id == user.id && message.conversation.sender_id == user.id
end

这按预期工作,但令人惊讶的是,此 rspec 测试用户是否可以访问消息的 new 操作失败:

it 'A user should not be able to access their own message new action' do
  expect(ability).to_not be_able_to(:new, message)
end

因此用户可以访问new 操作以获取他们的消息。为什么是这样?访问create 操作是否也意味着访问new?还是我在某个地方误解或犯了错误?

【问题讨论】:

    标签: ruby-on-rails cancan cancancan


    【解决方案1】:

    是的:new:create 的别名

    看这里:

    https://github.com/CanCanCommunity/cancancan/wiki/Action-Aliases

    【讨论】:

      猜你喜欢
      • 2015-12-01
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 2020-07-29
      • 2021-10-01
      • 2013-02-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多