Class: PlanMyStuff::CommentsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/plan_my_stuff/comments_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /issues/:issue_id/comments



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/plan_my_stuff/comments_controller.rb', line 6

def create
  @issue = PlanMyStuff::Issue.find(params[:issue_id])

  comment = PlanMyStuff::Comment.create!(
    issue: @issue,
    body: comment_params[:body],
    user: pms_current_user,
    visibility: comment_params[:visibility]&.to_sym || :public,
    waiting_on_reply: comment_params[:waiting_on_reply] == '1',
  )

  yield(comment) if block_given?
  return if performed?

  flash[:success] = 'Comment was successfully created.'
  redirect_to(plan_my_stuff.issue_path(@issue))
rescue PlanMyStuff::LockedIssueError => e
  pms_handle_rescue(e)
  flash[:error] = 'This issue is locked; no new comments can be posted.'
  redirect_to(plan_my_stuff.issue_path(@issue))
end

#edit {|@comment| ... } ⇒ Object

GET /issues/:issue_id/comments/:id/edit

Yields:

  • (@comment)


29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/plan_my_stuff/comments_controller.rb', line 29

def edit
  load_comment
  return unless @comment
  return redirect_to_issue if issue_body_comment?

  unless can_edit?(@comment)
    redirect_to_unauthorized(plan_my_stuff.issue_path(@issue))

    return
  end

  yield(@comment) if block_given?
end

#updateObject

PATCH/PUT /issues/:issue_id/comments/:id



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/plan_my_stuff/comments_controller.rb', line 44

def update
  load_comment
  return unless @comment
  return redirect_to_issue if issue_body_comment?

  unless can_edit?(@comment)
    redirect_to_unauthorized(plan_my_stuff.issue_path(@issue))

    return
  end

  update_attrs = { body: comment_params[:body] }
  update_attrs[:visibility] = comment_params[:visibility].to_sym if @support_user && comment_params[:visibility]

  @comment.update!(**update_attrs, user: pms_current_user)

  yield(@comment) if block_given?
  return if performed?

  flash[:success] = 'Comment was successfully updated.'
  redirect_to(plan_my_stuff.issue_path(@issue))
rescue PlanMyStuff::StaleObjectError => e
  pms_handle_rescue(e)
  flash.now[:error] = 'Comment was modified by someone else. Please review the latest changes and try again.'
  render(:edit, status: PlanMyStuff.unprocessable_status)
end