Commit 02837e31e202d241f32fa135d8a0ff5e606c4caa
1 parent
707a3093
Exists in
restore_rejected_proposal
New feature: Restore a rejected proposal to initial status
Showing
5 changed files
with
107 additions
and
0 deletions
Show diff stats
controllers/myprofile/proposals_discussion_plugin_tasks_controller.rb
... | ... | @@ -78,4 +78,11 @@ class ProposalsDiscussionPluginTasksController < TasksController |
78 | 78 | |
79 | 79 | end |
80 | 80 | |
81 | + def undo_flags | |
82 | + if params[:tasks].present? | |
83 | + ProposalsDiscussionPlugin::ProposalTask.undo_flags params[:tasks], current_user | |
84 | + end | |
85 | + redirect_to :controller => 'tasks', :action => 'processed', :filter => {type: 'ProposalsDiscussionPlugin::ProposalTask'} | |
86 | + end | |
87 | + | |
81 | 88 | end | ... | ... |
lib/proposals_discussion_plugin/proposal_task.rb
... | ... | @@ -20,6 +20,8 @@ class ProposalsDiscussionPlugin::ProposalTask < Task |
20 | 20 | settings_items :article, :type => Hash, :default => {} |
21 | 21 | settings_items :closing_statment, :article_parent_id |
22 | 22 | |
23 | + attr_accessible :requestor, :target, :article, :status, :end_date, :closed_by | |
24 | + | |
23 | 25 | |
24 | 26 | scope :pending_evaluated, lambda { |profile, filter_type, filter_text| |
25 | 27 | self |
... | ... | @@ -128,6 +130,20 @@ class ProposalsDiscussionPlugin::ProposalTask < Task |
128 | 130 | end |
129 | 131 | end |
130 | 132 | |
133 | + def self.undo_flags(tasks, user) | |
134 | + fields = "status = #{Task::Status::ACTIVE}, end_date = NULL, closed_by_id = #{user.id}" | |
135 | + result = self.update_all(fields, ["id IN (?)",tasks]) | |
136 | + result | |
137 | + end | |
138 | + | |
139 | + def undo_flag(user) | |
140 | + if flagged? | |
141 | + self.status = Task::Status::ACTIVE | |
142 | + self.end_date = nil | |
143 | + self.closed_by = user | |
144 | + self.save! | |
145 | + end | |
146 | + end | |
131 | 147 | |
132 | 148 | def schedule_spam_checking |
133 | 149 | self.delay.check_for_spam | ... | ... |
test/unit/proposal_task_test.rb
... | ... | @@ -77,6 +77,31 @@ class ProposalTaskTest < ActiveSupport::TestCase |
77 | 77 | assert_equal person2, task.responsible |
78 | 78 | end |
79 | 79 | |
80 | + should 'undo proposal task reject flag' do | |
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) | |
83 | + | |
84 | + person1 = fast_create(Person) | |
85 | + person1.define_roles([role1], profile) | |
86 | + person2 = fast_create(Person) | |
87 | + person2.define_roles([role2], profile) | |
88 | + | |
89 | + task = ProposalsDiscussionPlugin::ProposalTask.create!(:requestor => person, :target => profile, :article => {:name => 'proposal 1', :abstract => 'proposal 1'}) | |
90 | + task_two = ProposalsDiscussionPlugin::ProposalTask.create!(:requestor => person, :target => profile, :article => {:name => 'proposal 2', :abstract => 'proposal 2'}) | |
91 | + task.categories = task_two.categories = [fast_create(ProposalsDiscussionPlugin::TaskCategory)] | |
92 | + task.flag_reject_proposal(person2) | |
93 | + task_two.flag_reject_proposal(person2) | |
94 | + assert task.flagged? | |
95 | + assert task_two.flagged? | |
96 | + | |
97 | + ProposalsDiscussionPlugin::ProposalTask.undo_flags([task.id,task_two.id], person) | |
98 | + task.reload | |
99 | + task_two.reload | |
100 | + | |
101 | + assert_equal [false,false], [task.flagged?,task_two.flagged?] | |
102 | + assert_equal [Task::Status::ACTIVE,Task::Status::ACTIVE], [task.status, task_two.status] | |
103 | + end | |
104 | + | |
80 | 105 | should 'do not fail on task information with integer as abstract' do |
81 | 106 | task = ProposalsDiscussionPlugin::ProposalTask.new |
82 | 107 | task.expects(:abstract).returns(49) | ... | ... |
... | ... | @@ -0,0 +1,58 @@ |
1 | +<%= stylesheet_link_tag 'tasks' %> | |
2 | + | |
3 | +<div class="task-processed"> | |
4 | +<h1><%= _("%s's processed tasks") % profile.name %></h1> | |
5 | + | |
6 | +<div class="task-processed-filter"> | |
7 | +<% | |
8 | + type_collection = [[nil, _('All')]] + @task_types | |
9 | +%> | |
10 | + <%= form_tag '#', :method => 'get' do %> | |
11 | + <%= field_set_tag _('Filter'), :class => 'filter_fields' do %> | |
12 | + <div> | |
13 | + <%= labelled_select(_('Type of task')+': ', 'filter[type]', :first, :last, @filter[:type], type_collection, {:id => 'filter-type'}) %> | |
14 | + <%= 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] ]) %> | |
15 | + </div> | |
16 | + | |
17 | + <div> | |
18 | + <%= labelled_text_field(_('Text Filter:'), 'filter[text]', @filter[:text]) %> | |
19 | + </div> | |
20 | + | |
21 | + <div> | |
22 | + <%= labelled_text_field(_('Requestor:'), 'filter[requestor]', @filter[:requestor]) %> | |
23 | + <%= labelled_text_field(_('Closed by:'), 'filter[closed_by]', @filter[:closed_by]) %> | |
24 | + </div> | |
25 | + | |
26 | + <%= 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' })) %> | |
27 | + <%= 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' })) %> | |
28 | + | |
29 | + <div class="actions"> | |
30 | + <%= submit_button(:search, _('Search')) %> | |
31 | + </div> | |
32 | + <% end %> | |
33 | + <% end %> | |
34 | +</div> | |
35 | + | |
36 | +<p> | |
37 | +<% if @tasks.empty? %> | |
38 | + <em><%= _('No processed tasks.') %></em> | |
39 | +<% else %> | |
40 | + <%= form_tag :controller => :proposals_discussion_plugin_tasks, :action => 'undo_flags', :method => 'post' do %> | |
41 | + <ul class="task-list"> | |
42 | + <% @tasks.each do |item| %> | |
43 | + <li class="task status-<%= item.status%>"> | |
44 | + <%= render :partial => partial_for_class(item.class, nil, 'processed'), :locals => {:task => item} %> | |
45 | + </li> | |
46 | + <% end %> | |
47 | + </ul> | |
48 | + <%= pagination_links(@tasks)%> | |
49 | + <input type="submit" name="commit" value="Restore" class="button with-text icon-child-article submit"> | |
50 | + <% end %> | |
51 | +<% end %> | |
52 | +</p> | |
53 | + | |
54 | +<% button_bar do %> | |
55 | + <%= button(:back, _('Back'), :action => 'index') %> | |
56 | +<% end %> | |
57 | + | |
58 | +</div> | ... | ... |
views/tasks/proposals_discussion_plugin/_proposal_task_processed.html.erb
-
I just think some error handling is missing.
We would just check for error in the controller call to the method ProposalTask #undo_flags
The method #undo_flag on ProposalTask isn't being used
-
Hello @abner. I made this changes that you suggested. The method
#undo_flag
was renamed toundo_flags
to remove flag of a specific proposal task or a array of tasks.So, you can use like this:
ProposalDiscussionPlugin::ProposalTask.undo_flags()
ortask.undo_flags()
.The unit tests for both situations was changed/created.
Please, verify if this feature it's ok now! :)