Sha256: 2e1a8cb090b54daa6e15ab1ead1fdcfe3be8b604f24ea65ba7e5401c4f667851

Contents?: true

Size: 1.77 KB

Versions: 7

Compression:

Stored size: 1.77 KB

Contents

module PaidUp
  module Ability
    include CanCan::Ability

    def initialize_paid_up(user)
      features = PaidUp::Feature.all
      for feature in features
        case feature.setting_type
          when 'table_rows'
            can :read, feature.feature_model
            if user.table_rows_allowed(feature.slug) > 0 || user.table_rows_unlimited?(feature.slug)
              can :manage, feature.feature_model, :user => user
              can :own, feature.feature_model
              unless user.table_rows_remaining(feature.slug) > 0
                cannot :create, feature.feature_model
              end
            else
              cannot :delete, feature.feature_model
              cannot :update, feature.feature_model
              cannot :own, feature.feature_model
              cannot :create, feature.feature_model
            end
          when 'rolify_rows'
            can :read, feature.feature_model
            if user.rolify_rows_allowed(feature.slug) > 0 || user.rolify_rows_unlimited?(feature.slug)
              can :manage, feature.feature_model do |record|
                user.has_role? :owner, record
              end
              can :own, feature.feature_model
              unless user.rolify_rows_remaining(feature.slug) > 0
                cannot :create, feature.feature_model
              end
            else
              cannot :delete, feature.feature_model
              cannot :update, feature.feature_model
              cannot :own, feature.feature_model
              cannot :create, feature.feature_model
            end
          when 'boolean'
            if user.plan.feature_setting feature.slug
              can :use, feature.slug.to_sym
            end
          else
            raise(:unknown_feature_type.l)
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
paid_up-0.5.0 app/models/paid_up/ability.rb
paid_up-0.4.4 app/models/paid_up/ability.rb
paid_up-0.4.3 app/models/paid_up/ability.rb
paid_up-0.4.2 app/models/paid_up/ability.rb
paid_up-0.4.1 app/models/paid_up/ability.rb
paid_up-0.4.0 app/models/paid_up/ability.rb
paid_up-0.3.0 app/models/paid_up/ability.rb