Allow user to mark each task as done manually

parent c8f2d18a
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
......@@ -17,6 +17,7 @@ class Ability
when Namespace then namespace_abilities(user, subject)
when GroupMember then group_member_abilities(user, subject)
when ProjectMember then project_member_abilities(user, subject)
when Task then task_abilities(user, subject)
else []
end.concat(global_abilities(user))
end
......@@ -416,6 +417,16 @@ class Ability
rules
end
def task_abilities(user, task)
rules = []
if task && task.user == user
rules << :destroy_task
end
rules
end
def abilities
@abilities ||= begin
abilities = Six.new
......
......@@ -32,6 +32,10 @@ class Task < ActiveRecord::Base
scope :done, -> { with_state(:done) }
state_machine :state, initial: :pending do
event :done do
transition pending: :done
end
state :pending
state :done
end
......
......@@ -11,6 +11,10 @@
&middot; #{time_ago_with_tooltip(task.created_at)}
- if task.pending?
.task-actions.pull-right
= link_to 'Done', [:dashboard, task], method: :delete, class: 'btn'
- if task.body?
.task-body
.task-note
......
......@@ -333,7 +333,7 @@ Rails.application.routes.draw do
resources :groups, only: [:index]
resources :snippets, only: [:index]
resources :tasks, only: [:index]
resources :tasks, only: [:index, :destroy]
resources :projects, only: [:index] do
collection do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment