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 %> - - - - - - - - - - - - - - - + + <% unless @action %> + <% cache_timeout(profile.identifier + '-profile-general-info', 4.hours.from_now) do %> + + + + + <% profile.blogs.each do |blog| %> + + + + + <% end %> + <% profile.image_galleries.each do |gallery| %> + + + + + <% end %> + + + + + + + + + + + <% if !environment.enabled?('disable_categories') && !profile.interests.empty? %> + + + + <% profile.interests.each do |item| %> + + + + + <% end %> + <% end %> + <% end %> <% end %>
    - <%= _('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%> -
    + <%= _('Content') %> +
    <%= blog.name + ':' %> + <%= link_to(n_('One post', '%{num} posts', blog.posts.count) % { :num => blog.posts.count }, blog.url) %> +
    <%= gallery.name + ':' %> + <%= link_to(n_('One picture', '%{num} pictures', gallery.images.count) % { :num => gallery.images.count }, gallery.url) %> +
    <%= _('Events:') %> + <%= link_to profile.events.count, :controller => 'events', :action => 'events' %> +
    + <%= _('Tags:') %> + + <%= tag_cloud @tags, :id, { :action => 'tag' }, :max_size => 18, :min_size => 10%> +
    <%= _('Interests') %>
    <%= link_to item.name, :controller => 'search', :action => 'category_index', :category_path => item.explode_path %>
    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 @@