Class: Decidim::Proposals::Import::ProposalCreator

Inherits:
Admin::Import::Creator
  • Object
show all
Defined in:
lib/decidim/proposals/import/proposal_creator.rb

Overview

This class is responsible for creating the imported proposals and must be included in proposals component’s import manifest.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, context = nil) ⇒ ProposalCreator

Returns a new instance of ProposalCreator.



20
21
22
23
# File 'lib/decidim/proposals/import/proposal_creator.rb', line 20

def initialize(data, context = nil)
  @data = data.except(:id, "id")
  @context = context
end

Class Method Details

.resource_klassObject

Returns the resource class to be created with the provided data.



10
11
12
# File 'lib/decidim/proposals/import/proposal_creator.rb', line 10

def self.resource_klass
  Decidim::Proposals::Proposal
end

.verifier_klassObject

Returns a verifier class to be used to verify the correctness of the import data.



16
17
18
# File 'lib/decidim/proposals/import/proposal_creator.rb', line 16

def self.verifier_klass
  Decidim::Proposals::Import::ProposalsVerifier
end

Instance Method Details

#finish!Object

Saves the proposal



35
36
37
38
39
40
41
42
# File 'lib/decidim/proposals/import/proposal_creator.rb', line 35

def finish!
  Decidim.traceability.perform_action!(:create, self.class.resource_klass, context[:current_user], visibility: "admin-only") do
    resource.save!
    resource
  end
  notify(resource)
  publish(resource)
end

#produceObject

Produces a proposal from parsed data

Returns a proposal



28
29
30
31
32
# File 'lib/decidim/proposals/import/proposal_creator.rb', line 28

def produce
  resource.add_coauthor(context[:current_user], user_group: context[:user_group])

  resource
end