Class: CoPlan::CommentThreadsController

Inherits:
ApplicationController show all
Includes:
ActionView::RecordIdentifier
Defined in:
app/controllers/coplan/comment_threads_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

controller_path

Instance Method Details

#acceptObject



41
42
43
44
45
46
# File 'app/controllers/coplan/comment_threads_controller.rb', line 41

def accept
  authorize!(@thread, :accept?)
  @thread.accept!(current_user)
  broadcast_thread_move(@thread, from: "comment-threads", to: "resolved-comment-threads")
  respond_with_stream_or_redirect("Thread accepted.")
end

#createObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/coplan/comment_threads_controller.rb', line 8

def create
  authorize!(@plan, :show?)

  thread = @plan.comment_threads.new(
    plan_version: @plan.current_plan_version,
    anchor_text: params[:comment_thread][:anchor_text].presence,
    anchor_context: params[:comment_thread][:anchor_context].presence,
    start_line: params[:comment_thread][:start_line].presence,
    end_line: params[:comment_thread][:end_line].presence,
    created_by_user: current_user
  )

  thread.save!

  comment = thread.comments.create!(
    author_type: "human",
    author_id: current_user.id,
    body_markdown: params[:comment_thread][:body_markdown]
  )

  broadcast_new_thread(thread)
  broadcast_tab_counts

  respond_with_stream_or_redirect("Comment added.")
end

#dismissObject



48
49
50
51
52
53
# File 'app/controllers/coplan/comment_threads_controller.rb', line 48

def dismiss
  authorize!(@thread, :dismiss?)
  @thread.dismiss!(current_user)
  broadcast_thread_move(@thread, from: "comment-threads", to: "resolved-comment-threads")
  respond_with_stream_or_redirect("Thread dismissed.")
end

#reopenObject



55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/coplan/comment_threads_controller.rb', line 55

def reopen
  authorize!(@thread, :reopen?)
  @thread.update!(status: "open", resolved_by_user: nil)
  # Out-of-date threads stay in the archived list even when reopened,
  # since the active scope excludes out_of_date rows.
  if @thread.out_of_date?
    broadcast_thread_replace(@thread)
  else
    broadcast_thread_move(@thread, from: "resolved-comment-threads", to: "comment-threads")
  end
  respond_with_stream_or_redirect("Thread reopened.")
end

#resolveObject



34
35
36
37
38
39
# File 'app/controllers/coplan/comment_threads_controller.rb', line 34

def resolve
  authorize!(@thread, :resolve?)
  @thread.resolve!(current_user)
  broadcast_thread_move(@thread, from: "comment-threads", to: "resolved-comment-threads")
  respond_with_stream_or_redirect("Thread resolved.")
end