[Git][noosfero/noosfero][master] 2 commits: Hide private profiles from blocks

Bráulio Bhavamitra gitlab at gitlab.com
Mon Aug 10 13:40:42 BRT 2015


Bráulio Bhavamitra pushed to branch master at Noosfero / noosfero


Commits:
bc24852b by Braulio Bhavamitra at 2015-08-10T12:25:18Z
Hide private profiles from blocks

- - - - -
9f253807 by Braulio Bhavamitra at 2015-08-10T13:39:54Z
Merge branch 'blogoosfero258' into noosfero

- - - - -


2 changed files:

- app/models/profile_list_block.rb
- test/unit/profile_list_block_test.rb


Changes:

=====================================
app/models/profile_list_block.rb
=====================================
--- a/app/models/profile_list_block.rb
+++ b/app/models/profile_list_block.rb
@@ -16,19 +16,19 @@ class ProfileListBlock < Block
 
   def profile_list
     result = nil
-    visible_profiles = profiles.visible.includes([:image,:domains,:preferred_domain,:environment])
+    public_profiles = profiles.public.includes([:image,:domains,:preferred_domain,:environment])
     if !prioritize_profiles_with_image
-      result = visible_profiles.all(:limit => get_limit, :order => 'profiles.updated_at DESC').sort_by{ rand }
+result = public_profiles.all(:limit => get_limit, :order => 'profiles.updated_at DESC').sort_by{ rand }
     elsif profiles.visible.with_image.count >= get_limit
-      result = visible_profiles.with_image.all(:limit => get_limit * 5, :order => 'profiles.updated_at DESC').sort_by{ rand }
+      result = public_profiles.with_image.all(:limit => get_limit * 5, :order => 'profiles.updated_at DESC').sort_by{ rand }
     else
-      result = visible_profiles.with_image.sort_by{ rand } + visible_profiles.without_image.all(:limit => get_limit * 5, :order => 'profiles.updated_at DESC').sort_by{ rand }
+      result = public_profiles.with_image.sort_by{ rand } + public_profiles.without_image.all(:limit => get_limit * 5, :order => 'profiles.updated_at DESC').sort_by{ rand }
     end
     result.slice(0..get_limit-1)
   end
 
   def profile_count
-    profiles.visible.length
+    profiles.public.length
   end
 
   # the title of the block. Probably will be overriden in subclasses.


=====================================
test/unit/profile_list_block_test.rb
=====================================
--- a/test/unit/profile_list_block_test.rb
+++ b/test/unit/profile_list_block_test.rb
@@ -77,7 +77,7 @@ class ProfileListBlockTest < ActiveSupport::TestCase
     block.save!
     assert_equal 'Title from block', block.view_title
   end
-  
+
   should 'provide view title with variables' do
     env = fast_create(Environment)
     env.boxes << Box.new
@@ -87,7 +87,7 @@ class ProfileListBlockTest < ActiveSupport::TestCase
     assert_equal '0 members', block.view_title
   end
 
-  should 'count number of public and private profiles' do
+  should 'count number of only public profiles' do
     env = fast_create(Environment)
     env.boxes << Box.new
     block = ProfileListBlock.new
@@ -103,7 +103,7 @@ class ProfileListBlockTest < ActiveSupport::TestCase
     priv_e = fast_create(Enterprise, :public_profile => false , :environment_id => env.id)
     pub_e = fast_create(Enterprise, :public_profile => true , :environment_id => env.id)
 
-    assert_equal 6, block.profile_count
+    assert_equal 3, block.profile_count
   end
 
   should 'only count number of visible profiles' do



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/fea4d5ef42cad7d46c19d65f821226b55fe358a9...9f25380720013b83ff64a484856f537aa8a8cbe9
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150810/12eac290/attachment.html>


More information about the Noosfero-dev mailing list