diff --git a/controllers/myprofile/proposals_discussion_plugin_tasks_controller.rb b/controllers/myprofile/proposals_discussion_plugin_tasks_controller.rb index 5c1e191..30ed11f 100644 --- a/controllers/myprofile/proposals_discussion_plugin_tasks_controller.rb +++ b/controllers/myprofile/proposals_discussion_plugin_tasks_controller.rb @@ -78,4 +78,11 @@ class ProposalsDiscussionPluginTasksController < TasksController end + def undo_flags + if params[:tasks].present? + ProposalsDiscussionPlugin::ProposalTask.undo_flags params[:tasks], current_user + end + redirect_to :controller => 'tasks', :action => 'processed', :filter => {type: 'ProposalsDiscussionPlugin::ProposalTask'} + end + end diff --git a/lib/proposals_discussion_plugin/proposal_task.rb b/lib/proposals_discussion_plugin/proposal_task.rb index 743a920..250c6da 100644 --- a/lib/proposals_discussion_plugin/proposal_task.rb +++ b/lib/proposals_discussion_plugin/proposal_task.rb @@ -20,6 +20,8 @@ class ProposalsDiscussionPlugin::ProposalTask < Task settings_items :article, :type => Hash, :default => {} settings_items :closing_statment, :article_parent_id + attr_accessible :requestor, :target, :article, :status, :end_date, :closed_by + scope :pending_evaluated, lambda { |profile, filter_type, filter_text| self @@ -128,6 +130,20 @@ class ProposalsDiscussionPlugin::ProposalTask < Task end end + def self.undo_flags(tasks, user) + fields = "status = #{Task::Status::ACTIVE}, end_date = NULL, closed_by_id = #{user.id}" + result = self.update_all(fields, ["id IN (?)",tasks]) + result + end + + def undo_flag(user) + if flagged? + self.status = Task::Status::ACTIVE + self.end_date = nil + self.closed_by = user + self.save! + end + end def schedule_spam_checking self.delay.check_for_spam diff --git a/test/unit/proposal_task_test.rb b/test/unit/proposal_task_test.rb index 7546691..b9bf223 100644 --- a/test/unit/proposal_task_test.rb +++ b/test/unit/proposal_task_test.rb @@ -77,6 +77,31 @@ class ProposalTaskTest < ActiveSupport::TestCase assert_equal person2, task.responsible end + should 'undo proposal task reject flag' do + role1 = Role.create!(:name => 'profile_role2', :permissions => ['perform_task'], :environment => Environment.default) + role2 = Role.create!(:name => 'profile_role', :permissions => ['view_tasks'], :environment => Environment.default) + + person1 = fast_create(Person) + person1.define_roles([role1], profile) + person2 = fast_create(Person) + person2.define_roles([role2], profile) + + task = ProposalsDiscussionPlugin::ProposalTask.create!(:requestor => person, :target => profile, :article => {:name => 'proposal 1', :abstract => 'proposal 1'}) + task_two = ProposalsDiscussionPlugin::ProposalTask.create!(:requestor => person, :target => profile, :article => {:name => 'proposal 2', :abstract => 'proposal 2'}) + task.categories = task_two.categories = [fast_create(ProposalsDiscussionPlugin::TaskCategory)] + task.flag_reject_proposal(person2) + task_two.flag_reject_proposal(person2) + assert task.flagged? + assert task_two.flagged? + + ProposalsDiscussionPlugin::ProposalTask.undo_flags([task.id,task_two.id], person) + task.reload + task_two.reload + + assert_equal [false,false], [task.flagged?,task_two.flagged?] + assert_equal [Task::Status::ACTIVE,Task::Status::ACTIVE], [task.status, task_two.status] + end + should 'do not fail on task information with integer as abstract' do task = ProposalsDiscussionPlugin::ProposalTask.new task.expects(:abstract).returns(49) diff --git a/views/tasks/processed.html.erb b/views/tasks/processed.html.erb new file mode 100644 index 0000000..ebc4931 --- /dev/null +++ b/views/tasks/processed.html.erb @@ -0,0 +1,58 @@ +<%= stylesheet_link_tag 'tasks' %> + +
+<% if @tasks.empty? %> + <%= _('No processed tasks.') %> +<% else %> + <%= form_tag :controller => :proposals_discussion_plugin_tasks, :action => 'undo_flags', :method => 'post' do %> +