11factory / activeadmin-cancan

CanCan integration for ActiveAdmin
MIT License
36 stars 9 forks source link

Not sure if it is working #1

Closed miguelperez closed 12 years ago

miguelperez commented 12 years ago

Hi,

So far I have no errors on the logs...

The thing is that I have some abilities that allow a user with role 'leader' only read projects with an status of finished... But still the projects index page is listing all the projects, and if I click on the show page of a started project that leader user is still able of seeing the information.

Is this the correct behavior?

11factory commented 12 years ago

Hi Miguel,

can you send me your ability file ?

2012/5/13 Miguel < reply@reply.github.com

Hi,

So far I have no errors on the logs...

The thing is that I have some abilities that allow a user with role 'leader' only read projects with an status of finished... But still the projects index page is listing all the projects, and if I click on the show page of a started project that leader user is still able of seeing the information.

Is this the correct behavior?


Reply to this email directly or view it on GitHub: https://github.com/11factory/activeadmin-cancan/issues/1

miguelperez commented 12 years ago

active_admin.rb

ActiveAdmin::ResourceController.class_eval do
  protected

  def current_ability
    @current_ability ||= AdminAbility.new(current_admin_user)
  end
end

admin_ability

class AdminAbility
  include CanCan::Ability

  def initialize(user)

    user ||= AdminUser.new
    case user.role
      when "admin"
        can :manage, :all
      when 'directivo'
        can :read, :all
      when 'coordinador'
        can :manage, AdminUser, :role => 'gestor'

    end
  end
end

This way it works, the thing is that defining a can action like this does not work:

  can :manage, AdminUser do |admin_user|
        AVAILABLE_ROLES.include?(admin_user.role)
  end

And also, when creating an admin_user, I wanted to disallow the creation of admin_user with a role different than 'gestor'

Thanks in advance.

11factory commented 12 years ago

It should be fixed in new version 0.1.2

Let me know if it works.

Thanks a lot!

miguelperez commented 12 years ago

Thanks a lot to you!...