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



53
54
55
56
57
58
# File 'app/controllers/coplan/comment_threads_controller.rb', line 53

def accept
  authorize!(@thread, :accept?)
  @thread.accept!(current_user)
  broadcast_thread_replace(@thread)
  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
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/coplan/comment_threads_controller.rb', line 8

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

  # Author's own comments start as "todo" (self-assigned work item);
  # non-author comments start as "pending" (awaiting author triage).
  initial_status = current_user.id == @plan.created_by_user_id ? "todo" : "pending"

  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,
    anchor_occurrence: params[:comment_thread][:anchor_occurrence].presence&.to_i,
    start_line: params[:comment_thread][:start_line].presence,
    end_line: params[:comment_thread][:end_line].presence,
    created_by_user: current_user,
    status: initial_status
  )

  thread.save!

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

  if thread.anchored?
    Broadcaster.append_to(
      @plan,
      target: "plan-threads",
      partial: "coplan/comment_threads/thread_popover",
      locals: { thread: thread, plan: @plan }
    )
  end

  respond_with_stream_or_redirect("Comment added.")
end

#discardObject



60
61
62
63
64
65
# File 'app/controllers/coplan/comment_threads_controller.rb', line 60

def discard
  authorize!(@thread, :discard?)
  @thread.discard!(current_user)
  broadcast_thread_replace(@thread)
  respond_with_stream_or_redirect("Thread discarded.")
end

#reopenObject



67
68
69
70
71
72
# File 'app/controllers/coplan/comment_threads_controller.rb', line 67

def reopen
  authorize!(@thread, :reopen?)
  @thread.update!(status: "pending", resolved_by_user: nil)
  broadcast_thread_replace(@thread)
  respond_with_stream_or_redirect("Thread reopened.")
end

#resolveObject



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

def resolve
  authorize!(@thread, :resolve?)
  @thread.resolve!(current_user)
  broadcast_thread_replace(@thread)
  respond_with_stream_or_redirect("Thread resolved.")
end