Commit fe715b1332ed72537d39d60664781db2834224e6

Authored by Victor Costa
2 parents a463ffe9 cee435f6

Merge branch 'target_detail' into 'master'

explicit target detail in task information

Now the tasks management are getting tasks of different profiles. In some cases we need to display the target detail to decide about task approval

See merge request !1012
app/helpers/application_helper.rb
@@ -964,11 +964,16 @@ module ApplicationHelper @@ -964,11 +964,16 @@ module ApplicationHelper
964 content_tag(:div, _('Source: %s') % source_url, :id => 'article-source') unless source_url.nil? 964 content_tag(:div, _('Source: %s') % source_url, :id => 'article-source') unless source_url.nil?
965 end 965 end
966 966
967 - def task_information(task) 967 + def task_information(task, params = {})
968 values = {} 968 values = {}
969 values.merge!(task.information[:variables]) if task.information[:variables] 969 values.merge!(task.information[:variables]) if task.information[:variables]
970 values.merge!({:requestor => link_to(task.requestor.name, task.requestor.url)}) if task.requestor 970 values.merge!({:requestor => link_to(task.requestor.name, task.requestor.url)}) if task.requestor
971 - values.merge!({:target => link_to(task.target.name, task.target.url)}) if (task.target && task.target.respond_to?(:url)) 971 + if (task.target && task.target.respond_to?(:url))
  972 + values.merge!({:target => link_to(task.target.name, task.target.url)})
  973 + target_detail = _("in %s").html_safe % values[:target]
  974 + target_detail = '' if task.target.identifier == params[:profile]
  975 + values.merge!({:target_detail => target_detail})
  976 + end
