Class: BudgetsWorkflowRandom

Inherits:
Decidim::Budgets::Workflows::Base show all
Defined in:
decidim-generators/lib/decidim/generators/app_templates/budgets_workflow_random.rb

Overview

This Workflow allows users to vote only in one budget, selected randomly.

Note: random selection should be deterministic for the same user and the same budgets component. As the budget resources list could change and affect the random selection, it also allows to finish orders created on other budgets.

Instance Attribute Summary

Attributes inherited from Decidim::Budgets::Workflows::Base

#budgets_component, #user

Instance Method Summary collapse

Methods inherited from Decidim::Budgets::Workflows::Base

#allowed, #budgets, #highlighted, #initialize, #limit_reached?, #progress, #progress?, #single, #single?, #status, #voted, #voted?

Constructor Details

This class inherits a constructor from Decidim::Budgets::Workflows::Base

Instance Method Details

#discardableObject


24
25
26
# File 'decidim-generators/lib/decidim/generators/app_templates/budgets_workflow_random.rb', line 24

def discardable
  []
end

#highlighted?(resource) ⇒ Boolean

Highlight the resource if the user didn't vote and is allowed to vote on it.

Returns:

  • (Boolean)

9
10
11
# File 'decidim-generators/lib/decidim/generators/app_templates/budgets_workflow_random.rb', line 9

def highlighted?(resource)
  vote_allowed?(resource)
end

#vote_allowed?(resource, consider_progress: true) ⇒ Boolean

User can vote in the resource where they have an order in progress or in the randomly selected resource.

Returns:

  • (Boolean)

14
15
16
17
18
19
20
21
22
# File 'decidim-generators/lib/decidim/generators/app_templates/budgets_workflow_random.rb', line 14

def vote_allowed?(resource, consider_progress: true)
  return false if voted.any?

  if consider_progress
    progress?(resource) || (progress.none? && resource == random_resource)
  else
    resource == random_resource
  end
end