Commit 1f9140cd38a89fe45b7b3fa14dbba49101de72b3

Authored by Daniela Feitosa
Committed by Antonio Terceiro
1 parent f72561ee

Allowing private users/organizations to be viewed

  * Added migration to add visible to profiles
  * Some improvements on profile screen
  * A private profile displays a different profile screen
    * added profile image, name, description and message
    * added link to join if profile is a community
    * added link to "add friend" if profile is a person
  * Added description in profile
  * Added field description to organization and person form
  * Removed link and added button on not_found page
  * Added css for not access_denied message
  * Changed css for flash messages
  * Recent articles doens't list private profile's articles
  * Private profiles are listed on blocks and searches
  * Invisible profiles are never listed
  * Join community popup will be displayed if profile is private
  * Join community popup will not be displayed if profile is invisible
  * If an organization is private, it is also closed
Showing 50 changed files with 717 additions and 209 deletions   Show diff stats
app/controllers/public/content_viewer_controller.rb
@@ -47,7 +47,13 @@ class ContentViewerController < ApplicationController @@ -47,7 +47,13 @@ class ContentViewerController < ApplicationController
47 end 47 end
48 48
49 if !@page.display_to?(user) 49 if !@page.display_to?(user)
50 - render_access_denied(_('You are not allowed to view this content. You can contact the owner of this profile to request access then.')) 50 + if profile.display_info_to?(user) || !profile.visible?
  51 + message = _('You are not allowed to view this content. You can contact the owner of this profile to request access then.')
  52 + render_access_denied(message)
  53 + elsif !profile.public?
  54 + redirect_to :controller => 'profile', :action => 'index', :profile => profile.identifier
  55 + end
  56 + return
51 end 57 end
52 58
53 # At this point the page will be showed 59 # At this point the page will be showed
app/controllers/public/profile_controller.rb
1 class ProfileController < PublicController 1 class ProfileController < PublicController
2 2
3 needs_profile 3 needs_profile
4 - before_filter :check_access_to_profile 4 + before_filter :check_access_to_profile, :except => [:join, :refuse_join, :refuse_for_now, :index]
5 before_filter :store_before_join, :only => [:join] 5 before_filter :store_before_join, :only => [:join]
6 before_filter :login_required, :only => [:join, :refuse_join, :leave] 6 before_filter :login_required, :only => [:join, :refuse_join, :leave]
7 7
@@ -9,6 +9,9 @@ class ProfileController &lt; PublicController @@ -9,6 +9,9 @@ class ProfileController &lt; PublicController
9 9
10 def index 10 def index
11 @tags = profile.article_tags 11 @tags = profile.article_tags
  12 + unless profile.display_info_to?(user)
  13 + profile.visible? ? private_profile : invisible_profile
  14 + end
12 end 15 end
13 16
14 def tags 17 def tags
@@ -112,7 +115,7 @@ class ProfileController &lt; PublicController @@ -112,7 +115,7 @@ class ProfileController &lt; PublicController
112 115
113 def check_access_to_profile 116 def check_access_to_profile
114 unless profile.display_info_to?(user) 117 unless profile.display_info_to?(user)
115 - render_access_denied(_("Sorry, this profile was defined as private by its owner. You'll not be able to view content here unless the profile owner adds you."), _("Oops ... you cannot go ahead here")) 118 + redirect_to :action => 'index'
116 end 119 end
117 end 120 end
118 121
@@ -130,6 +133,21 @@ class ProfileController &lt; PublicController @@ -130,6 +133,21 @@ class ProfileController &lt; PublicController
130 end 133 end
131 end 134 end
132 135
  136 + def private_profile
  137 + if profile.person?
  138 + @action = :add_friend
  139 + @message = _("The content here is available to %s's friends only." % profile.short_name)
  140 + else
  141 + @action = :join
  142 + @message = _('The contents in this community is available to members only.')
  143 + end
  144 + @no_design_blocks = true
  145 + end
  146 +
  147 + def invisible_profile
  148 + render_access_denied(_("Sorry, this profile was defined as private by its owner. You'll not be able to view content here unless the profile owner adds adds you."), _("Oops ... you cannot go ahead here"))
  149 + end
  150 +
133 def per_page 151 def per_page
134 Noosfero::Constants::PROFILE_PER_PAGE 152 Noosfero::Constants::PROFILE_PER_PAGE
135 end 153 end
app/models/article.rb
@@ -125,8 +125,9 @@ class Article &lt; ActiveRecord::Base @@ -125,8 +125,9 @@ class Article &lt; ActiveRecord::Base
125 "advertise = ? AND 125 "advertise = ? AND
126 public_article = ? AND 126 public_article = ? AND
127 published = ? AND 127 published = ? AND
  128 + profiles.visible = ? AND
128 profiles.public_profile = ? AND 129 profiles.public_profile = ? AND
129 - ((articles.type != ? and articles.type != ? and articles.type != ?) OR articles.type is NULL)", true, true, true, true, 'UploadedFile', 'RssFeed', 'Blog' 130 + ((articles.type != ? and articles.type != ? and articles.type != ?) OR articles.type is NULL)", true, true, true, true, true, 'UploadedFile', 'RssFeed', 'Blog'
130 ], 131 ],
131 :include => 'profile', 132 :include => 'profile',
132 :order => 'articles.published_at desc, articles.id desc' 133 :order => 'articles.published_at desc, articles.id desc'
@@ -220,6 +221,8 @@ class Article &lt; ActiveRecord::Base @@ -220,6 +221,8 @@ class Article &lt; ActiveRecord::Base
220 false 221 false
221 end 222 end
222 223
  224 + named_scope :folders, :conditions => { :type => ['Folder', 'Blog'] }
  225 +
223 def display_to?(user) 226 def display_to?(user)
224 if self.public_article 227 if self.public_article
225 self.profile.display_info_to?(user) 228 self.profile.display_info_to?(user)
@@ -249,7 +252,7 @@ class Article &lt; ActiveRecord::Base @@ -249,7 +252,7 @@ class Article &lt; ActiveRecord::Base
249 end 252 end
250 253
251 def public? 254 def public?
252 - profile.public? && public_article 255 + profile.visible? && profile.public? && public_article
253 end 256 end
254 257
255 def copy(options) 258 def copy(options)
app/models/communities_block.rb
@@ -34,9 +34,9 @@ class CommunitiesBlock &lt; ProfileListBlock @@ -34,9 +34,9 @@ class CommunitiesBlock &lt; ProfileListBlock
34 34
35 def profile_count 35 def profile_count
36 if owner.kind_of?(Environment) 36 if owner.kind_of?(Environment)
37 - owner.communities.count(:conditions => { :public_profile => true }) 37 + owner.communities.count(:conditions => { :visible => true })
38 else 38 else
39 - owner.communities(:public_profile => true).count 39 + owner.communities(:visible => true).count
40 end 40 end
41 end 41 end
42 42
@@ -49,9 +49,9 @@ class CommunitiesBlock &lt; ProfileListBlock @@ -49,9 +49,9 @@ class CommunitiesBlock &lt; ProfileListBlock
49 # FIXME when owner is an environment (i.e. listing communities globally 49 # FIXME when owner is an environment (i.e. listing communities globally
50 # this can become SLOW) 50 # this can become SLOW)
51 if block.owner.kind_of?(Environment) 51 if block.owner.kind_of?(Environment)
52 - Community.find(:all, :conditions => {:environment_id => block.owner.id, :public_profile => true}, :limit => block.limit, :order => 'random()').map(&:id) 52 + block.owner.communities.all(:conditions => {:visible => true}, :limit => block.limit, :order => 'random()').map(&:id)
53 else 53 else
54 - block.owner.communities.select(&:public_profile).map(&:id) 54 + block.owner.communities(:visible => true).map(&:id)
55 end 55 end
56 end 56 end
57 end 57 end
app/models/community.rb
@@ -2,7 +2,6 @@ class Community &lt; Organization @@ -2,7 +2,6 @@ class Community &lt; Organization
2 N_('Community') 2 N_('Community')
3 N_('Language') 3 N_('Language')
4 4
5 - settings_items :description  
6 settings_items :language 5 settings_items :language
7 settings_items :zip_code, :city, :state, :country 6 settings_items :zip_code, :city, :state, :country
8 7
@@ -28,7 +27,6 @@ class Community &lt; Organization @@ -28,7 +27,6 @@ class Community &lt; Organization
28 state 27 state
29 country 28 country
30 zip_code 29 zip_code
31 - description  
32 language 30 language
33 ] 31 ]
34 32
app/models/enterprises_block.rb
@@ -30,9 +30,9 @@ class EnterprisesBlock &lt; ProfileListBlock @@ -30,9 +30,9 @@ class EnterprisesBlock &lt; ProfileListBlock
30 30
31 def profile_count 31 def profile_count
32 if owner.kind_of?(Environment) 32 if owner.kind_of?(Environment)
33 - owner.enterprises.count(:conditions => { :public_profile => true }) 33 + owner.enterprises.count(:conditions => { :visible => true })
34 else 34 else
35 - owner.enterprises(:public_profile => true).count 35 + owner.enterprises(:visible => true).count
36 end 36 end
37 37
38 end 38 end
@@ -46,9 +46,9 @@ class EnterprisesBlock &lt; ProfileListBlock @@ -46,9 +46,9 @@ class EnterprisesBlock &lt; ProfileListBlock
46 # FIXME when owner is an environment (i.e. listing enterprises globally 46 # FIXME when owner is an environment (i.e. listing enterprises globally
47 # this can become SLOW) 47 # this can become SLOW)
48 if block.owner.kind_of?(Environment) 48 if block.owner.kind_of?(Environment)
49 - Enterprise.find(:all, :conditions => {:environment_id => block.owner.id, :public_profile => true}, :limit => block.limit, :order => 'random()').map(&:id) 49 + block.owner.enterprises.all(:conditions => {:visible => true}, :limit => block.limit, :order => 'random()').map(&:id)
50 else 50 else
51 - block.owner.enterprises.select(&:public_profile).map(&:id) 51 + block.owner.enterprises.select(&:visible).map(&:id)
52 end 52 end
53 end 53 end
54 end 54 end
app/models/environment.rb
@@ -683,11 +683,11 @@ class Environment &lt; ActiveRecord::Base @@ -683,11 +683,11 @@ class Environment &lt; ActiveRecord::Base
683 683
684 def create_templates 684 def create_templates
685 pre = self.name.to_slug + '_' 685 pre = self.name.to_slug + '_'
686 - ent_id = Enterprise.create!(:name => 'Enterprise template', :identifier => pre + 'enterprise_template', :environment => self, :public_profile => false).id  
687 - com_id = Community.create!(:name => 'Community template', :identifier => pre + 'community_template', :environment => self, :public_profile => false).id 686 + ent_id = Enterprise.create!(:name => 'Enterprise template', :identifier => pre + 'enterprise_template', :environment => self, :visible => false).id
  687 + com_id = Community.create!(:name => 'Community template', :identifier => pre + 'community_template', :environment => self, :visible => false).id
688 pass = Digest::MD5.hexdigest rand.to_s 688 pass = Digest::MD5.hexdigest rand.to_s
689 user = User.create!(:login => (pre + 'person_template'), :email => (pre + 'template@template.noo'), :password => pass, :password_confirmation => pass, :environment => self).person 689 user = User.create!(:login => (pre + 'person_template'), :email => (pre + 'template@template.noo'), :password => pass, :password_confirmation => pass, :environment => self).person
690 - user.public_profile = false 690 + user.visible = false
691 user.save! 691 user.save!
692 usr_id = user.id 692 usr_id = user.id
693 self.settings[:enterprise_template_id] = ent_id 693 self.settings[:enterprise_template_id] = ent_id
app/models/environment_statistics_block.rb
@@ -13,9 +13,9 @@ class EnvironmentStatisticsBlock &lt; Block @@ -13,9 +13,9 @@ class EnvironmentStatisticsBlock &lt; Block
13 end 13 end
14 14
15 def content 15 def content
16 - users = owner.people.count(:conditions => { :public_profile => true })  
17 - enterprises = owner.enterprises.count(:conditions => { :public_profile => true })  
18 - communities = owner.communities.count(:conditions => { :public_profile => true }) 16 + users = owner.people.visible.count
  17 + enterprises = owner.enterprises.visible.count
  18 + communities = owner.communities.visible.count
