app/commands/decidim/proposals/update_proposal.rb in decidim-proposals-0.8.2 vs app/commands/decidim/proposals/update_proposal.rb in decidim-proposals-0.8.3
- old
+ new
@@ -24,26 +24,20 @@
def call
return broadcast(:invalid) if form.invalid?
return broadcast(:invalid) unless proposal.editable_by?(current_user)
return broadcast(:invalid) if proposal_limit_reached?
- if process_attachments?
- build_attachment
- return broadcast(:invalid) if attachment_invalid?
- end
-
transaction do
update_proposal
- create_attachment if process_attachments?
end
broadcast(:ok, proposal)
end
private
- attr_reader :form, :proposal, :attachment, :current_user
+ attr_reader :form, :proposal, :current_user
def update_proposal
@proposal.update_attributes!(
title: form.title,
body: form.body,
@@ -53,41 +47,9 @@
decidim_user_group_id: user_group.try(:id),
address: form.address,
latitude: form.latitude,
longitude: form.longitude
)
- end
-
- def build_attachment
- @attachment = Attachment.new(
- title: form.attachment.title,
- file: form.attachment.file,
- attached_to: proposal
- )
- end
-
- def attachment_invalid?
- if attachment.invalid? && attachment.errors.has_key?(:file)
- form.attachment.errors.add :file, attachment.errors[:file]
- true
- end
- end
-
- def attachment_present?
- form.attachment.file.present?
- end
-
- def create_attachment
- attachment.attached_to = proposal
- attachment.save!
- end
-
- def attachments_allowed?
- form.current_feature.settings.attachments_allowed?
- end
-
- def process_attachments?
- attachments_allowed? && attachment_present?
end
def proposal_limit_reached?
proposal_limit = form.current_feature.settings.proposal_limit