Sha256: 315bb5cd86007ab4e8a0ed58ce10b25c9a8c91f104f209c1648a9c420331d797

Contents?: true

Size: 1.95 KB

Versions: 14

Compression:

Stored size: 1.95 KB

Contents

# frozen_string_literal: true

require 'eac_active_scaffold'
require 'active_scaffold/bridges/cancan/cancan_bridge'

module EacRailsBase0
  module AppBase
    class Ability
      include CanCan::Ability

      def initialize(user)
        as_action_aliases
        user ||= ::EacUsersSupport::User.new
        devise_rules(user)
        administrator_rules(user)
      end

      def devise_confirmation_rules(user)
        return unless user.new_record?

        can :create, 'Devise::Confirmation'
        can :read, 'Devise::Confirmation'
      end

      def devise_invitable_rules(user)
        can :create, 'Devise::Invitation' if user.administrator?
        can :update, 'Devise::Invitation'
        if user.new_record?
          can :create, 'DeviseInvitable::Registration'
        else
          can :update, 'DeviseInvitable::Registration'
        end
      end

      def devise_password_rules(user)
        return unless user.new_record?

        can :manage, 'Devise::Password'
      end

      def devise_registration_rules(user)
        can :create, 'Devise::Registration' if user.new_record?
        can :update, 'Devise::Registration' unless user.new_record?
      end

      def devise_session_rules(user)
        can :destroy, 'Devise::Session' unless user.new_record?
        can :create, 'Devise::Session'
      end

      def devise_rules(user)
        %w[confirmation invitable password registration session].each do |devise_module|
          send("devise_#{devise_module}_rules", user)
        end
      end

      def administrator_rules(user)
        return unless user.administrator?

        can :manage, ::EacUsersSupport::User
        can :manage, ::Aranha::Address
        can :manage, ::Aranha::ProcessorConfiguration
        can :manage, ::Aranha::StartPoint
        can :manage, ::BrRailties::FederalUnit
        can :manage, ::BrRailties::Municipality
        can :manage, ::ScheduledTask
        can :manage, :eac_rails_base0_mailer
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
eac_rails_base0-0.62.0 lib/eac_rails_base0/app_base/ability.rb
eac_rails_base0-0.61.1 lib/eac_rails_base0/app_base/ability.rb
eac_rails_base0-0.61.0 lib/eac_rails_base0/app_base/ability.rb
eac_rails_base0-0.60.4 lib/eac_rails_base0/app_base/ability.rb
eac_rails_base0-0.60.3 lib/eac_rails_base0/app_base/ability.rb
eac_rails_base0-0.60.2 lib/eac_rails_base0/app_base/ability.rb
eac_rails_base0-0.60.1 lib/eac_rails_base0/app_base/ability.rb
eac_rails_base0-0.60.0 lib/eac_rails_base0/app_base/ability.rb
eac_rails_base0-0.59.0 lib/eac_rails_base0/app_base/ability.rb
eac_rails_base0-0.58.0 lib/eac_rails_base0/app_base/ability.rb
eac_rails_base0-0.57.0 lib/eac_rails_base0/app_base/ability.rb
eac_rails_base0-0.56.0 lib/eac_rails_base0/app_base/ability.rb
eac_rails_base0-0.55.3 lib/eac_rails_base0/app_base/ability.rb
eac_rails_base0-0.55.2 lib/eac_rails_base0/app_base/ability.rb