Role permit does not wok

42 views
Skip to first unread message

Allan

unread,
Jun 29, 2012, 11:31:35 AM6/29/12
to cant...@googlegroups.com
Hi all,

I set up the app with the cantango 0.9.4.7, and using the simple_roles gem.


config\initializers\simple_roles.rb

SimpleRoles.configure do
  valid_roles :teacher, :parent, :student
  strategy    :one # Default is :one
end

config\initializers\cantango.rb

CanTango.config do |config|
  config.debug!

 config.permits.disable :account, :special, :role_group
   config.engine(:permission).set :off
   config.engine(:permit).set :on

   config.ability.mode = :no_cache
  # more configuration here...

  config.guest.user Proc.new { Guest.new }
  config.roles.role_system = :simple_roles

end

# in order to make #current_admin accessible at the class level
module CanTango::Api
  def self.current_admin
    @current_admin ||= AdminUser.first
  end
end

app\models\user.rb

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable,
  # :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me, :role

  tango_user
  simple_roles

end

And I defined three Role Permit in \app\permits
For example ParentRolePermit

But I found that all there Permit had been registered, however, none of them was builded, see the debug logs as following:
permits registry:[#<Hashie::Mash admin_user=AdminUserPermit guest=GuestPermit>, #<Hashie::Mash>, #<Hashie::Mash parent=ParentRolePermit parent_role=ParentRolePermit student=StudentRolePermit teacher=TeacherRolePermit>, #<Hashie::Mash>]
Ability: read on Wordlist
permits allowed:[]
permits denied:[]
++ Permit Builder: CanTango::Permits::UserPermit::Builder
Permit Finder: CanTango::Permits::UserPermit::Finder
no account permits found for user
no permits found for user
Not building any UserPermit
Permit Finder: CanTango::Permits::UserPermit::Finder
no account permits found for user
no permits found for user
== Permits built: 0
++ Permit Builder: CanTango::Permits::RolePermit::Builder
Not building any RolePermit
== Permits built: 0
Permit Engine executing...
Execute user permits
Done user permits
Execute role permits
Done role permits
Done Permit Engine

My question is how to make cantango build these Permit?

Kristian Mandrup

unread,
Jun 29, 2012, 11:54:36 AM6/29/12
to cant...@googlegroups.com
Hi Allan,

Can you please show me the code for those role Permits. How did you create them? Did you use the role permit generator?
I've sadly not had the time or energy to work on this project for along time, and it really needs some love in order to fully work spin like a cat again. 
As stated repeatedly in this group, I started working on a whole new refactoring of the project into smaller, more manageable gems, but sadly never finished that mission either.
The project has potential, but is just too much for me to handle by myself in my spare time. I would recommend anyone to debug, by finding the debugging statements in the code where it doesn't act as it should and reverse engineer from there in order to understand what goes on behind the scenes and then fix whatever needs fixing. Sorry I can't be of more help now.

Kristian

Allan

unread,
Jun 29, 2012, 6:41:10 PM6/29/12
to cant...@googlegroups.com
Hi Kristian,

Here is the parent_role_permit.rb, which I create by the generator

class ParentRolePermit < CanTango::RolePermit
  def initialize ability
    super
  end

  protected

  def permit_rules
    # insert your can, cannot and any other rule statements here
    can :read, Wordlist
  end

  module Cached
    def permit_rules
    end
  end

  module NonCached
    def permit_rules
    end
  end
end

在 2012年6月29日星期五UTC+8下午11时54分36秒,Kristian Mandrup写道:
Reply all
Reply to author
Forward
0 new messages