19 19
20 info = [ 20 info = [
21 n_('One user', '%{num} users', users) % { :num => users }, 21 n_('One user', '%{num} users', users) % { :num => users },
app/models/friends_block.rb
@@ -30,7 +30,7 @@ class FriendsBlock &lt; ProfileListBlock @@ -30,7 +30,7 @@ class FriendsBlock &lt; ProfileListBlock
30 end 30 end
31 31
32 def profile_count 32 def profile_count
33 - owner.friends.count(:conditions => { :public_profile => true }) 33 + owner.friends.visible.count
34 end 34 end
35 35
36 end 36 end
app/models/members_block.rb
@@ -20,7 +20,7 @@ class MembersBlock &lt; ProfileListBlock @@ -20,7 +20,7 @@ class MembersBlock &lt; ProfileListBlock
20 end 20 end
21 21
22 def profile_count 22 def profile_count
23 - owner.members.select {|member| member.public_profile? }.count 23 + owner.members.select {|member| member.visible? }.count
24 end 24 end
25 25
26 def profile_finder 26 def profile_finder
@@ -30,7 +30,7 @@ class MembersBlock &lt; ProfileListBlock @@ -30,7 +30,7 @@ class MembersBlock &lt; ProfileListBlock
30 # Finds random members, up to the limit. 30 # Finds random members, up to the limit.
31 class Finder < ProfileListBlock::Finder 31 class Finder < ProfileListBlock::Finder
32 def ids 32 def ids
33 - block.owner.members.map(&:id) 33 + block.owner.members.select {|member| member.visible? }.map(&:id)
34 end 34 end
35 end 35 end
36 36
app/models/organization.rb
@@ -6,6 +6,10 @@ class Organization &lt; Profile @@ -6,6 +6,10 @@ class Organization &lt; Profile
6 closed 6 closed
7 end 7 end
8 8
  9 + before_save do |organization|
  10 + organization.closed = true if !organization.public_profile?
  11 + end
  12 +
9 settings_items :moderated_articles, :type => :boolean, :default => false 13 settings_items :moderated_articles, :type => :boolean, :default => false
10 def moderated_articles? 14 def moderated_articles?
11 moderated_articles 15 moderated_articles
@@ -47,6 +51,7 @@ class Organization &lt; Profile @@ -47,6 +51,7 @@ class Organization &lt; Profile
47 contact_person 51 contact_person
48 contact_phone 52 contact_phone
49 contact_email 53 contact_email
  54 + description
50 legal_form 55 legal_form
51 economic_activity 56 economic_activity
52 management_information 57 management_information
app/models/people_block.rb
@@ -18,7 +18,7 @@ class PeopleBlock &lt; ProfileListBlock @@ -18,7 +18,7 @@ class PeopleBlock &lt; ProfileListBlock
18 18
19 class Finder < ProfileListBlock::Finder 19 class Finder < ProfileListBlock::Finder
20 def ids 20 def ids
21 - Person.find(:all, :select => 'id', :conditions => { :environment_id => block.owner.id, :public_profile => true}, :limit => block.limit, :order => 'random()') 21 + block.owner.people.visible.all(:limit => block.limit, :order => 'random()').map(&:id)
22 end 22 end
23 end 23 end
24 24
@@ -29,7 +29,7 @@ class PeopleBlock &lt; ProfileListBlock @@ -29,7 +29,7 @@ class PeopleBlock &lt; ProfileListBlock
29 end 29 end
30 30
31 def profile_count 31 def profile_count
32 - owner.people.count(:conditions => {:public_profile => true}) 32 + owner.people.visible.count
33 end 33 end
34 34
35 end 35 end
app/models/person.rb
@@ -66,6 +66,7 @@ class Person &lt; Profile @@ -66,6 +66,7 @@ class Person &lt; Profile
66 custom_formation 66 custom_formation
67 contact_phone 67 contact_phone
68 contact_information 68 contact_information
  69 + description
69 ] 70 ]
70 71
71 def self.fields 72 def self.fields
@@ -121,6 +122,7 @@ class Person &lt; Profile @@ -121,6 +122,7 @@ class Person &lt; Profile
121 end 122 end
122 123
123 def memberships(conditions = {}) 124 def memberships(conditions = {})
  125 + # FIXME this should be a proper ActiveRecord relationship!
124 Profile.find( 126 Profile.find(
125 :all, 127 :all,
126 :conditions => self.class.conditions_for_profiles(conditions, self), 128 :conditions => self.class.conditions_for_profiles(conditions, self),
@@ -236,7 +238,7 @@ class Person &lt; Profile @@ -236,7 +238,7 @@ class Person &lt; Profile
236 has_and_belongs_to_many :refused_communities, :class_name => 'Community', :join_table => 'refused_join_community' 238 has_and_belongs_to_many :refused_communities, :class_name => 'Community', :join_table => 'refused_join_community'
237 239
238 def ask_to_join?(community) 240 def ask_to_join?(community)
239 - return false if !community.public_profile 241 + return false if !community.visible?
240 return false if memberships.include?(community) 242 return false if memberships.include?(community)
241 return false if AddMember.find(:first, :conditions => {:requestor_id => self.id, :target_id => community.id}) 243 return false if AddMember.find(:first, :conditions => {:requestor_id => self.id, :target_id => community.id})
242 !refused_communities.include?(community) 244 !refused_communities.include?(community)
app/models/profile.rb
@@ -53,6 +53,8 @@ class Profile &lt; ActiveRecord::Base @@ -53,6 +53,8 @@ class Profile &lt; ActiveRecord::Base
53 53
54 acts_as_taggable 54 acts_as_taggable
55 55
  56 + named_scope :visible, :conditions => { :visible => true }
  57 +
56 # FIXME ugly workaround 58 # FIXME ugly workaround
57 def self.human_attribute_name(attrib) 59 def self.human_attribute_name(attrib)
58 _(self.superclass.human_attribute_name(attrib)) 60 _(self.superclass.human_attribute_name(attrib))
@@ -73,6 +75,9 @@ class Profile &lt; ActiveRecord::Base @@ -73,6 +75,9 @@ class Profile &lt; ActiveRecord::Base
73 acts_as_having_settings :field => :data 75 acts_as_having_settings :field => :data
74 76
75 settings_items :public_content, :type => :boolean, :default => true 77 settings_items :public_content, :type => :boolean, :default => true
  78 + settings_items :description
  79 +
  80 + validates_length_of :description, :maximum => 550, :allow_nil => true
76 81
77 acts_as_mappable :default_units => :kms 82 acts_as_mappable :default_units => :kms
78 83
@@ -283,7 +288,7 @@ class Profile &lt; ActiveRecord::Base @@ -283,7 +288,7 @@ class Profile &lt; ActiveRecord::Base
283 self.save_without_validation! 288 self.save_without_validation!
284 end 289 end
285 290
286 - xss_terminate :only => [ :name, :nickname, :address, :contact_phone ] 291 + xss_terminate :only => [ :name, :nickname, :address, :contact_phone, :description ]
287 xss_terminate :only => [ :custom_footer, :custom_header ], :with => 'white_list' 292 xss_terminate :only => [ :custom_footer, :custom_header ], :with => 'white_list'
288 293
289 # returns the contact email for this profile. 294 # returns the contact email for this profile.
@@ -508,15 +513,10 @@ private :generate_url, :url_options @@ -508,15 +513,10 @@ private :generate_url, :url_options
508 # returns +true+ if the given +user+ can see profile information about this 513 # returns +true+ if the given +user+ can see profile information about this
509 # +profile+, and +false+ otherwise. 514 # +profile+, and +false+ otherwise.
510 def display_info_to?(user) 515 def display_info_to?(user)
511 - if self.public_profile 516 + if self.public?
512 true 517 true
513 else 518 else
514 - if user.nil?  
515 - false  
516 - else  
517 - # other possibilities would come here  
518 - (user == self) || (user.is_admin?(self.environment)) || (user.memberships.include?(self))  
519 - end 519 + display_private_info_to?(user)
520 end 520 end
521 end 521 end
522 522
@@ -587,7 +587,11 @@ private :generate_url, :url_options @@ -587,7 +587,11 @@ private :generate_url, :url_options
587 end 587 end
588 588
589 def public? 589 def public?
590 - public_profile 590 + visible && public_profile
  591 + end
  592 +
  593 + def privacy_setting
  594 + self.public? ? _('Public profile') : _('Private profile')
591 end 595 end
592 596
593 def themes 597 def themes
@@ -623,7 +627,11 @@ private :generate_url, :url_options @@ -623,7 +627,11 @@ private :generate_url, :url_options
623 end 627 end
624 628
625 def folders 629 def folders
626 - self.articles.find(:all, :conditions => ['type in (?)', ['Folder', 'Blog']]) 630 + articles.folders
  631 + end
  632 +
  633 + def image_galleries
  634 + folders.select { |folder| folder.display_as_gallery?}
627 end 635 end
628 636
629 def blocks_to_expire_cache 637 def blocks_to_expire_cache
@@ -668,4 +676,13 @@ private :generate_url, :url_options @@ -668,4 +676,13 @@ private :generate_url, :url_options
668 self.update_attribute(:layout_template, template) 676 self.update_attribute(:layout_template, template)
669 end 677 end
670 678
  679 + protected
  680 +
  681 + def display_private_info_to?(user)
  682 + if user.nil?
  683 + false
  684 + else
  685 + (user == self) || (user.is_admin?(self.environment)) || (user.memberships.include?(self))
  686 + end
  687 + end
671 end 688 end
app/models/profile_list_block.rb
@@ -42,7 +42,7 @@ class ProfileListBlock &lt; Block @@ -42,7 +42,7 @@ class ProfileListBlock &lt; Block
42 rand(top) 42 rand(top)
43 end 43 end
44 def ids 44 def ids
45 - Profile.find(:all, :limit => block.limit, :order => 'random()', :conditions => {:environment_id => block.owner.id, :public_profile => true}).map(&:id) 45 + block.owner.profiles.visible.all(:limit => block.limit, :order => 'random()').map(&:id)
46 end 46 end
47 end 47 end
48 48
@@ -90,7 +90,7 @@ class ProfileListBlock &lt; Block @@ -90,7 +90,7 @@ class ProfileListBlock &lt; Block
90 end 90 end
91 91
92 def profile_count 92 def profile_count
93 - owner.profiles.count(:conditions => {:public_profile => true}) 93 + owner.profiles.visible.count
94 end 94 end
95 95
96 end 96 end
app/views/blocks/my_network/person.rhtml
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 content_tag('b', owner.articles.count), owner.public_profile_url.merge(:action => 'sitemap') ) %></li> 3 content_tag('b', owner.articles.count), owner.public_profile_url.merge(:action => 'sitemap') ) %></li>
4 <li><%= link_to(n__('One friend', '%s friends', owner.friends.count) % 4 <li><%= link_to(n__('One friend', '%s friends', owner.friends.count) %
5 content_tag('b', owner.friends.count), owner.public_profile_url.merge(:action => 'friends')) %></li> 5 content_tag('b', owner.friends.count), owner.public_profile_url.merge(:action => 'friends')) %></li>
6 - <li><%= link_to(n__('One community', '%{num} communities', owner.communities.size) % 6 + <li><%= link_to(n__('One community', '%{num} communities', owner.communities(:visible => true).size) %
7 {:num => content_tag('b', owner.communities.size)}, owner.public_profile_url.merge(:action => 'communities')) %></li> 7 {:num => content_tag('b', owner.communities.size)}, owner.public_profile_url.merge(:action => 'communities')) %></li>
8 <li><%= link_to(n_('One tag', '%s tags', owner.article_tags.size) % 8 <li><%= link_to(n_('One tag', '%s tags', owner.article_tags.size) %
9 content_tag('b', owner.article_tags.size), owner.public_profile_url.merge(:action => 'tags')) %></li> 9 content_tag('b', owner.article_tags.size), owner.public_profile_url.merge(:action => 'tags')) %></li>
app/views/profile/_organization.rhtml
1 <tr> 1 <tr>
2 <th colspan='2'><%= _('Basic information')%></th> 2 <th colspan='2'><%= _('Basic information')%></th>
3 </tr> 3 </tr>
4 -<%= display_field(_('Name:'), profile, :name) { |name| link_to name, profile.url } %> 4 +<%= display_field(_('Description:'), profile, :description) if !@action %>
  5 +
