summaryrefslogtreecommitdiff
path: root/app/controllers/dashboard
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/dashboard')
-rw-r--r--app/controllers/dashboard/tasks_controller.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/app/controllers/dashboard/tasks_controller.rb b/app/controllers/dashboard/tasks_controller.rb
index 66d891e3dfa..1102745067f 100644
--- a/app/controllers/dashboard/tasks_controller.rb
+++ b/app/controllers/dashboard/tasks_controller.rb
@@ -1,4 +1,6 @@
class Dashboard::TasksController < Dashboard::ApplicationController
+ before_action :authorize_destroy_task!, only: [:destroy]
+
def index
@tasks = case params[:state]
when 'done'
@@ -12,4 +14,25 @@ class Dashboard::TasksController < Dashboard::ApplicationController
@pending_count = current_user.tasks.pending.count
@done_count = current_user.tasks.done.count
end
+
+ def destroy
+ task.done!
+
+ respond_to do |format|
+ format.html { redirect_to dashboard_tasks_path, notice: 'Task was successfully marked as done.' }
+ format.js { render nothing: true }
+ end
+ end
+
+ private
+
+ def authorize_destroy_task!
+ unless can?(current_user, :destroy_task, task)
+ return render_404
+ end
+ end
+
+ def task
+ @task ||= current_user.tasks.find(params[:id])
+ end
end