summaryrefslogtreecommitdiff
path: root/app/controllers/projects/todos_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/projects/todos_controller.rb')
-rw-r--r--app/controllers/projects/todos_controller.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/app/controllers/projects/todos_controller.rb b/app/controllers/projects/todos_controller.rb
new file mode 100644
index 00000000000..23868d986e9
--- /dev/null
+++ b/app/controllers/projects/todos_controller.rb
@@ -0,0 +1,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