2016-06-16 23:09:34 +05:30
|
|
|
class Projects::TodosController < Projects::ApplicationController
|
2016-06-22 15:30:34 +05:30
|
|
|
before_action :authenticate_user!, only: [:create]
|
2016-06-16 23:09:34 +05:30
|
|
|
|
2016-06-22 15:30:34 +05:30
|
|
|
def create
|
|
|
|
todo = TodoService.new.mark_todo(issuable, current_user)
|
2016-06-16 23:09:34 +05:30
|
|
|
|
|
|
|
render json: {
|
2016-08-24 12:49:21 +05:30
|
|
|
count: TodosFinder.new(current_user, state: :pending).execute.count,
|
2016-06-22 15:30:34 +05:30
|
|
|
delete_path: dashboard_todo_path(todo)
|
2016-06-16 23:09:34 +05:30
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def issuable
|
|
|
|
@issuable ||= begin
|
|
|
|
case params[:issuable_type]
|
|
|
|
when "issue"
|
2016-06-22 15:30:34 +05:30
|
|
|
issue = @project.issues.find(params[:issuable_id])
|
|
|
|
|
|
|
|
if can?(current_user, :read_issue, issue)
|
|
|
|
issue
|
|
|
|
else
|
|
|
|
render_404
|
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
when "merge_request"
|
|
|
|
@project.merge_requests.find(params[:issuable_id])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|