5 <tr> 6 <tr>
6 - <td></td> 7 + <td class='field-name'><%= _('Members') %></td>
7 <td> 8 <td>
8 - <%= link_to _('Members') + " (%s)" % profile.members.count, :controller => 'profile', :action => 'members' %> 9 + <%= link_to profile.members.count, :controller => 'profile', :action => 'members' %>
9 </td> 10 </td>
10 </tr> 11 </tr>
  12 +
  13 +<%= display_field(_('Type:'), profile, :privacy_setting, true) %>
  14 +
  15 +<%= display_field(_('Location:'), profile, :location, true) %>
  16 +
  17 +<tr>
  18 + <td class='field-name'><%= _('Created at:') %></td>
  19 + <td><%= show_date(profile.created_at) %></td>
  20 +</tr>
  21 +
11 <% if profile.kind_of?(Enterprise) && !profile.environment.enabled?('disable_products_for_enterprises') %> 22 <% if profile.kind_of?(Enterprise) && !profile.environment.enabled?('disable_products_for_enterprises') %>
12 <tr> 23 <tr>
13 <td></td> 24 <td></td>
@@ -16,3 +27,10 @@ @@ -16,3 +27,10 @@
16 </td> 27 </td>
17 </tr> 28 </tr>
18 <% end %> 29 <% end %>
  30 +
  31 +<tr>
  32 + <td class='field-name'><%= _('Administrators:') %></td>
  33 + <td>
  34 + <%= profile.admins.map { |admin| link_to(admin.short_name, admin.url)}.join(', ') %>
  35 + </td>
  36 +</tr>
app/views/profile/_person.rhtml
1 <tr> 1 <tr>
2 <th colspan='2'><%= _('Basic information')%></th> 2 <th colspan='2'><%= _('Basic information')%></th>
3 </tr> 3 </tr>
4 -<%= display_field(_('Name:'), profile, :name, true) { |name| link_to name, profile.url } %> 4 +<%= display_field(_('About:'), profile, :description) if !@action %>
5 <%= display_field(_('Sex:'), profile, :sex) { |gender| { 'male' => _('Male'), 'female' => _('Female') }[gender] } %> 5 <%= display_field(_('Sex:'), profile, :sex) { |gender| { 'male' => _('Male'), 'female' => _('Female') }[gender] } %>
6 <%= display_field(_('Date of birth:'), profile, :birth_date) { |date| show_date(date) }%> 6 <%= display_field(_('Date of birth:'), profile, :birth_date) { |date| show_date(date) }%>
7 <%= display_field(_('Location:'), profile, :location, true) %> 7 <%= display_field(_('Location:'), profile, :location, true) %>
8 8
  9 +<%= display_field(_('Type:'), profile, :privacy_setting, true) %>
  10 +
  11 +<tr>
  12 + <td class='field-name'><%= _('Created at:') %></td>
  13 + <td><%= show_date(profile.created_at) %></td>
  14 +</tr>
  15 +
9 <% if profile == user || profile.friends.include?(user) %> 16 <% if profile == user || profile.friends.include?(user) %>
10 <tr> 17 <tr>
11 <th colspan='2'><%= _('Contact')%></th> 18 <th colspan='2'><%= _('Contact')%></th>
@@ -42,12 +49,12 @@ @@ -42,12 +49,12 @@
42 <th colspan='2'><%= _('Network')%></th> 49 <th colspan='2'><%= _('Network')%></th>
43 </tr> 50 </tr>
44 <tr> 51 <tr>
45 - <td></td>  
46 - <td><%= link_to __('Friends') + (' (%d)' % profile.friends.count), { :controller => 'profile', :action => 'friends' } %></td> 52 + <td><%= __('Friends') + ':' %></td>
  53 + <td><%= link_to profile.friends.count, { :controller => 'profile', :action => 'friends' } %></td>
47 </tr> 54 </tr>
48 <tr> 55 <tr>
49 - <td></td>  
50 - <td><%= link_to __('Communities') + (' (%d)' % profile.communities.count), :controller => "profile", :action => 'communities' %></td> 56 + <td><%= __('Communities') + ':' %></td>
  57 + <td><%= link_to profile.communities.count, :controller => "profile", :action => 'communities' %></td>
51 </tr> 58 </tr>
52 59
53 <% if !environment.enabled?('disable_categories') && !profile.interests.empty? %> 60 <% if !environment.enabled?('disable_categories') && !profile.interests.empty? %>
app/views/profile/_private_profile.rhtml 0 → 100644
@@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
  1 +<div class='profile-picture' style='float: left; margin-top: 5px'>
  2 + <%= profile_image(profile, :big) %>
  3 +</div>
  4 +
  5 +<div class='private-profile-message'><%= @message %></div>
  6 +<div class='private-profile-description'><%= profile.description %></div>
  7 +
  8 +<% button_bar do %>
  9 + <% if @action == :join && logged_in? %>
  10 + <%= lightbox_link_to content_tag('span', _('Join')), profile.join_url, :class => 'button with-text icon-add', :title => _('Join this community') %>
  11 + <% end %>
  12 + <% if @action == :add_friend && logged_in? && !user.already_request_friendship?(profile) %>
  13 + <%= link_to content_tag('span', __('Add friend')), user.url.merge(:controller => 'friends', :action => 'add', :id => profile.id), :class => 'button with-text icon-add' %>
  14 + <% end %>
  15 + <%= button :back, _('Go back'), :back %>
  16 + <%= button :home, _("Go to %s home page") % environment.name, :controller => 'home' %>
  17 +<% end %>
app/views/profile/index.rhtml
@@ -4,38 +4,66 @@ @@ -4,38 +4,66 @@
4 </div> 4 </div>
5 <% end %> 5 <% end %>
6 6
7 -<h1><%= _("%s's profile") % profile.name %></h1> 7 +<h1><%= profile.name %></h1>
  8 +
  9 +<% if @action %>
  10 + <%= render :partial => 'private_profile' %>
  11 +<% end %>
8 12
9 <table class='profile'> 13 <table class='profile'>
10 <%= render :partial => partial_for_class(profile.class) %> 14 <%= render :partial => partial_for_class(profile.class) %>
11 - <% cache_timeout(profile.identifier + '-profile-general-info', 4.hours.from_now) do %>  
12 - <tr>  
13 - <th colspan='2'>  
14 - <%= _('Content') %>  
15 - </th>  
16 - </tr>  
17 - <tr>  
18 - <td>  
19 - <%= _('Content published:') %>  
20 - </td>  
21 - <td>  
22 - <%= link_to _('Site map'), :controller => 'profile', :action => 'sitemap' %>  
23 - </td>  
24 - </tr>  
25 - <tr>  
26 - <td>  
27 - </td>  
28 - <td>  
29 - <%= link_to _('Events'), :controller => 'events', :action => 'events' %>  
30 - </td>  
31 - </tr>  
32 - <tr>  
33 - <td>  
34 - <%= _('Tags:') %>  
35 - </td>  
36 - <td>  
37 - <%= tag_cloud @tags, :id, { :action => 'tag' }, :max_size => 18, :min_size => 10%>  
38 - </td>  
39 - </tr> 15 +
  16 + <% unless @action %>
  17 + <% cache_timeout(profile.identifier + '-profile-general-info', 4.hours.from_now) do %>
  18 + <tr>
  19 + <th colspan='2'>
  20 + <%= _('Content') %>
  21 + </th>
  22 + </tr>
  23 +
  24 + <% profile.blogs.each do |blog| %>
  25 + <tr>
  26 + <td><%= blog.name + ':' %></td>
  27 + <td>
  28 + <%= link_to(n_('One post', '%{num} posts', blog.posts.count) % { :num => blog.posts.count }, blog.url) %>
  29 + </td>
  30 + </tr>
  31 + <% end %>
  32 + <% profile.image_galleries.each do |gallery| %>
  33 + <tr>
  34 + <td><%= gallery.name + ':' %></td>
  35 + <td>
  36 + <%= link_to(n_('One picture', '%{num} pictures', gallery.images.count) % { :num => gallery.images.count }, gallery.url) %>
  37 + </td>
  38 + </tr>
  39 + <% end %>
  40 +
  41 + <tr>
  42 + <td><%= _('Events:') %></td>
  43 + <td>
  44 + <%= link_to profile.events.count, :controller => 'events', :action => 'events' %>
  45 + </td>
  46 + </tr>
  47 + <tr>
  48 + <td>
  49 + <%= _('Tags:') %>
  50 + </td>
  51 + <td>
  52 + <%= tag_cloud @tags, :id, { :action => 'tag' }, :max_size => 18, :min_size => 10%>
  53 + </td>
  54 + </tr>
  55 +
  56 + <% if !environment.enabled?('disable_categories') && !profile.interests.empty? %>
  57 + <tr>
  58 + <th colspan='2'><%= _('Interests') %></th>
  59 + </tr>
  60 + <% profile.interests.each do |item| %>
  61 + <tr>
  62 + <td></td>
  63 + <td><%= link_to item.name, :controller => 'search', :action => 'category_index', :category_path => item.explode_path %></td>
  64 + </tr>
  65 + <% end %>
  66 + <% end %>
  67 + <% end %>
40 <% end %> 68 <% end %>
41 </table> 69 </table>
app/views/profile_editor/_person_form.rhtml
@@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
9 </div> 9 </div>
10 <% end %> 10 <% end %>
11 11
  12 +<%= optional_field(@person, 'description', f.text_area(:description, :rows => 5)) %>
