Commit 5666676ac868e8d88501af7b0bc5a5916d19f0c4
1 parent
02837e31
Exists in
restore_rejected_proposal
Rafactor into undo_flags model and controller methods
Showing
3 changed files
with
30 additions
and
4 deletions
Show diff stats
controllers/myprofile/proposals_discussion_plugin_tasks_controller.rb
| @@ -80,7 +80,10 @@ class ProposalsDiscussionPluginTasksController < TasksController | @@ -80,7 +80,10 @@ class ProposalsDiscussionPluginTasksController < TasksController | ||
| 80 | 80 | ||
| 81 | def undo_flags | 81 | def undo_flags |
| 82 | if params[:tasks].present? | 82 | if params[:tasks].present? |
| 83 | - ProposalsDiscussionPlugin::ProposalTask.undo_flags params[:tasks], current_user | 83 | + result = ProposalsDiscussionPlugin::ProposalTask.undo_flags params[:tasks], current_user |
| 84 | + unless result | ||
| 85 | + session[:notice] = _("Error to undo flags. Please, verify with the admin") | ||
| 86 | + end | ||
| 84 | end | 87 | end |
| 85 | redirect_to :controller => 'tasks', :action => 'processed', :filter => {type: 'ProposalsDiscussionPlugin::ProposalTask'} | 88 | redirect_to :controller => 'tasks', :action => 'processed', :filter => {type: 'ProposalsDiscussionPlugin::ProposalTask'} |
| 86 | end | 89 | end |
lib/proposals_discussion_plugin/proposal_task.rb
| @@ -132,11 +132,13 @@ class ProposalsDiscussionPlugin::ProposalTask < Task | @@ -132,11 +132,13 @@ class ProposalsDiscussionPlugin::ProposalTask < Task | ||
| 132 | 132 | ||
| 133 | def self.undo_flags(tasks, user) | 133 | def self.undo_flags(tasks, user) |
| 134 | fields = "status = #{Task::Status::ACTIVE}, end_date = NULL, closed_by_id = #{user.id}" | 134 | fields = "status = #{Task::Status::ACTIVE}, end_date = NULL, closed_by_id = #{user.id}" |
| 135 | - result = self.update_all(fields, ["id IN (?)",tasks]) | 135 | + conditions = "status = #{Status::FLAGGED_FOR_REPROVAL} OR status = #{Status::FLAGGED_FOR_APPROVAL}" |
| 136 | + | ||
| 137 | + result = self.where(conditions).update_all(fields, ["id IN (?)",tasks]) | ||
| 136 | result | 138 | result |
| 137 | end | 139 | end |
| 138 | 140 | ||
| 139 | - def undo_flag(user) | 141 | + def undo_flags(user) |
| 140 | if flagged? | 142 | if flagged? |
| 141 | self.status = Task::Status::ACTIVE | 143 | self.status = Task::Status::ACTIVE |
| 142 | self.end_date = nil | 144 | self.end_date = nil |
test/unit/proposal_task_test.rb
| @@ -77,7 +77,7 @@ class ProposalTaskTest < ActiveSupport::TestCase | @@ -77,7 +77,7 @@ class ProposalTaskTest < ActiveSupport::TestCase | ||
| 77 | assert_equal person2, task.responsible | 77 | assert_equal person2, task.responsible |
| 78 | end | 78 | end |
| 79 | 79 | ||
| 80 | - should 'undo proposal task reject flag' do | 80 | + should 'undo flags from one or more proposal tasks' do |
| 81 | role1 = Role.create!(:name => 'profile_role2', :permissions => ['perform_task'], :environment => Environment.default) | 81 | role1 = Role.create!(:name => 'profile_role2', :permissions => ['perform_task'], :environment => Environment.default) |
| 82 | role2 = Role.create!(:name => 'profile_role', :permissions => ['view_tasks'], :environment => Environment.default) | 82 | role2 = Role.create!(:name => 'profile_role', :permissions => ['view_tasks'], :environment => Environment.default) |
| 83 | 83 | ||
| @@ -102,6 +102,27 @@ class ProposalTaskTest < ActiveSupport::TestCase | @@ -102,6 +102,27 @@ class ProposalTaskTest < ActiveSupport::TestCase | ||
| 102 | assert_equal [Task::Status::ACTIVE,Task::Status::ACTIVE], [task.status, task_two.status] | 102 | assert_equal [Task::Status::ACTIVE,Task::Status::ACTIVE], [task.status, task_two.status] |
| 103 | end | 103 | end |
| 104 | 104 | ||
| 105 | + should 'undo flags from a specific proposal task' do | ||
| 106 | + role1 = Role.create!(:name => 'profile_role2', :permissions => ['perform_task'], :environment => Environment.default) | ||
| 107 | + role2 = Role.create!(:name => 'profile_role', :permissions => ['view_tasks'], :environment => Environment.default) | ||
| 108 | + | ||
| 109 | + person1 = fast_create(Person) | ||
| 110 | + person1.define_roles([role1], profile) | ||
| 111 | + person2 = fast_create(Person) | ||
| 112 | + person2.define_roles([role2], profile) | ||
| 113 | + | ||
| 114 | + task = ProposalsDiscussionPlugin::ProposalTask.create!(:requestor => person, :target => profile, :article => {:name => 'proposal', :abstract => 'proposal'}) | ||
| 115 | + task.categories = [fast_create(ProposalsDiscussionPlugin::TaskCategory)] | ||
| 116 | + task.flag_reject_proposal(person1) | ||
| 117 | + assert task.flagged? | ||
| 118 | + | ||
| 119 | + task.undo_flags(person) | ||
| 120 | + task.reload | ||
| 121 | + | ||
| 122 | + assert_equal false, task.flagged? | ||
| 123 | + assert_equal Task::Status::ACTIVE, task.status | ||
| 124 | + end | ||
| 125 | + | ||
| 105 | should 'do not fail on task information with integer as abstract' do | 126 | should 'do not fail on task information with integer as abstract' do |
| 106 | task = ProposalsDiscussionPlugin::ProposalTask.new | 127 | task = ProposalsDiscussionPlugin::ProposalTask.new |
| 107 | task.expects(:abstract).returns(49) | 128 | task.expects(:abstract).returns(49) |