Class: Commontator::ThreadsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/commontator/threads_controller.rb

Instance Method Summary collapse

Instance Method Details

#closeObject

PUT /threads/1/close



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/commontator/threads_controller.rb', line 16

def close
  security_transgression_unless @commontator_thread.can_be_edited_by?(@commontator_user)

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

  respond_to do |format|
    format.html { redirect_to commontable_url }
    format.js   do
      commontator_thread_show(@commontator_thread.commontable)
      render :show
    end
  end
end

#mentionsObject

GET /threads/1/mentions.json



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/commontator/threads_controller.rb', line 48

def mentions
  security_transgression_unless @commontator_thread.can_be_read_by?(@commontator_user) &&
                                @commontator_thread.config.mentions_enabled

  respond_to do |format|
    format.json do
      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: {
          mentions: Commontator.commontator_mentions(
            @commontator_user, @commontator_thread, query
          ).map { |user| { id: user.id, name: Commontator.commontator_name(user), type: 'user' } }
        }
      end
    end
  end
end

#reopenObject

PUT /threads/1/reopen



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/commontator/threads_controller.rb', line 32

def reopen
  security_transgression_unless @commontator_thread.can_be_edited_by?(@commontator_user)

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

  respond_to do |format|
    format.html { redirect_to commontable_url }
    format.js   do
      commontator_thread_show(@commontator_thread.commontable)
      render :show
    end
  end
end

#showObject

GET /threads/1



8
9
10
11
12
13
# File 'app/controllers/commontator/threads_controller.rb', line 8

def show
  respond_to do |format|
    format.html { redirect_to commontable_url }
    format.js   { commontator_thread_show(@commontator_thread.commontable) }
  end
end