Sha256: 15de6e64fec9b7f2ad9e0d980c02977d9275d98ca28bb89a2ed841d1a887d032

Contents?: true

Size: 1.08 KB

Versions: 40

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module Decidim
  module Proposals
    module Abilities
      # Defines the abilities related to proposals for a logged in admin user.
      # Intended to be used with `cancancan`.
      class AdminAbility < Decidim::Abilities::AdminAbility
        def define_abilities
          super

          can :manage, Proposal
          can :unreport, Proposal
          can :hide, Proposal
          cannot :create, Proposal unless can_create_proposal?
          cannot :update, Proposal unless can_update_proposal?
        end

        private

        def current_settings
          @context.fetch(:current_settings, nil)
        end

        def feature_settings
          @context.fetch(:feature_settings, nil)
        end

        def can_create_proposal?
          current_settings.try(:creation_enabled?) &&
            feature_settings.try(:official_proposals_enabled)
        end

        def can_update_proposal?
          current_settings.try(:proposal_answering_enabled) &&
            feature_settings.try(:proposal_answering_enabled)
        end
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 2 rubygems

Version Path
decidim-proposals-0.6.3 app/models/decidim/proposals/abilities/admin_ability.rb
decidim-0.6.3 decidim-proposals/app/models/decidim/proposals/abilities/admin_ability.rb
decidim-proposals-0.6.2 app/models/decidim/proposals/abilities/admin_ability.rb
decidim-0.6.2 decidim-proposals/app/models/decidim/proposals/abilities/admin_ability.rb
decidim-proposals-0.6.1 app/models/decidim/proposals/abilities/admin_ability.rb
decidim-0.6.1 decidim-proposals/app/models/decidim/proposals/abilities/admin_ability.rb
decidim-proposals-0.6.0 app/models/decidim/proposals/abilities/admin_ability.rb
decidim-0.6.0 decidim-proposals/app/models/decidim/proposals/abilities/admin_ability.rb
decidim-proposals-0.5.1 app/models/decidim/proposals/abilities/admin_ability.rb
decidim-0.5.1 decidim-proposals/app/models/decidim/proposals/abilities/admin_ability.rb
decidim-proposals-0.5.0 app/models/decidim/proposals/abilities/admin_ability.rb
decidim-0.5.0 decidim-proposals/app/models/decidim/proposals/abilities/admin_ability.rb
decidim-proposals-0.4.4 app/models/decidim/proposals/abilities/admin_ability.rb
decidim-0.4.4 decidim-proposals/app/models/decidim/proposals/abilities/admin_ability.rb
decidim-proposals-0.4.3 app/models/decidim/proposals/abilities/admin_ability.rb
decidim-proposals-0.4.2 app/models/decidim/proposals/abilities/admin_ability.rb
decidim-proposals-0.4.1 app/models/decidim/proposals/abilities/admin_ability.rb
decidim-0.4.3 decidim-proposals/app/models/decidim/proposals/abilities/admin_ability.rb
decidim-0.4.2 decidim-proposals/app/models/decidim/proposals/abilities/admin_ability.rb
decidim-0.4.1 decidim-proposals/app/models/decidim/proposals/abilities/admin_ability.rb