[Git][noosfero/noosfero][master] 3 commits: explicit target detail in task information

Victor Costa gitlab at mg.gitlab.com
Wed Aug 31 14:43:44 BRT 2016


Victor Costa pushed to branch master at Noosfero / noosfero


Commits:
58a43daa by Leandro Nunes dos Santos at 2016-08-30T17:35:58-03:00
explicit target detail in task information

- - - - -
cee435f6 by Leandro Nunes dos Santos at 2016-08-30T18:49:12-03:00
passing params to task_information helper

- - - - -
fe715b13 by Victor Costa at 2016-08-31T17:43:21+00:00
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
- - - - -


7 changed files:

- app/helpers/application_helper.rb
- app/models/suggest_article.rb
- app/views/profile_editor/_pending_tasks.html.erb
- app/views/spam/_task.html.erb
- app/views/tasks/_task.html.erb
- app/views/tasks/_task_processed.html.erb
- test/unit/application_helper_test.rb


Changes:

=====================================
app/helpers/application_helper.rb
=====================================
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -964,11 +964,16 @@ module ApplicationHelper
     content_tag(:div, _('Source: %s') % source_url, :id => 'article-source') unless source_url.nil?
   end
 
-  def task_information(task)
+  def task_information(task, params = {})
     values = {}
     values.merge!(task.information[:variables]) if task.information[:variables]
     values.merge!({:requestor => link_to(task.requestor.name, task.requestor.url)}) if task.requestor
-    values.merge!({:target => link_to(task.target.name, task.target.url)}) if (task.target && task.target.respond_to?(:url))
+    if (task.target && task.target.respond_to?(:url))
+      values.merge!({:target => link_to(task.target.name, task.target.url)})
+      target_detail = _("in %s").html_safe % values[:target]
+      target_detail = '' if task.target.identifier == params[:profile]
+      values.merge!({:target_detail => target_detail}) 
+    end
     values.merge!({:subject => content_tag('span', task.subject, :class=>'task_target')}) if task.subject
     values.merge!({:linked_subject => link_to(content_tag('span', task.linked_subject[:text], :class => 'task_target'), task.linked_subject[:url])}) if task.linked_subject
     (task.information[:message] % values).html_safe


=====================================
app/models/suggest_article.rb
=====================================
--- a/app/models/suggest_article.rb
+++ b/app/models/suggest_article.rb
@@ -65,7 +65,7 @@ class SuggestArticle < Task
 
   def information
     variables = requestor.blank? ? {:requestor => sender} : {}
-    { :message => _('%{requestor} suggested the publication of the article: %{subject}.').html_safe,
+    { :message => _('%{requestor} suggested the publication %{target_detail} of the article: %{subject}.').html_safe,
       :variables => variables }
   end
 


=====================================
app/views/profile_editor/_pending_tasks.html.erb
=====================================
--- a/app/views/profile_editor/_pending_tasks.html.erb
+++ b/app/views/profile_editor/_pending_tasks.html.erb
@@ -4,7 +4,7 @@
   <div class='pending-tasks'>
     <h2><%= _('You have %s pending requests' % @pending_tasks.count) %></h2>
     <ul>
-      <%= safe_join(@pending_tasks.limit(5).map {|task| content_tag('li', task_information(task).html_safe)}) %>
+      <%= safe_join(@pending_tasks.limit(5).map {|task| content_tag('li', task_information(task, params).html_safe)}) %>
     </ul>
     <%= button(:todo, _('Process requests'), :controller => 'tasks', :action => 'index') %>
   </div>


=====================================
app/views/spam/_task.html.erb
=====================================
--- a/app/views/spam/_task.html.erb
+++ b/app/views/spam/_task.html.erb
@@ -2,7 +2,7 @@
   <%= render :partial => 'tasks/task_icon', :locals => {:task => task} %>
   <%= render :partial => 'tasks/task_title', :locals => {:task => task} %>
   <div class="task-information">
-    <%= task_information(task) %>
+    <%= task_information(task, params) %>
   </div>
 
   <%= yield %> <%# ??? %>


=====================================
app/views/tasks/_task.html.erb
=====================================
--- a/app/views/tasks/_task.html.erb
+++ b/app/views/tasks/_task.html.erb
@@ -47,7 +47,7 @@
 
 
   <div class="task_information">
-    <%= task_information(task) %>
+    <%= task_information(task, params) %>
   </div>
 
   <%= fields_for "tasks[#{task.id}][task]", task do |f| %>


=====================================
app/views/tasks/_task_processed.html.erb
=====================================
--- a/app/views/tasks/_task_processed.html.erb
+++ b/app/views/tasks/_task_processed.html.erb
@@ -1,5 +1,5 @@
 <div class="title">
-  <%= task_information(task) %>
+  <%= task_information(task, params) %>
 </div>
 <div class="status">
   <%= _(Task::Status.names[task.status]) %>


=====================================
test/unit/application_helper_test.rb
=====================================
--- a/test/unit/application_helper_test.rb
+++ b/test/unit/application_helper_test.rb
@@ -545,12 +545,6 @@ class ApplicationHelperTest < ActionView::TestCase
     assert_equal ["1 for b", "2 for c", "3 for a"], unique_with_count(%w(a b c a c a))
   end
 
-  should 'show task information with the requestor' do
-    person = create_user('usertest').person
-    task = create(Task, :requestor => person)
-    assert_match person.name, task_information(task)
-  end
-
   should 'return nil when :show_zoom_button_on_article_images is not enabled in environment' do
     env = Environment.default
     env.stubs(:enabled?).with(:show_zoom_button_on_article_images).returns(false)
@@ -960,6 +954,37 @@ class ApplicationHelperTest < ActionView::TestCase
     refute current_editor_is?(nil)
   end
 
+  should 'show task information with the requestor' do
+    person = create_user('usertest').person
+    task = create(Task, :requestor => person)
+    assert_match person.name, task_information(task)
+  end
+
+  should 'show task information with variables information on suggest article tasks' do
+    person = create_user('usertest').person
+    task = create(SuggestArticle, :name => person.name, :target => person)
+    assert_match person.name, task_information(task)
+  end
+
+  should 'show task information with target detail information on suggest article tasks' do
+    person = create_user('usertest').person
+    task = create(SuggestArticle, :target => person)
+    assert_match /in.*#{person.name}/, task_information(task)
+  end
+
+  should "show task information without target detail information on suggest article tasks if it's in the same profile" do
+    profile = fast_create(Community)
+    task = create(SuggestArticle, :target => profile)
+    assert_no_match /in.*#{profile.name}/, task_information(task, {:profile => profile.identifier})
+  end
+
+  should "show task information with target detail information on suggest article with profile parameter to another profile" do
+    profile = fast_create(Community)
+    another_profile = fast_create(Community)
+    task = create(SuggestArticle, :target => profile)
+    assert_match /in.*#{profile.name}/, task_information(task, {:profile => another_profile.identifier})
+  end
+
   protected
   include NoosferoTestHelper
 



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/a463ffe90058ef7793f127a3f7d4f10db473517e...fe715b1332ed72537d39d60664781db2834224e6
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160831/70f657e3/attachment-0001.html>


More information about the Noosfero-dev mailing list