Class: Decidim::Proposals::Admin::UpdateProposalScope
- Inherits:
 - 
      Command
      
        
- Object
 - Command
 - Decidim::Proposals::Admin::UpdateProposalScope
 
 
- Includes:
 - TranslatableAttributes
 
- Defined in:
 - app/commands/decidim/proposals/admin/update_proposal_scope.rb
 
Overview
A command with all the business logic when an admin batch updates proposals scope.
Instance Method Summary collapse
- 
  
    
      #call  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Executes the command.
 - 
  
    
      #initialize(scope_id, proposal_ids)  ⇒ UpdateProposalScope 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
Public: Initializes the command.
 
Constructor Details
#initialize(scope_id, proposal_ids) ⇒ UpdateProposalScope
Public: Initializes the command.
scope_id - the scope id to update proposal_ids - the proposals ids to update.
      13 14 15 16 17  | 
    
      # File 'app/commands/decidim/proposals/admin/update_proposal_scope.rb', line 13 def initialize(scope_id, proposal_ids) @scope = Decidim::Scope.find_by id: scope_id @proposal_ids = proposal_ids @response = { scope_name: "", successful: [], errored: [] } end  | 
  
Instance Method Details
#call ⇒ Object
Executes the command. Broadcasts these events:
- 
:update_proposals_scope - when everything is ok, returns @response.
 - 
:invalid_scope - if the scope is blank.
 - 
:invalid_proposal_ids - if the proposal_ids is blank.
 
Returns @response hash:
- 
:scope_name - the translated_name of the scope assigned
 - 
:successful - Array of names of the updated proposals
 - 
:errored - Array of names of the proposals not updated because they already had the scope assigned
 
      30 31 32 33 34 35 36 37  | 
    
      # File 'app/commands/decidim/proposals/admin/update_proposal_scope.rb', line 30 def call return broadcast(:invalid_scope) if @scope.blank? return broadcast(:invalid_proposal_ids) if @proposal_ids.blank? update_proposals_scope broadcast(:update_proposals_scope, @response) end  |