Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38d4654523 | ||
|
|
3f4ee12025 | ||
|
|
4dcd544594 | ||
|
|
f5b3fcd8db | ||
|
|
3b50fedd5d | ||
|
|
d4be93bc83 | ||
|
|
9a84277549 | ||
|
|
857dd075c5 | ||
|
|
b4285ae43c | ||
|
|
2db73e60c6 | ||
|
|
cad4db2d7b | ||
|
|
d20d90d2c2 | ||
|
|
8b993ee27d | ||
|
|
60bc9e98a7 | ||
|
|
925274d29a | ||
|
|
b162871c6d | ||
|
|
cfc355c006 |
@@ -1,3 +1,14 @@
|
|||||||
|
1.6.9 (February 4, 2013)
|
||||||
|
|
||||||
|
* fix inserting AND (NULL) to end of SQL queries (thanks jonsgreen) - issue #687
|
||||||
|
|
||||||
|
* fix merge_joins for nested association hashes (thanks DavidMikeSimon) - issues #655, #560
|
||||||
|
|
||||||
|
* raise error on recursive alias_action (thanks fl00r) - issue #660
|
||||||
|
|
||||||
|
* fix namespace controllers not loading params (thanks andhapp) - issues #670, #664
|
||||||
|
|
||||||
|
|
||||||
1.6.8 (June 25, 2012)
|
1.6.8 (June 25, 2012)
|
||||||
|
|
||||||
* improved support for namespaced controllers and models
|
* improved support for namespaced controllers and models
|
||||||
|
|||||||
11
CONTRIBUTING.md
Normal file
11
CONTRIBUTING.md
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
### Please read before contributing
|
||||||
|
|
||||||
|
1) If you have any questions about CanCan, search the [Wiki](https://github.com/ryanb/cancan/wiki) or use [Stack Overflow](http://stackoverflow.com/questions/tagged/cancan). Do not post questions here.
|
||||||
|
|
||||||
|
2) If you find a security bug, **DO NOT** submit an issue here. Please send an e-mail to [ryan@railscasts.com](mailto:ryan@railscasts.com) instead.
|
||||||
|
|
||||||
|
3) Do a small search on the issues tracker before submitting your issue to see if it was already reported / fixed. In case it was not, create your report including Rails and CanCan versions. If you are getting exceptions, please include the full backtrace.
|
||||||
|
|
||||||
|
That's it! The more information you give, the more easy it becomes for us to track it down and fix it. Ideal scenario would be adding the issue to CanCan test suite or to a sample application.
|
||||||
|
|
||||||
|
Thanks!
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
= CanCan {<img src="https://secure.travis-ci.org/ryanb/cancan.png" />}[http://travis-ci.org/ryanb/cancan]
|
= CanCan {<img src="https://fury-badge.herokuapp.com/rb/cancan.png" alt="Gem Version" />}[http://badge.fury.io/rb/cancan] {<img src="https://secure.travis-ci.org/ryanb/cancan.png?branch=master" />}[http://travis-ci.org/ryanb/cancan] {<img src="https://codeclimate.com/badge.png" />}[https://codeclimate.com/github/ryanb/cancan]
|
||||||
|
|
||||||
Wiki[https://github.com/ryanb/cancan/wiki] | RDocs[http://rdoc.info/projects/ryanb/cancan] | Screencast[http://railscasts.com/episodes/192-authorization-with-cancan]
|
Wiki[https://github.com/ryanb/cancan/wiki] | RDocs[http://rdoc.info/projects/ryanb/cancan] | Screencast[http://railscasts.com/episodes/192-authorization-with-cancan]
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = "cancan"
|
s.name = "cancan"
|
||||||
s.version = "1.6.8"
|
s.version = "1.6.9"
|
||||||
s.author = "Ryan Bates"
|
s.author = "Ryan Bates"
|
||||||
s.email = "ryan@railscasts.com"
|
s.email = "ryan@railscasts.com"
|
||||||
s.homepage = "http://github.com/ryanb/cancan"
|
s.homepage = "http://github.com/ryanb/cancan"
|
||||||
|
|||||||
@@ -172,10 +172,16 @@ module CanCan
|
|||||||
# This way one can use params[:action] in the controller to determine the permission.
|
# This way one can use params[:action] in the controller to determine the permission.
|
||||||
def alias_action(*args)
|
def alias_action(*args)
|
||||||
target = args.pop[:to]
|
target = args.pop[:to]
|
||||||
|
validate_target(target)
|
||||||
aliased_actions[target] ||= []
|
aliased_actions[target] ||= []
|
||||||
aliased_actions[target] += args
|
aliased_actions[target] += args
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# User shouldn't specify targets with names of real actions or it will cause Seg fault
|
||||||
|
def validate_target(target)
|
||||||
|
raise Error, "You can't specify target (#{target}) as alias because it is real action name" if aliased_actions.values.flatten.include? target
|
||||||
|
end
|
||||||
|
|
||||||
# Returns a hash of aliased actions. The key is the target and the value is an array of actions aliasing the key.
|
# Returns a hash of aliased actions. The key is the target and the value is an array of actions aliasing the key.
|
||||||
def aliased_actions
|
def aliased_actions
|
||||||
@aliased_actions ||= default_alias_actions
|
@aliased_actions ||= default_alias_actions
|
||||||
|
|||||||
@@ -213,10 +213,15 @@ module CanCan
|
|||||||
|
|
||||||
def resource_params
|
def resource_params
|
||||||
if @options[:class]
|
if @options[:class]
|
||||||
@params[@options[:class].to_s.underscore.gsub('/', '_')]
|
params_key = extract_key(@options[:class])
|
||||||
else
|
return @params[params_key] if @params[params_key]
|
||||||
@params[namespaced_name.to_s.underscore.gsub("/", "_")]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
resource_params_by_namespaced_name
|
||||||
|
end
|
||||||
|
|
||||||
|
def resource_params_by_namespaced_name
|
||||||
|
@params[extract_key(namespaced_name)]
|
||||||
end
|
end
|
||||||
|
|
||||||
def namespace
|
def namespace
|
||||||
@@ -244,5 +249,11 @@ module CanCan
|
|||||||
def new_actions
|
def new_actions
|
||||||
[:new, :create] + [@options[:new]].flatten
|
[:new, :create] + [@options[:new]].flatten
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def extract_key(value)
|
||||||
|
value.to_s.underscore.gsub('/', '_')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -145,8 +145,8 @@ module CanCan
|
|||||||
# Takes two hashes and does a deep merge.
|
# Takes two hashes and does a deep merge.
|
||||||
def merge_joins(base, add)
|
def merge_joins(base, add)
|
||||||
add.each do |name, nested|
|
add.each do |name, nested|
|
||||||
if base[name].is_a?(Hash) && !nested.empty?
|
if base[name].is_a?(Hash)
|
||||||
merge_joins(base[name], nested)
|
merge_joins(base[name], nested) unless nested.empty?
|
||||||
else
|
else
|
||||||
base[name] = nested
|
base[name] = nested
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -55,7 +55,8 @@ module CanCan
|
|||||||
end
|
end
|
||||||
|
|
||||||
def unmergeable?
|
def unmergeable?
|
||||||
@conditions.respond_to?(:keys) && (! @conditions.keys.first.kind_of? Symbol)
|
@conditions.respond_to?(:keys) && @conditions.present? &&
|
||||||
|
(!@conditions.keys.first.kind_of? Symbol)
|
||||||
end
|
end
|
||||||
|
|
||||||
def associations_hash(conditions = @conditions)
|
def associations_hash(conditions = @conditions)
|
||||||
|
|||||||
@@ -11,18 +11,22 @@ class Ability
|
|||||||
# can :read, :all
|
# can :read, :all
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# The first argument to `can` is the action you are giving the user permission to do.
|
# The first argument to `can` is the action you are giving the user
|
||||||
# If you pass :manage it will apply to every action. Other common actions here are
|
# permission to do.
|
||||||
# :read, :create, :update and :destroy.
|
# If you pass :manage it will apply to every action. Other common actions
|
||||||
|
# here are :read, :create, :update and :destroy.
|
||||||
#
|
#
|
||||||
# The second argument is the resource the user can perform the action on. If you pass
|
# The second argument is the resource the user can perform the action on.
|
||||||
# :all it will apply to every resource. Otherwise pass a Ruby class of the resource.
|
# If you pass :all it will apply to every resource. Otherwise pass a Ruby
|
||||||
|
# class of the resource.
|
||||||
#
|
#
|
||||||
# The third argument is an optional hash of conditions to further filter the objects.
|
# The third argument is an optional hash of conditions to further filter the
|
||||||
|
# objects.
|
||||||
# For example, here the user can only update published articles.
|
# For example, here the user can only update published articles.
|
||||||
#
|
#
|
||||||
# can :update, Article, :published => true
|
# can :update, Article, :published => true
|
||||||
#
|
#
|
||||||
# See the wiki for details: https://github.com/ryanb/cancan/wiki/Defining-Abilities
|
# See the wiki for details:
|
||||||
|
# https://github.com/ryanb/cancan/wiki/Defining-Abilities
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -87,6 +87,10 @@ describe CanCan::Ability do
|
|||||||
@ability.can?(:increment, 123).should be_true
|
@ability.can?(:increment, 123).should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should raise an Error if alias target is an exist action" do
|
||||||
|
lambda{ @ability.alias_action :show, :to => :show }.should raise_error(CanCan::Error, "You can't specify target (show) as alias because it is real action name")
|
||||||
|
end
|
||||||
|
|
||||||
it "should always call block with arguments when passing no arguments to can" do
|
it "should always call block with arguments when passing no arguments to can" do
|
||||||
@ability.can do |action, object_class, object|
|
@ability.can do |action, object_class, object|
|
||||||
action.should == :foo
|
action.should == :foo
|
||||||
|
|||||||
@@ -75,13 +75,19 @@ describe CanCan::ControllerResource do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "should build a new resource for namespaced model with hash if params[:id] is not specified" do
|
it "should build a new resource for namespaced model with hash if params[:id] is not specified" do
|
||||||
project = Sub::Project.create!
|
|
||||||
@params.merge!(:action => "create", 'sub_project' => {:name => "foobar"})
|
@params.merge!(:action => "create", 'sub_project' => {:name => "foobar"})
|
||||||
resource = CanCan::ControllerResource.new(@controller, :class => ::Sub::Project)
|
resource = CanCan::ControllerResource.new(@controller, :class => ::Sub::Project)
|
||||||
resource.load_resource
|
resource.load_resource
|
||||||
@controller.instance_variable_get(:@project).name.should == "foobar"
|
@controller.instance_variable_get(:@project).name.should == "foobar"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should build a new resource for namespaced controller and namespaced model with hash if params[:id] is not specified" do
|
||||||
|
@params.merge!(:controller => "Admin::SubProjectsController", :action => "create", 'sub_project' => {:name => "foobar"})
|
||||||
|
resource = CanCan::ControllerResource.new(@controller, :class => Project)
|
||||||
|
resource.load_resource
|
||||||
|
@controller.instance_variable_get(:@sub_project).name.should == "foobar"
|
||||||
|
end
|
||||||
|
|
||||||
it "should build a new resource with attributes from current ability" do
|
it "should build a new resource with attributes from current ability" do
|
||||||
@params.merge!(:action => "new")
|
@params.merge!(:action => "new")
|
||||||
@ability.can(:create, Project, :name => "from conditions")
|
@ability.can(:create, Project, :name => "from conditions")
|
||||||
|
|||||||
@@ -20,10 +20,12 @@ if ENV["MODEL_ADAPTER"].nil? || ENV["MODEL_ADAPTER"] == "active_record"
|
|||||||
t.boolean "secret"
|
t.boolean "secret"
|
||||||
t.integer "priority"
|
t.integer "priority"
|
||||||
t.integer "category_id"
|
t.integer "category_id"
|
||||||
|
t.integer "user_id"
|
||||||
end
|
end
|
||||||
model do
|
model do
|
||||||
belongs_to :category
|
belongs_to :category
|
||||||
has_many :comments
|
has_many :comments
|
||||||
|
belongs_to :user
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -37,6 +39,15 @@ if ENV["MODEL_ADAPTER"].nil? || ENV["MODEL_ADAPTER"] == "active_record"
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
with_model :user do
|
||||||
|
table do |t|
|
||||||
|
|
||||||
|
end
|
||||||
|
model do
|
||||||
|
has_many :articles
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
Article.delete_all
|
Article.delete_all
|
||||||
Comment.delete_all
|
Comment.delete_all
|
||||||
@@ -227,6 +238,21 @@ if ENV["MODEL_ADAPTER"].nil? || ENV["MODEL_ADAPTER"] == "active_record"
|
|||||||
@ability.model_adapter(Article, :read).joins.should == [:project]
|
@ability.model_adapter(Article, :read).joins.should == [:project]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should merge nested and non-nested joins" do
|
||||||
|
@ability.can :read, Article, :project => { :blocked => false }
|
||||||
|
@ability.can :read, Article, :project => { :comments => { :spam => true } }
|
||||||
|
@ability.model_adapter(Article, :read).joins.should == [{:project=>[:comments]}]
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should merge :all conditions with other conditions" do
|
||||||
|
user = User.create!
|
||||||
|
article = Article.create!(:user => user)
|
||||||
|
ability = Ability.new(user)
|
||||||
|
ability.can :manage, :all
|
||||||
|
ability.can :manage, Article, :user_id => user.id
|
||||||
|
Article.accessible_by(ability).should == [article]
|
||||||
|
end
|
||||||
|
|
||||||
it "should restrict articles given a MetaWhere condition" do
|
it "should restrict articles given a MetaWhere condition" do
|
||||||
@ability.can :read, Article, :priority.lt => 2
|
@ability.can :read, Article, :priority.lt => 2
|
||||||
article1 = Article.create!(:priority => 1)
|
article1 = Article.create!(:priority => 1)
|
||||||
|
|||||||
@@ -44,4 +44,9 @@ describe CanCan::Rule do
|
|||||||
|
|
||||||
@rule.should be_unmergeable
|
@rule.should be_unmergeable
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should be mergeable if conditions is an empty hash" do
|
||||||
|
@conditions = {}
|
||||||
|
@rule.should_not be_unmergeable
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user