Allow user to mark each task as done manually

parent c8f2d18a
class Dashboard::TasksController < Dashboard::ApplicationController class Dashboard::TasksController < Dashboard::ApplicationController
before_action :authorize_destroy_task!, only: [:destroy]
def index def index
@tasks = case params[:state] @tasks = case params[:state]
when 'done' when 'done'
...@@ -12,4 +14,25 @@ class Dashboard::TasksController < Dashboard::ApplicationController ...@@ -12,4 +14,25 @@ class Dashboard::TasksController < Dashboard::ApplicationController
@pending_count = current_user.tasks.pending.count @pending_count = current_user.tasks.pending.count
@done_count = current_user.tasks.done.count @done_count = current_user.tasks.done.count
end 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 end
...@@ -17,6 +17,7 @@ class Ability ...@@ -17,6 +17,7 @@ class Ability
when Namespace then namespace_abilities(user, subject) when Namespace then namespace_abilities(user, subject)
when GroupMember then group_member_abilities(user, subject) when GroupMember then group_member_abilities(user, subject)
when ProjectMember then project_member_abilities(user, subject) when ProjectMember then project_member_abilities(user, subject)
when Task then task_abilities(user, subject)
else [] else []
end.concat(global_abilities(user)) end.concat(global_abilities(user))
end end
...@@ -416,6 +417,16 @@ class Ability ...@@ -416,6 +417,16 @@ class Ability
rules rules
end end
def task_abilities(user, task)
rules = []
if task && task.user == user
rules << :destroy_task
end
rules
end
def abilities def abilities
@abilities ||= begin @abilities ||= begin
abilities = Six.new abilities = Six.new
......
...@@ -32,6 +32,10 @@ class Task < ActiveRecord::Base ...@@ -32,6 +32,10 @@ class Task < ActiveRecord::Base
scope :done, -> { with_state(:done) } scope :done, -> { with_state(:done) }
state_machine :state, initial: :pending do state_machine :state, initial: :pending do
event :done do
transition pending: :done
end
state :pending state :pending
state :done state :done
end end
......
...@@ -11,6 +11,10 @@ ...@@ -11,6 +11,10 @@
&middot; #{time_ago_with_tooltip(task.created_at)} &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? - if task.body?
.task-body .task-body
.task-note .task-note
......
...@@ -333,7 +333,7 @@ Rails.application.routes.draw do ...@@ -333,7 +333,7 @@ Rails.application.routes.draw do
resources :groups, only: [:index] resources :groups, only: [:index]
resources :snippets, only: [:index] resources :snippets, only: [:index]
resources :tasks, only: [:index] resources :tasks, only: [:index, :destroy]
resources :projects, only: [:index] do resources :projects, only: [:index] do
collection 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