Sha256: 773167269da123a0a2eeb8de3b66269a486b010917e572010aa88108839d1c37

Contents?: true

Size: 1.95 KB

Versions: 2

Compression:

Stored size: 1.95 KB

Contents

module Commontator
  class ThreadsController < Commontator::ApplicationController
    skip_before_filter :ensure_user, :only => :show
    before_filter :set_thread

    # GET /threads/1
    def show
      commontator_thread_show(@thread.commontable)
      @show_all = params[:show_all] && @thread.can_be_edited_by?(@user)

      respond_to do |format|
        format.html { redirect_to main_app.polymorphic_path(@thread.commontable) }
        format.js
      end
    end

    # GET /threads/1/hide
    def hide
      respond_to do |format|
        format.js
      end
    end
    
    # PUT /threads/1/close
    def close
      security_transgression_unless @thread.can_be_edited_by?(@user)

      @thread.errors.add(:base, t('commontator.thread.errors.already_closed')) \
        unless @thread.close(@user)

      @show_all = true

      respond_to do |format|
        format.html { redirect_to @thread }
        format.js { render :show }
      end
    end
    
    # PUT /threads/1/reopen
    def reopen
      security_transgression_unless @thread.can_be_edited_by?(@user)

      @thread.errors.add(:base, t('commontator.thread.errors.not_closed')) \
        unless @thread.reopen

      @show_all = true

      respond_to do |format|
        format.html { redirect_to @thread }
        format.js { render :show }
      end
    end

    # GET /threads/1/mentions.json
    def mentions
      security_transgression_unless @thread.can_be_read_by?(@user) && Commontator.mentions_enabled
      query = params[:q].to_s

      if query.size < 3
        render json: { errors: ['Query string is too short (minimum 3 characters)'] },
               status: :unprocessable_entity
      else
        render json: serialized_mentions(query)
      end
    end

    protected

    def serialized_mentions(query)
      { mentions: Commontator.commontator_mentions(@user, query).map do |user|
        { id: user.id, name: Commontator.commontator_name(user), type: 'user' }
      end }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
commontator-5.1.0 app/controllers/commontator/threads_controller.rb~
commontator-4.11.0 app/controllers/commontator/threads_controller.rb~