Class: BudgetsWorkflowRandom

Inherits:
Decidim::Budgets::Workflows::Base
  • Object
show all
Defined in:
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 Method Summary collapse

Instance Method Details

#discardableObject



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

def discardable
  []
end

#highlighted?(resource) ⇒ Boolean

Highlight the resource if the user did not vote and is allowed to vote on it.

Returns:

  • (Boolean)


9
10
11
# File '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 '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