diff --git a/app/controllers/public/content_viewer_controller.rb b/app/controllers/public/content_viewer_controller.rb
index f843298..13d98e9 100644
--- a/app/controllers/public/content_viewer_controller.rb
+++ b/app/controllers/public/content_viewer_controller.rb
@@ -47,7 +47,13 @@ class ContentViewerController < ApplicationController
end
if !@page.display_to?(user)
- render_access_denied(_('You are not allowed to view this content. You can contact the owner of this profile to request access then.'))
+ if profile.display_info_to?(user) || !profile.visible?
+ message = _('You are not allowed to view this content. You can contact the owner of this profile to request access then.')
+ render_access_denied(message)
+ elsif !profile.public?
+ redirect_to :controller => 'profile', :action => 'index', :profile => profile.identifier
+ end
+ return
end
# At this point the page will be showed
diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb
index af4b43a..cee2a6b 100644
--- a/app/controllers/public/profile_controller.rb
+++ b/app/controllers/public/profile_controller.rb
@@ -1,7 +1,7 @@
class ProfileController < PublicController
needs_profile
- before_filter :check_access_to_profile
+ before_filter :check_access_to_profile, :except => [:join, :refuse_join, :refuse_for_now, :index]
before_filter :store_before_join, :only => [:join]
before_filter :login_required, :only => [:join, :refuse_join, :leave]
@@ -9,6 +9,9 @@ class ProfileController < PublicController
def index
@tags = profile.article_tags
+ unless profile.display_info_to?(user)
+ profile.visible? ? private_profile : invisible_profile
+ end
end
def tags
@@ -112,7 +115,7 @@ class ProfileController < PublicController
def check_access_to_profile
unless profile.display_info_to?(user)
- 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"))
+ redirect_to :action => 'index'
end
end
@@ -130,6 +133,21 @@ class ProfileController < PublicController
end
end
+ def private_profile
+ if profile.person?
+ @action = :add_friend
+ @message = _("The content here is available to %s's friends only." % profile.short_name)
+ else
+ @action = :join
+ @message = _('The contents in this community is available to members only.')
+ end
+ @no_design_blocks = true
+ end
+
+ def invisible_profile
+ 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"))
+ end
+
def per_page
Noosfero::Constants::PROFILE_PER_PAGE
end
diff --git a/app/models/article.rb b/app/models/article.rb
index 2f4fb14..e23ea3d 100644
--- a/app/models/article.rb
+++ b/app/models/article.rb
@@ -125,8 +125,9 @@ class Article < ActiveRecord::Base
"advertise = ? AND
public_article = ? AND
published = ? AND
+ profiles.visible = ? AND
profiles.public_profile = ? AND
- ((articles.type != ? and articles.type != ? and articles.type != ?) OR articles.type is NULL)", true, true, true, true, 'UploadedFile', 'RssFeed', 'Blog'
+ ((articles.type != ? and articles.type != ? and articles.type != ?) OR articles.type is NULL)", true, true, true, true, true, 'UploadedFile', 'RssFeed', 'Blog'
],
:include => 'profile',
:order => 'articles.published_at desc, articles.id desc'
@@ -220,6 +221,8 @@ class Article < ActiveRecord::Base
false
end
+ named_scope :folders, :conditions => { :type => ['Folder', 'Blog'] }
+
def display_to?(user)
if self.public_article
self.profile.display_info_to?(user)
@@ -249,7 +252,7 @@ class Article < ActiveRecord::Base
end
def public?
- profile.public? && public_article
+ profile.visible? && profile.public? && public_article
end
def copy(options)
diff --git a/app/models/communities_block.rb b/app/models/communities_block.rb
index e82d47e..a99f5f2 100644
--- a/app/models/communities_block.rb
+++ b/app/models/communities_block.rb
@@ -34,9 +34,9 @@ class CommunitiesBlock < ProfileListBlock
def profile_count
if owner.kind_of?(Environment)
- owner.communities.count(:conditions => { :public_profile => true })
+ owner.communities.count(:conditions => { :visible => true })
else
- owner.communities(:public_profile => true).count
+ owner.communities(:visible => true).count
end
end
@@ -49,9 +49,9 @@ class CommunitiesBlock < ProfileListBlock
# FIXME when owner is an environment (i.e. listing communities globally
# this can become SLOW)
if block.owner.kind_of?(Environment)
- Community.find(:all, :conditions => {:environment_id => block.owner.id, :public_profile => true}, :limit => block.limit, :order => 'random()').map(&:id)
+ block.owner.communities.all(:conditions => {:visible => true}, :limit => block.limit, :order => 'random()').map(&:id)
else
- block.owner.communities.select(&:public_profile).map(&:id)
+ block.owner.communities(:visible => true).map(&:id)
end
end
end
diff --git a/app/models/community.rb b/app/models/community.rb
index d56ffad..5fca3ad 100644
--- a/app/models/community.rb
+++ b/app/models/community.rb
@@ -2,7 +2,6 @@ class Community < Organization
N_('Community')
N_('Language')
- settings_items :description
settings_items :language
settings_items :zip_code, :city, :state, :country
@@ -28,7 +27,6 @@ class Community < Organization
state
country
zip_code
- description
language
]
diff --git a/app/models/enterprises_block.rb b/app/models/enterprises_block.rb
index edcade0..f0c791d 100644
--- a/app/models/enterprises_block.rb
+++ b/app/models/enterprises_block.rb
@@ -30,9 +30,9 @@ class EnterprisesBlock < ProfileListBlock
def profile_count
if owner.kind_of?(Environment)
- owner.enterprises.count(:conditions => { :public_profile => true })
+ owner.enterprises.count(:conditions => { :visible => true })
else
- owner.enterprises(:public_profile => true).count
+ owner.enterprises(:visible => true).count
end
end
@@ -46,9 +46,9 @@ class EnterprisesBlock < ProfileListBlock
# FIXME when owner is an environment (i.e. listing enterprises globally
# this can become SLOW)
if block.owner.kind_of?(Environment)
- Enterprise.find(:all, :conditions => {:environment_id => block.owner.id, :public_profile => true}, :limit => block.limit, :order => 'random()').map(&:id)
+ block.owner.enterprises.all(:conditions => {:visible => true}, :limit => block.limit, :order => 'random()').map(&:id)
else
- block.owner.enterprises.select(&:public_profile).map(&:id)
+ block.owner.enterprises.select(&:visible).map(&:id)
end
end
end
diff --git a/app/models/environment.rb b/app/models/environment.rb
index 72f96b9..62bc523 100644
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -683,11 +683,11 @@ class Environment < ActiveRecord::Base
def create_templates
pre = self.name.to_slug + '_'
- ent_id = Enterprise.create!(:name => 'Enterprise template', :identifier => pre + 'enterprise_template', :environment => self, :public_profile => false).id
- com_id = Community.create!(:name => 'Community template', :identifier => pre + 'community_template', :environment => self, :public_profile => false).id
+ ent_id = Enterprise.create!(:name => 'Enterprise template', :identifier => pre + 'enterprise_template', :environment => self, :visible => false).id
+ com_id = Community.create!(:name => 'Community template', :identifier => pre + 'community_template', :environment => self, :visible => false).id
pass = Digest::MD5.hexdigest rand.to_s
user = User.create!(:login => (pre + 'person_template'), :email => (pre + 'template@template.noo'), :password => pass, :password_confirmation => pass, :environment => self).person
- user.public_profile = false
+ user.visible = false
user.save!
usr_id = user.id
self.settings[:enterprise_template_id] = ent_id
diff --git a/app/models/environment_statistics_block.rb b/app/models/environment_statistics_block.rb
index ac7f767..0125295 100644
--- a/app/models/environment_statistics_block.rb
+++ b/app/models/environment_statistics_block.rb
@@ -13,9 +13,9 @@ class EnvironmentStatisticsBlock < Block
end
def content
- users = owner.people.count(:conditions => { :public_profile => true })
- enterprises = owner.enterprises.count(:conditions => { :public_profile => true })
- communities = owner.communities.count(:conditions => { :public_profile => true })
+ users = owner.people.visible.count
+ enterprises = owner.enterprises.visible.count
+ communities = owner.communities.visible.count
info = [
n_('One user', '%{num} users', users) % { :num => users },
diff --git a/app/models/friends_block.rb b/app/models/friends_block.rb
index 4454aa8..594f382 100644
--- a/app/models/friends_block.rb
+++ b/app/models/friends_block.rb
@@ -30,7 +30,7 @@ class FriendsBlock < ProfileListBlock
end
def profile_count
- owner.friends.count(:conditions => { :public_profile => true })
+ owner.friends.visible.count
end
end
diff --git a/app/models/members_block.rb b/app/models/members_block.rb
index aea9eef..600c030 100644
--- a/app/models/members_block.rb
+++ b/app/models/members_block.rb
@@ -20,7 +20,7 @@ class MembersBlock < ProfileListBlock
end
def profile_count
- owner.members.select {|member| member.public_profile? }.count
+ owner.members.select {|member| member.visible? }.count
end
def profile_finder
@@ -30,7 +30,7 @@ class MembersBlock < ProfileListBlock
# Finds random members, up to the limit.
class Finder < ProfileListBlock::Finder
def ids
- block.owner.members.map(&:id)
+ block.owner.members.select {|member| member.visible? }.map(&:id)
end
end
diff --git a/app/models/organization.rb b/app/models/organization.rb
index d718866..7dd87f8 100644
--- a/app/models/organization.rb
+++ b/app/models/organization.rb
@@ -6,6 +6,10 @@ class Organization < Profile
closed
end
+ before_save do |organization|
+ organization.closed = true if !organization.public_profile?
+ end
+
settings_items :moderated_articles, :type => :boolean, :default => false
def moderated_articles?
moderated_articles
@@ -47,6 +51,7 @@ class Organization < Profile
contact_person
contact_phone
contact_email
+ description
legal_form
economic_activity
management_information
diff --git a/app/models/people_block.rb b/app/models/people_block.rb
index 88a226d..803c408 100644
--- a/app/models/people_block.rb
+++ b/app/models/people_block.rb
@@ -18,7 +18,7 @@ class PeopleBlock < ProfileListBlock
class Finder < ProfileListBlock::Finder
def ids
- Person.find(:all, :select => 'id', :conditions => { :environment_id => block.owner.id, :public_profile => true}, :limit => block.limit, :order => 'random()')
+ block.owner.people.visible.all(:limit => block.limit, :order => 'random()').map(&:id)
end
end
@@ -29,7 +29,7 @@ class PeopleBlock < ProfileListBlock
end
def profile_count
- owner.people.count(:conditions => {:public_profile => true})
+ owner.people.visible.count
end
end
diff --git a/app/models/person.rb b/app/models/person.rb
index 5d5a197..53bbcf7 100644
--- a/app/models/person.rb
+++ b/app/models/person.rb
@@ -66,6 +66,7 @@ class Person < Profile
custom_formation
contact_phone
contact_information
+ description
]
def self.fields
@@ -121,6 +122,7 @@ class Person < Profile
end
def memberships(conditions = {})
+ # FIXME this should be a proper ActiveRecord relationship!
Profile.find(
:all,
:conditions => self.class.conditions_for_profiles(conditions, self),
@@ -236,7 +238,7 @@ class Person < Profile
has_and_belongs_to_many :refused_communities, :class_name => 'Community', :join_table => 'refused_join_community'
def ask_to_join?(community)
- return false if !community.public_profile
+ return false if !community.visible?
return false if memberships.include?(community)
return false if AddMember.find(:first, :conditions => {:requestor_id => self.id, :target_id => community.id})
!refused_communities.include?(community)
diff --git a/app/models/profile.rb b/app/models/profile.rb
index e9498d2..e497c56 100644
--- a/app/models/profile.rb
+++ b/app/models/profile.rb
@@ -53,6 +53,8 @@ class Profile < ActiveRecord::Base
acts_as_taggable
+ named_scope :visible, :conditions => { :visible => true }
+
# FIXME ugly workaround
def self.human_attribute_name(attrib)
_(self.superclass.human_attribute_name(attrib))
@@ -73,6 +75,9 @@ class Profile < ActiveRecord::Base
acts_as_having_settings :field => :data
settings_items :public_content, :type => :boolean, :default => true
+ settings_items :description
+
+ validates_length_of :description, :maximum => 550, :allow_nil => true
acts_as_mappable :default_units => :kms
@@ -283,7 +288,7 @@ class Profile < ActiveRecord::Base
self.save_without_validation!
end
- xss_terminate :only => [ :name, :nickname, :address, :contact_phone ]
+ xss_terminate :only => [ :name, :nickname, :address, :contact_phone, :description ]
xss_terminate :only => [ :custom_footer, :custom_header ], :with => 'white_list'
# returns the contact email for this profile.
@@ -508,15 +513,10 @@ private :generate_url, :url_options
# returns +true+ if the given +user+ can see profile information about this
# +profile+, and +false+ otherwise.
def display_info_to?(user)
- if self.public_profile
+ if self.public?
true
else
- if user.nil?
- false
- else
- # other possibilities would come here
- (user == self) || (user.is_admin?(self.environment)) || (user.memberships.include?(self))
- end
+ display_private_info_to?(user)
end
end
@@ -587,7 +587,11 @@ private :generate_url, :url_options
end
def public?
- public_profile
+ visible && public_profile
+ end
+
+ def privacy_setting
+ self.public? ? _('Public profile') : _('Private profile')
end
def themes
@@ -623,7 +627,11 @@ private :generate_url, :url_options
end
def folders
- self.articles.find(:all, :conditions => ['type in (?)', ['Folder', 'Blog']])
+ articles.folders
+ end
+
+ def image_galleries
+ folders.select { |folder| folder.display_as_gallery?}
end
def blocks_to_expire_cache
@@ -668,4 +676,13 @@ private :generate_url, :url_options
self.update_attribute(:layout_template, template)
end
+ protected
+
+ def display_private_info_to?(user)
+ if user.nil?
+ false
+ else
+ (user == self) || (user.is_admin?(self.environment)) || (user.memberships.include?(self))
+ end
+ end
end
diff --git a/app/models/profile_list_block.rb b/app/models/profile_list_block.rb
index 392b6fa..4b8fe90 100644
--- a/app/models/profile_list_block.rb
+++ b/app/models/profile_list_block.rb
@@ -42,7 +42,7 @@ class ProfileListBlock < Block
rand(top)
end
def ids
- Profile.find(:all, :limit => block.limit, :order => 'random()', :conditions => {:environment_id => block.owner.id, :public_profile => true}).map(&:id)
+ block.owner.profiles.visible.all(:limit => block.limit, :order => 'random()').map(&:id)
end
end
@@ -90,7 +90,7 @@ class ProfileListBlock < Block
end
def profile_count
- owner.profiles.count(:conditions => {:public_profile => true})
+ owner.profiles.visible.count
end
end
diff --git a/app/views/blocks/my_network/person.rhtml b/app/views/blocks/my_network/person.rhtml
index c53654a..9099aa0 100644
--- a/app/views/blocks/my_network/person.rhtml
+++ b/app/views/blocks/my_network/person.rhtml
@@ -3,7 +3,7 @@
content_tag('b', owner.articles.count), owner.public_profile_url.merge(:action => 'sitemap') ) %>
<%= link_to(n__('One friend', '%s friends', owner.friends.count) %
content_tag('b', owner.friends.count), owner.public_profile_url.merge(:action => 'friends')) %>
- <%= link_to(n__('One community', '%{num} communities', owner.communities.size) %
+ <%= link_to(n__('One community', '%{num} communities', owner.communities(:visible => true).size) %
{:num => content_tag('b', owner.communities.size)}, owner.public_profile_url.merge(:action => 'communities')) %>
<%= link_to(n_('One tag', '%s tags', owner.article_tags.size) %
content_tag('b', owner.article_tags.size), owner.public_profile_url.merge(:action => 'tags')) %>
diff --git a/app/views/profile/_organization.rhtml b/app/views/profile/_organization.rhtml
index 63fdf22..4fd2cf6 100644
--- a/app/views/profile/_organization.rhtml
+++ b/app/views/profile/_organization.rhtml
@@ -1,13 +1,24 @@
<%= _('Basic information')%> |
-<%= display_field(_('Name:'), profile, :name) { |name| link_to name, profile.url } %>
+<%= display_field(_('Description:'), profile, :description) if !@action %>
+
- |
+ <%= _('Members') %> |
- <%= link_to _('Members') + " (%s)" % profile.members.count, :controller => 'profile', :action => 'members' %>
+ <%= link_to profile.members.count, :controller => 'profile', :action => 'members' %>
|
+
+<%= display_field(_('Type:'), profile, :privacy_setting, true) %>
+
+<%= display_field(_('Location:'), profile, :location, true) %>
+
+
+ <%= _('Created at:') %> |
+ <%= show_date(profile.created_at) %> |
+
+
<% if profile.kind_of?(Enterprise) && !profile.environment.enabled?('disable_products_for_enterprises') %>
|
@@ -16,3 +27,10 @@
<% end %>
+
+
+ <%= _('Administrators:') %> |
+
+ <%= profile.admins.map { |admin| link_to(admin.short_name, admin.url)}.join(', ') %>
+ |
+
diff --git a/app/views/profile/_person.rhtml b/app/views/profile/_person.rhtml
index 202300a..cffeeb2 100644
--- a/app/views/profile/_person.rhtml
+++ b/app/views/profile/_person.rhtml
@@ -1,11 +1,18 @@
<%= _('Basic information')%> |
-<%= display_field(_('Name:'), profile, :name, true) { |name| link_to name, profile.url } %>
+<%= display_field(_('About:'), profile, :description) if !@action %>
<%= display_field(_('Sex:'), profile, :sex) { |gender| { 'male' => _('Male'), 'female' => _('Female') }[gender] } %>
<%= display_field(_('Date of birth:'), profile, :birth_date) { |date| show_date(date) }%>
<%= display_field(_('Location:'), profile, :location, true) %>
+<%= display_field(_('Type:'), profile, :privacy_setting, true) %>
+
+
+ <%= _('Created at:') %> |
+ <%= show_date(profile.created_at) %> |
+
+
<% if profile == user || profile.friends.include?(user) %>
<%= _('Contact')%> |
@@ -42,12 +49,12 @@
<%= _('Network')%> |
- |
- <%= link_to __('Friends') + (' (%d)' % profile.friends.count), { :controller => 'profile', :action => 'friends' } %> |
+ <%= __('Friends') + ':' %> |
+ <%= link_to profile.friends.count, { :controller => 'profile', :action => 'friends' } %> |
- |
- <%= link_to __('Communities') + (' (%d)' % profile.communities.count), :controller => "profile", :action => 'communities' %> |
+ <%= __('Communities') + ':' %> |
+ <%= link_to profile.communities.count, :controller => "profile", :action => 'communities' %> |
<% if !environment.enabled?('disable_categories') && !profile.interests.empty? %>
diff --git a/app/views/profile/_private_profile.rhtml b/app/views/profile/_private_profile.rhtml
new file mode 100644
index 0000000..1bff167
--- /dev/null
+++ b/app/views/profile/_private_profile.rhtml
@@ -0,0 +1,17 @@
+
+ <%= profile_image(profile, :big) %>
+
+
+<%= @message %>
+<%= profile.description %>
+
+<% button_bar do %>
+ <% if @action == :join && logged_in? %>
+ <%= lightbox_link_to content_tag('span', _('Join')), profile.join_url, :class => 'button with-text icon-add', :title => _('Join this community') %>
+ <% end %>
+ <% if @action == :add_friend && logged_in? && !user.already_request_friendship?(profile) %>
+ <%= link_to content_tag('span', __('Add friend')), user.url.merge(:controller => 'friends', :action => 'add', :id => profile.id), :class => 'button with-text icon-add' %>
+ <% end %>
+ <%= button :back, _('Go back'), :back %>
+ <%= button :home, _("Go to %s home page") % environment.name, :controller => 'home' %>
+<% end %>
diff --git a/app/views/profile/index.rhtml b/app/views/profile/index.rhtml
index 7b97cd2..306a8cb 100644
--- a/app/views/profile/index.rhtml
+++ b/app/views/profile/index.rhtml
@@ -4,38 +4,66 @@
<% end %>
-<%= _("%s's profile") % profile.name %>
+<%= profile.name %>
+
+<% if @action %>
+ <%= render :partial => 'private_profile' %>
+<% end %>
<%= render :partial => partial_for_class(profile.class) %>
- <% cache_timeout(profile.identifier + '-profile-general-info', 4.hours.from_now) do %>
-
-
- <%= _('Content') %>
- |
-
-
-
- <%= _('Content published:') %>
- |
-
- <%= link_to _('Site map'), :controller => 'profile', :action => 'sitemap' %>
- |
-
-
-
- |
-
- <%= link_to _('Events'), :controller => 'events', :action => 'events' %>
- |
-
-
-
- <%= _('Tags:') %>
- |
-
- <%= tag_cloud @tags, :id, { :action => 'tag' }, :max_size => 18, :min_size => 10%>
- |
-
+
+ <% unless @action %>
+ <% cache_timeout(profile.identifier + '-profile-general-info', 4.hours.from_now) do %>
+
+
+ <%= _('Content') %>
+ |
+
+
+ <% profile.blogs.each do |blog| %>
+
+ <%= blog.name + ':' %> |
+
+ <%= link_to(n_('One post', '%{num} posts', blog.posts.count) % { :num => blog.posts.count }, blog.url) %>
+ |
+
+ <% end %>
+ <% profile.image_galleries.each do |gallery| %>
+
+ <%= gallery.name + ':' %> |
+
+ <%= link_to(n_('One picture', '%{num} pictures', gallery.images.count) % { :num => gallery.images.count }, gallery.url) %>
+ |
+
+ <% end %>
+
+
+ <%= _('Events:') %> |
+
+ <%= link_to profile.events.count, :controller => 'events', :action => 'events' %>
+ |
+
+
+
+ <%= _('Tags:') %>
+ |
+
+ <%= tag_cloud @tags, :id, { :action => 'tag' }, :max_size => 18, :min_size => 10%>
+ |
+
+
+ <% if !environment.enabled?('disable_categories') && !profile.interests.empty? %>
+
+ <%= _('Interests') %> |
+
+ <% profile.interests.each do |item| %>
+
+ |
+ <%= link_to item.name, :controller => 'search', :action => 'category_index', :category_path => item.explode_path %> |
+
+ <% end %>
+ <% end %>
+ <% end %>
<% end %>
diff --git a/app/views/profile_editor/_person_form.rhtml b/app/views/profile_editor/_person_form.rhtml
index 0821c40..dc847a5 100644
--- a/app/views/profile_editor/_person_form.rhtml
+++ b/app/views/profile_editor/_person_form.rhtml
@@ -9,6 +9,7 @@
<% end %>
+<%= optional_field(@person, 'description', f.text_area(:description, :rows => 5)) %>
<%= optional_field(@person, 'preferred_domain', select_preferred_domain(:profile_data)) %>
<%= optional_field(@person, 'contact_information', f.text_field(:contact_information)) %>
<%= optional_field(@person, 'contact_phone', labelled_form_field(_('Home phone'), text_field(:profile_data, :contact_phone))) %>
diff --git a/app/views/profile_editor/edit.rhtml b/app/views/profile_editor/edit.rhtml
index 094c068..fcade60 100644
--- a/app/views/profile_editor/edit.rhtml
+++ b/app/views/profile_editor/edit.rhtml
@@ -35,13 +35,13 @@
<%= _('Activate Intranet access (restricted area only for me)') %> | <%= _('Yes') %> | <%= _('Yes') %> |
- <%= _('Show my website to all internet users') %> | <%= _('Yes') %> | <%= _('No') %> |
+ <%= _('Include my contact in directory of people') %> | <%= _('Yes') %> | <%= _('Yes') %> |
- <%= _('Show my website to my contacts (persons)') %> | <%= _('Yes') %> | <%= _('Yes') %> |
+ <%= _('Show my contents to all internet users') %> | <%= _('Yes') %> | <%= _('No') %> |
- <%= _('Include my contact in directory of people') %> | <%= _('Yes') %> | <%= _('No') %> |
+ <%= _('Show my contents to my friends (person)') %> | <%= _('Yes') %> | <%= _('Yes') %> |
<% else %>
@@ -63,13 +63,13 @@
<%= _('Activate Intranet access (restricted area only for members)') %> | <%= _('Yes') %> | <%= _('Yes') %> |
- <%= _('Show website of this group to all internet users') %> | <%= _('Yes') %> | <%= _('No') %> |
+ <%= _('Include this group directory of groups') %> | <%= _('Yes') %> | <%= _('Yes') %> |
- <%= _('Show my website to members') %> | <%= _('Yes') %> | <%= _('Yes') %> |
+ <%= _('Show content of this group to all internet users') %> | <%= _('Yes') %> | <%= _('No') %> |
- <%= _('Include this group directory of groups') %> | <%= _('Yes') %> | <%= _('No') %> |
+ <%= _('Show content of this group to members') %> | <%= _('Yes') %> | <%= _('Yes') %> |
<% end %>
diff --git a/app/views/search/_display_results.rhtml b/app/views/search/_display_results.rhtml
index 97ce519..7ba45e4 100644
--- a/app/views/search/_display_results.rhtml
+++ b/app/views/search/_display_results.rhtml
@@ -45,7 +45,7 @@
<% hit_pos = 0 %>
<% results.each do |hit| %>
- <% next if hit.respond_to?(:public?) && !hit.public? %>
+ <% next if hit.respond_to?(:visible) && !hit.visible? %>
<%= render :partial => partial_for_class(hit.class),
:object => hit,
diff --git a/app/views/shared/_custom_fields.rhtml b/app/views/shared/_custom_fields.rhtml
index 7def9c8..b045963 100644
--- a/app/views/shared/_custom_fields.rhtml
+++ b/app/views/shared/_custom_fields.rhtml
@@ -1,8 +1,8 @@
<% if profile.community? %>
- <%= optional_field(profile, 'description', f.text_area(:description, :rows => 5)) %>
<%= optional_field(profile, 'language', f.text_field(:language), only_required) %>
<% end %>
+<%= optional_field(profile, 'description', f.text_area(:description, :rows => 5)) %>
<%= optional_field(profile, 'contact_person', f.text_field(:contact_person), only_required) %>
<%= optional_field(profile, 'contact_email', f.text_field(:contact_email), only_required) %>
<%= optional_field(profile, 'contact_phone', f.text_field(:contact_phone), only_required) %>
diff --git a/app/views/shared/access_denied.rhtml b/app/views/shared/access_denied.rhtml
index 044a32e..9daed0c 100644
--- a/app/views/shared/access_denied.rhtml
+++ b/app/views/shared/access_denied.rhtml
@@ -9,9 +9,11 @@
<%= _("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.") %>
<% end %>
-
- - <%= link_to _('Go to the site home page'), :controller => 'home' %>
- - <%= link_to _('Go back'), :back %>
-
+
+
+ <% button_bar do %>
+ <%= button :back, _('Go back'), :back %>
+ <%= button :home, _('Go to the site home page'), :controller => 'home' %>
+ <% end %>
diff --git a/app/views/shared/not_found.rhtml b/app/views/shared/not_found.rhtml
index 473beec..62c7ba8 100644
--- a/app/views/shared/not_found.rhtml
+++ b/app/views/shared/not_found.rhtml
@@ -4,8 +4,8 @@
<%= _('You may have clicked an expired link or mistyped the address.') %>
<%= _('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.') %>
-
- - <%= link_to _('Go to the site home page'), :controller => 'home' %>
- - <%= link_to _('Go back'), :back %>
-
+ <% button_bar do %>
+ <%= button :back, _('Go back'), :back %>
+ <%= button :home, _('Go to %s home page') % environment.name, :controller => 'home' %>
+ <% end %>
diff --git a/db/migrate/080_add_visible_to_profiles.rb b/db/migrate/080_add_visible_to_profiles.rb
new file mode 100644
index 0000000..68ecc1d
--- /dev/null
+++ b/db/migrate/080_add_visible_to_profiles.rb
@@ -0,0 +1,9 @@
+class AddVisibleToProfiles < ActiveRecord::Migration
+ def self.up
+ add_column :profiles, :visible, :boolean, :default => true
+ end
+
+ def self.down
+ remove_column :profiles, :visible
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index f548cb5..20d41c0 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 79) do
+ActiveRecord::Schema.define(:version => 80) do
create_table "article_versions", :force => true do |t|
t.integer "article_id"
@@ -270,6 +270,7 @@ ActiveRecord::Schema.define(:version => 79) do
t.date "birth_date"
t.integer "preferred_domain_id"
t.datetime "updated_at"
+ t.boolean "visible", :default => true
end
add_index "profiles", ["environment_id"], :name => "index_profiles_on_environment_id"
diff --git a/features/my_network_block.feature b/features/my_network_block.feature
new file mode 100644
index 0000000..b5ef0fb
--- /dev/null
+++ b/features/my_network_block.feature
@@ -0,0 +1,68 @@
+Feature: my_network_block
+ As a blog owner
+ I want to see a summary of my network
+
+ Background:
+ Given the following users
+ | login | name |
+ | joaosilva | Joao Silva |
+ And the following blocks
+ | owner | type |
+ | joaosilva | MyNetworkBlock |
+ And the following communities
+ | identifier | name | public_profile |
+ | public-community | Public Community | true |
+
+ Scenario: display how many public/private communities I am member
+ Given the following communities
+ | identifier | name | owner | public_profile |
+ | other-public-community | Other Public Community | joaosilva | true |
+ | private-community | Private Community | joaosilva | false |
+ And I am logged in as "joaosilva"
+ And I am on Joao Silva's homepage
+ Then I should see "2 communities"
+ When I go to Public Community's homepage
+ And I follow "Join"
+ And I press "Yes, I want to join."
+ When I go to Joao Silva's homepage
+ Then I should see "3 communities"
+
+ Scenario: not display how many invisible communities I am member
+ Given the following communities
+ | identifier | name | owner | visible |
+ | visible-community | Visible Community | joaosilva | true |
+ | not-visible-community | Not Visible Community | joaosilva | false |
+ And I am logged in as "joaosilva"
+ And I am on Joao Silva's homepage
+ Then I should see "One community"
+ When I go to Public Community's homepage
+ And I follow "Join"
+ And I press "Yes, I want to join."
+ When I go to Joao Silva's homepage
+ Then I should see "2 communities"
+
+ Scenario: display how many public/private friends I have
+ Given the following users
+ | login | name | public_profile |
+ | mariasilva | Maria Silva | true |
+ | josesilva | Jose Silva | false |
+ And "joaosilva" is friend of "mariasilva"
+ And I am logged in as "joaosilva"
+ And I am on Joao Silva's homepage
+ Then I should see "1 friend"
+ And "joaosilva" is friend of "josesilva"
+ When I go to Joao Silva's homepage
+ Then I should see "2 friends"
+
+ Scenario: not display how many invisible friends I have
+ Given the following users
+ | login | name | visible |
+ | mariasilva | Maria Silva | true |
+ | josesilva | Jose Silva | false |
+ And "joaosilva" is friend of "mariasilva"
+ And I am logged in as "joaosilva"
+ When I go to Joao Silva's homepage
+ Then I should see "1 friend"
+ And "joaosilva" is friend of "josesilva"
+ When I go to Joao Silva's homepage
+ Then I should see "1 friend"
diff --git a/features/private_profile.feature b/features/private_profile.feature
new file mode 100644
index 0000000..bc6983b
--- /dev/null
+++ b/features/private_profile.feature
@@ -0,0 +1,31 @@
+Feature: private profiles
+ As a profile administrator
+ I want to set it to private
+ So that only members/friends can view its contents
+
+ Background:
+ Given the following community
+ | identifier | name | public_profile |
+ | safernet | Safernet | false |
+ And the following users
+ | login | public_profile |
+ | joao | true |
+ | shygirl | false |
+
+ Scenario: joining a private community
+ Given I am logged in as "joao"
+ When I go to Safernet's homepage
+ Then I should see "members only"
+ When I follow "Join"
+ And I press "Yes, I want to join"
+ And "joao" is accepted on community "Safernet"
+ Then "joao" should be a member of "Safernet"
+ When I go to Safernet's homepage
+ And I should not see "members only"
+
+ Scenario: adding a friend with private profile
+ Given I am logged in as "joao"
+ When I go to shygirl's homepage
+ Then I should see "friends only"
+ When I follow "Add friend"
+ And I press "Yes, I want"
diff --git a/features/publish_article.feature b/features/publish_article.feature
index af4e005..75b02c2 100644
--- a/features/publish_article.feature
+++ b/features/publish_article.feature
@@ -27,7 +27,7 @@ Feature: publish article
And I press "Publish"
And I am on Sample Community's homepage
And I follow "View profile"
- And I follow "Site map"
+ And I go to Sample Community's sitemap
When I follow "Sample Article"
Then I should see "This is the first published article"
@@ -82,11 +82,11 @@ Feature: publish article
Then I should see "Validation failed: Slug (the code generated from the article name) is already being used by another article.:"
And I am on Another Community1's homepage
And I follow "View profile"
- When I follow "Site map"
+ When I go to Another Community1's sitemap
Then I should see "Sample Article"
And I am on Another Community2's homepage
And I follow "View profile"
- When I follow "Site map"
+ When I go to Another Community2's sitemap
Then I should see "Sample Article"
Scenario: publishing articles with the same name in a moderated community
diff --git a/features/step_definitions/noosfero_steps.rb b/features/step_definitions/noosfero_steps.rb
index 22376c5..e662020 100644
--- a/features/step_definitions/noosfero_steps.rb
+++ b/features/step_definitions/noosfero_steps.rb
@@ -101,6 +101,12 @@ Then /^"(.+)" should be a member of "(.+)"$/ do |person,profile|
Profile.find_by_name(profile).members.should include(Person.find_by_name(person))
end
+When /^"(.*)" is accepted on community "(.*)"$/ do |person, community|
+ person = Person.find_by_name(person)
+ community = Community.find_by_name(community)
+ community.affiliate(person, Profile::Roles.member(community.environment.id))
+end
+
Given /^"(.+)" is admin of "(.+)"$/ do |person, organization|
org = Profile.find_by_name(organization)
user = Profile.find_by_name(person)
@@ -135,3 +141,7 @@ end
Given /^(.+) is member of (.+)$/ do |person, group|
Organization[group].add_member(Person[person])
end
+
+Given /^"(.+)" is friend of "(.+)"$/ do |person, friend|
+ Person[person].add_friend(Person[friend])
+end
diff --git a/features/support/paths.rb b/features/support/paths.rb
index ddc22dd..e258b0e 100644
--- a/features/support/paths.rb
+++ b/features/support/paths.rb
@@ -26,6 +26,9 @@ module NavigationHelpers
when /^(.*)'s homepage$/
'/%s' % Profile.find_by_name($1).identifier
+ when /^(.*)'s sitemap/
+ '/profile/%s/sitemap' % Profile.find_by_name($1).identifier
+
when /^login page$/
'/account/login'
diff --git a/public/images/icons-app/alert-icon.png b/public/images/icons-app/alert-icon.png
deleted file mode 100644
index 68a0c5f..0000000
Binary files a/public/images/icons-app/alert-icon.png and /dev/null differ
diff --git a/public/stylesheets/common.css b/public/stylesheets/common.css
index b25af1c..c37b11d 100644
--- a/public/stylesheets/common.css
+++ b/public/stylesheets/common.css
@@ -31,9 +31,6 @@ code, pre { color: #666; }
padding: 0em;
}
-#notice {
- cursor: pointer;
-}
#environment_identification {
position: absolute !important;
@@ -134,9 +131,8 @@ div#notice {
left: 50%;
margin-left: -200px;
width: 400px;
- border: 1px solid #545454;
- background: #ffffa9;
- padding: 10px;
+ border: 1px solid #ddd;
+ background: #ffd;
}
/* * * Generic Content Formating * * */
@@ -280,6 +276,7 @@ td.field-name {
color: #888;
width: 150px;
text-align: left;
+ vertical-align: top;
}
table.profile th {
@@ -495,8 +492,7 @@ div.pending-tasks {
#content #not-found h1,
#content #access-denied h1 {
text-align: left;
- background: url(../images/icons-app/alert-icon.png) no-repeat;
- padding-left: 30px;
+ margin-top: 0px;
}
#content #not-found p,
@@ -504,6 +500,11 @@ div.pending-tasks {
text-align: justify;
}
+#content #not-found .button-bar,
+#content #access-denied .button-bar {
+ margin-bottom: 0px;
+}
+
/**** Signup wizard ****/
#wizard-iframe {
diff --git a/public/stylesheets/controller_profile.css b/public/stylesheets/controller_profile.css
index 8843504..82626ac 100644
--- a/public/stylesheets/controller_profile.css
+++ b/public/stylesheets/controller_profile.css
@@ -9,3 +9,28 @@
#pagination-profiles .pagination span {
display: inline;
}
+
+.no-boxes {
+ margin: 0px 260px 0px 260px;
+}
+
+#content .no-boxes h1 {
+ margin: 1px 0px 1px 160px;
+}
+
+#content .no-boxes h1,
+#content .no-boxes table th {
+ text-align: left;
+}
+
+.private-profile-message {
+ font-style: italic;
+ border: 1px solid #ddd;
+ background: #ffd;
+ padding: 10px;
+}
+
+.private-profile-message,
+.private-profile-description {
+ margin: 5px 0px 5px 160px;
+}
diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb
index ee8933b..5d0ecf3 100644
--- a/test/functional/content_viewer_controller_test.rb
+++ b/test/functional/content_viewer_controller_test.rb
@@ -577,9 +577,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase
should 'deny access before trying SSL when SSL is disabled' do
@controller.expects(:redirect_to_ssl).returns(false)
- profile = create_user('testuser').person
- profile.public_profile = false
- profile.save!
+ profile = create_user('testuser', {}, :visible => false).person
get :view_page, :profile => 'testuser', :page => profile.home_page.explode_path
assert_response 403
diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb
index 0416a72..e692be5 100644
--- a/test/functional/profile_controller_test.rb
+++ b/test/functional/profile_controller_test.rb
@@ -136,7 +136,7 @@ class ProfileControllerTest < Test::Unit::TestCase
should 'show friends link to person' do
person = create_user('person_1').person
get :index, :profile => person.identifier
- assert_tag :tag => 'a', :content => /Friends/, :attributes => { :href => /profile\/#{person.identifier}\/friends$/ }
+ assert_tag :tag => 'a', :content => /#{profile.friends.count}/, :attributes => { :href => /profile\/#{person.identifier}\/friends$/ }
end
should 'display tag for profile' do
@@ -223,6 +223,9 @@ class ProfileControllerTest < Test::Unit::TestCase
should 'check access before displaying profile' do
Person.any_instance.expects(:display_info_to?).with(anything).returns(false)
+ @profile.visible = false
+ @profile.save
+
get :index, :profile => @profile.identifier
assert_response 403
end
@@ -299,12 +302,6 @@ class ProfileControllerTest < Test::Unit::TestCase
assert_no_tag :tag => 'a', :attributes => { :href => '/catalog/my-test-enterprise'}, :content => /Products\/Services/
end
- should 'display "Site map" link for profiles' do
- profile = create_user('testmapuser').person
- get :index, :profile => profile.identifier
- assert_tag :tag => 'a', :content => "Site map", :attributes => { :href => '/profile/testmapuser/sitemap' }
- end
-
should 'list top level articles in sitemap' do
get :sitemap, :profile => 'testuser'
assert_equal @profile.top_level_articles, assigns(:articles)
diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb
index a9db772..c0893a0 100644
--- a/test/unit/article_test.rb
+++ b/test/unit/article_test.rb
@@ -177,9 +177,17 @@ class ArticleTest < Test::Unit::TestCase
end
should 'not show documents from a private profile as recent' do
- p = create_user('usr1').person
- p.public_profile = false
- p.save!
+ p = fast_create(Person, :public_profile => false)
+ Article.destroy_all
+
+ first = p.articles.build(:name => 'first', :published => true); first.save!
+ second = p.articles.build(:name => 'second', :published => false); second.save!
+
+ assert_equal [ ], Article.recent(nil)
+ end
+
+ should 'not show documents from a invisible profile as recent' do
+ p = fast_create(Person, :visible => false)
Article.destroy_all
first = p.articles.build(:name => 'first', :published => true); first.save!
@@ -520,6 +528,15 @@ class ArticleTest < Test::Unit::TestCase
assert !a2.public?
end
+ should 'respond to public? as false if profile is invisible' do
+ profile = fast_create(Profile, :visible => false)
+ article1 = fast_create(Article, :profile_id => profile.id)
+ article2 = fast_create(Article, :profile_id => profile.id, :public_article => false)
+
+ assert !article1.public?
+ assert !article2.public?
+ end
+
should 'save as private' do
profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile')
folder = Folder.create!(:name => 'my_intranet', :profile => profile, :public_article => false)
diff --git a/test/unit/communities_block_test.rb b/test/unit/communities_block_test.rb
index 967fc73..ae1cf72 100644
--- a/test/unit/communities_block_test.rb
+++ b/test/unit/communities_block_test.rb
@@ -30,19 +30,19 @@ class CommunitiesBlockTest < Test::Unit::TestCase
owner = mock
block.expects(:owner).at_least_once.returns(owner)
- member1 = mock; member1.stubs(:id).returns(1); member1.stubs(:public_profile).returns(true)
- member2 = mock; member2.stubs(:id).returns(2); member2.stubs(:public_profile).returns(true)
- member3 = mock; member3.stubs(:id).returns(3); member3.stubs(:public_profile).returns(true)
+ community1 = mock; community1.stubs(:id).returns(1); community1.stubs(:visible).returns(true)
+ community2 = mock; community2.stubs(:id).returns(2); community2.stubs(:visible).returns(true)
+ community3 = mock; community3.stubs(:id).returns(3); community3.stubs(:visible).returns(true)
- owner.expects(:communities).returns([member1, member2, member3])
+ owner.expects(:communities).returns([community1, community2, community3])
block.profile_finder.expects(:pick_random).with(3).returns(2)
block.profile_finder.expects(:pick_random).with(2).returns(0)
- Profile.expects(:find).with(3).returns(member3)
- Profile.expects(:find).with(1).returns(member1)
+ Profile.expects(:find).with(3).returns(community3)
+ Profile.expects(:find).with(1).returns(community1)
- assert_equal [member3, member1], block.profiles
+ assert_equal [community3, community1], block.profiles
end
should 'link to all communities of profile' do
@@ -72,28 +72,43 @@ class CommunitiesBlockTest < Test::Unit::TestCase
assert_equal '', block.footer
end
- should 'not list non-public communities' do
+ should 'list non-public communities' do
user = create_user('testuser').person
- public_community = Community.create!(:name => 'test community 1', :identifier => 'comm1', :environment => Environment.default)
+ public_community = fast_create(Community, :environment_id => Environment.default.id)
public_community.add_member(user)
- private_community = Community.create!(:name => 'test community 2', :identifier => 'comm2', :environment => Environment.default, :public_profile => false)
+ private_community = fast_create(Community, :environment_id => Environment.default.id, :public_profile => false)
private_community.add_member(user)
block = CommunitiesBlock.new
block.expects(:owner).at_least_once.returns(user)
- assert_equal [public_community], block.profiles
+ assert_equivalent [public_community, private_community], block.profiles
+ end
+
+ should 'not list non-visible communities' do
+ user = create_user('testuser').person
+
+ visible_community = fast_create(Community, :environment_id => Environment.default.id)
+ visible_community.add_member(user)
+
+ not_visible_community = fast_create(Community, :environment_id => Environment.default.id, :visible => false)
+ not_visible_community.add_member(user)
+
+ block = CommunitiesBlock.new
+ block.expects(:owner).at_least_once.returns(user)
+
+ assert_equal [visible_community], block.profiles
end
should 'count number of owner communities' do
user = create_user('testuser').person
- community1 = Community.create!(:name => 'test community 1', :identifier => 'comm1', :environment => Environment.default, :public_profile => true)
+ community1 = fast_create(Community, :environment_id => Environment.default.id, :visible => true)
community1.add_member(user)
- community2 = Community.create!(:name => 'test community 2', :identifier => 'comm2', :environment => Environment.default, :public_profile => true)
+ community2 = fast_create(Community, :environment_id => Environment.default.id, :visible => true)
community2.add_member(user)
block = CommunitiesBlock.new
@@ -102,22 +117,37 @@ class CommunitiesBlockTest < Test::Unit::TestCase
assert_equal 2, block.profile_count
end
- should 'not count non-public profile communities' do
+ should 'count non-public profile communities' do
user = create_user('testuser').person
- community_public = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default, :public_profile => true)
+ community_public = fast_create(Community, :environment_id => Environment.default.id, :public_profile => true)
community_public.add_member(user)
- community_private = Community.create!(:name => ' community 2', :identifier => 'comm2', :environment => Environment.default, :public_profile => false)
+ community_private = fast_create(Community, :environment_id => Environment.default.id, :public_profile => false)
community_private.add_member(user)
block = CommunitiesBlock.new
block.expects(:owner).at_least_once.returns(user)
+ assert_equal 2, block.profile_count
+ end
+
+ should 'not count non-visible profile communities' do
+ user = create_user('testuser').person
+
+ visible_community = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default, :visible => true)
+ visible_community.add_member(user)
+
+ not_visible_community = Community.create!(:name => ' community 2', :identifier => 'comm2', :environment => Environment.default, :visible => false)
+ not_visible_community.add_member(user)
+
+ block = CommunitiesBlock.new
+ block.expects(:owner).at_least_once.returns(user)
+
assert_equal 1, block.profile_count
end
- should 'not count non-public environment communities' do
+ should 'count non-public environment communities' do
community_public = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default, :public_profile => true)
community_private = Community.create!(:name => ' community 2', :identifier => 'comm2', :environment => Environment.default, :public_profile => false)
@@ -125,6 +155,17 @@ class CommunitiesBlockTest < Test::Unit::TestCase
block = CommunitiesBlock.new
block.expects(:owner).at_least_once.returns(Environment.default)
+ assert_equal 2, block.profile_count
+ end
+
+ should 'not count non-visible environment communities' do
+ visible_community = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default, :visible => true)
+
+ not_visible_community = Community.create!(:name => ' community 2', :identifier => 'comm2', :environment => Environment.default, :visible => false)
+
+ block = CommunitiesBlock.new
+ block.expects(:owner).at_least_once.returns(Environment.default)
+
assert_equal 1, block.profile_count
end
diff --git a/test/unit/enterprises_block_test.rb b/test/unit/enterprises_block_test.rb
index a052f10..3b3be1a 100644
--- a/test/unit/enterprises_block_test.rb
+++ b/test/unit/enterprises_block_test.rb
@@ -29,9 +29,9 @@ class EnterprisesBlockTest < Test::Unit::TestCase
owner = mock
block.expects(:owner).at_least_once.returns(owner)
- member1 = stub(:id => 1, :public_profile => true )
- member2 = stub(:id => 2, :public_profile => true )
- member3 = stub(:id => 3, :public_profile => true )
+ member1 = stub(:id => 1, :visible => true )
+ member2 = stub(:id => 2, :visible => true )
+ member3 = stub(:id => 3, :visible => true )
owner.expects(:enterprises).returns([member1, member2, member3])
@@ -44,31 +44,58 @@ class EnterprisesBlockTest < Test::Unit::TestCase
assert_equal [member3, member1], block.profiles
end
- should 'not list private enterprises in environment' do
- env = Environment.create!(:name => 'test env')
- p1 = Enterprise.create!(:name => 'test1', :identifier => 'test1', :environment_id => env.id, :public_profile => true)
- p2 = Enterprise.create!(:name => 'test2', :identifier => 'test2', :environment_id => env.id, :public_profile => false) #private profile
+ should 'list private enterprises in environment' do
+ env = Environment.create!(:name => 'test_env')
+ enterprise1 = fast_create(Enterprise, :environment_id => env.id, :public_profile => true)
+ enterprise2 = fast_create(Enterprise, :environment_id => env.id, :public_profile => false) #private profile
+ block = EnterprisesBlock.new
+ env.boxes.first.blocks << block
+ block.save!
+ ids = block.profile_finder.ids
+ assert_includes ids, enterprise1.id
+ assert_includes ids, enterprise2.id
+ end
+
+ should 'not list invisible enterprises in environment' do
+ env = Environment.create!(:name => 'test_env')
+ enterprise1 = fast_create(Enterprise, :environment_id => env.id, :visible => true)
+ enterprise2 = fast_create(Enterprise, :environment_id => env.id, :visible => false) #invisible profile
block = EnterprisesBlock.new
env.boxes.first.blocks << block
block.save!
ids = block.profile_finder.ids
- assert_includes ids, p1.id
- assert_not_includes ids, p2.id
+ assert_includes ids, enterprise1.id
+ assert_not_includes ids, enterprise2.id
end
- should 'not list private enterprises in profile' do
- person = create_user('test_user').person
- e1 = Enterprise.create!(:name => 'test1', :identifier => 'test1', :public_profile => true)
- role = Profile::Roles.member(e1.environment.id)
- e1.affiliate(person, role)
- e2 = Enterprise.create!(:name => 'test2', :identifier => 'test2', :public_profile => false) #private profile
- e2.affiliate(person, role)
+ should 'list private enterprises in profile' do
+ person = create_user('testuser').person
+ enterprise1 = fast_create(Enterprise, :public_profile => true)
+ role = Profile::Roles.member(enterprise1.environment.id)
+ enterprise1.affiliate(person, role)
+ enterprise2 = fast_create(Enterprise, :public_profile => false)
+ enterprise2.affiliate(person, role)
block = EnterprisesBlock.new
person.boxes.first.blocks << block
block.save!
ids = block.profile_finder.ids
- assert_includes ids, e1.id
- assert_not_includes ids, e2.id
+ assert_includes ids, enterprise1.id
+ assert_includes ids, enterprise2.id
+ end
+
+ should 'not list invisible enterprises in profile' do
+ person = create_user('testuser').person
+ enterprise1 = fast_create(Enterprise, :visible => true)
+ role = Profile::Roles.member(enterprise1.environment.id)
+ enterprise1.affiliate(person, role)
+ enterprise2 = fast_create(Enterprise, :visible => false)
+ enterprise2.affiliate(person, role)
+ block = EnterprisesBlock.new
+ person.boxes.first.blocks << block
+ block.save!
+ ids = block.profile_finder.ids
+ assert_includes ids, enterprise1.id
+ assert_not_includes ids, enterprise2.id
end
should 'link to all enterprises for profile' do
@@ -114,14 +141,31 @@ class EnterprisesBlockTest < Test::Unit::TestCase
assert_equal 2, block.profile_count
end
- should 'not count non-public person enterprises' do
- user = create_user('testuser').person
+ should 'count non-public person enterprises' do
+ user = fast_create(Person)
- ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'ent1', :environment => Environment.default, :public_profile => true)
+ ent1 = fast_create(Enterprise, :public_profile => true)
ent1.expects(:closed?).returns(false)
ent1.add_member(user)
- ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'ent2', :environment => Environment.default, :public_profile => false)
+ ent2 = fast_create(Enterprise, :public_profile => false)
+ ent2.expects(:closed?).returns(false)
+ ent2.add_member(user)
+
+ block = EnterprisesBlock.new
+ block.expects(:owner).at_least_once.returns(user)
+
+ assert_equal 2, block.profile_count
+ end
+
+ should 'not count non-visible person enterprises' do
+ user = fast_create(Person)
+
+ ent1 = fast_create(Enterprise, :visible => true)
+ ent1.expects(:closed?).returns(false)
+ ent1.add_member(user)
+
+ ent2 = fast_create(Enterprise, :visible => false)
ent2.expects(:closed?).returns(false)
ent2.add_member(user)
@@ -131,11 +175,22 @@ class EnterprisesBlockTest < Test::Unit::TestCase
assert_equal 1, block.profile_count
end
- should 'not count non-public environment enterprises' do
- env = Environment.create!(:name => 'test_env')
- ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'ent1', :environment => env, :public_profile => true)
- ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'ent2', :environment => env, :public_profile => false)
+ should 'count non-public environment enterprises' do
+ env = fast_create(Environment)
+ ent1 = fast_create(Enterprise, :environment_id => env.id, :public_profile => true)
+ ent2 = fast_create(Enterprise, :environment_id => env.id, :public_profile => false)
+
+ block = EnterprisesBlock.new
+ block.expects(:owner).at_least_once.returns(env)
+
+ assert_equal 2, block.profile_count
+ end
+
+ should 'not count non-visible environment enterprises' do
+ env = Environment.create!(:name => 'test_env')
+ ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'ent1', :environment => env, :visible => true)
+ ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'ent2', :environment => env, :visible => false)
block = EnterprisesBlock.new
block.expects(:owner).at_least_once.returns(env)
diff --git a/test/unit/environment_statistics_block_test.rb b/test/unit/environment_statistics_block_test.rb
index 82134e5..9c49830 100644
--- a/test/unit/environment_statistics_block_test.rb
+++ b/test/unit/environment_statistics_block_test.rb
@@ -37,7 +37,7 @@ class EnvironmentStatisticsBlockTest < Test::Unit::TestCase
assert_match(/One community/, content)
end
- should 'generate statistics but not for private profiles' do
+ should 'generate statistics including private profiles' do
env = create(Environment)
user1 = create_user('testuser1', :environment_id => env.id)
user2 = create_user('testuser2', :environment_id => env.id)
@@ -55,6 +55,29 @@ class EnvironmentStatisticsBlockTest < Test::Unit::TestCase
content = block.content
+ assert_match /2 enterprises/, content
+ assert_match /3 users/, content
+ assert_match /2 communities/, content
+ end
+
+ should 'generate statistics but not for not visible profiles' do
+ env = create(Environment)
+ user1 = create_user('testuser1', :environment_id => env.id)
+ user2 = create_user('testuser2', :environment_id => env.id)
+ user3 = create_user('testuser3', :environment_id => env.id)
+ p = user3.person; p.visible = false; p.save!
+
+ fast_create(Enterprise, :environment_id => env.id)
+ fast_create(Enterprise, :environment_id => env.id, :visible => false)
+
+ fast_create(Community, :environment_id => env.id)
+ fast_create(Community, :environment_id => env.id, :visible => false)
+
+ block = EnvironmentStatisticsBlock.new
+ env.boxes.first.blocks << block
+
+ content = block.content
+
assert_match /One enterprise/, content
assert_match /2 users/, content
assert_match /One community/, content
diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb
index 2e0ab90..acb9b85 100644
--- a/test/unit/environment_test.rb
+++ b/test/unit/environment_test.rb
@@ -460,9 +460,9 @@ class EnvironmentTest < Test::Unit::TestCase
assert_kind_of Person, e.person_template
# the templates must be private
- assert !e.enterprise_template.public?
- assert !e.community_template.public?
- assert !e.person_template.public?
+ assert !e.enterprise_template.visible?
+ assert !e.community_template.visible?
+ assert !e.person_template.visible?
end
should 'set templates' do
diff --git a/test/unit/friends_block_test.rb b/test/unit/friends_block_test.rb
index d7072cb..82c9f60 100644
--- a/test/unit/friends_block_test.rb
+++ b/test/unit/friends_block_test.rb
@@ -62,10 +62,24 @@ class FriendsBlockTest < ActiveSupport::TestCase
assert_equal 3, block.profile_count
end
- should 'count number of public people' do
+ should 'count number of public and private people' do
owner = create_user('testuser1').person
- private_p = create_user('private', {}, {:public_profile => false}).person
- public_p = create_user('public', {}, {:public_profile => true}).person
+ private_p = fast_create(Person, {:public_profile => false})
+ public_p = fast_create(Person, {:public_profile => true})
+
+ owner.add_friend(private_p)
+ owner.add_friend(public_p)
+
+ block = FriendsBlock.new
+ block.expects(:owner).returns(owner)
+
+ assert_equal 2, block.profile_count
+ end
+
+ should 'not count number of invisible people' do
+ owner = create_user('testuser1').person
+ private_p = fast_create(Person, {:visible => false})
+ public_p = fast_create(Person, {:visible => true})
owner.add_friend(private_p)
owner.add_friend(public_p)
@@ -75,4 +89,5 @@ class FriendsBlockTest < ActiveSupport::TestCase
assert_equal 1, block.profile_count
end
+
end
diff --git a/test/unit/members_block_test.rb b/test/unit/members_block_test.rb
index 8816984..4ae2647 100644
--- a/test/unit/members_block_test.rb
+++ b/test/unit/members_block_test.rb
@@ -27,19 +27,16 @@ class MembersBlockTest < Test::Unit::TestCase
end
should 'pick random members' do
-
- profile = create_user('mytestuser').person
block = MembersBlock.new
- block.box = profile.boxes.first
block.limit = 2
block.save!
owner = mock
block.expects(:owner).returns(owner)
- member1 = mock; member1.stubs(:id).returns(1)
- member2 = mock; member2.stubs(:id).returns(2)
- member3 = mock; member3.stubs(:id).returns(3)
+ member1 = stub(:id => 1, :visible? => true)
+ member2 = stub(:id => 2, :visible? => true)
+ member3 = stub(:id => 3, :visible? => true)
owner.expects(:members).returns([member1, member2, member3])
@@ -56,13 +53,13 @@ class MembersBlockTest < Test::Unit::TestCase
profile = create_user('mytestuser').person
owner = mock
- member1 = mock; member1.stubs(:id).returns(1)
- member2 = mock; member2.stubs(:id).returns(2)
- member3 = mock; member3.stubs(:id).returns(3)
+ member1 = mock
+ member2 = mock
+ member3 = mock
- member1.stubs(:public_profile?).returns(true)
- member2.stubs(:public_profile?).returns(true)
- member3.stubs(:public_profile?).returns(true)
+ member1.stubs(:visible?).returns(true)
+ member2.stubs(:visible?).returns(true)
+ member3.stubs(:visible?).returns(true)
owner.expects(:members).returns([member1, member2, member3])
@@ -71,11 +68,26 @@ class MembersBlockTest < Test::Unit::TestCase
assert_equal 3, block.profile_count
end
- should 'not count non-public community members' do
- community = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default)
+ should 'count non-public community members' do
+ community = fast_create(Community)
+
+ private_p = fast_create(Person, :public_profile => false)
+ public_p = fast_create(Person, :public_profile => true)
+
+ community.add_member(private_p)
+ community.add_member(public_p)
+
+ block = MembersBlock.new
+ block.expects(:owner).at_least_once.returns(community)
+
+ assert_equal 2, block.profile_count
+ end
+
+ should 'not count non-visible community members' do
+ community = fast_create(Community)
- private_p = create_user('private', {}, {:public_profile => false}).person
- public_p = create_user('public', {}, {:public_profile => true}).person
+ private_p = fast_create(Person, :visible => false)
+ public_p = fast_create(Person, :visible => true)
community.add_member(private_p)
community.add_member(public_p)
@@ -85,5 +97,6 @@ class MembersBlockTest < Test::Unit::TestCase
assert_equal 1, block.profile_count
end
+
end
diff --git a/test/unit/organization_test.rb b/test/unit/organization_test.rb
index 8bcfd05..a5d267f 100644
--- a/test/unit/organization_test.rb
+++ b/test/unit/organization_test.rb
@@ -239,4 +239,13 @@ class OrganizationTest < Test::Unit::TestCase
end
end
+ should 'be closed if organization is not public' do
+ organization = fast_create(Organization)
+ assert !organization.closed
+
+ organization.public_profile = false
+ organization.save!
+
+ assert organization.closed
+ end
end
diff --git a/test/unit/people_block_test.rb b/test/unit/people_block_test.rb
index 88c2b8c..752dfea 100644
--- a/test/unit/people_block_test.rb
+++ b/test/unit/people_block_test.rb
@@ -25,10 +25,19 @@ class PeopleBlockTest < ActiveSupport::TestCase
should 'list people' do
owner = Environment.create!(:name => 'test environment')
- Person.expects(:find).with(:all, :select => 'id', :conditions => { :environment_id => owner.id, :public_profile => true}, :limit => 6, :order => 'random()').returns([])
block = PeopleBlock.new
block.expects(:owner).returns(owner).at_least_once
- block.content
+ person1 = fast_create(Person, :environment_id => owner.id)
+ person2 = fast_create(Person, :environment_id => owner.id)
+
+ expects(:profile_image_link).with(person1).returns(person1.name)
+ expects(:profile_image_link).with(person2).returns(person2.name)
+ expects(:block_title).with(anything).returns('')
+
+ content = instance_eval(&block.content)
+
+ assert_match(/#{person1.name}/, content)
+ assert_match(/#{person2.name}/, content)
end
should 'link to people directory' do
@@ -40,13 +49,27 @@ class PeopleBlockTest < ActiveSupport::TestCase
instance_eval(&block.footer)
end
- should 'count number of public people' do
+ should 'count number of public and private people' do
+ env = Environment.create!(:name => 'test environment')
+ private_p = fast_create(Person, :environment_id => env.id, :public_profile => false)
+ public_p = fast_create(Person, :environment_id => env.id, :public_profile => true)
+
+ env.boxes.first.blocks << block = PeopleBlock.new
+ assert_equal 2, block.profile_count
+ end
+
+ should 'count number of visible people' do
env = Environment.create!(:name => 'test environment')
- private_p = create_user('private', {:environment => env}, {:public_profile => false})
- public_p = create_user('public', {:environment => env}, {:public_profile => true})
+ invisible_p = fast_create(Person, :environment_id => env.id, :visible => false)
+ visible_p = fast_create(Person, :environment_id => env.id, :visible => true)
env.boxes.first.blocks << block = PeopleBlock.new
assert_equal 1, block.profile_count
end
+ protected
+
+ def content_tag(tag, text, options = {})
+ text
+ end
end
diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb
index 00b8c1a..e9556bd 100644
--- a/test/unit/person_test.rb
+++ b/test/unit/person_test.rb
@@ -510,11 +510,18 @@ class PersonTest < Test::Unit::TestCase
assert !p.ask_to_join?(c)
end
- should 'not ask to join if community is not public' do
- p = create_user('test_user').person
- c = Community.create!(:name => 'Test community', :identifier => 'test_community', :public_profile => false)
+ should 'ask to join if community is not public' do
+ person = fast_create(Person)
+ community = fast_create(Community, :public_profile => false)
- assert !p.ask_to_join?(c)
+ assert person.ask_to_join?(community)
+ end
+
+ should 'not ask to join if community is not visible' do
+ person = fast_create(Person)
+ community = fast_create(Community, :visible => false)
+
+ assert !person.ask_to_join?(community)
end
should 'save organization_website with http' do
diff --git a/test/unit/profile_list_block_test.rb b/test/unit/profile_list_block_test.rb
index 9583f93..6a5b8e1 100644
--- a/test/unit/profile_list_block_test.rb
+++ b/test/unit/profile_list_block_test.rb
@@ -42,17 +42,30 @@ class ProfileListBlockTest < Test::Unit::TestCase
assert_kind_of String, instance_eval(&block.content)
end
- should 'not list private profiles' do
+ should 'list private profiles' do
env = Environment.create!(:name => 'test env')
- p1 = Profile.create!(:name => 'test1', :identifier => 'test1', :environment => env)
- p2 = Profile.create!(:name => 'test2', :identifier => 'test2', :environment => env, :public_profile => false) # private profile
+ profile1 = fast_create(Profile, :environment_id => env.id)
+ profile2 = fast_create(Profile, :environment_id => env.id, :public_profile => false) # private profile
block = ProfileListBlock.new
env.boxes.first.blocks << block
block.save!
ids = block.profile_finder.ids
- assert_includes ids, p1.id
- assert_not_includes ids, p2.id
+ assert_includes ids, profile1.id
+ assert_includes ids, profile2.id
+ end
+
+ should 'not list invisible profiles' do
+ env = Environment.create!(:name => 'test env')
+ profile1 = fast_create(Profile, :environment_id => env.id)
+ profile2 = fast_create(Profile, :environment_id => env.id, :visible => false) # not visible profile
+ block = ProfileListBlock.new
+ env.boxes.first.blocks << block
+ block.save!
+
+ ids = block.profile_finder.ids
+ assert_includes ids, profile1.id
+ assert_not_includes ids, profile2.id
end
should 'use finders to find profiles to be listed' do
@@ -83,21 +96,40 @@ class ProfileListBlockTest < Test::Unit::TestCase
assert_equal '0 members', block.view_title
end
- should 'count number of public profiles' do
+ should 'count number of public and private profiles' do
env = Environment.create!(:name => 'test env')
block = ProfileListBlock.new
env.boxes.first.blocks << block
block.save!
- priv_p = create_user('private', {:environment => env}, {:public_profile => false})
- pub_p = create_user('public', {:environment => env}, {:public_profile => true})
+ priv_p = fast_create(Person, :environment_id => env.id, :public_profile => false)
+ pub_p = fast_create(Person, :environment_id => env.id, :public_profile => true)
- priv_c = Community.create!(:name => 'com 1', :public_profile => false, :environment => env)
- pub_c = Community.create!(:name => 'com 2', :public_profile => true , :environment => env)
+ priv_c = fast_create(Community, :public_profile => false, :environment_id => env.id)
+ pub_c = fast_create(Community, :public_profile => true , :environment_id => env.id)
- priv_e = Enterprise.create!(:name => 'ent 1', :identifier => 'ent1', :public_profile => false , :environment => env)
- pub_e = Enterprise.create!(:name => 'ent 2', :identifier => 'ent2', :public_profile => true , :environment => env)
+ priv_e = fast_create(Enterprise, :public_profile => false , :environment_id => env.id)
+ pub_e = fast_create(Enterprise, :public_profile => true , :environment_id => env.id)
+
+ assert_equal 6, block.profile_count
+ end
+
+ should 'only count number of visible profiles' do
+ env = Environment.create!(:name => 'test env')
+ block = ProfileListBlock.new
+ env.boxes.first.blocks << block
+ block.save!
+
+ priv_p = fast_create(Person, :environment_id => env.id, :visible => false)
+ pub_p = fast_create(Person, :environment_id => env.id, :visible => true)
+
+ priv_c = fast_create(Community, :visible => false, :environment_id => env.id)
+ pub_c = fast_create(Community, :visible => true , :environment_id => env.id)
+
+ priv_e = fast_create(Enterprise, :visible => false , :environment_id => env.id)
+ pub_e = fast_create(Enterprise, :visible => true , :environment_id => env.id)
assert_equal 3, block.profile_count
end
+
end
diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb
index 0f47b7b..e4699c7 100644
--- a/test/unit/profile_test.rb
+++ b/test/unit/profile_test.rb
@@ -501,10 +501,10 @@ class ProfileTest < Test::Unit::TestCase
end
should 'display private profile for members' do
- p = create_user('testuser').person
- c = Community.create!(:name => 'my community', :public_profile => false)
+ p = fast_create(Person)
+ c = fast_create(Community, :public_profile => false)
+ c.expects(:closed).returns(false)
c.add_member(p)
-
assert c.display_info_to?(p)
end
@@ -1509,6 +1509,14 @@ class ProfileTest < Test::Unit::TestCase
assert_equal false, Profile.is_available?('identifier-test', Environment.default)
end
+ should 'not have long descriptions' do
+ long_description = 'a' * 600
+ profile = Profile.new
+ profile.description = long_description
+ profile.valid?
+ assert profile.errors.invalid?(:description)
+ end
+
private
def assert_invalid_identifier(id)
--
libgit2 0.21.2