Class: PlanMyStuff::Issues::ClosuresController

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

Overview

Handles closing and reopening issues via CRUD-style routes. Backs the Close/Reopen buttons on the issue show view (T-044).

POST /issues/:issue_id/closure -> create (closes) DELETE /issues/:issue_id/closure -> destroy (reopens)

Instance Method Summary collapse

Instance Method Details

#createObject

POST /issues/:issue_id/closure



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/plan_my_stuff/issues/closures_controller.rb', line 13

def create
  issue = PlanMyStuff::Issue.find(params[:issue_id])
  to_update = {}
  if PlanMyStuff.configuration.issue_fields_enabled
    to_update[:issue_fields] = { 'Issue Status' => 'Fixed' }
  end
  issue.update!(state: :closed, **to_update)

  yield(issue) if block_given?
  return if performed?

  flash[:success] = 'Issue was successfully closed.'
  redirect_to(plan_my_stuff.issue_path(issue))
rescue PlanMyStuff::Error, ArgumentError => e
  pms_handle_rescue(e)
  flash[:error] = e.message
  redirect_to(plan_my_stuff.issue_path(params[:issue_id]))
end

#destroyObject

DELETE /issues/:issue_id/closure



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/plan_my_stuff/issues/closures_controller.rb', line 33

def destroy
  issue = PlanMyStuff::Issue.find(params[:issue_id])
  to_update = {}
  if PlanMyStuff.configuration.issue_fields_enabled
    to_update[:issue_fields] = { 'Issue Status' => 'Reopened' }
  end
  issue.update!(state: :open, **to_update)

  yield(issue) if block_given?
  return if performed?

  flash[:success] = 'Issue was successfully reopened.'
  redirect_to(plan_my_stuff.issue_path(issue))
rescue PlanMyStuff::Error, ArgumentError => e
  pms_handle_rescue(e)
  flash[:error] = e.message
  redirect_to(plan_my_stuff.issue_path(params[:issue_id]))
end