app/commands/decidim/conferences/admin/create_partner.rb in decidim-conferences-0.28.4 vs app/commands/decidim/conferences/admin/create_partner.rb in decidim-conferences-0.29.0.rc1
- old
+ new
@@ -3,84 +3,31 @@
module Decidim
module Conferences
module Admin
# A command with all the business logic when creating a new partner
# in the system.
- class CreatePartner < Decidim::Command
- # Public: Initializes the command.
- #
- # form - A form object with the params.
- # conference - The Conference that will hold the speaker
- def initialize(form, current_user, conference)
- @form = form
- @current_user = current_user
- @conference = conference
- end
+ class CreatePartner < Decidim::Commands::CreateResource
+ fetch_file_attributes :logo
- # Executes the command. Broadcasts these events:
- #
- # - :ok when everything is valid.
- # - :invalid if the form was not valid and we could not proceed.
- #
- # Returns nothing.
- def call
- return broadcast(:invalid) if form.invalid?
+ fetch_form_attributes :name, :weight, :link, :partner_type
- if conference_partner.valid?
- transaction do
- create_partner!
- end
+ protected
- broadcast(:ok)
- else
- form.errors.add(:logo, conference_partner.errors[:logo]) if conference_partner.errors.include? :logo
+ def resource_class = Decidim::Conferences::Partner
- broadcast(:invalid)
- end
- end
-
- private
-
- attr_reader :form, :conference, :current_user
-
- def create_partner!
- log_info = {
+ def extra_params
+ {
resource: {
title: form.name
},
participatory_space: {
- title: conference.title
+ title: form.current_participatory_space.title
}
}
-
- @partner = Decidim.traceability.create!(
- Decidim::Conferences::Partner,
- form.current_user,
- attributes,
- log_info
- )
end
- def conference_partner
- return @conference_partner if defined?(@conference_partner)
-
- @conference_partner = conference.partners.build
- @conference_partner.conference = conference
- @conference_partner.assign_attributes(attributes)
- @conference_partner
- end
-
def attributes
- { conference: }.merge(
- form.attributes.slice(
- "name",
- "weight",
- "link",
- "partner_type",
- "logo",
- "remove_avatar"
- ).symbolize_keys
- )
+ super.merge(conference: form.participatory_space)
end
end
end
end
end