Commit caf5954c86a60963bddeb41a0ed5ff324ebb6dad

Authored by Thiago Ribeiro
1 parent 12ab2e97

Change visibility to admins

- Admins now can be see secret profiles
- Secret profiles are hachured in searches
- closes #176

Signed-off-by: Artur Bersan de Faria <arturbersan@gmail.com>
Signed-off-by: Thiago Ribeiro <thiagitosouza@gmail.com>
Signed-off-by: Sabryna Sousa  <sabryna.sousa1323@gmail.com>
app/controllers/public/search_controller.rb
... ... @@ -244,7 +244,11 @@ class SearchController &lt; PublicController
244 244 def visible_profiles(klass, *extra_relations)
245 245 relations = [:image, :domains, :environment, :preferred_domain]
246 246 relations += extra_relations
247   - @environment.send(klass.name.underscore.pluralize).visible.includes(relations)
  247 + if current_user && current_user.person.is_admin?
  248 + @environment.send(klass.name.underscore.pluralize).includes(relations)
  249 + else
  250 + @environment.send(klass.name.underscore.pluralize).visible.includes(relations)
  251 + end
248 252 end
249 253  
250 254 def per_page
... ...
app/helpers/profile_image_helper.rb
... ... @@ -114,7 +114,12 @@ module ProfileImageHelper
114 114 end
115 115  
116 116 extra_info_tag = ''
117   - img_class = 'profile-image'
  117 +
  118 + if profile.secret?
  119 + img_class = 'profile-image secret-profile'
  120 + else
  121 + img_class = 'profile-image'
  122 + end
118 123  
119 124 if extra_info.is_a? Hash
120 125 extra_info_tag = content_tag( 'span', extra_info[:value], :class => 'extra_info '+extra_info[:class])
... ... @@ -137,4 +142,4 @@ module ProfileImageHelper
137 142 :title => profile.name ),
138 143 :class => 'vcard'), :class => 'common-profile-list-block')
139 144 end
140   -end
141 145 \ No newline at end of file
  146 +end
... ...
public/stylesheets/blocks/profile-list.scss
... ... @@ -83,6 +83,12 @@
83 83 vertical-align: middle;
84 84 height: 64px;
85 85 }
  86 +.common-profile-list-block .secret-profile {
  87 + background: url(../images/hachure.png);
  88 + opacity: 0.25;
  89 + filter: alpha(opacity=5);
  90 + zoom: 1;
  91 +}
86 92 .common-profile-list-block img {
87 93 border: none;
88 94 max-width: 50px;
... ...
test/functional/search_controller_test.rb
... ... @@ -541,6 +541,16 @@ class SearchControllerTest &lt; ActionController::TestCase
541 541 assert_equal [c2,c1,c3] , assigns(:searches)[:communities][:results]
542 542 end
543 543  
  544 + should "only admin can view invisible people" do
  545 + # assuming that all filters behave the same!
  546 + p1 = fast_create(Person, :visible => false)
  547 + admin = create_user('admin').person;
  548 + Environment.default.add_admin admin
  549 + login_as("admin")
  550 + get :people, :order => 'more_recent'
  551 + assert_includes assigns(:searches)[:people][:results], p1
  552 + end
  553 +
544 554 should "only include visible people in more_recent filter" do
545 555 # assuming that all filters behave the same!
546 556 p1 = fast_create(Person, :visible => false)
... ...
test/unit/profile_image_helper_test.rb
... ... @@ -135,4 +135,16 @@ class ProfileImageHelperTest &lt; ActionView::TestCase
135 135 NOOSFERO_CONF.stubs(:[]).with('gravatar').returns('nicevatar')
136 136 assert_equal gravatar_default, 'nicevatar'
137 137 end
138   -end
139 138 \ No newline at end of file
  139 +
  140 + should "secret-profile css applied in the secret profile image" do
  141 + @plugins = mock
  142 + @plugins.stubs(:dispatch_first).returns(false)
  143 + env = Environment.default
  144 + stubs(:environment).returns(env)
  145 + stubs(:profile).returns(profile)
  146 + profile = fast_create(Community, :environment_id => env.id, :secret => true)
  147 + info = {:value =>_('New'), :class => 'new-profile'}
  148 + html = profile_image_link(profile, size=:portrait, tag='li', extra_info = info)
  149 + assert_tag_in_string html, :tag => 'span', :attributes => { :class => 'profile-image secret-profile new-profile' }
  150 + end
  151 +end
... ...