From 02837e31e202d241f32fa135d8a0ff5e606c4caa Mon Sep 17 00:00:00 2001 From: Michel Felipe de Oliveira Ferreira Date: Tue, 29 Dec 2015 15:06:21 -0300 Subject: [PATCH] New feature: Restore a rejected proposal to initial status --- controllers/myprofile/proposals_discussion_plugin_tasks_controller.rb | 7 +++++++ lib/proposals_discussion_plugin/proposal_task.rb | 16 ++++++++++++++++ test/unit/proposal_task_test.rb | 25 +++++++++++++++++++++++++ views/tasks/processed.html.erb | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ views/tasks/proposals_discussion_plugin/_proposal_task_processed.html.erb | 1 + 5 files changed, 107 insertions(+), 0 deletions(-) create mode 100644 views/tasks/processed.html.erb 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' %> + +
+

<%= _("%s's processed tasks") % profile.name %>

+ +
+<% + type_collection = [[nil, _('All')]] + @task_types +%> + <%= form_tag '#', :method => 'get' do %> + <%= field_set_tag _('Filter'), :class => 'filter_fields' do %> +
+ <%= labelled_select(_('Type of task')+': ', 'filter[type]', :first, :last, @filter[:type], type_collection, {:id => 'filter-type'}) %> + <%= labelled_select(_('Status:'), 'filter[status]', :last, :first, @filter[:status], [[_('Any'), nil], [_(Task::Status.names[Task::Status::CANCELLED]), 2], [_(Task::Status.names[Task::Status::FINISHED]), 3] ]) %> +
+ +
+ <%= labelled_text_field(_('Text Filter:'), 'filter[text]', @filter[:text]) %> +
+ +
+ <%= labelled_text_field(_('Requestor:'), 'filter[requestor]', @filter[:requestor]) %> + <%= labelled_text_field(_('Closed by:'), 'filter[closed_by]', @filter[:closed_by]) %> +
+ + <%= labelled_form_field(_('Creation date'), date_range_field('filter[created_from]', 'filter[created_until]', @filter[:created_from], @filter[:created_until], '%Y-%m-%d', { :change_month => true, :change_year => true, :date_format => 'yy-mm-dd' }, { :size => 14, :from_id => 'filter_created_from', :to_id => 'filter_created_until' })) %> + <%= labelled_form_field(_('Processed date'), date_range_field('filter[closed_from]', 'filter[closed_until]', @filter[:closed_from], @filter[:closed_until], '%Y-%m-%d', { :change_month => true, :change_year => true, :date_format => 'yy-mm-dd' }, { :size => 14, :from_id => 'filter_closed_from', :to_id => 'filter_closed_until' })) %> + +
+ <%= submit_button(:search, _('Search')) %> +
+ <% end %> + <% end %> +
+ +

+<% if @tasks.empty? %> + <%= _('No processed tasks.') %> +<% else %> + <%= form_tag :controller => :proposals_discussion_plugin_tasks, :action => 'undo_flags', :method => 'post' do %> +

+ <%= pagination_links(@tasks)%> + + <% end %> +<% end %> +

+ +<% button_bar do %> + <%= button(:back, _('Back'), :action => 'index') %> +<% end %> + +
diff --git a/views/tasks/proposals_discussion_plugin/_proposal_task_processed.html.erb b/views/tasks/proposals_discussion_plugin/_proposal_task_processed.html.erb index f5f2e70..decd2a7 100644 --- a/views/tasks/proposals_discussion_plugin/_proposal_task_processed.html.erb +++ b/views/tasks/proposals_discussion_plugin/_proposal_task_processed.html.erb @@ -2,6 +2,7 @@ <%= _('Source') %>: <%= task.proposal_source %>
+
-- libgit2 0.21.2