972 values.merge!({:subject => content_tag('span', task.subject, :class=>'task_target')}) if task.subject 977 values.merge!({:subject => content_tag('span', task.subject, :class=>'task_target')}) if task.subject
973 values.merge!({:linked_subject => link_to(content_tag('span', task.linked_subject[:text], :class => 'task_target'), task.linked_subject[:url])}) if task.linked_subject 978 values.merge!({:linked_subject => link_to(content_tag('span', task.linked_subject[:text], :class => 'task_target'), task.linked_subject[:url])}) if task.linked_subject
974 (task.information[:message] % values).html_safe 979 (task.information[:message] % values).html_safe
app/models/suggest_article.rb
@@ -65,7 +65,7 @@ class SuggestArticle < Task @@ -65,7 +65,7 @@ class SuggestArticle < Task
65 65
66 def information 66 def information
67 variables = requestor.blank? ? {:requestor => sender} : {} 67 variables = requestor.blank? ? {:requestor => sender} : {}
68 - { :message => _('%{requestor} suggested the publication of the article: %{subject}.').html_safe, 68 + { :message => _('%{requestor} suggested the publication %{target_detail} of the article: %{subject}.').html_safe,
69 :variables => variables } 69 :variables => variables }
70 end 70 end
71 71
app/views/profile_editor/_pending_tasks.html.erb
@@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
4 <div class='pending-tasks'> 4 <div class='pending-tasks'>
5 <h2><%= _('You have %s pending requests' % @pending_tasks.count) %></h2> 5 <h2><%= _('You have %s pending requests' % @pending_tasks.count) %></h2>
6 <ul> 6 <ul>
7 - <%= safe_join(@pending_tasks.limit(5).map {|task| content_tag('li', task_information(task).html_safe)}) %> 7 + <%= safe_join(@pending_tasks.limit(5).map {|task| content_tag('li', task_information(task, params).html_safe)}) %>
8 </ul> 8 </ul>
9 <%= button(:todo, _('Process requests'), :controller => 'tasks', :action => 'index') %> 9 <%= button(:todo, _('Process requests'), :controller => 'tasks', :action => 'index') %>
10 </div> 10 </div>
app/views/spam/_task.html.erb
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 <%= render :partial => 'tasks/task_icon', :locals => {:task => task} %> 2 <%= render :partial => 'tasks/task_icon', :locals => {:task => task} %>
3 <%= render :partial => 'tasks/task_title', :locals => {:task => task} %> 3 <%= render :partial => 'tasks/task_title', :locals => {:task => task} %>
4 <div class="task-information"> 4 <div class="task-information">
5 - <%= task_information(task) %> 5 + <%= task_information(task, params) %>
6 </div> 6 </div>
7 7
8 <%= yield %> <%# ??? %> 8 <%= yield %> <%# ??? %>
app/views/tasks/_task.html.erb
@@ -47,7 +47,7 @@ @@ -47,7 +47,7 @@
47 47
48 48
49 <div class="task_information"> 49 <div class="task_information">
50 - <%= task_information(task) %> 50 + <%= task_information(task, params) %>
51 </div> 51 </div>
52 52
53 <%= fields_for "tasks[#{task.id}][task]", task do |f| %> 53 <%= fields_for "tasks[#{task.id}][task]", task do |f| %>
app/views/tasks/_task_processed.html.erb
1 <div class="title"> 1 <div class="title">
2 - <%= task_information(task) %> 2 + <%= task_information(task, params) %>
3 </div> 3 </div>
4 <div class="status"> 4 <div class="status">
5 <%= _(Task::Status.names[task.status]) %> 5 <%= _(Task::Status.names[task.status]) %>
test/unit/application_helper_test.rb
@@ -545,12 +545,6 @@ class ApplicationHelperTest &lt; ActionView::TestCase @@ -545,12 +545,6 @@ class ApplicationHelperTest &lt; ActionView::TestCase
545 assert_equal ["1 for b", "2 for c", "3 for a"], unique_with_count(%w(a b c a c a)) 545 assert_equal ["1 for b", "2 for c", "3 for a"], unique_with_count(%w(a b c a c a))
546 end 546 end
547 547
548 - should 'show task information with the requestor' do  
549 - person = create_user('usertest').person  
550 - task = create(Task, :requestor => person)  
551 - assert_match person.name, task_information(task)  
552 - end  
553 -  
554 should 'return nil when :show_zoom_button_on_article_images is not enabled in environment' do 548 should 'return nil when :show_zoom_button_on_article_images is not enabled in environment' do
555 env = Environment.default 549 env = Environment.default
556 env.stubs(:enabled?).with(:show_zoom_button_on_article_images).returns(false) 550 env.stubs(:enabled?).with(:show_zoom_button_on_article_images).returns(false)
@@ -960,6 +954,37 @@ class ApplicationHelperTest &lt; ActionView::TestCase @@ -960,6 +954,37 @@ class ApplicationHelperTest &lt; ActionView::TestCase
960 refute current_editor_is?(nil) 954 refute current_editor_is?(nil)
961 end 955 end
962 956
  957 + should 'show task information with the requestor' do
  958 + person = create_user('usertest').person
  959 + task = create(Task, :requestor => person)
  960 + assert_match person.name, task_information(task)
  961 + end
  962 +
  963 + should 'show task information with variables information on suggest article tasks' do
  964 + person = create_user('usertest').person
  965 + task = create(SuggestArticle, :name => person.name, :target => person)
  966 + assert_match person.name, task_information(task)
  967 + end
  968 +
  969 + should 'show task information with target detail information on suggest article tasks' do
  970 + person = create_user('usertest').person
  971 + task = create(SuggestArticle, :target => person)
  972 + assert_match /in.*#{person.name}/, task_information(task)
  973 + end
  974 +
  975 + should "show task information without target detail information on suggest article tasks if it's in the same profile" do
  976 + profile = fast_create(Community)
  977 + task = create(SuggestArticle, :target => profile)
  978 + assert_no_match /in.*#{profile.name}/, task_information(task, {:profile => profile.identifier})
  979 + end
  980 +
  981 + should "show task information with target detail information on suggest article with profile parameter to another profile" do
  982 + profile = fast_create(Community)
  983 + another_profile = fast_create(Community)
  984 + task = create(SuggestArticle, :target => profile)
  985 + assert_match /in.*#{profile.name}/, task_information(task, {:profile => another_profile.identifier})
  986 + end
  987 +
963 protected 988 protected
964 include NoosferoTestHelper 989 include NoosferoTestHelper
965 990