12 <%= optional_field(@person, 'preferred_domain', select_preferred_domain(:profile_data)) %> 13 <%= optional_field(@person, 'preferred_domain', select_preferred_domain(:profile_data)) %>
13 <%= optional_field(@person, 'contact_information', f.text_field(:contact_information)) %> 14 <%= optional_field(@person, 'contact_information', f.text_field(:contact_information)) %>
14 <%= optional_field(@person, 'contact_phone', labelled_form_field(_('Home phone'), text_field(:profile_data, :contact_phone))) %> 15 <%= optional_field(@person, 'contact_phone', labelled_form_field(_('Home phone'), text_field(:profile_data, :contact_phone))) %>
app/views/profile_editor/edit.rhtml
@@ -35,13 +35,13 @@ @@ -35,13 +35,13 @@
35 <td> <%= _('Activate Intranet access (restricted area only for me)') %> </td><td><%= _('Yes') %></td><td><%= _('Yes') %></td> 35 <td> <%= _('Activate Intranet access (restricted area only for me)') %> </td><td><%= _('Yes') %></td><td><%= _('Yes') %></td>
36 </tr> 36 </tr>
37 <tr> 37 <tr>
38 - <td> <%= _('Show my website to all internet users') %> </td><td><%= _('Yes') %></td><td><%= _('No') %></td> 38 + <td> <%= _('Include my contact in directory of people') %> </td><td><%= _('Yes') %></td><td><%= _('Yes') %></td>
39 </tr> 39 </tr>
40 <tr> 40 <tr>
41 - <td> <%= _('Show my website to my contacts (persons)') %> </td><td><%= _('Yes') %></td><td><%= _('Yes') %></td> 41 + <td> <%= _('Show my contents to all internet users') %> </td><td><%= _('Yes') %></td><td><%= _('No') %></td>
42 </tr> 42 </tr>
43 <tr> 43 <tr>
44 - <td> <%= _('Include my contact in directory of people') %> </td><td><%= _('Yes') %></td><td><%= _('No') %></td> 44 + <td> <%= _('Show my contents to my friends (person)') %> </td><td><%= _('Yes') %></td><td><%= _('Yes') %></td>
45 </tr> 45 </tr>
46 </table> 46 </table>
47 <% else %> 47 <% else %>
@@ -63,13 +63,13 @@ @@ -63,13 +63,13 @@
63 <td> <%= _('Activate Intranet access (restricted area only for members)') %> </td><td><%= _('Yes') %></td><td><%= _('Yes') %></td> 63 <td> <%= _('Activate Intranet access (restricted area only for members)') %> </td><td><%= _('Yes') %></td><td><%= _('Yes') %></td>
64 </tr> 64 </tr>
65 <tr> 65 <tr>
66 - <td> <%= _('Show website of this group to all internet users') %> </td><td><%= _('Yes') %></td><td><%= _('No') %></td> 66 + <td> <%= _('Include this group directory of groups') %> </td><td><%= _('Yes') %></td><td><%= _('Yes') %></td>
67 </tr> 67 </tr>
68 <tr> 68 <tr>
69 - <td> <%= _('Show my website to members') %> </td><td><%= _('Yes') %></td><td><%= _('Yes') %></td> 69 + <td> <%= _('Show content of this group to all internet users') %> </td><td><%= _('Yes') %></td><td><%= _('No') %></td>
70 </tr> 70 </tr>
71 <tr> 71 <tr>
72 - <td> <%= _('Include this group directory of groups') %> </td><td><%= _('Yes') %></td><td><%= _('No') %></td> 72 + <td> <%= _('Show content of this group to members') %> </td><td><%= _('Yes') %></td><td><%= _('Yes') %></td>
73 </tr> 73 </tr>
74 </table> 74 </table>
75 <% end %> 75 <% end %>
app/views/search/_display_results.rhtml
@@ -45,7 +45,7 @@ @@ -45,7 +45,7 @@
45 <ul> 45 <ul>
46 <% hit_pos = 0 %> 46 <% hit_pos = 0 %>
47 <% results.each do |hit| %> 47 <% results.each do |hit| %>
48 - <% next if hit.respond_to?(:public?) && !hit.public? %> 48 + <% next if hit.respond_to?(:visible) && !hit.visible? %>
49 <%= render :partial => partial_for_class(hit.class), 49 <%= render :partial => partial_for_class(hit.class),
50 50
51 :object => hit, 51 :object => hit,
app/views/shared/_custom_fields.rhtml
1 <% if profile.community? %> 1 <% if profile.community? %>
2 - <%= optional_field(profile, 'description', f.text_area(:description, :rows => 5)) %>  
3 <%= optional_field(profile, 'language', f.text_field(:language), only_required) %> 2 <%= optional_field(profile, 'language', f.text_field(:language), only_required) %>
4 <% end %> 3 <% end %>
5 4
  5 +<%= optional_field(profile, 'description', f.text_area(:description, :rows => 5)) %> <!-- , :maxlength => 10 -->
6 <%= optional_field(profile, 'contact_person', f.text_field(:contact_person), only_required) %> 6 <%= optional_field(profile, 'contact_person', f.text_field(:contact_person), only_required) %>
7 <%= optional_field(profile, 'contact_email', f.text_field(:contact_email), only_required) %> 7 <%= optional_field(profile, 'contact_email', f.text_field(:contact_email), only_required) %>
8 <%= optional_field(profile, 'contact_phone', f.text_field(:contact_phone), only_required) %> 8 <%= optional_field(profile, 'contact_phone', f.text_field(:contact_phone), only_required) %>
app/views/shared/access_denied.rhtml
@@ -9,9 +9,11 @@ @@ -9,9 +9,11 @@
9 <p><%= _("If you are supposed to have access to this area, you'll probably want to talk to the people responsible and ask them to give you access.") %></p> 9 <p><%= _("If you are supposed to have access to this area, you'll probably want to talk to the people responsible and ask them to give you access.") %></p>
10 <% end %> 10 <% end %>
11 11
12 - <ul>  
13 - <li><%= link_to _('Go to the site home page'), :controller => 'home' %></li>  
14 - <li><%= link_to _('Go back'), :back %></li>  
15 - </ul> 12 + <hr/>
  13 +
  14 + <% button_bar do %>
  15 + <%= button :back, _('Go back'), :back %>
  16 + <%= button :home, _('Go to the site home page'), :controller => 'home' %>
  17 + <% end %>
16 18
17 </div> 19 </div>
app/views/shared/not_found.rhtml
@@ -4,8 +4,8 @@ @@ -4,8 +4,8 @@
4 <%= _('You may have clicked an expired link or mistyped the address.') %> 4 <%= _('You may have clicked an expired link or mistyped the address.') %>
5 <%= _('If you clicked a link that was in another site, or was given to you by someone else, it would be nice if you tell them that their link is not valid anymore.') %> 5 <%= _('If you clicked a link that was in another site, or was given to you by someone else, it would be nice if you tell them that their link is not valid anymore.') %>
6 </p> 6 </p>
7 - <ul>  
8 - <li><%= link_to _('Go to the site home page'), :controller => 'home' %></li>  
9 - <li><%= link_to _('Go back'), :back %></li>  
10 - </ul> 7 + <% button_bar do %>
  8 + <%= button :back, _('Go back'), :back %>
  9 + <%= button :home, _('Go to %s home page') % environment.name, :controller => 'home' %>
  10 + <% end %>
11 </div> 11 </div>
db/migrate/080_add_visible_to_profiles.rb 0 → 100644
@@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
  1 +class AddVisibleToProfiles < ActiveRecord::Migration
  2 + def self.up
  3 + add_column :profiles, :visible, :boolean, :default => true
  4 + end
  5 +
  6 + def self.down
  7 + remove_column :profiles, :visible
  8 + end
  9 +end
@@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
9 # 9 #
10 # It's strongly recommended to check this file into your version control system. 10 # It's strongly recommended to check this file into your version control system.
11 11
12 -ActiveRecord::Schema.define(:version => 79) do 12 +ActiveRecord::Schema.define(:version => 80) do
13 13
14 create_table "article_versions", :force => true do |t| 14 create_table "article_versions", :force => true do |t|
15 t.integer "article_id" 15 t.integer "article_id"
@@ -270,6 +270,7 @@ ActiveRecord::Schema.define(:version =&gt; 79) do @@ -270,6 +270,7 @@ ActiveRecord::Schema.define(:version =&gt; 79) do
270 t.date "birth_date" 270 t.date "birth_date"
271 t.integer "preferred_domain_id" 271 t.integer "preferred_domain_id"
272 t.datetime "updated_at" 272 t.datetime "updated_at"
  273 + t.boolean "visible", :default => true
273 end 274 end
274 275
275 add_index "profiles", ["environment_id"], :name => "index_profiles_on_environment_id" 276 add_index "profiles", ["environment_id"], :name => "index_profiles_on_environment_id"
features/my_network_block.feature 0 → 100644
@@ -0,0 +1,68 @@ @@ -0,0 +1,68 @@
  1 +Feature: my_network_block
  2 + As a blog owner
  3 + I want to see a summary of my network
  4 +
  5 + Background:
  6 + Given the following users
  7 + | login | name |
  8 + | joaosilva | Joao Silva |
  9 + And the following blocks
  10 + | owner | type |
  11 + | joaosilva | MyNetworkBlock |
  12 + And the following communities
  13 + | identifier | name | public_profile |
  14 + | public-community | Public Community | true |
  15 +
  16 + Scenario: display how many public/private communities I am member
  17 + Given the following communities
  18 + | identifier | name | owner | public_profile |
  19 + | other-public-community | Other Public Community | joaosilva | true |
  20 + | private-community | Private Community | joaosilva | false |
  21 + And I am logged in as "joaosilva"
  22 + And I am on Joao Silva's homepage
  23 + Then I should see "2 communities"
  24 + When I go to Public Community's homepage
  25 + And I follow "Join"
  26 + And I press "Yes, I want to join."
  27 + When I go to Joao Silva's homepage
  28 + Then I should see "3 communities"
  29 +
  30 + Scenario: not display how many invisible communities I am member
  31 + Given the following communities
  32 + | identifier | name | owner | visible |
  33 + | visible-community | Visible Community | joaosilva | true |
  34 + | not-visible-community | Not Visible Community | joaosilva | false |
  35 + And I am logged in as "joaosilva"
  36 + And I am on Joao Silva's homepage
  37 + Then I should see "One community"
  38 + When I go to Public Community's homepage
  39 + And I follow "Join"
  40 + And I press "Yes, I want to join."
  41 + When I go to Joao Silva's homepage
  42 + Then I should see "2 communities"
  43 +
  44 + Scenario: display how many public/private friends I have
  45 + Given the following users
  46 + | login | name | public_profile |
  47 + | mariasilva | Maria Silva | true |
  48 + | josesilva | Jose Silva | false |
  49 + And "joaosilva" is friend of "mariasilva"
  50 + And I am logged in as "joaosilva"
  51 + And I am on Joao Silva's homepage
  52 + Then I should see "1 friend"
  53 + And "joaosilva" is friend of "josesilva"
  54 + When I go to Joao Silva's homepage
  55 + Then I should see "2 friends"
  56 +
  57 + Scenario: not display how many invisible friends I have
  58 + Given the following users
  59 + | login | name | visible |
  60 + | mariasilva | Maria Silva | true |
  61 + | josesilva | Jose Silva | false |
  62 + And "joaosilva" is friend of "mariasilva"
  63 + And I am logged in as "joaosilva"
  64 + When I go to Joao Silva's homepage
  65 + Then I should see "1 friend"
  66 + And "joaosilva" is friend of "josesilva"
  67 + When I go to Joao Silva's homepage
  68 + Then I should see "1 friend"
features/private_profile.feature 0 → 100644
@@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
  1 +Feature: private profiles
  2 + As a profile administrator
  3 + I want to set it to private
  4 + So that only members/friends can view its contents
  5 +
  6 + Background:
  7 + Given the following community
  8 + | identifier | name | public_profile |
  9 + | safernet | Safernet | false |
  10 + And the following users
  11 + | login | public_profile |
  12 + | joao | true |
  13 + | shygirl | false |
  14 +
  15 + Scenario: joining a private community
  16 + Given I am logged in as "joao"
  17 + When I go to Safernet's homepage
  18 + Then I should see "members only"
  19 + When I follow "Join"
  20 + And I press "Yes, I want to join"
  21 + And "joao" is accepted on community "Safernet"
  22 + Then "joao" should be a member of "Safernet"
  23 + When I go to Safernet's homepage
  24 + And I should not see "members only"
  25 +
  26 + Scenario: adding a friend with private profile
  27 + Given I am logged in as "joao"
  28 + When I go to shygirl's homepage
  29 + Then I should see "friends only"
  30 + When I follow "Add friend"
  31 + And I press "Yes, I want"
