Commit 24429b78d1026a67465c52d9ebe15b5eec0f5abb
Exists in
master
and in
24 other branches
Merge branch 'task_closed_by' into 'master'
Store the person that closes a task See merge request !590
Showing
5 changed files
with
40 additions
and
9 deletions
Show diff stats
app/controllers/my_profile/tasks_controller.rb
| ... | ... | @@ -49,7 +49,7 @@ class TasksController < MyProfileController |
| 49 | 49 | task = profile.find_in_all_tasks(id) |
| 50 | 50 | begin |
| 51 | 51 | task.update_attributes(value[:task]) |
| 52 | - task.send(decision) | |
| 52 | + task.send(decision, current_person) | |
| 53 | 53 | rescue Exception => ex |
| 54 | 54 | message = "#{task.title} (#{task.requestor ? task.requestor.name : task.author_name})" |
| 55 | 55 | failed[ex.message] ? failed[ex.message] << message : failed[ex.message] = [message] | ... | ... |
app/models/task.rb
| ... | ... | @@ -34,6 +34,7 @@ class Task < ActiveRecord::Base |
| 34 | 34 | belongs_to :requestor, :class_name => 'Profile', :foreign_key => :requestor_id |
| 35 | 35 | belongs_to :target, :foreign_key => :target_id, :polymorphic => true |
| 36 | 36 | belongs_to :responsible, :class_name => 'Person', :foreign_key => :responsible_id |
| 37 | + belongs_to :closed_by, :class_name => 'Person', :foreign_key => :closed_by_id | |
| 37 | 38 | |
| 38 | 39 | validates_uniqueness_of :code, :on => :create |
| 39 | 40 | validates_presence_of :code |
| ... | ... | @@ -77,11 +78,9 @@ class Task < ActiveRecord::Base |
| 77 | 78 | # this method finished the task. It calls #perform, which must be overriden |
| 78 | 79 | # by subclasses. At the end a message (as returned by #finish_message) is |
| 79 | 80 | # sent to the requestor with #notify_requestor. |
| 80 | - def finish | |
| 81 | + def finish(closed_by=nil) | |
| 81 | 82 | transaction do |
| 82 | - self.status = Task::Status::FINISHED | |
| 83 | - self.end_date = Time.now | |
| 84 | - self.save! | |
| 83 | + close(Task::Status::FINISHED, closed_by) | |
| 85 | 84 | self.perform |
| 86 | 85 | begin |
| 87 | 86 | send_notification(:finished) |
| ... | ... | @@ -106,11 +105,9 @@ class Task < ActiveRecord::Base |
| 106 | 105 | |
| 107 | 106 | # this method cancels the task. At the end a message (as returned by |
| 108 | 107 | # #cancel_message) is sent to the requestor with #notify_requestor. |
| 109 | - def cancel | |
| 108 | + def cancel(closed_by=nil) | |
| 110 | 109 | transaction do |
| 111 | - self.status = Task::Status::CANCELLED | |
| 112 | - self.end_date = Time.now | |
| 113 | - self.save! | |
| 110 | + close(Task::Status::CANCELLED, closed_by) | |
| 114 | 111 | begin |
| 115 | 112 | send_notification(:cancelled) |
| 116 | 113 | rescue NotImplementedError => ex |
| ... | ... | @@ -119,6 +116,13 @@ class Task < ActiveRecord::Base |
| 119 | 116 | end |
| 120 | 117 | end |
| 121 | 118 | |
| 119 | + def close(status, closed_by) | |
| 120 | + self.status = status | |
| 121 | + self.end_date = Time.now | |
| 122 | + self.closed_by = closed_by | |
| 123 | + self.save! | |
| 124 | + end | |
| 125 | + | |
| 122 | 126 | # Here are the tasks customizable options. |
| 123 | 127 | |
| 124 | 128 | def title | ... | ... |
test/functional/tasks_controller_test.rb
| ... | ... | @@ -628,6 +628,12 @@ class TasksControllerTest < ActionController::TestCase |
| 628 | 628 | |
| 629 | 629 | assert_select ".task_responsible select", 0 |
| 630 | 630 | assert_select ".task_responsible .value" |
| 631 | + end | |
| 632 | + | |
| 633 | + should 'store the person who closes a task' do | |
| 634 | + t = profile.tasks.build; t.save! | |
| 635 | + post :close, :tasks => {t.id => {:decision => 'finish', :task => {}}} | |
| 636 | + assert_equal profile, t.reload.closed_by | |
| 631 | 637 | end |
| 632 | 638 | |
| 633 | 639 | end | ... | ... |
test/unit/task_test.rb
| ... | ... | @@ -440,6 +440,20 @@ class TaskTest < ActiveSupport::TestCase |
| 440 | 440 | assert_equal person, task.responsible |
| 441 | 441 | end |
| 442 | 442 | |
| 443 | + should 'store who finish the task' do | |
| 444 | + t = Task.create | |
| 445 | + person = fast_create(Person) | |
| 446 | + t.finish(person) | |
| 447 | + assert_equal person, t.reload.closed_by | |
| 448 | + end | |
| 449 | + | |
| 450 | + should 'store who cancel the task' do | |
| 451 | + t = Task.create | |
| 452 | + person = fast_create(Person) | |
| 453 | + t.cancel(person) | |
| 454 | + assert_equal person, t.reload.closed_by | |
| 455 | + end | |
| 456 | + | |
| 443 | 457 | protected |
| 444 | 458 | |
| 445 | 459 | def sample_user | ... | ... |