Sha256: 99abc88d4564063e760f3f744c2633bcdb5ba8aa3efa829cb2a027c130bed895

Contents?: true

Size: 1.19 KB

Versions: 39

Compression:

Stored size: 1.19 KB

Contents

class DiscussionsMessagesController < AjaxController
  include WithUserDiscussionValidation

  before_action :set_discussion!, only: [:create, :destroy]
  before_action :authorize_user!, only: [:destroy]
  before_action :authorize_moderator!, only: [:question, :approve, :preview]

  def create
    @discussion.submit_message! message_params, current_user
    redirect_back(fallback_location: root_path)
  end

  def destroy
    authorize_moderator! unless params[:motive] == :self_deleted.to_s

    current_message.soft_delete! params[:motive], current_user
    redirect_back(fallback_location: root_path)
  end

  def preview
    render json: { preview: Message.new(content: params[:content]).content_html }
  end

  def approve
    current_message.toggle_approved! current_user
    head :ok
  end

  def question
    current_message.toggle_not_actually_a_question!
    head :ok
  end

  private

  def set_discussion!
    @discussion ||= Discussion.find_by(id: params[:discussion_id])
  end

  def authorize_user!
    current_message.authorize! current_user
  end

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

  def message_params
    params.require(:message).permit(:content)
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
mumuki-laboratory-9.23.0 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-9.22.0 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-9.21.0 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-9.20.1 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-9.20.0 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-9.19.0 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-9.18.1 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-9.18.0 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-9.17.0 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-9.16.0 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-9.15.0 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-9.14.1 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-9.14.0 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-9.13.2 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-9.13.1 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-9.13.0 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-9.12.1 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-9.12.0 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-9.11.0 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-9.10.0 app/controllers/discussions_messages_controller.rb