Commit 01d166f2 by liyijie

feat: policy,传入上下文等参数信息

parent e17edc53
......@@ -170,12 +170,22 @@ class SimpleController::BaseController < ::InheritedResources::Base
# 对于resource的相关操作,都调用policy进行authorize
def set_resource_ivar(resource)
_resource = authorize_if_policy_class resource, "#{action_name}?"
policy_info = {
record: resource,
klass: resource_class,
context: params,
}
_resource = authorize_if_policy_class policy_info, "#{action_name}?"
instance_variable_set("@#{resource_instance_name}", _resource)
end
def set_collection_ivar(collection)
authorize_if_policy_class resource_class, "#{action_name}?"
policy_info = {
collection: collection,
klass: resource_class,
context: params,
}
authorize_if_policy_class policy_info, "#{action_name}?"
instance_variable_set("@#{resource_collection_name}", collection)
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment