Class: Api::V1::SprintTasksController

Inherits:
ApplicationController show all
Defined in:
app/controllers/api/v1/sprint_tasks_controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationController

#after_sign_in_path_for, #api_authenticate!, #current_project, #expire_revision!, #followed_projects, #no_cache, #read_revision, #require_login, #return_or_cache_revision!, #revision, #save_current_project, #set_current_project, #unfurling?

Methods included from UrlHelper

#edit_release_path, #edit_release_url, #feature_path, #github_commit_range_url, #github_commit_url, #github_project_url, #github_url?, #goldmine_case_number_url, #link_to_project_feature, #new_release_url, #release_path, #release_url, #releases_path

Instance Attribute Details

#sprintObject (readonly)

Returns the value of attribute sprint.



9
10
11
# File 'app/controllers/api/v1/sprint_tasks_controller.rb', line 9

def sprint
  @sprint
end

#taskObject (readonly)

Returns the value of attribute task.



9
10
11
# File 'app/controllers/api/v1/sprint_tasks_controller.rb', line 9

def task
  @task
end

Instance Method Details

#createObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/api/v1/sprint_tasks_controller.rb', line 28

def create
  authorize! :update, sprint

  if sprint.completed?
    render text: "The Sprint is completed. You cannot add or remove tasks.", status: :unprocessable_entity
    return
  end

  if sprint.locked? && !task.ticket_id.in?(sprint.ticket_ids)
    render text: "The Sprint is locked. You can add tasks for tickets that are already in the Sprint, but you can't add new tickets to the Sprint.", status: :unprocessable_entity
    return
  end

  # Putting a task into a Sprint implies that you're able to estimate this ticket
  task.ticket.able_to_estimate! if task.ticket.respond_to?(:able_to_estimate!)

  task.update_attributes(effort: params[:effort]) if params[:effort]

  if task.completed? && task.completed_at < sprint.starts_at
    render text: "Task ##{task.shorthand} cannot be added to the Sprint because it was completed before the Sprint began", status: :unprocessable_entity
  elsif task.effort.nil? or task.effort.zero?
    render text: "Task ##{task.shorthand} cannot be added to the Sprint because it has no effort", status: :unprocessable_entity
  else
    sprint.tasks.add task
    task.check_out!(sprint, current_user) unless task.checked_out?(sprint)
    render json: SprintTaskPresenter.new(sprint, task).to_json
  end
end

#destroyObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/api/v1/sprint_tasks_controller.rb', line 57

def destroy
  authorize! :update, sprint

  if sprint.completed?
    render text: "The Sprint is completed. You cannot add or remove tasks.", status: :unprocessable_entity
    return
  end

  if sprint.locked?
    render text: "The Sprint is locked; tasks cannot be removed", status: :unprocessable_entity
    return
  end

  SprintTask.where(sprint_id: sprint.id, task_id: task.id).delete_all
  head :ok
end

#indexObject



15
16
17
18
19
# File 'app/controllers/api/v1/sprint_tasks_controller.rb', line 15

def index
  render json: sprint.tasks
    .includes(:ticket => :project)
    .map { |task| present_task(task) }
end

#mineObject



21
22
23
24
25
26
# File 'app/controllers/api/v1/sprint_tasks_controller.rb', line 21

def mine
  render json: sprint.tasks
    .includes(:ticket => :project)
    .checked_out_by(current_user)
    .map { |task| present_task(task) }
end