Sha256: 999310400d6f28f7d404b7523a636b1ce5567ff1efa83ee8f6ede9dd069eff24
Contents?: true
Size: 1.47 KB
Versions: 12
Compression:
Stored size: 1.47 KB
Contents
# frozen_string_literal: true module Decidim module Initiatives module Admin # A command with all the business logic that publishes an # existing initiative. class PublishInitiative < Decidim::Command # Public: Initializes the command. # # initiative - Decidim::Initiative # current_user - the user performing the action def initialize(initiative, current_user) @initiative = initiative @current_user = current_user end # Executes the command. Broadcasts these events: # # - :ok when everything is valid. # - :invalid if the form wasn't valid and we couldn't proceed. # # Returns nothing. def call return broadcast(:invalid) if initiative.published? @initiative = Decidim.traceability.perform_action!( :publish, initiative, current_user, visibility: "all" ) do initiative.publish! increment_score initiative end broadcast(:ok, initiative) end private attr_reader :initiative, :current_user def increment_score if initiative.user_group Decidim::Gamification.increment_score(initiative.user_group, :initiatives) else Decidim::Gamification.increment_score(initiative.author, :initiatives) end end end end end end
Version data entries
12 entries across 12 versions & 1 rubygems