summaryrefslogtreecommitdiff
path: root/app/controllers/projects/todos_controller.rb
blob: 23868d986e9626975f78010333b36090430d741a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class Projects::TodosController < Projects::ApplicationController
  before_action :authenticate_user!, only: [:create]

  def create
    todo = TodoService.new.mark_todo(issuable, current_user)

    render json: {
      count: current_user.todos_pending_count,
      delete_path: dashboard_todo_path(todo)
    }
  end

  private

  def issuable
    @issuable ||= begin
      case params[:issuable_type]
      when "issue"
        issue = @project.issues.find(params[:issuable_id])

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