app/commands/decidim/meetings/admin/update_agenda.rb in decidim-meetings-0.28.4 vs app/commands/decidim/meetings/admin/update_agenda.rb in decidim-meetings-0.29.0.rc1
- old
+ new
@@ -1,37 +1,18 @@
# frozen_string_literal: true
module Decidim
module Meetings
module Admin
- # This command is executed when the user creates a Meeting from the admin
+ # This command is executed when the user updates a Meeting from the admin
# panel.
- class UpdateAgenda < Decidim::Command
- def initialize(form, agenda)
- @form = form
- @agenda = agenda
- end
+ class UpdateAgenda < Decidim::Commands::UpdateResource
+ fetch_form_attributes :title, :visible
- # Creates the agenda if valid.
- #
- # Broadcasts :ok if successful, :invalid otherwise.
- def call
- return broadcast(:invalid) if @form.invalid?
+ protected
- transaction do
- update_agenda!
- update_agenda_items
- end
-
- broadcast(:ok, @agenda)
- end
-
- private
-
- attr_reader :form
-
- def update_agenda_items
+ def run_after_hooks
@form.agenda_items.each do |form_agenda_item|
update_agenda_item(form_agenda_item)
end
end
@@ -42,19 +23,19 @@
position: form_agenda_item.position,
duration: form_agenda_item.duration,
parent_id: form_agenda_item.parent_id
}
- update_nested_model(form_agenda_item, agenda_item_attributes, @agenda.agenda_items) do |agenda_item|
+ update_nested_model(form_agenda_item, agenda_item_attributes, resource.agenda_items) do |agenda_item|
form_agenda_item.agenda_item_children.each do |form_agenda_item_child|
agenda_item_child_attributes = {
title: form_agenda_item_child.title,
description: form_agenda_item_child.description,
position: form_agenda_item_child.position,
duration: form_agenda_item_child.duration,
parent_id: agenda_item.id,
- agenda: @agenda
+ agenda: resource
}
update_nested_model(form_agenda_item_child, agenda_item_child_attributes, agenda_item.agenda_item_children)
end
end
@@ -72,18 +53,9 @@
record.update!(attributes)
end
else
record.save!
end
- end
-
- def update_agenda!
- Decidim.traceability.update!(
- @agenda,
- form.current_user,
- title: form.title,
- visible: form.visible
- )
end
end
end
end
end