BigW Consortium Gitlab

todos_controller.rb 736 Bytes
Newer Older
1
class Projects::TodosController < Projects::ApplicationController
2
  before_action :authenticate_user!, only: [:create]
3

Phil Hughes committed
4 5
  def create
    todo = TodoService.new.mark_todo(issuable, current_user)
6

7
    render json: {
8
      count: TodosFinder.new(current_user, state: :pending).execute.count,
Phil Hughes committed
9
      delete_path: dashboard_todo_path(todo)
10
    }
11 12 13
  end

  private
14

15 16 17 18
  def issuable
    @issuable ||= begin
      case params[:issuable_type]
      when "issue"
Phil Hughes committed
19 20 21 22 23 24 25
        issue = @project.issues.find(params[:issuable_id])

        if can?(current_user, :read_issue, issue)
          issue
        else
          render_404
        end
26 27 28 29 30 31
      when "merge_request"
        @project.merge_requests.find(params[:issuable_id])
      end
    end
  end
end