features/publish_article.feature
@@ -27,7 +27,7 @@ Feature: publish article @@ -27,7 +27,7 @@ Feature: publish article
27 And I press "Publish" 27 And I press "Publish"
28 And I am on Sample Community's homepage 28 And I am on Sample Community's homepage
29 And I follow "View profile" 29 And I follow "View profile"
30 - And I follow "Site map" 30 + And I go to Sample Community's sitemap
31 When I follow "Sample Article" 31 When I follow "Sample Article"
32 Then I should see "This is the first published article" 32 Then I should see "This is the first published article"
33 33
@@ -82,11 +82,11 @@ Feature: publish article @@ -82,11 +82,11 @@ Feature: publish article
82 Then I should see "Validation failed: Slug (the code generated from the article name) is already being used by another article.:" 82 Then I should see "Validation failed: Slug (the code generated from the article name) is already being used by another article.:"
83 And I am on Another Community1's homepage 83 And I am on Another Community1's homepage
84 And I follow "View profile" 84 And I follow "View profile"
85 - When I follow "Site map" 85 + When I go to Another Community1's sitemap
86 Then I should see "Sample Article" 86 Then I should see "Sample Article"
87 And I am on Another Community2's homepage 87 And I am on Another Community2's homepage
88 And I follow "View profile" 88 And I follow "View profile"
89 - When I follow "Site map" 89 + When I go to Another Community2's sitemap
90 Then I should see "Sample Article" 90 Then I should see "Sample Article"
91 91
92 Scenario: publishing articles with the same name in a moderated community 92 Scenario: publishing articles with the same name in a moderated community
features/step_definitions/noosfero_steps.rb
@@ -101,6 +101,12 @@ Then /^&quot;(.+)&quot; should be a member of &quot;(.+)&quot;$/ do |person,profile| @@ -101,6 +101,12 @@ Then /^&quot;(.+)&quot; should be a member of &quot;(.+)&quot;$/ do |person,profile|
101 Profile.find_by_name(profile).members.should include(Person.find_by_name(person)) 101 Profile.find_by_name(profile).members.should include(Person.find_by_name(person))
102 end 102 end
103 103
  104 +When /^"(.*)" is accepted on community "(.*)"$/ do |person, community|
  105 + person = Person.find_by_name(person)
  106 + community = Community.find_by_name(community)
  107 + community.affiliate(person, Profile::Roles.member(community.environment.id))
  108 +end
  109 +
104 Given /^"(.+)" is admin of "(.+)"$/ do |person, organization| 110 Given /^"(.+)" is admin of "(.+)"$/ do |person, organization|
105 org = Profile.find_by_name(organization) 111 org = Profile.find_by_name(organization)
106 user = Profile.find_by_name(person) 112 user = Profile.find_by_name(person)
@@ -135,3 +141,7 @@ end @@ -135,3 +141,7 @@ end
135 Given /^(.+) is member of (.+)$/ do |person, group| 141 Given /^(.+) is member of (.+)$/ do |person, group|
136 Organization[group].add_member(Person[person]) 142 Organization[group].add_member(Person[person])
137 end 143 end
  144 +
  145 +Given /^"(.+)" is friend of "(.+)"$/ do |person, friend|
  146 + Person[person].add_friend(Person[friend])
  147 +end
features/support/paths.rb
@@ -26,6 +26,9 @@ module NavigationHelpers @@ -26,6 +26,9 @@ module NavigationHelpers
26 when /^(.*)'s homepage$/ 26 when /^(.*)'s homepage$/
27 '/%s' % Profile.find_by_name($1).identifier 27 '/%s' % Profile.find_by_name($1).identifier
28 28
  29 + when /^(.*)'s sitemap/
  30 + '/profile/%s/sitemap' % Profile.find_by_name($1).identifier
  31 +
29 when /^login page$/ 32 when /^login page$/
30 '/account/login' 33 '/account/login'
31 34
public/images/icons-app/alert-icon.png

1 KB

public/stylesheets/common.css
@@ -31,9 +31,6 @@ code, pre { color: #666; } @@ -31,9 +31,6 @@ code, pre { color: #666; }
31 padding: 0em; 31 padding: 0em;
32 } 32 }
33 33
34 -#notice {  
35 - cursor: pointer;  
36 -}  
37 34
38 #environment_identification { 35 #environment_identification {
39 position: absolute !important; 36 position: absolute !important;
@@ -134,9 +131,8 @@ div#notice { @@ -134,9 +131,8 @@ div#notice {
134 left: 50%; 131 left: 50%;
135 margin-left: -200px; 132 margin-left: -200px;
136 width: 400px; 133 width: 400px;
137 - border: 1px solid #545454;  
138 - background: #ffffa9;  
139 - padding: 10px; 134 + border: 1px solid #ddd;
  135 + background: #ffd;
140 } 136 }
141 137
142 /* * * Generic Content Formating * * */ 138 /* * * Generic Content Formating * * */
@@ -280,6 +276,7 @@ td.field-name { @@ -280,6 +276,7 @@ td.field-name {
280 color: #888; 276 color: #888;
281 width: 150px; 277 width: 150px;
282 text-align: left; 278 text-align: left;
  279 + vertical-align: top;
283 } 280 }
284 281
285 table.profile th { 282 table.profile th {
@@ -495,8 +492,7 @@ div.pending-tasks { @@ -495,8 +492,7 @@ div.pending-tasks {
495 #content #not-found h1, 492 #content #not-found h1,
496 #content #access-denied h1 { 493 #content #access-denied h1 {
497 text-align: left; 494 text-align: left;
498 - background: url(../images/icons-app/alert-icon.png) no-repeat;  
499 - padding-left: 30px; 495 + margin-top: 0px;
500 } 496 }
501 497
502 #content #not-found p, 498 #content #not-found p,
@@ -504,6 +500,11 @@ div.pending-tasks { @@ -504,6 +500,11 @@ div.pending-tasks {
504 text-align: justify; 500 text-align: justify;
505 } 501 }
506 502
  503 +#content #not-found .button-bar,
  504 +#content #access-denied .button-bar {
  505 + margin-bottom: 0px;
  506 +}
  507 +
507 /**** Signup wizard ****/ 508 /**** Signup wizard ****/
508 509
509 #wizard-iframe { 510 #wizard-iframe {
public/stylesheets/controller_profile.css
@@ -9,3 +9,28 @@ @@ -9,3 +9,28 @@
9 #pagination-profiles .pagination span { 9 #pagination-profiles .pagination span {
10 display: inline; 10 display: inline;
11 } 11 }
  12 +
  13 +.no-boxes {
  14 + margin: 0px 260px 0px 260px;
  15 +}
  16 +
  17 +#content .no-boxes h1 {
  18 + margin: 1px 0px 1px 160px;
  19 +}
  20 +
  21 +#content .no-boxes h1,
  22 +#content .no-boxes table th {
  23 + text-align: left;
  24 +}
  25 +
  26 +.private-profile-message {
  27 + font-style: italic;
  28 + border: 1px solid #ddd;
  29 + background: #ffd;
  30 + padding: 10px;
  31 +}
  32 +
  33 +.private-profile-message,
  34 +.private-profile-description {
  35 + margin: 5px 0px 5px 160px;
  36 +}
test/functional/content_viewer_controller_test.rb
@@ -577,9 +577,7 @@ class ContentViewerControllerTest &lt; Test::Unit::TestCase @@ -577,9 +577,7 @@ class ContentViewerControllerTest &lt; Test::Unit::TestCase
577 577
578 should 'deny access before trying SSL when SSL is disabled' do 578 should 'deny access before trying SSL when SSL is disabled' do
579 @controller.expects(:redirect_to_ssl).returns(false) 579 @controller.expects(:redirect_to_ssl).returns(false)
580 - profile = create_user('testuser').person  
581 - profile.public_profile = false  
582 - profile.save! 580 + profile = create_user('testuser', {}, :visible => false).person
583 581
584 get :view_page, :profile => 'testuser', :page => profile.home_page.explode_path 582 get :view_page, :profile => 'testuser', :page => profile.home_page.explode_path
585 assert_response 403 583 assert_response 403
test/functional/profile_controller_test.rb
@@ -136,7 +136,7 @@ class ProfileControllerTest &lt; Test::Unit::TestCase @@ -136,7 +136,7 @@ class ProfileControllerTest &lt; Test::Unit::TestCase
136 should 'show friends link to person' do 136 should 'show friends link to person' do
137 person = create_user('person_1').person 137 person = create_user('person_1').person
138 get :index, :profile => person.identifier 138 get :index, :profile => person.identifier
139 - assert_tag :tag => 'a', :content => /Friends/, :attributes => { :href => /profile\/#{person.identifier}\/friends$/ } 139 + assert_tag :tag => 'a', :content => /#{profile.friends.count}/, :attributes => { :href => /profile\/#{person.identifier}\/friends$/ }
140 end 140 end
141 141
142 should 'display tag for profile' do 142 should 'display tag for profile' do
@@ -223,6 +223,9 @@ class ProfileControllerTest &lt; Test::Unit::TestCase @@ -223,6 +223,9 @@ class ProfileControllerTest &lt; Test::Unit::TestCase
223 223
224 should 'check access before displaying profile' do 224 should 'check access before displaying profile' do
225 Person.any_instance.expects(:display_info_to?).with(anything).returns(false) 225 Person.any_instance.expects(:display_info_to?).with(anything).returns(false)
  226 + @profile.visible = false
  227 + @profile.save
  228 +
226 get :index, :profile => @profile.identifier 229 get :index, :profile => @profile.identifier
227 assert_response 403 230 assert_response 403
228 end 231 end
@@ -299,12 +302,6 @@ class ProfileControllerTest &lt; Test::Unit::TestCase @@ -299,12 +302,6 @@ class ProfileControllerTest &lt; Test::Unit::TestCase
299 assert_no_tag :tag => 'a', :attributes => { :href => '/catalog/my-test-enterprise'}, :content => /Products\/Services/ 302 assert_no_tag :tag => 'a', :attributes => { :href => '/catalog/my-test-enterprise'}, :content => /Products\/Services/
300 end 303 end
301 304
302 - should 'display "Site map" link for profiles' do  
303 - profile = create_user('testmapuser').person  
304 - get :index, :profile => profile.identifier  
305 - assert_tag :tag => 'a', :content => "Site map", :attributes => { :href => '/profile/testmapuser/sitemap' }  
306 - end  
307 -  
308 should 'list top level articles in sitemap' do 305 should 'list top level articles in sitemap' do
309 get :sitemap, :profile => 'testuser' 306 get :sitemap, :profile => 'testuser'
310 assert_equal @profile.top_level_articles, assigns(:articles) 307 assert_equal @profile.top_level_articles, assigns(:articles)
test/unit/article_test.rb
@@ -177,9 +177,17 @@ class ArticleTest &lt; Test::Unit::TestCase @@ -177,9 +177,17 @@ class ArticleTest &lt; Test::Unit::TestCase
177 end 177 end
178 178
179 should 'not show documents from a private profile as recent' do 179 should 'not show documents from a private profile as recent' do
180 - p = create_user('usr1').person  
181 - p.public_profile = false  
182 - p.save! 180 + p = fast_create(Person, :public_profile => false)
  181 + Article.destroy_all
  182 +
  183 + first = p.articles.build(:name => 'first', :published => true); first.save!
  184 + second = p.articles.build(:name => 'second', :published => false); second.save!
  185 +
  186 + assert_equal [ ], Article.recent(nil)
  187 + end
  188 +
  189 + should 'not show documents from a invisible profile as recent' do
  190 + p = fast_create(Person, :visible => false)
183 Article.destroy_all 191 Article.destroy_all
184 192
185 first = p.articles.build(:name => 'first', :published => true); first.save! 193 first = p.articles.build(:name => 'first', :published => true); first.save!
@@ -520,6 +528,15 @@ class ArticleTest &lt; Test::Unit::TestCase @@ -520,6 +528,15 @@ class ArticleTest &lt; Test::Unit::TestCase
520 assert !a2.public? 528 assert !a2.public?
521 end 529 end
522 530
  531 + should 'respond to public? as false if profile is invisible' do
  532 + profile = fast_create(Profile, :visible => false)
  533 + article1 = fast_create(Article, :profile_id => profile.id)
  534 + article2 = fast_create(Article, :profile_id => profile.id, :public_article => false)
  535 +
  536 + assert !article1.public?
  537 + assert !article2.public?
  538 + end
  539 +
523 should 'save as private' do 540 should 'save as private' do
524 profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') 541 profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile')
525 folder = Folder.create!(:name => 'my_intranet', :profile => profile, :public_article => false) 542 folder = Folder.create!(:name => 'my_intranet', :profile => profile, :public_article => false)
test/unit/communities_block_test.rb
@@ -30,19 +30,19 @@ class CommunitiesBlockTest &lt; Test::Unit::TestCase @@ -30,19 +30,19 @@ class CommunitiesBlockTest &lt; Test::Unit::TestCase
30 owner = mock 30 owner = mock
31 block.expects(:owner).at_least_once.returns(owner) 31 block.expects(:owner).at_least_once.returns(owner)
32 32
33 - member1 = mock; member1.stubs(:id).returns(1); member1.stubs(:public_profile).returns(true)  
34 - member2 = mock; member2.stubs(:id).returns(2); member2.stubs(:public_profile).returns(true)  
35 - member3 = mock; member3.stubs(:id).returns(3); member3.stubs(:public_profile).returns(true) 33 + community1 = mock; community1.stubs(:id).returns(1); community1.stubs(:visible).returns(true)
  34 + community2 = mock; community2.stubs(:id).returns(2); community2.stubs(:visible).returns(true)
  35 + community3 = mock; community3.stubs(:id).returns(3); community3.stubs(:visible).returns(true)
