2016-06-08 04:29:19 -04:00
|
|
|
class Projects::TodosController < Projects::ApplicationController
|
2016-06-17 04:06:00 -04:00
|
|
|
before_action :authenticate_user!, only: [:create]
|
2016-06-08 04:29:19 -04:00
|
|
|
|
2016-06-17 04:01:03 -04:00
|
|
|
def create
|
|
|
|
todo = TodoService.new.mark_todo(issuable, current_user)
|
2016-06-08 04:29:19 -04:00
|
|
|
|
2016-06-09 03:50:18 -04:00
|
|
|
render json: {
|
2016-07-11 02:10:04 -04:00
|
|
|
count: TodosFinder.new(current_user, state: :pending).execute.count,
|
2016-06-17 04:01:03 -04:00
|
|
|
delete_path: dashboard_todo_path(todo)
|
2016-06-09 03:50:18 -04:00
|
|
|
}
|
2016-06-08 04:29:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2016-06-09 03:50:18 -04:00
|
|
|
|
2016-06-08 04:29:19 -04:00
|
|
|
def issuable
|
|
|
|
@issuable ||= begin
|
|
|
|
case params[:issuable_type]
|
|
|
|
when "issue"
|
2016-06-17 04:01:03 -04:00
|
|
|
issue = @project.issues.find(params[:issuable_id])
|
|
|
|
|
|
|
|
if can?(current_user, :read_issue, issue)
|
|
|
|
issue
|
|
|
|
else
|
|
|
|
render_404
|
|
|
|
end
|
2016-06-08 04:29:19 -04:00
|
|
|
when "merge_request"
|
|
|
|
@project.merge_requests.find(params[:issuable_id])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|