Skip to content

Commit

Permalink
bringing up to date with master branch
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanb committed Jun 27, 2012
2 parents de000fd + 1e89b31 commit 6886aec
Show file tree
Hide file tree
Showing 17 changed files with 269 additions and 24 deletions.
1 change: 1 addition & 0 deletions .rbenv-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.9.3-p194
90 changes: 90 additions & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,48 @@
1.6.8 (June 25, 2012)

* improved support for namespaced controllers and models

* pass :if and :unless options for load and authorize resource (thanks mauriciozaffari)

* Travis CI badge (thanks plentz)

* adding Ability#merge for combining multiple abilities (thanks rogercampos)

* support for multiple MetaWhere rules (thanks andhapp)

* various fixes for DataMapper, Mongoid, and Inherited Resource integration

* {see the full list of changes}[https://github.com/ryanb/cancan/compare/1.6.7...1.6.8]


1.6.7 (October 4, 2011)

* fixing nested resource problem caused by namespace addition - issue #482

* {see the full list of changes}[https://github.com/ryanb/cancan/compare/1.6.6...1.6.7]


1.6.6 (September 28, 2011)

* correct "return cant jump across threads" error when using check_authorization (thanks codeprimate) - issues #463, #469

* fixing tests in development by specifying with_model version (thanks kirkconnell) - issue #476

* added travis.yml file for TravisCI support (thanks bai) - issue #427

* better support for namespaced models (thanks whilefalse) - issues #424

* adding :id_param option to load_and_authorize_resource (thanks skhisma) - issue #425

* make default unauthorized message translatable text (thanks nhocki) - issue #409

* improving DataMapper behavior (thanks psanford, maxsum-corin) - issue #410, #373

* allow :find_by option to be full find method name - issue #335

* {see the full list of changes}[https://github.com/ryanb/cancan/compare/1.6.5...1.6.6]


1.6.5 (May 18, 2011)

* pass action and subject through AccessDenied exception when :through isn't found - issue #366
Expand All @@ -14,24 +59,31 @@

* improve scope merging - issue #328

* {see the full list of changes}[https://github.com/ryanb/cancan/compare/1.6.4...1.6.5]


1.6.4 (March 29, 2011)

* Fixed mongoid 'or' error - see issue #322

* {see the full list of changes}[https://github.com/ryanb/cancan/compare/1.6.3...1.6.4]


1.6.3 (March 25, 2011)

* Make sure ActiveRecord::Relation is defined before checking conditions against it so Rails 2 is supported again - see issue #312

* Return subject passed to authorize! - see issue #314

* {see the full list of changes}[https://github.com/ryanb/cancan/compare/1.6.2...1.6.3]


1.6.2 (March 18, 2011)

* Fixed instance loading when :singleton option is used - see issue #310

* {see the full list of changes}[https://github.com/ryanb/cancan/compare/1.6.1...1.6.2]


1.6.1 (March 15, 2011)

Expand All @@ -41,6 +93,8 @@

* Reverted Inherited Resources "collection" override since it doesn't seem to be working - see issue #305

* {see the full list of changes}[https://github.com/ryanb/cancan/compare/1.6.0...1.6.1]


1.6.0 (March 11, 2011)

Expand All @@ -62,13 +116,17 @@

* Raise an exception when trying to make a Ability condition with both a hash of conditions and a block - see issue #269

* {see the full list of changes}[https://github.com/ryanb/cancan/compare/1.5.1...1.6.0]


1.5.1 (January 20, 2011)

* Fixing deeply nested conditions in Active Record adapter - see issue #246

* Improving Mongoid support for multiple can and cannot definitions (thanks stellard) - see issue #239

* {see the full list of changes}[https://github.com/ryanb/cancan/compare/1.5.0...1.5.1]


1.5.0 (January 11, 2011)

Expand All @@ -90,6 +148,8 @@

* Internal: added .rvmrc to auto-switch to 1.8.7 with gemset - see issue #231

* {see the full list of changes}[https://github.com/ryanb/cancan/compare/1.4.1...1.5.0]


1.4.1 (November 12, 2010)

Expand All @@ -103,6 +163,8 @@

* Fix odd behavior when "cache_classes = false" (thanks mphalliday) - see issue #174

* {see the full list of changes}[https://github.com/ryanb/cancan/compare/1.4.0...1.4.1]


1.4.0 (October 5, 2010)

Expand Down Expand Up @@ -142,28 +204,38 @@

* No longer calling block in +can+ definition when checking on class - see issue #116

* {see the full list of changes}[https://github.com/ryanb/cancan/compare/1.3.4...1.4.0]


1.3.4 (August 31, 2010)

* Don't stop at +cannot+ with hash conditions when checking class (thanks tamoya) - see issue #131

* {see the full list of changes}[https://github.com/ryanb/cancan/compare/1.3.3...1.3.4]


1.3.3 (August 20, 2010)

* Switching to Rspec namespace to remove deprecation warning in Rspec 2 - see issue #119

* Pluralize nested associations for conditions in accessible_by (thanks mlooney) - see issue #123

* {see the full list of changes}[https://github.com/ryanb/cancan/compare/1.3.2...1.3.3]


1.3.2 (August 7, 2010)

* Fixing slice error when passing in custom resource name - see issue #112

* {see the full list of changes}[https://github.com/ryanb/cancan/compare/1.3.1...1.3.2]


1.3.1 (August 6, 2010)

* Fixing protected sanitize_sql error - see issue #111

* {see the full list of changes}[https://github.com/ryanb/cancan/compare/1.3.0...1.3.1]


1.3.0 (August 6, 2010)

Expand Down Expand Up @@ -191,6 +263,8 @@

* Supporting deeply nested aliases - see issue #98

* {see the full list of changes}[https://github.com/ryanb/cancan/compare/1.2.0...1.3.0]


1.2.0 (July 16, 2010)

Expand All @@ -206,11 +280,15 @@

* Adding joins clause to accessible_by when conditions are across associations

* {see the full list of changes}[https://github.com/ryanb/cancan/compare/1.1.1...1.2.0]


1.1.1 (April 17, 2010)

* Fixing behavior in Rails 3 by properly initializing ResourceAuthorization

* {see the full list of changes}[https://github.com/ryanb/cancan/compare/1.1...1.1.1]


1.1.0 (April 17, 2010)

Expand All @@ -234,6 +312,8 @@

* Support additional arguments to can? which get passed to the block - see issue #48

* {see the full list of changes}[https://github.com/ryanb/cancan/compare/1.0.2...1.1]


1.0.2 (Dec 30, 2009)

Expand All @@ -243,13 +323,17 @@

* Adding custom message argument to unauthorized! method (thanks tjwallace) - see issue #18

* {see the full list of changes}[https://github.com/ryanb/cancan/compare/1.0.1...1.0.2]


1.0.1 (Dec 14, 2009)

* Adding :class option to load_resource so one can customize which class to use for the model - see issue #17

* Don't fetch parent of nested resource if *_id parameter is missing so it works with shallow nested routes - see issue #14

* {see the full list of changes}[https://github.com/ryanb/cancan/compare/1.0.0...1.0.1]


1.0.0 (Dec 13, 2009)

Expand All @@ -265,6 +349,8 @@

* BACKWARDS INCOMPATIBLE: turning load and authorize resource methods into class methods which set up the before filter so they can accept additional arguments.

* {see the full list of changes}[https://github.com/ryanb/cancan/compare/0.2.1...1.0.0]


0.2.1 (Nov 26, 2009)

Expand All @@ -274,6 +360,8 @@

* support custom objects (usually symbols) in can definition - see issue #8

* {see the full list of changes}[https://github.com/ryanb/cancan/compare/0.2.0...0.2.1]


0.2.0 (Nov 17, 2009)

Expand All @@ -285,6 +373,8 @@

* BACKWARDS INCOMPATIBLE: use Ability#initialize instead of 'prepare' to set up abilities - see issue #4

* {see the full list of changes}[https://github.com/ryanb/cancan/compare/0.1.0...0.2.0]


0.1.0 (Nov 16, 2009)

Expand Down
2 changes: 1 addition & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
= CanCan
= CanCan {<img src="https://secure.travis-ci.org/ryanb/cancan.png" />}[http://travis-ci.org/ryanb/cancan]

This is the branch for CanCan 2.0 which is in very early development. For a stable release please check out the {master branch}[https://github.com/ryanb/cancan]

Expand Down
7 changes: 7 additions & 0 deletions lib/cancan/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,13 @@ def fully_authorized!(action, subject)
@fully_authorized << [action.to_sym, subject.to_sym]
end

def merge(ability)
ability.send(:rules).each do |rule|
rules << rule.dup
end
self
end

private

def unauthorized_message_keys(action, subject)
Expand Down
7 changes: 5 additions & 2 deletions lib/cancan/controller_additions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def load_and_authorize_resource(*args)
# [:+find_by+]
# Find using a different attribute other than id. For example.
#
# load_resource :find_by => :permalink # will use find_by_permlink!(params[:id])
# load_resource :find_by => :permalink # will use find_by_permalink!(params[:id])
#
# [:+collection+]
# Specify which actions are resource collection actions in addition to :+index+. This
Expand Down Expand Up @@ -152,6 +152,9 @@ def load_resource(*args)
# [:+except+]
# Does not apply before filter to given actions.
#
# [:+singleton+]
# Pass +true+ if this is a singleton resource through a +has_one+ association.
#
# [:+parent+]
# True or false depending on if the resource is considered a parent resource. This defaults to +true+ if a resource
# name is given which does not match the controller.
Expand Down Expand Up @@ -382,7 +385,7 @@ def cannot?(*args)
end
end

if defined? ActionController
if defined? ActionController::Base
ActionController::Base.class_eval do
include CanCan::ControllerAdditions
end
Expand Down
21 changes: 16 additions & 5 deletions lib/cancan/controller_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ def self.add_before_filter(controller_class, behavior, *args)
options = args.extract_options!.merge(behavior)
resource_name = args.first
before_filter_method = options.delete(:prepend) ? :prepend_before_filter : :before_filter
controller_class.send(before_filter_method, options.slice(:only, :except)) do |controller|
controller.class.cancan_resource_class.new(controller, resource_name, options.except(:only, :except)).process
controller_class.send(before_filter_method, options.slice(:only, :except, :if, :unless)) do |controller|
controller.class.cancan_resource_class.new(controller, resource_name, options.except(:only, :except, :if, :unless)).process
end
end

Expand Down Expand Up @@ -81,6 +81,10 @@ def load_collection

def build_resource
resource = resource_base.new(resource_params || {})
assign_attributes(resource)
end

def assign_attributes(resource)
resource.send("#{parent_name}=", parent_resource) if @options[:singleton] && parent_resource
initial_attributes.each do |attr_name, value|
resource.send("#{attr_name}=", value)
Expand Down Expand Up @@ -225,12 +229,19 @@ def name
end

def resource_params
# since Rails includes the namespace in the params sent by the form (issue #349)
@params[namespaced_name.to_s.underscore.gsub("/", "_")]
if @options[:class]
@params[@options[:class].to_s.underscore.gsub('/', '_')]
else
@params[namespaced_name.to_s.underscore.gsub("/", "_")]
end
end

def namespace
@params[:controller].split("::")[0..-2]
end

def namespaced_name
(@name || @params[:controller].sub("Controller", "")).singularize.camelize.constantize
[namespace, name.camelize].join('::').singularize.camelize.constantize
rescue NameError
name
end
Expand Down
3 changes: 2 additions & 1 deletion lib/cancan/inherited_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ def load_resource_instance
@controller.send :association_chain
@controller.instance_variable_get("@#{instance_name}")
elsif new_actions.include? @params[:action].to_sym
@controller.send :build_resource
resource = @controller.send :build_resource
assign_attributes(resource)
else
@controller.send :resource
end
Expand Down
7 changes: 6 additions & 1 deletion lib/cancan/model_adapters/active_record_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ def database_records
if override_scope
@model_class.scoped.merge(override_scope)
elsif @model_class.respond_to?(:where) && @model_class.respond_to?(:joins)
@model_class.where(conditions).joins(joins)
mergeable_conditions = @rules.select {|rule| rule.unmergeable? }.blank?
if mergeable_conditions
@model_class.where(conditions).joins(joins)
else
@model_class.where(*(@rules.map(&:conditions))).joins(joins)
end
else
@model_class.scoped(:conditions => conditions, :joins => joins)
end
Expand Down
3 changes: 2 additions & 1 deletion lib/cancan/model_adapters/mongoid_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ def database_records
else
# we only need to process can rules if
# there are no rules with empty conditions
rules = @rules.reject { |rule| rule.conditions.empty? }
rules = @rules.reject { |rule| rule.conditions.empty? && rule.base_behavior }
process_can_rules = @rules.count == rules.count

rules.inject(@model_class.all) do |records, rule|
if process_can_rules && rule.base_behavior
records.or rule.conditions
Expand Down
Loading

0 comments on commit 6886aec

Please sign in to comment.