app/commands/decidim/proposals/update_proposal.rb in decidim-proposals-0.22.0 vs app/commands/decidim/proposals/update_proposal.rb in decidim-proposals-0.23.0
- old
+ new
@@ -2,11 +2,12 @@
module Decidim
module Proposals
# A command with all the business logic when a user updates a proposal.
class UpdateProposal < Rectify::Command
- include ::Decidim::AttachmentMethods
+ include ::Decidim::MultipleAttachmentsMethods
+ include GalleryMethods
include HashtagsMethods
# Public: Initializes the command.
#
# form - A form object with the params.
@@ -24,37 +25,48 @@
# - :ok when everything is valid, together with the proposal.
# - :invalid if the form wasn't valid and we couldn't proceed.
#
# Returns nothing.
def call
- return broadcast(:invalid) if form.invalid?
- return broadcast(:invalid) unless proposal.editable_by?(current_user)
- return broadcast(:invalid) if proposal_limit_reached?
+ return broadcast(:invalid) if invalid?
if process_attachments?
@proposal.attachments.destroy_all
- build_attachment
- return broadcast(:invalid) if attachment_invalid?
+ build_attachments
+ return broadcast(:invalid) if attachments_invalid?
end
+ if process_gallery?
+ build_gallery
+ return broadcast(:invalid) if gallery_invalid?
+ end
+
transaction do
if @proposal.draft?
update_draft
else
update_proposal
end
- create_attachment if process_attachments?
+ create_gallery if process_gallery?
+ create_attachments if process_attachments?
+
+ photo_cleanup!
+ document_cleanup!
end
broadcast(:ok, proposal)
end
private
attr_reader :form, :proposal, :current_user, :attachment
+ def invalid?
+ form.invalid? || !proposal.editable_by?(current_user) || proposal_limit_reached?
+ end
+
# Prevent PaperTrail from creating an additional version
# in the proposal multi-step creation process (step 3: complete)
#
# A first version will be created in step 4: publish
# for diff rendering in the proposal control version
@@ -77,11 +89,15 @@
@proposal.add_coauthor(current_user, user_group: user_group)
end
def attributes
{
- title: title_with_hashtags,
- body: body_with_hashtags,
+ title: {
+ I18n.locale => title_with_hashtags
+ },
+ body: {
+ I18n.locale => body_with_hashtags
+ },
category: form.category,
scope: form.scope,
address: form.address,
latitude: form.latitude,
longitude: form.longitude