Sha256: 0d034afb31be934ad4c920962a38f0aad98a1c3f70eb0a4e4b8f479059aab176

Contents?: true

Size: 1.18 KB

Versions: 45

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

require "active_support/concern"

module Decidim
  module Budgets
    # Shared behaviour for controllers that need the current order to be present.
    module NeedsCurrentOrder
      extend ActiveSupport::Concern

      included do
        helper_method :current_order, :can_have_order?, :voted_for?

        # The current order created by the user.
        #
        # Returns an Order.
        def current_order
          @current_order ||= Order.includes(:projects).find_or_initialize_by(user: current_user, budget: budget)
        end

        def current_order=(order)
          @current_order = order
        end

        def persisted_current_order
          current_order if current_order&.persisted?
        end

        def can_have_order?
          current_user.present? &&
            voting_open? &&
            current_participatory_space.can_participate?(current_user) &&
            allowed_to?(:create, :order, budget: budget, workflow: current_workflow)
        end

        # Return true if the user has voted the project
        def voted_for?(project)
          current_order && current_order.projects.include?(project)
        end
      end
    end
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
decidim-budgets-0.27.9 app/controllers/concerns/decidim/budgets/needs_current_order.rb
decidim-budgets-0.27.8 app/controllers/concerns/decidim/budgets/needs_current_order.rb
decidim-budgets-0.27.7 app/controllers/concerns/decidim/budgets/needs_current_order.rb
decidim-budgets-0.27.6 app/controllers/concerns/decidim/budgets/needs_current_order.rb
decidim-budgets-0.26.10 app/controllers/concerns/decidim/budgets/needs_current_order.rb
decidim-budgets-0.26.9 app/controllers/concerns/decidim/budgets/needs_current_order.rb
decidim-budgets-0.27.5 app/controllers/concerns/decidim/budgets/needs_current_order.rb
decidim-budgets-0.26.8 app/controllers/concerns/decidim/budgets/needs_current_order.rb
decidim-budgets-0.27.4 app/controllers/concerns/decidim/budgets/needs_current_order.rb
decidim-budgets-0.27.3 app/controllers/concerns/decidim/budgets/needs_current_order.rb
decidim-budgets-0.26.7 app/controllers/concerns/decidim/budgets/needs_current_order.rb
decidim-budgets-0.26.5 app/controllers/concerns/decidim/budgets/needs_current_order.rb
decidim-budgets-0.27.2 app/controllers/concerns/decidim/budgets/needs_current_order.rb
decidim-budgets-0.27.1 app/controllers/concerns/decidim/budgets/needs_current_order.rb
decidim-budgets-0.26.4 app/controllers/concerns/decidim/budgets/needs_current_order.rb
decidim-budgets-0.27.0 app/controllers/concerns/decidim/budgets/needs_current_order.rb
decidim-budgets-0.26.3 app/controllers/concerns/decidim/budgets/needs_current_order.rb
decidim-budgets-0.27.0.rc2 app/controllers/concerns/decidim/budgets/needs_current_order.rb
decidim-budgets-0.27.0.rc1 app/controllers/concerns/decidim/budgets/needs_current_order.rb
decidim-budgets-0.26.2 app/controllers/concerns/decidim/budgets/needs_current_order.rb