Sha256: c9e4ca961d568f3009dd369c82828836d199e0048e9d55c000f3abafd65f172c

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

class GeneralAbility
  include CanCan::Ability

  def initialize(user)
    if alpha?(user)
      can :see, :mailchimp
      if petal_enabled?(user,'mailchimp')
        can :configure, :mailchimp
      end
      can :manage, :planning
    end

    if beta?(user)
    end

    if in_country?(user,'Argentina')
      can :manage, :derose_events
    end
  end
  
  private

  def in_country?(user,country_name)
    name = user.current_account.try(:name)
    if name
      @country = Rails.cache.fetch("countryfor#{name}") do
        padma_account(user).try(:country)
      end
      @country == country_name
    end
  end

  def padma_account(user)
    if user.current_account.is_a?(PadmaAccount)
      user.current_account
    else
      user.current_account.padma
    end
  end

  def petal_enabled?(user,petal_name)
    petal_name.in?(padma_account(user).enabled_petals||[])
  end
  
  def alpha?(user)
    user.account_tester_level == 'alpha'
  end

  def beta?(user)
    tl = user.account_tester_level 
    tl == 'alpha' || tl == 'beta'
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
padma-assets-0.2.9 app/abilities/general_ability.rb