Sha256: e0149b911b84fc6b7dba13907a5f40b036005173e1f4d93e3848c4246251db9c

Contents?: true

Size: 1.37 KB

Versions: 28

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

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

          can [:manage, :unreport, :hide], Proposal do |proposal|
            can_manage_process?(proposal.feature.participatory_space)
          end

          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 current_feature
          @context.fetch(:current_feature, nil)
        end

        def can_create_proposal?
          current_settings.try(:creation_enabled?) &&
            feature_settings.try(:official_proposals_enabled) &&
            can_manage_process?(current_feature.try(:participatory_space))
        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

28 entries across 28 versions & 2 rubygems

Version Path
decidim-proposals-0.8.4 app/models/decidim/proposals/abilities/participatory_process_admin_ability.rb
decidim-proposals-0.8.3 app/models/decidim/proposals/abilities/participatory_process_admin_ability.rb
decidim-proposals-0.8.2 app/models/decidim/proposals/abilities/participatory_process_admin_ability.rb
decidim-proposals-0.8.1 app/models/decidim/proposals/abilities/participatory_process_admin_ability.rb
decidim-proposals-0.8.0 app/models/decidim/proposals/abilities/participatory_process_admin_ability.rb
decidim-proposals-0.7.4 app/models/decidim/proposals/abilities/participatory_process_admin_ability.rb
decidim-proposals-0.7.3 app/models/decidim/proposals/abilities/participatory_process_admin_ability.rb
decidim-proposals-0.7.2 app/models/decidim/proposals/abilities/participatory_process_admin_ability.rb
decidim-proposals-0.7.1 app/models/decidim/proposals/abilities/participatory_process_admin_ability.rb
decidim-proposals-0.7.0 app/models/decidim/proposals/abilities/participatory_process_admin_ability.rb
decidim-proposals-0.6.8 app/models/decidim/proposals/abilities/participatory_process_admin_ability.rb
decidim-0.6.8 decidim-proposals/app/models/decidim/proposals/abilities/participatory_process_admin_ability.rb
decidim-proposals-0.6.7 app/models/decidim/proposals/abilities/participatory_process_admin_ability.rb
decidim-0.6.7 decidim-proposals/app/models/decidim/proposals/abilities/participatory_process_admin_ability.rb
decidim-proposals-0.6.6 app/models/decidim/proposals/abilities/participatory_process_admin_ability.rb
decidim-0.6.6 decidim-proposals/app/models/decidim/proposals/abilities/participatory_process_admin_ability.rb
decidim-proposals-0.6.5 app/models/decidim/proposals/abilities/participatory_process_admin_ability.rb
decidim-0.6.5 decidim-proposals/app/models/decidim/proposals/abilities/participatory_process_admin_ability.rb
decidim-proposals-0.6.4 app/models/decidim/proposals/abilities/participatory_process_admin_ability.rb
decidim-0.6.4 decidim-proposals/app/models/decidim/proposals/abilities/participatory_process_admin_ability.rb