36 36
37 - owner.expects(:communities).returns([member1, member2, member3]) 37 + owner.expects(:communities).returns([community1, community2, community3])
38 38
39 block.profile_finder.expects(:pick_random).with(3).returns(2) 39 block.profile_finder.expects(:pick_random).with(3).returns(2)
40 block.profile_finder.expects(:pick_random).with(2).returns(0) 40 block.profile_finder.expects(:pick_random).with(2).returns(0)
41 41
42 - Profile.expects(:find).with(3).returns(member3)  
43 - Profile.expects(:find).with(1).returns(member1) 42 + Profile.expects(:find).with(3).returns(community3)
  43 + Profile.expects(:find).with(1).returns(community1)
44 44
45 - assert_equal [member3, member1], block.profiles 45 + assert_equal [community3, community1], block.profiles
46 end 46 end
47 47
48 should 'link to all communities of profile' do 48 should 'link to all communities of profile' do
@@ -72,28 +72,43 @@ class CommunitiesBlockTest &lt; Test::Unit::TestCase @@ -72,28 +72,43 @@ class CommunitiesBlockTest &lt; Test::Unit::TestCase
72 assert_equal '', block.footer 72 assert_equal '', block.footer
73 end 73 end
74 74
75 - should 'not list non-public communities' do 75 + should 'list non-public communities' do
76 user = create_user('testuser').person 76 user = create_user('testuser').person
77 77
78 - public_community = Community.create!(:name => 'test community 1', :identifier => 'comm1', :environment => Environment.default) 78 + public_community = fast_create(Community, :environment_id => Environment.default.id)
79 public_community.add_member(user) 79 public_community.add_member(user)
80 80
81 - private_community = Community.create!(:name => 'test community 2', :identifier => 'comm2', :environment => Environment.default, :public_profile => false) 81 + private_community = fast_create(Community, :environment_id => Environment.default.id, :public_profile => false)
82 private_community.add_member(user) 82 private_community.add_member(user)
83 83
84 block = CommunitiesBlock.new 84 block = CommunitiesBlock.new
85 block.expects(:owner).at_least_once.returns(user) 85 block.expects(:owner).at_least_once.returns(user)
86 86
87 - assert_equal [public_community], block.profiles 87 + assert_equivalent [public_community, private_community], block.profiles
  88 + end
  89 +
  90 + should 'not list non-visible communities' do
  91 + user = create_user('testuser').person
  92 +
  93 + visible_community = fast_create(Community, :environment_id => Environment.default.id)
  94 + visible_community.add_member(user)
  95 +
  96 + not_visible_community = fast_create(Community, :environment_id => Environment.default.id, :visible => false)
  97 + not_visible_community.add_member(user)
  98 +
  99 + block = CommunitiesBlock.new
  100 + block.expects(:owner).at_least_once.returns(user)
  101 +
  102 + assert_equal [visible_community], block.profiles
88 end 103 end
89 104
90 should 'count number of owner communities' do 105 should 'count number of owner communities' do
91 user = create_user('testuser').person 106 user = create_user('testuser').person
92 107
93 - community1 = Community.create!(:name => 'test community 1', :identifier => 'comm1', :environment => Environment.default, :public_profile => true) 108 + community1 = fast_create(Community, :environment_id => Environment.default.id, :visible => true)
94 community1.add_member(user) 109 community1.add_member(user)
95 110
96 - community2 = Community.create!(:name => 'test community 2', :identifier => 'comm2', :environment => Environment.default, :public_profile => true) 111 + community2 = fast_create(Community, :environment_id => Environment.default.id, :visible => true)
97 community2.add_member(user) 112 community2.add_member(user)
98 113
99 block = CommunitiesBlock.new 114 block = CommunitiesBlock.new
@@ -102,22 +117,37 @@ class CommunitiesBlockTest &lt; Test::Unit::TestCase @@ -102,22 +117,37 @@ class CommunitiesBlockTest &lt; Test::Unit::TestCase
102 assert_equal 2, block.profile_count 117 assert_equal 2, block.profile_count
103 end 118 end
104 119
105 - should 'not count non-public profile communities' do 120 + should 'count non-public profile communities' do
106 user = create_user('testuser').person 121 user = create_user('testuser').person
107 122
108 - community_public = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default, :public_profile => true) 123 + community_public = fast_create(Community, :environment_id => Environment.default.id, :public_profile => true)
109 community_public.add_member(user) 124 community_public.add_member(user)
110 125
111 - community_private = Community.create!(:name => ' community 2', :identifier => 'comm2', :environment => Environment.default, :public_profile => false) 126 + community_private = fast_create(Community, :environment_id => Environment.default.id, :public_profile => false)
112 community_private.add_member(user) 127 community_private.add_member(user)
113 128
114 block = CommunitiesBlock.new 129 block = CommunitiesBlock.new
115 block.expects(:owner).at_least_once.returns(user) 130 block.expects(:owner).at_least_once.returns(user)
116 131
  132 + assert_equal 2, block.profile_count
  133 + end
  134 +
  135 + should 'not count non-visible profile communities' do
  136 + user = create_user('testuser').person
  137 +
  138 + visible_community = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default, :visible => true)
  139 + visible_community.add_member(user)
  140 +
  141 + not_visible_community = Community.create!(:name => ' community 2', :identifier => 'comm2', :environment => Environment.default, :visible => false)
  142 + not_visible_community.add_member(user)
  143 +
  144 + block = CommunitiesBlock.new
  145 + block.expects(:owner).at_least_once.returns(user)
  146 +
117 assert_equal 1, block.profile_count 147 assert_equal 1, block.profile_count
118 end 148 end
119 149
120 - should 'not count non-public environment communities' do 150 + should 'count non-public environment communities' do
121 community_public = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default, :public_profile => true) 151 community_public = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default, :public_profile => true)
122 152
123 community_private = Community.create!(:name => ' community 2', :identifier => 'comm2', :environment => Environment.default, :public_profile => false) 153 community_private = Community.create!(:name => ' community 2', :identifier => 'comm2', :environment => Environment.default, :public_profile => false)
@@ -125,6 +155,17 @@ class CommunitiesBlockTest &lt; Test::Unit::TestCase @@ -125,6 +155,17 @@ class CommunitiesBlockTest &lt; Test::Unit::TestCase
125 block = CommunitiesBlock.new 155 block = CommunitiesBlock.new
126 block.expects(:owner).at_least_once.returns(Environment.default) 156 block.expects(:owner).at_least_once.returns(Environment.default)
127 157
  158 + assert_equal 2, block.profile_count
  159 + end
  160 +
  161 + should 'not count non-visible environment communities' do
  162 + visible_community = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default, :visible => true)
  163 +
  164 + not_visible_community = Community.create!(:name => ' community 2', :identifier => 'comm2', :environment => Environment.default, :visible => false)
  165 +
  166 + block = CommunitiesBlock.new
  167 + block.expects(:owner).at_least_once.returns(Environment.default)
  168 +
128 assert_equal 1, block.profile_count 169 assert_equal 1, block.profile_count
129 end 170 end
130 171
test/unit/enterprises_block_test.rb
@@ -29,9 +29,9 @@ class EnterprisesBlockTest &lt; Test::Unit::TestCase @@ -29,9 +29,9 @@ class EnterprisesBlockTest &lt; Test::Unit::TestCase
29 owner = mock 29 owner = mock
30 block.expects(:owner).at_least_once.returns(owner) 30 block.expects(:owner).at_least_once.returns(owner)
31 31
32 - member1 = stub(:id => 1, :public_profile => true )  
33 - member2 = stub(:id => 2, :public_profile => true )  
34 - member3 = stub(:id => 3, :public_profile => true ) 32 + member1 = stub(:id => 1, :visible => true )
  33 + member2 = stub(:id => 2, :visible => true )
  34 + member3 = stub(:id => 3, :visible => true )
35 35
36 owner.expects(:enterprises).returns([member1, member2, member3]) 36 owner.expects(:enterprises).returns([member1, member2, member3])
37 37
@@ -44,31 +44,58 @@ class EnterprisesBlockTest &lt; Test::Unit::TestCase @@ -44,31 +44,58 @@ class EnterprisesBlockTest &lt; Test::Unit::TestCase
44 assert_equal [member3, member1], block.profiles 44 assert_equal [member3, member1], block.profiles
45 end 45 end
46 46
47 - should 'not list private enterprises in environment' do  
48 - env = Environment.create!(:name => 'test env')  
49 - p1 = Enterprise.create!(:name => 'test1', :identifier => 'test1', :environment_id => env.id, :public_profile => true)  
50 - p2 = Enterprise.create!(:name => 'test2', :identifier => 'test2', :environment_id => env.id, :public_profile => false) #private profile 47 + should 'list private enterprises in environment' do
  48 + env = Environment.create!(:name => 'test_env')
  49 + enterprise1 = fast_create(Enterprise, :environment_id => env.id, :public_profile => true)
  50 + enterprise2 = fast_create(Enterprise, :environment_id => env.id, :public_profile => false) #private profile
  51 + block = EnterprisesBlock.new
  52 + env.boxes.first.blocks << block
  53 + block.save!
  54 + ids = block.profile_finder.ids
  55 + assert_includes ids, enterprise1.id
  56 + assert_includes ids, enterprise2.id
  57 + end
  58 +
  59 + should 'not list invisible enterprises in environment' do
  60 + env = Environment.create!(:name => 'test_env')
  61 + enterprise1 = fast_create(Enterprise, :environment_id => env.id, :visible => true)
  62 + enterprise2 = fast_create(Enterprise, :environment_id => env.id, :visible => false) #invisible profile
51 block = EnterprisesBlock.new 63 block = EnterprisesBlock.new
52 env.boxes.first.blocks << block 64 env.boxes.first.blocks << block
53 block.save! 65 block.save!
54 ids = block.profile_finder.ids 66 ids = block.profile_finder.ids
55 - assert_includes ids, p1.id  
56 - assert_not_includes ids, p2.id 67 + assert_includes ids, enterprise1.id
  68 + assert_not_includes ids, enterprise2.id
57 end 69 end
58 70
59 - should 'not list private enterprises in profile' do  
60 - person = create_user('test_user').person  
61 - e1 = Enterprise.create!(:name => 'test1', :identifier => 'test1', :public_profile => true)  
62 - role = Profile::Roles.member(e1.environment.id)  
63 - e1.affiliate(person, role)  
64 - e2 = Enterprise.create!(:name => 'test2', :identifier => 'test2', :public_profile => false) #private profile  
65 - e2.affiliate(person, role) 71 + should 'list private enterprises in profile' do
  72 + person = create_user('testuser').person
  73 + enterprise1 = fast_create(Enterprise, :public_profile => true)
  74 + role = Profile::Roles.member(enterprise1.environment.id)
  75 + enterprise1.affiliate(person, role)
  76 + enterprise2 = fast_create(Enterprise, :public_profile => false)
  77 + enterprise2.affiliate(person, role)
