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
# File 'app/controllers/plan_my_stuff/comments_controller.rb', line 6

def create
  @issue = PMS::Issue.find(params[:issue_id].to_i, repo: params[:repo]&.to_sym)

  PMS::Comment.create!(
    issue: @issue,
    body: comment_params[:body],
    user: pms_current_user,
    visibility: comment_params[:visibility]&.to_sym || :public,
  )

  flash[:success] = 'Comment was successfully created.'
  redirect_to(plan_my_stuff.issue_path(@issue.number))
end

#editObject

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



21
22
23
24
25
26
27
# File 'app/controllers/plan_my_stuff/comments_controller.rb', line 21

def edit
  load_comment
  return unless @comment

  @support_user = support_user?
  return redirect_to_unauthorized(plan_my_stuff.issue_path(@issue.number)) unless can_edit?(@comment)
end

#updateObject

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



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/plan_my_stuff/comments_controller.rb', line 30

def update
  load_comment
  return unless @comment

  @support_user = support_user?
  return redirect_to_unauthorized(plan_my_stuff.issue_path(@issue.number)) unless can_edit?(@comment)

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

  @comment.update!(**update_attrs)

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