[Git][noosfero/noosfero][master] refactoring display_filter to filter all article of friends marked as show_to_followers

Leandro Nunes gitlab at gitlab.com
Mon Jul 20 14:12:02 BRT 2015


Leandro Nunes pushed to branch master at Noosfero / noosfero


Commits:
e833fc77 by Leandro Nunes dos Santos at 2015-07-20T14:11:23Z
refactoring display_filter to filter all article of friends marked as show_to_followers

- - - - -


6 changed files:

- app/models/article.rb
- plugins/event/lib/event_plugin/event_block.rb
- + plugins/event/test/test_helper.rb
- plugins/event/test/unit/event_block_test.rb
- plugins/event/test/unit/event_plugin_test.rb
- test/unit/article_test.rb


Changes:

=====================================
app/models/article.rb
=====================================
--- a/app/models/article.rb
+++ b/app/models/article.rb
@@ -504,9 +504,9 @@ class Article < ActiveRecord::Base
     where(
       [
        "published = ? OR last_changed_by_id = ? OR profile_id = ? OR ?
-        OR  (show_to_followers = ? AND ? AND profile_id = ?)", true, user.id, user.id,
+        OR  (show_to_followers = ? AND ? AND profile_id IN (?))", true, user.id, user.id,
         profile.nil? ?  false : user.has_permission?(:view_private_content, profile),
-        true, user.follows?(profile), (profile.nil? ? nil : profile.id)
+        true, (profile.nil? ? true : user.follows?(profile)),  ( profile.nil? ? (user.friends.select('profiles.id')) : [profile.id])
       ]
     )
   }


=====================================
plugins/event/lib/event_plugin/event_block.rb
=====================================
--- a/plugins/event/lib/event_plugin/event_block.rb
+++ b/plugins/event/lib/event_plugin/event_block.rb
@@ -26,8 +26,8 @@ class EventPlugin::EventBlock < Block
   end
 
   def events(user = nil)
-    events = events_source.events
-    events = events.published.order('start_date')
+    events = events_source.events.order('start_date')
+    events = user.nil? ? events.public : events.display_filter(user,nil)
 
     if future_only
       events = events.where('start_date >= ?', Date.today)


=====================================
plugins/event/test/test_helper.rb
=====================================
--- /dev/null
+++ b/plugins/event/test/test_helper.rb
@@ -0,0 +1 @@
+require_relative '../../../test/test_helper'


=====================================
plugins/event/test/unit/event_block_test.rb
=====================================
--- a/plugins/event/test/unit/event_block_test.rb
+++ b/plugins/event/test/unit/event_block_test.rb
@@ -1,6 +1,6 @@
-require File.dirname(__FILE__) + '/../../../../test/test_helper'
+require_relative '../test_helper'
 
-class EventPlugin::EventBlockTest < ActiveSupport::TestCase
+class EventBlockTest < ActiveSupport::TestCase
 
   def setup
     @env = Environment.default
@@ -165,7 +165,7 @@ class EventPlugin::EventBlockTest < ActiveSupport::TestCase
 
   def visibility_content_test_from_a_profile(profile)
     @block.box.owner = @env
-    ev = fast_create Event, :name => '2 de Julho', :profile_id => profile.id
+    ev = Event.create!(:name => '2 de Julho', :profile => profile)
     @block.all_env_events = true
 
     # Do not list event from private profile for non logged visitor


=====================================
plugins/event/test/unit/event_plugin_test.rb
=====================================
--- a/plugins/event/test/unit/event_plugin_test.rb
+++ b/plugins/event/test/unit/event_plugin_test.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/../../../../test/test_helper'
+require_relative '../test_helper'
 
 class EventPluginTest < ActiveSupport::TestCase
 


=====================================
test/unit/article_test.rb
=====================================
--- a/test/unit/article_test.rb
+++ b/test/unit/article_test.rb
@@ -1970,6 +1970,19 @@ class ArticleTest < ActiveSupport::TestCase
     assert_equal [a], Article.display_filter(user, p)
   end
 
+  should 'display_filter show person private content to friends when no profile is passed as parameter' do
+    user = create_user('someuser').person
+    p = fast_create(Person)
+    user.add_friend(p)
+    user.stubs(:has_permission?).with(:view_private_content, p).returns(false)
+    Article.delete_all
+    a = fast_create(Article, :published => false, :show_to_followers => true, :profile_id => p.id)
+    fast_create(Article, :published => false, :show_to_followers => false, :profile_id => p.id)
+    fast_create(Article, :published => false, :show_to_followers => false, :profile_id => p.id)
+    assert_equal [a], Article.display_filter(user, nil)
+  end
+
+
   should 'display_filter show community private content to members' do
     user = create_user('someuser').person
     p = fast_create(Community)



View it on GitLab: https://gitlab.com/noosfero/noosfero/commit/e833fc77060d5f80d0827677a472bb8949d40e9f
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150720/6e1b084e/attachment.html>


More information about the Noosfero-dev mailing list