summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-02-15 17:49:28 -0200
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-02-20 12:10:26 -0200
commit77d7910b8b4497dc52a80f8a35b765c978d547a4 (patch)
tree1830a4bfd7f99dcc6f640a1d105717359d956797
parentc8f2d18abde050c3b6d15ee32c99495c77b2a222 (diff)
downloadgitlab-ce-77d7910b8b4497dc52a80f8a35b765c978d547a4.tar.gz
Allow user to mark each task as done manually
-rw-r--r--app/controllers/dashboard/tasks_controller.rb23
-rw-r--r--app/models/ability.rb11
-rw-r--r--app/models/task.rb4
-rw-r--r--app/views/dashboard/tasks/_task.html.haml4
-rw-r--r--config/routes.rb2
5 files changed, 43 insertions, 1 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
diff --git a/app/models/ability.rb b/app/models/ability.rb
index a866eadeebb..5e0c76004d2 100644
--- a/app/models/ability.rb
+++ b/app/models/ability.rb
@@ -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
diff --git a/app/models/task.rb b/app/models/task.rb
index 37e752bd350..b9e5152b819 100644
--- a/app/models/task.rb
+++ b/app/models/task.rb
@@ -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
diff --git a/app/views/dashboard/tasks/_task.html.haml b/app/views/dashboard/tasks/_task.html.haml
index c7b952f0cb5..b33f3894fd3 100644
--- a/app/views/dashboard/tasks/_task.html.haml
+++ b/app/views/dashboard/tasks/_task.html.haml
@@ -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
diff --git a/config/routes.rb b/config/routes.rb
index 17c0bb22a8c..0b263933fba 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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