Problems starting with cantango

28 views
Skip to first unread message

Daniele

unread,
Jan 30, 2012, 9:49:35 AM1/30/12
to cantango
Hi,
cantango seems a really interesting project! I was testing it to see
if it can replace an in-house built permission system.
I followed the quickstart but I was unable to replicate a simple
scenario where an user has a single permission.

The config:
http://pastie.org/3282499

When I create an user and test the permission I get this error:
http://pastie.org/3282512

Clearly there must be a configuration error .. where?

Thank you,
Daniele

Kristian Mandrup

unread,
Jan 30, 2012, 10:33:24 AM1/30/12
to cant...@googlegroups.com
Hi Daniele,

This error sounds to me like an old bug that I thought I had squashed! It is due to the CanCan compatible rules array being generated, having not been flattened.
It is supposed to end up as a one dimensional array of rules, but for some reason it ends up with some array entries still in the form of Rule arrays, hence CanCan
in

    def relevant_rules(action, subject)
      rules.reverse.select do |rule|
        rule.expanded_actions = expand_actions(rule.actions)
        rule.relevant? action, subject
      end
    end

Tries to do rule.actions, expecting the rule to be a CanCan Rule, but operates instead on an Array. I think the error is in CanTango::Ability::Executor

      def execute!
        return if !valid?
        start_execute
        return cached_rules if cached? && cached_rules?

        clear_rules!
        permit_rules

        cache_rules! if cached?
        end_execute
        rules
      end

Try perhaps instead returning

  rules.flatten
  

From the paste error:

from /Users/xx/.rvm/gems/ruby-1.9.2-p290@test/gems/cantango-0.9.4.7/lib/cantango/users/user.rb:14:in `can?'

      def can? *args
        CanTango::Ability.new(active_account).can?(*args)
      end

So it created a new CanTango::Ability, using the active_account (or the user itself as candidate) and then attempts to call can? (from CanCan::Ability)

can? expects there to be a #rules method which returns the array of rules

I think you could just patch CanTango::Ability with

def rules
  @rules.flatten.compact
end

and it should work.

Let me know how it works for you. I have been spending most of my latest efforts on a total redesign of the whole framework… 

Kristian

Daniele

unread,
Jan 30, 2012, 11:16:01 AM1/30/12
to cantango
Hi Kristian,
thank you for your super-fast and detailed reply! And yesss, the patch
works! :)
Perhaps the bug could be related to the fact I use ruby 1.9.2? I have
already found some strange behaviors with array manipulation compared
to ruby 1.8.7.

Let's go on with my tests.
Thank you again.

Daniele

Kristian Mandrup

unread,
Feb 1, 2012, 4:10:37 AM2/1/12
to cant...@googlegroups.com
You are most welcome to make a pull request with the patch that worked for you ;)
Reply all
Reply to author
Forward
0 new messages