66 block = EnterprisesBlock.new 78 block = EnterprisesBlock.new
67 person.boxes.first.blocks << block 79 person.boxes.first.blocks << block
68 block.save! 80 block.save!
69 ids = block.profile_finder.ids 81 ids = block.profile_finder.ids
70 - assert_includes ids, e1.id  
71 - assert_not_includes ids, e2.id 82 + assert_includes ids, enterprise1.id
  83 + assert_includes ids, enterprise2.id
  84 + end
  85 +
  86 + should 'not list invisible enterprises in profile' do
  87 + person = create_user('testuser').person
  88 + enterprise1 = fast_create(Enterprise, :visible => true)
  89 + role = Profile::Roles.member(enterprise1.environment.id)
  90 + enterprise1.affiliate(person, role)
  91 + enterprise2 = fast_create(Enterprise, :visible => false)
  92 + enterprise2.affiliate(person, role)
  93 + block = EnterprisesBlock.new
  94 + person.boxes.first.blocks << block
  95 + block.save!
  96 + ids = block.profile_finder.ids
  97 + assert_includes ids, enterprise1.id
  98 + assert_not_includes ids, enterprise2.id
72 end 99 end
73 100
74 should 'link to all enterprises for profile' do 101 should 'link to all enterprises for profile' do
@@ -114,14 +141,31 @@ class EnterprisesBlockTest &lt; Test::Unit::TestCase @@ -114,14 +141,31 @@ class EnterprisesBlockTest &lt; Test::Unit::TestCase
114 assert_equal 2, block.profile_count 141 assert_equal 2, block.profile_count
115 end 142 end
116 143
117 - should 'not count non-public person enterprises' do  
118 - user = create_user('testuser').person 144 + should 'count non-public person enterprises' do
  145 + user = fast_create(Person)
119 146
120 - ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'ent1', :environment => Environment.default, :public_profile => true) 147 + ent1 = fast_create(Enterprise, :public_profile => true)
121 ent1.expects(:closed?).returns(false) 148 ent1.expects(:closed?).returns(false)
122 ent1.add_member(user) 149 ent1.add_member(user)
123 150
124 - ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'ent2', :environment => Environment.default, :public_profile => false) 151 + ent2 = fast_create(Enterprise, :public_profile => false)
  152 + ent2.expects(:closed?).returns(false)
  153 + ent2.add_member(user)
  154 +
  155 + block = EnterprisesBlock.new
  156 + block.expects(:owner).at_least_once.returns(user)
  157 +
  158 + assert_equal 2, block.profile_count
  159 + end
  160 +
  161 + should 'not count non-visible person enterprises' do
  162 + user = fast_create(Person)
  163 +
  164 + ent1 = fast_create(Enterprise, :visible => true)
  165 + ent1.expects(:closed?).returns(false)
  166 + ent1.add_member(user)
  167 +
  168 + ent2 = fast_create(Enterprise, :visible => false)
125 ent2.expects(:closed?).returns(false) 169 ent2.expects(:closed?).returns(false)
126 ent2.add_member(user) 170 ent2.add_member(user)
127 171
@@ -131,11 +175,22 @@ class EnterprisesBlockTest &lt; Test::Unit::TestCase @@ -131,11 +175,22 @@ class EnterprisesBlockTest &lt; Test::Unit::TestCase
131 assert_equal 1, block.profile_count 175 assert_equal 1, block.profile_count
132 end 176 end
133 177
134 - should 'not count non-public environment enterprises' do  
135 - env = Environment.create!(:name => 'test_env')  
136 - ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'ent1', :environment => env, :public_profile => true)  
137 178
138 - ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'ent2', :environment => env, :public_profile => false) 179 + should 'count non-public environment enterprises' do
  180 + env = fast_create(Environment)
  181 + ent1 = fast_create(Enterprise, :environment_id => env.id, :public_profile => true)
  182 + ent2 = fast_create(Enterprise, :environment_id => env.id, :public_profile => false)
  183 +
  184 + block = EnterprisesBlock.new
  185 + block.expects(:owner).at_least_once.returns(env)
  186 +
  187 + assert_equal 2, block.profile_count
  188 + end
  189 +
  190 + should 'not count non-visible environment enterprises' do
  191 + env = Environment.create!(:name => 'test_env')
  192 + ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'ent1', :environment => env, :visible => true)
  193 + ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'ent2', :environment => env, :visible => false)
139 194
140 block = EnterprisesBlock.new 195 block = EnterprisesBlock.new
141 block.expects(:owner).at_least_once.returns(env) 196 block.expects(:owner).at_least_once.returns(env)
test/unit/environment_statistics_block_test.rb
@@ -37,7 +37,7 @@ class EnvironmentStatisticsBlockTest &lt; Test::Unit::TestCase @@ -37,7 +37,7 @@ class EnvironmentStatisticsBlockTest &lt; Test::Unit::TestCase
37 assert_match(/One community/, content) 37 assert_match(/One community/, content)
38 end 38 end
39 39
40 - should 'generate statistics but not for private profiles' do 40 + should 'generate statistics including private profiles' do
41 env = create(Environment) 41 env = create(Environment)
42 user1 = create_user('testuser1', :environment_id => env.id) 42 user1 = create_user('testuser1', :environment_id => env.id)
43 user2 = create_user('testuser2', :environment_id => env.id) 43 user2 = create_user('testuser2', :environment_id => env.id)
@@ -55,6 +55,29 @@ class EnvironmentStatisticsBlockTest &lt; Test::Unit::TestCase @@ -55,6 +55,29 @@ class EnvironmentStatisticsBlockTest &lt; Test::Unit::TestCase
55 55
56 content = block.content 56 content = block.content
57 57
  58 + assert_match /2 enterprises/, content
  59 + assert_match /3 users/, content
  60 + assert_match /2 communities/, content
  61 + end
  62 +
  63 + should 'generate statistics but not for not visible profiles' do
  64 + env = create(Environment)
  65 + user1 = create_user('testuser1', :environment_id => env.id)
  66 + user2 = create_user('testuser2', :environment_id => env.id)
  67 + user3 = create_user('testuser3', :environment_id => env.id)
  68 + p = user3.person; p.visible = false; p.save!
  69 +
  70 + fast_create(Enterprise, :environment_id => env.id)
  71 + fast_create(Enterprise, :environment_id => env.id, :visible => false)
  72 +
  73 + fast_create(Community, :environment_id => env.id)
  74 + fast_create(Community, :environment_id => env.id, :visible => false)
  75 +
  76 + block = EnvironmentStatisticsBlock.new
  77 + env.boxes.first.blocks << block
  78 +
  79 + content = block.content
  80 +
58 assert_match /One enterprise/, content 81 assert_match /One enterprise/, content
59 assert_match /2 users/, content 82 assert_match /2 users/, content
60 assert_match /One community/, content 83 assert_match /One community/, content
test/unit/environment_test.rb
@@ -460,9 +460,9 @@ class EnvironmentTest &lt; Test::Unit::TestCase @@ -460,9 +460,9 @@ class EnvironmentTest &lt; Test::Unit::TestCase
460 assert_kind_of Person, e.person_template 460 assert_kind_of Person, e.person_template
461 461
462 # the templates must be private 462 # the templates must be private
463 - assert !e.enterprise_template.public?  
464 - assert !e.community_template.public?  
465 - assert !e.person_template.public? 463 + assert !e.enterprise_template.visible?
  464 + assert !e.community_template.visible?
  465 + assert !e.person_template.visible?
466 end 466 end
467 467
468 should 'set templates' do 468 should 'set templates' do
test/unit/friends_block_test.rb
@@ -62,10 +62,24 @@ class FriendsBlockTest &lt; ActiveSupport::TestCase @@ -62,10 +62,24 @@ class FriendsBlockTest &lt; ActiveSupport::TestCase
62 assert_equal 3, block.profile_count 62 assert_equal 3, block.profile_count
63 end 63 end
64 64
65 - should 'count number of public people' do 65 + should 'count number of public and private people' do
66 owner = create_user('testuser1').person 66 owner = create_user('testuser1').person
67 - private_p = create_user('private', {}, {:public_profile => false}).person  
68 - public_p = create_user('public', {}, {:public_profile => true}).person 67 + private_p = fast_create(Person, {:public_profile => false})
  68 + public_p = fast_create(Person, {:public_profile => true})
  69 +
  70 + owner.add_friend(private_p)
  71 + owner.add_friend(public_p)
  72 +
  73 + block = FriendsBlock.new
  74 + block.expects(:owner).returns(owner)
  75 +
  76 + assert_equal 2, block.profile_count
  77 + end
  78 +
  79 + should 'not count number of invisible people' do
  80 + owner = create_user('testuser1').person
  81 + private_p = fast_create(Person, {:visible => false})
  82 + public_p = fast_create(Person, {:visible => true})
69 83
70 owner.add_friend(private_p) 84 owner.add_friend(private_p)
71 owner.add_friend(public_p) 85 owner.add_friend(public_p)
@@ -75,4 +89,5 @@ class FriendsBlockTest &lt; ActiveSupport::TestCase @@ -75,4 +89,5 @@ class FriendsBlockTest &lt; ActiveSupport::TestCase
75 89
76 assert_equal 1, block.profile_count 90 assert_equal 1, block.profile_count
77 end 91 end
  92 +
78 end 93 end
test/unit/members_block_test.rb
@@ -27,19 +27,16 @@ class MembersBlockTest &lt; Test::Unit::TestCase @@ -27,19 +27,16 @@ class MembersBlockTest &lt; Test::Unit::TestCase
27 end 27 end
28 28
29 should 'pick random members' do 29 should 'pick random members' do
30 -  
31 - profile = create_user('mytestuser').person  
32 block = MembersBlock.new 30 block = MembersBlock.new
33 - block.box = profile.boxes.first  
34 block.limit = 2 31 block.limit = 2
35 block.save! 32 block.save!
36 33
37 owner = mock 34 owner = mock
38 block.expects(:owner).returns(owner) 35 block.expects(:owner).returns(owner)
39 36
40 - member1 = mock; member1.stubs(:id).returns(1)  
41 - member2 = mock; member2.stubs(:id).returns(2)  
42 - member3 = mock; member3.stubs(:id).returns(3) 37 + member1 = stub(:id => 1, :visible? => true)
  38 + member2 = stub(:id => 2, :visible? => true)
  39 + member3 = stub(:id => 3, :visible? => true)
43 40
44 owner.expects(:members).returns([member1, member2, member3]) 41 owner.expects(:members).returns([member1, member2, member3])
45 42
@@ -56,13 +53,13 @@ class MembersBlockTest &lt; Test::Unit::TestCase @@ -56,13 +53,13 @@ class MembersBlockTest &lt; Test::Unit::TestCase
56 profile = create_user('mytestuser').person 53 profile = create_user('mytestuser').person
57 owner = mock 54 owner = mock
58 55
59 - member1 = mock; member1.stubs(:id).returns(1)  
60 - member2 = mock; member2.stubs(:id).returns(2)  
61 - member3 = mock; member3.stubs(:id).returns(3) 56 + member1 = mock
  57 + member2 = mock
  58 + member3 = mock
62 59
63 - member1.stubs(:public_profile?).returns(true)  
64 - member2.stubs(:public_profile?).returns(true)  
65 - member3.stubs(:public_profile?).returns(true) 60 + member1.stubs(:visible?).returns(true)
  61 + member2.stubs(:visible?).returns(true)
  62 + member3.stubs(:visible?).returns(true)
66 63
67 owner.expects(:members).returns([member1, member2, member3]) 64 owner.expects(:members).returns([member1, member2, member3])
68 65
@@ -71,11 +68,26 @@ class MembersBlockTest &lt; Test::Unit::TestCase @@ -71,11 +68,26 @@ class MembersBlockTest &lt; Test::Unit::TestCase
71 assert_equal 3, block.profile_count 68 assert_equal 3, block.profile_count
72 end 69 end
73 70
74 - should 'not count non-public community members' do  
75 - community = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default) 71 + should 'count non-public community members' do
  72 + community = fast_create(Community)
  73 +
  74 + private_p = fast_create(Person, :public_profile => false)
  75 + public_p = fast_create(Person, :public_profile => true)
  76 +
  77 + community.add_member(private_p)
  78 + community.add_member(public_p)
  79 +
  80 + block = MembersBlock.new
  81 + block.expects(:owner).at_least_once.returns(community)
  82 +
  83 + assert_equal 2, block.profile_count
  84 + end
  85 +
  86 + should 'not count non-visible community members' do
  87 + community = fast_create(Community)
