Sha256: df060a65194a4bd13843f2cbc56fb24e82c7416c3f34ca2427fea63d66f6ba62

Contents?: true

Size: 1.92 KB

Versions: 23

Compression:

Stored size: 1.92 KB

Contents

class Manage::MessagesController < Manage::ApplicationController
  before_action :set_message, only: [:show, :edit, :update, :destroy, :deliver, :preview, :duplicate]
  before_action :check_message_access, only: [:edit, :update, :destroy]

  respond_to :html

  def index
  end

  def datatable
    render json: MessageDatatable.new(view_context)
  end

  def show
    respond_with(:manage, @message)
  end

  def new
    @message = Message.new
    respond_with(:manage, @message)
  end

  def edit
  end

  def create
    @message = Message.new(message_params)
    @message.save
    respond_with(:manage, @message)
  end

  def update
    @message.update_attributes(message_params)
    respond_with(:manage, @message)
  end

  def destroy
    @message.destroy
    respond_with(:manage, @message)
  end

  def deliver
    if @message.status != "drafted"
      flash[:notice] = "Message cannot be re-delivered"
      return redirect_to manage_messages_path
    end
    @message.update_attribute(:queued_at, Time.now)
    BulkMessageWorker.perform_async(@message.id)
    flash[:notice] = "Message queued for delivery"
    redirect_to manage_message_path(@message)
  end

  def preview
    email = Mailer.bulk_message_email(@message.id, current_user.id)
    render html: email.body.raw_source.html_safe
  end

  def duplicate
    new_message = @message.dup
    new_message.update_attributes(
      delivered_at: nil,
      started_at: nil,
      queued_at: nil,
      name: "Copy of #{@message.name}"
    )
    new_message.save
    redirect_to edit_manage_message_path(new_message.reload)
  end

  private

  def message_params
    params.require(:message).permit(
      :name, :subject, :template, :body, recipients: []
    )
  end

  def set_message
    @message = Message.find(params[:id])
  end

  def check_message_access
    return if @message.can_edit?

    flash[:notice] = "Message can no longer be modified"
    redirect_to manage_message_path(@message)
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
hackathon_manager-0.5.11 app/controllers/manage/messages_controller.rb
hackathon_manager-0.5.10 app/controllers/manage/messages_controller.rb
hackathon_manager-0.5.9 app/controllers/manage/messages_controller.rb
hackathon_manager-0.5.8 app/controllers/manage/messages_controller.rb
hackathon_manager-0.5.7 app/controllers/manage/messages_controller.rb
hackathon_manager-0.5.6 app/controllers/manage/messages_controller.rb
hackathon_manager-0.5.5 app/controllers/manage/messages_controller.rb
hackathon_manager-0.5.4 app/controllers/manage/messages_controller.rb
hackathon_manager-0.5.3 app/controllers/manage/messages_controller.rb
hackathon_manager-0.5.2 app/controllers/manage/messages_controller.rb
hackathon_manager-0.5.1 app/controllers/manage/messages_controller.rb
hackathon_manager-0.5.0 app/controllers/manage/messages_controller.rb
hackathon_manager-0.4.4 app/controllers/manage/messages_controller.rb
hackathon_manager-0.4.3 app/controllers/manage/messages_controller.rb
hackathon_manager-0.4.2 app/controllers/manage/messages_controller.rb
hackathon_manager-0.4.1 app/controllers/manage/messages_controller.rb
hackathon_manager-0.4.0 app/controllers/manage/messages_controller.rb
hackathon_manager-0.3.3 app/controllers/manage/messages_controller.rb
hackathon_manager-0.3.2 app/controllers/manage/messages_controller.rb
hackathon_manager-0.3.1 app/controllers/manage/messages_controller.rb