Sha256: 3cfb77be6471d80f2cd3e24af4d3f6658e8ce597b2f4a43a2a4249ce22ffa0ce
Contents?: true
Size: 1.22 KB
Versions: 9
Compression:
Stored size: 1.22 KB
Contents
# frozen_string_literal: true module Decidim module System # A command with all the business logic when creating a new organization in # the system. It creates the organization and invites the admin to the # system. class UpdateOrganization < Rectify::Command # Public: Initializes the command. # # form - A form object with the params. def initialize(id, form) @organization_id = id @form = form end # Executes the command. Broadcasts these events: # # - :ok when everything is valid. # - :invalid if the form wasn't valid and we couldn't proceed. # # Returns nothing. def call return broadcast(:invalid) if form.invalid? transaction do save_organization end broadcast(:ok) rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotUnique broadcast(:invalid) end private attr_reader :form, :organization_id def organization @organization ||= Organization.find(organization_id) end def save_organization organization.name = form.name organization.host = form.host organization.save! end end end end
Version data entries
9 entries across 9 versions & 2 rubygems