0
我正在使用cancan gem进行授权。我已经定义了ability.rb模块来初始化不同模块的角色及其权限。如何使用cancan定义条件性能力
`def initialize(user)
user ||= User.new # guest user (not logged in)
members = user.members
members.each do |member|
role = member.role
if role.presence
permissions = role.permissions
permissions.each do |permission|
actions = Array.new
actions = permission.activity_name.split(",") if permission.activity_name.presence
app_module = permission.application_module
actions.each do |action|
if app_module.module_name == "Project"
Rails.logger.debug "in if"
can action.downcase.to_sym, app_module.module_name.constantize, :id => member.project_id if action.presence
elsif app_module.module_name == "Sequence"
Rails.logger.debug "in sequence and project id is #{member.project_id} and action is #{action}"
can action.downcase.to_sym, app_module.module_name.constantize, :project_id => 0..1 if action.presence
else
Rails.logger.debug "Module name is #{app_module.module_name}"
can action.downcase.to_sym, app_module.module_name.constantize if action.presence
end
end
end
end
end
end`
这里用户分配一个项目,项目有许多片断。 如果用户已分配了一个项目,然后ID 1我有只获取其项目编号为1
在控制器我写这些序列 - load_and_authorize_resource
的权限项目控制器是正确牵强,但对于序列控制器,如果我通过项目ID也不限制其他项目。
谁能帮我