76 88
77 - private_p = create_user('private', {}, {:public_profile => false}).person  
78 - public_p = create_user('public', {}, {:public_profile => true}).person 89 + private_p = fast_create(Person, :visible => false)
  90 + public_p = fast_create(Person, :visible => true)
79 91
80 community.add_member(private_p) 92 community.add_member(private_p)
81 community.add_member(public_p) 93 community.add_member(public_p)
@@ -85,5 +97,6 @@ class MembersBlockTest &lt; Test::Unit::TestCase @@ -85,5 +97,6 @@ class MembersBlockTest &lt; Test::Unit::TestCase
85 97
86 assert_equal 1, block.profile_count 98 assert_equal 1, block.profile_count
87 end 99 end
  100 +
88 end 101 end
89 102
test/unit/organization_test.rb
@@ -239,4 +239,13 @@ class OrganizationTest &lt; Test::Unit::TestCase @@ -239,4 +239,13 @@ class OrganizationTest &lt; Test::Unit::TestCase
239 end 239 end
240 end 240 end
241 241
  242 + should 'be closed if organization is not public' do
  243 + organization = fast_create(Organization)
  244 + assert !organization.closed
  245 +
  246 + organization.public_profile = false
  247 + organization.save!
  248 +
  249 + assert organization.closed
  250 + end
242 end 251 end
test/unit/people_block_test.rb
@@ -25,10 +25,19 @@ class PeopleBlockTest &lt; ActiveSupport::TestCase @@ -25,10 +25,19 @@ class PeopleBlockTest &lt; ActiveSupport::TestCase
25 25
26 should 'list people' do 26 should 'list people' do
27 owner = Environment.create!(:name => 'test environment') 27 owner = Environment.create!(:name => 'test environment')
28 - Person.expects(:find).with(:all, :select => 'id', :conditions => { :environment_id => owner.id, :public_profile => true}, :limit => 6, :order => 'random()').returns([])  
29 block = PeopleBlock.new 28 block = PeopleBlock.new
30 block.expects(:owner).returns(owner).at_least_once 29 block.expects(:owner).returns(owner).at_least_once
31 - block.content 30 + person1 = fast_create(Person, :environment_id => owner.id)
  31 + person2 = fast_create(Person, :environment_id => owner.id)
  32 +
  33 + expects(:profile_image_link).with(person1).returns(person1.name)
  34 + expects(:profile_image_link).with(person2).returns(person2.name)
  35 + expects(:block_title).with(anything).returns('')
  36 +
  37 + content = instance_eval(&block.content)
  38 +
  39 + assert_match(/#{person1.name}/, content)
  40 + assert_match(/#{person2.name}/, content)
32 end 41 end
33 42
34 should 'link to people directory' do 43 should 'link to people directory' do
@@ -40,13 +49,27 @@ class PeopleBlockTest &lt; ActiveSupport::TestCase @@ -40,13 +49,27 @@ class PeopleBlockTest &lt; ActiveSupport::TestCase
40 instance_eval(&block.footer) 49 instance_eval(&block.footer)
41 end 50 end
42 51
43 - should 'count number of public people' do 52 + should 'count number of public and private people' do
  53 + env = Environment.create!(:name => 'test environment')
  54 + private_p = fast_create(Person, :environment_id => env.id, :public_profile => false)
  55 + public_p = fast_create(Person, :environment_id => env.id, :public_profile => true)
  56 +
  57 + env.boxes.first.blocks << block = PeopleBlock.new
  58 + assert_equal 2, block.profile_count
  59 + end
  60 +
  61 + should 'count number of visible people' do
44 env = Environment.create!(:name => 'test environment') 62 env = Environment.create!(:name => 'test environment')
45 - private_p = create_user('private', {:environment => env}, {:public_profile => false})  
46 - public_p = create_user('public', {:environment => env}, {:public_profile => true}) 63 + invisible_p = fast_create(Person, :environment_id => env.id, :visible => false)
  64 + visible_p = fast_create(Person, :environment_id => env.id, :visible => true)
47 65
48 env.boxes.first.blocks << block = PeopleBlock.new 66 env.boxes.first.blocks << block = PeopleBlock.new
49 assert_equal 1, block.profile_count 67 assert_equal 1, block.profile_count
50 end 68 end
51 69
  70 + protected
  71 +
  72 + def content_tag(tag, text, options = {})
  73 + text
  74 + end
52 end 75 end
test/unit/person_test.rb
@@ -510,11 +510,18 @@ class PersonTest &lt; Test::Unit::TestCase @@ -510,11 +510,18 @@ class PersonTest &lt; Test::Unit::TestCase
510 assert !p.ask_to_join?(c) 510 assert !p.ask_to_join?(c)
511 end 511 end
512 512
513 - should 'not ask to join if community is not public' do  
514 - p = create_user('test_user').person  
515 - c = Community.create!(:name => 'Test community', :identifier => 'test_community', :public_profile => false) 513 + should 'ask to join if community is not public' do
  514 + person = fast_create(Person)
  515 + community = fast_create(Community, :public_profile => false)
516 516
517 - assert !p.ask_to_join?(c) 517 + assert person.ask_to_join?(community)
  518 + end
  519 +
  520 + should 'not ask to join if community is not visible' do
  521 + person = fast_create(Person)
  522 + community = fast_create(Community, :visible => false)
  523 +
  524 + assert !person.ask_to_join?(community)
518 end 525 end
519 526
520 should 'save organization_website with http' do 527 should 'save organization_website with http' do
test/unit/profile_list_block_test.rb
@@ -42,17 +42,30 @@ class ProfileListBlockTest &lt; Test::Unit::TestCase @@ -42,17 +42,30 @@ class ProfileListBlockTest &lt; Test::Unit::TestCase
42 assert_kind_of String, instance_eval(&block.content) 42 assert_kind_of String, instance_eval(&block.content)
43 end 43 end
44 44
45 - should 'not list private profiles' do 45 + should 'list private profiles' do
46 env = Environment.create!(:name => 'test env') 46 env = Environment.create!(:name => 'test env')
47 - p1 = Profile.create!(:name => 'test1', :identifier => 'test1', :environment => env)  
48 - p2 = Profile.create!(:name => 'test2', :identifier => 'test2', :environment => env, :public_profile => false) # private profile 47 + profile1 = fast_create(Profile, :environment_id => env.id)
  48 + profile2 = fast_create(Profile, :environment_id => env.id, :public_profile => false) # private profile
49 block = ProfileListBlock.new 49 block = ProfileListBlock.new
50 env.boxes.first.blocks << block 50 env.boxes.first.blocks << block
51 block.save! 51 block.save!
52 52
53 ids = block.profile_finder.ids 53 ids = block.profile_finder.ids
54 - assert_includes ids, p1.id  
55 - assert_not_includes ids, p2.id 54 + assert_includes ids, profile1.id
  55 + assert_includes ids, profile2.id
  56 + end
  57 +
  58 + should 'not list invisible profiles' do
  59 + env = Environment.create!(:name => 'test env')
  60 + profile1 = fast_create(Profile, :environment_id => env.id)
  61 + profile2 = fast_create(Profile, :environment_id => env.id, :visible => false) # not visible profile
  62 + block = ProfileListBlock.new
  63 + env.boxes.first.blocks << block
  64 + block.save!
  65 +
  66 + ids = block.profile_finder.ids
  67 + assert_includes ids, profile1.id
  68 + assert_not_includes ids, profile2.id
56 end 69 end
57 70
58 should 'use finders to find profiles to be listed' do 71 should 'use finders to find profiles to be listed' do
@@ -83,21 +96,40 @@ class ProfileListBlockTest &lt; Test::Unit::TestCase @@ -83,21 +96,40 @@ class ProfileListBlockTest &lt; Test::Unit::TestCase
83 assert_equal '0 members', block.view_title 96 assert_equal '0 members', block.view_title
84 end 97 end
85 98
86 - should 'count number of public profiles' do 99 + should 'count number of public and private profiles' do
87 env = Environment.create!(:name => 'test env') 100 env = Environment.create!(:name => 'test env')
88 block = ProfileListBlock.new 101 block = ProfileListBlock.new
89 env.boxes.first.blocks << block 102 env.boxes.first.blocks << block
90 block.save! 103 block.save!
91 104
92 - priv_p = create_user('private', {:environment => env}, {:public_profile => false})  
93 - pub_p = create_user('public', {:environment => env}, {:public_profile => true}) 105 + priv_p = fast_create(Person, :environment_id => env.id, :public_profile => false)
  106 + pub_p = fast_create(Person, :environment_id => env.id, :public_profile => true)
94 107
95 - priv_c = Community.create!(:name => 'com 1', :public_profile => false, :environment => env)  
96 - pub_c = Community.create!(:name => 'com 2', :public_profile => true , :environment => env) 108 + priv_c = fast_create(Community, :public_profile => false, :environment_id => env.id)
  109 + pub_c = fast_create(Community, :public_profile => true , :environment_id => env.id)
97 110
98 - priv_e = Enterprise.create!(:name => 'ent 1', :identifier => 'ent1', :public_profile => false , :environment => env)  
99 - pub_e = Enterprise.create!(:name => 'ent 2', :identifier => 'ent2', :public_profile => true , :environment => env) 111 + priv_e = fast_create(Enterprise, :public_profile => false , :environment_id => env.id)
  112 + pub_e = fast_create(Enterprise, :public_profile => true , :environment_id => env.id)
  113 +
  114 + assert_equal 6, block.profile_count
  115 + end
  116 +
  117 + should 'only count number of visible profiles' do
  118 + env = Environment.create!(:name => 'test env')
  119 + block = ProfileListBlock.new
  120 + env.boxes.first.blocks << block
  121 + block.save!
  122 +
  123 + priv_p = fast_create(Person, :environment_id => env.id, :visible => false)
  124 + pub_p = fast_create(Person, :environment_id => env.id, :visible => true)
  125 +
  126 + priv_c = fast_create(Community, :visible => false, :environment_id => env.id)
  127 + pub_c = fast_create(Community, :visible => true , :environment_id => env.id)
  128 +
  129 + priv_e = fast_create(Enterprise, :visible => false , :environment_id => env.id)
  130 + pub_e = fast_create(Enterprise, :visible => true , :environment_id => env.id)
100 131
101 assert_equal 3, block.profile_count 132 assert_equal 3, block.profile_count
102 end 133 end
  134 +
103 end 135 end
test/unit/profile_test.rb
@@ -501,10 +501,10 @@ class ProfileTest &lt; Test::Unit::TestCase @@ -501,10 +501,10 @@ class ProfileTest &lt; Test::Unit::TestCase
501 end 501 end
502 502
503 should 'display private profile for members' do 503 should 'display private profile for members' do
504 - p = create_user('testuser').person  
505 - c = Community.create!(:name => 'my community', :public_profile => false) 504 + p = fast_create(Person)
  505 + c = fast_create(Community, :public_profile => false)
  506 + c.expects(:closed).returns(false)
506 c.add_member(p) 507 c.add_member(p)
507 -  
508 assert c.display_info_to?(p) 508 assert c.display_info_to?(p)
509 end 509 end
510 510
@@ -1509,6 +1509,14 @@ class ProfileTest &lt; Test::Unit::TestCase @@ -1509,6 +1509,14 @@ class ProfileTest &lt; Test::Unit::TestCase
1509 assert_equal false, Profile.is_available?('identifier-test', Environment.default) 1509 assert_equal false, Profile.is_available?('identifier-test', Environment.default)
1510 end 1510 end
1511 1511
  1512 + should 'not have long descriptions' do
  1513 + long_description = 'a' * 600
  1514 + profile = Profile.new
  1515 + profile.description = long_description
  1516 + profile.valid?
  1517 + assert profile.errors.invalid?(:description)
  1518 + end
  1519 +
1512 private 1520 private
1513 1521
1514 def assert_invalid_identifier(id) 1522 def assert_invalid_identifier(id)