Class: PlanMyStuff::ProjectItems::AssignmentsController

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

Overview

Handles assigning and unassigning project item assignees via CRUD-style routes. Backs the assign/unassign forms on the project board view (T-047).

PATCH /projects/:project_id/items/:item_id/assignment -> update (assign) DELETE /projects/:project_id/items/:item_id/assignment -> destroy (unassign)

Instance Method Summary collapse

Instance Method Details

#destroyObject

DELETE /projects/:project_id/items/:item_id/assignment



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

def destroy
  if params[:username].blank?
    flash[:error] = 'Username is required to unassign.'
    redirect_to(plan_my_stuff.project_path(params[:project_id]))
    return
  end

  item = find_project_item
  current_assignees = item.field_values['Assignees'] || []
  remaining = current_assignees - [params[:username]]

  item.assign!(remaining)

  flash[:success] = "#{params[:username]} unassigned."
  redirect_to(plan_my_stuff.project_path(params[:project_id]))
rescue ArgumentError, PlanMyStuff::Error => e
  pms_handle_rescue(e)
  flash[:error] = e.message
  redirect_to(plan_my_stuff.project_path(params[:project_id]))
end

#updateObject

PATCH /projects/:project_id/items/:item_id/assignment



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

def update
  item = find_project_item
  assignees = parse_assignees(params[:assignee])

  item.assign!(assignees)

  flash[:success] =
    if assignees.present?
      "Item assigned to #{assignees.join(', ')}."
    else
      'All assignees removed.'
    end
  redirect_to(plan_my_stuff.project_path(params[:project_id]))
rescue ArgumentError, PlanMyStuff::Error => e
  pms_handle_rescue(e)
  flash[:error] = e.message
  redirect_to(plan_my_stuff.project_path(params[:project_id]))
end