Commit 974bc04868ba4eee5a8ea05e5ec1f155c7907a60
Exists in
master
and in
29 other branches
Merge branch 'stable'
Conflicts: app/views/shared/block.rhtml debian/changelog debian/control script/production
Showing
36 changed files
with
162 additions
and
46 deletions
Show diff stats
app/controllers/public/profile_controller.rb
| ... | ... | @@ -211,7 +211,8 @@ class ProfileController < PublicController |
| 211 | 211 | |
| 212 | 212 | def remove_activity |
| 213 | 213 | begin |
| 214 | - activity = current_person.tracked_actions.find(params[:activity_id]) | |
| 214 | + raise if !can_edit_profile | |
| 215 | + activity = ActionTracker::Record.find(params[:activity_id]) | |
| 215 | 216 | activity.destroy |
| 216 | 217 | render :text => _('Activity successfully removed.') |
| 217 | 218 | rescue |
| ... | ... | @@ -219,6 +220,17 @@ class ProfileController < PublicController |
| 219 | 220 | end |
| 220 | 221 | end |
| 221 | 222 | |
| 223 | + def remove_notification | |
| 224 | + begin | |
| 225 | + raise if !can_edit_profile | |
| 226 | + notification = ActionTrackerNotification.find(:first, :conditions => {:profile_id => profile.id, :action_tracker_id => params[:activity_id]}) | |
| 227 | + notification.destroy | |
| 228 | + render :text => _('Notification successfully removed.') | |
| 229 | + rescue | |
| 230 | + render :text => _('You could not remove this notification.') | |
| 231 | + end | |
| 232 | + end | |
| 233 | + | |
| 222 | 234 | def profile_info |
| 223 | 235 | begin |
| 224 | 236 | @block = profile.blocks.find(params[:block_id]) |
| ... | ... | @@ -320,4 +332,8 @@ class ProfileController < PublicController |
| 320 | 332 | 20 |
| 321 | 333 | end |
| 322 | 334 | |
| 335 | + def can_edit_profile | |
| 336 | + @can_edit_profile ||= user && user.has_permission?('edit_profile', profile) | |
| 337 | + end | |
| 338 | + helper_method :can_edit_profile | |
| 323 | 339 | end | ... | ... |
app/helpers/boxes_helper.rb
| ... | ... | @@ -81,8 +81,8 @@ module BoxesHelper |
| 81 | 81 | box_decorator == DontMoveBlocks |
| 82 | 82 | end |
| 83 | 83 | |
| 84 | - def display_block_content(block, main_content = nil) | |
| 85 | - content = block.main? ? wrap_main_content(main_content) : block.content | |
| 84 | + def display_block_content(block, person, main_content = nil) | |
| 85 | + content = block.main? ? wrap_main_content(main_content) : block.content({:person => person}) | |
| 86 | 86 | result = extract_block_content(content) |
| 87 | 87 | footer_content = extract_block_content(block.footer) |
| 88 | 88 | unless footer_content.blank? | ... | ... |
app/models/article_block.rb
| ... | ... | @@ -8,7 +8,7 @@ class ArticleBlock < Block |
| 8 | 8 | _('This block displays one of your articles. You can edit the block to select which one of your articles is going to be displayed in the block.') |
| 9 | 9 | end |
| 10 | 10 | |
| 11 | - def content | |
| 11 | + def content(args={}) | |
| 12 | 12 | block = self |
| 13 | 13 | lambda do |
| 14 | 14 | block_title(block.title) + | ... | ... |
app/models/block.rb
| ... | ... | @@ -81,7 +81,7 @@ class Block < ActiveRecord::Base |
| 81 | 81 | # The method can also return <tt>nil</tt>, which means "no content". |
| 82 | 82 | # |
| 83 | 83 | # See BoxesHelper#extract_block_content for implementation details. |
| 84 | - def content | |
| 84 | + def content(args={}) | |
| 85 | 85 | "This is block number %d" % self.id |
| 86 | 86 | end |
| 87 | 87 | ... | ... |
app/models/blog_archives_block.rb
| ... | ... | @@ -20,11 +20,15 @@ class BlogArchivesBlock < Block |
| 20 | 20 | blog_id && owner.blogs.exists?(blog_id) ? owner.blogs.find(blog_id) : owner.blog |
| 21 | 21 | end |
| 22 | 22 | |
| 23 | - def content | |
| 23 | + def visible_posts(person) | |
| 24 | + blog.posts.native_translations.select {|post| post.display_to?(person)} | |
| 25 | + end | |
| 26 | + | |
| 27 | + def content(args={}) | |
| 24 | 28 | owner_blog = self.blog |
| 25 | 29 | return nil unless owner_blog |
| 26 | 30 | results = '' |
| 27 | - owner_blog.posts.native_translations.group_by {|i| i.published_at.year }.sort_by { |year,count| -year }.each do |year, results_by_year| | |
| 31 | + visible_posts(args[:person]).group_by {|i| i.published_at.year }.sort_by { |year,count| -year }.each do |year, results_by_year| | |
| 28 | 32 | results << content_tag('li', content_tag('strong', "#{year} (#{results_by_year.size})")) |
| 29 | 33 | results << "<ul class='#{year}-archive'>" |
| 30 | 34 | results_by_year.group_by{|i| [ ('%02d' % i.published_at.month()), gettext(MONTHS[i.published_at.month() - 1])]}.sort.reverse.each do |month, results_by_month| | ... | ... |
app/models/categories_block.rb
| ... | ... | @@ -28,7 +28,7 @@ class CategoriesBlock < Block |
| 28 | 28 | Category.top_level_for(self.owner).from_types(self.category_types) |
| 29 | 29 | end |
| 30 | 30 | |
| 31 | - def content | |
| 31 | + def content(args={}) | |
| 32 | 32 | block = self |
| 33 | 33 | lambda do |
| 34 | 34 | render :file => 'blocks/categories', :locals => { :block => block } | ... | ... |
app/models/disabled_enterprise_message_block.rb
| ... | ... | @@ -12,7 +12,7 @@ class DisabledEnterpriseMessageBlock < Block |
| 12 | 12 | _('Message') |
| 13 | 13 | end |
| 14 | 14 | |
| 15 | - def content | |
| 15 | + def content(args={}) | |
| 16 | 16 | message = self.owner.environment.message_for_disabled_enterprise || '' |
| 17 | 17 | lambda do |
| 18 | 18 | render :file => 'blocks/disabled_enterprise_message', :locals => {:message => message} | ... | ... |
app/models/environment_statistics_block.rb
| ... | ... | @@ -12,7 +12,7 @@ class EnvironmentStatisticsBlock < Block |
| 12 | 12 | _('This block presents some statistics about your environment.') |
| 13 | 13 | end |
| 14 | 14 | |
| 15 | - def content | |
| 15 | + def content(args={}) | |
| 16 | 16 | users = owner.people.visible.count |
| 17 | 17 | enterprises = owner.enterprises.visible.count |
| 18 | 18 | communities = owner.communities.visible.count | ... | ... |
app/models/featured_products_block.rb
app/models/feed_reader_block.rb
app/models/highlights_block.rb
app/models/link_list_block.rb
| ... | ... | @@ -47,7 +47,7 @@ class LinkListBlock < Block |
| 47 | 47 | _('This block can be used to create a menu of links. You can add, remove and update the links as you wish.') |
| 48 | 48 | end |
| 49 | 49 | |
| 50 | - def content | |
| 50 | + def content(args={}) | |
| 51 | 51 | block_title(title) + |
| 52 | 52 | content_tag('ul', |
| 53 | 53 | links.select{|i| !i[:name].blank? and !i[:address].blank?}.map{|i| content_tag('li', link_html(i))} | ... | ... |
app/models/location_block.rb
app/models/login_block.rb
app/models/main_block.rb
app/models/my_network_block.rb
app/models/products_block.rb
app/models/profile_image_block.rb
app/models/profile_info_block.rb
| ... | ... | @@ -8,7 +8,7 @@ class ProfileInfoBlock < Block |
| 8 | 8 | _('Basic information about <i>%{user}</i>: how long <i>%{user}</i> is part of <i>%{env}</i> and useful links.') % { :user => self.owner.name(), :env => self.owner.environment.name() } |
| 9 | 9 | end |
| 10 | 10 | |
| 11 | - def content | |
| 11 | + def content(args={}) | |
| 12 | 12 | block = self |
| 13 | 13 | lambda do |
| 14 | 14 | render :file => 'blocks/profile_info', :locals => { :block => block } | ... | ... |
app/models/profile_list_block.rb
app/models/profile_search_block.rb
app/models/raw_html_block.rb
app/models/recent_documents_block.rb
| ... | ... | @@ -15,7 +15,7 @@ class RecentDocumentsBlock < Block |
| 15 | 15 | settings_items :limit, :type => :integer, :default => 5 |
| 16 | 16 | |
| 17 | 17 | include ActionController::UrlWriter |
| 18 | - def content | |
| 18 | + def content(args={}) | |
| 19 | 19 | docs = self.limit.nil? ? owner.recent_documents : owner.recent_documents(self.limit) |
| 20 | 20 | |
| 21 | 21 | block_title(title) + | ... | ... |
app/models/sellers_search_block.rb
| ... | ... | @@ -16,7 +16,7 @@ class SellersSearchBlock < Block |
| 16 | 16 | _('This block presents a search engine for products.') |
| 17 | 17 | end |
| 18 | 18 | |
| 19 | - def content | |
| 19 | + def content(args={}) | |
| 20 | 20 | title = self.title |
| 21 | 21 | lambda do |
| 22 | 22 | render :file => 'search/_sellers_form', :locals => { :title => title } | ... | ... |
app/models/slideshow_block.rb
app/models/tags_block.rb
app/views/profile/_profile_activities.rhtml
| ... | ... | @@ -6,7 +6,7 @@ |
| 6 | 6 | <div class='profile-activity-description'> |
| 7 | 7 | <p class='profile-activity-time'><%= time_ago_as_sentence(activity.created_at) + ' ' + _('ago') %></p> |
| 8 | 8 | <p class='profile-activity-text'><%= link_to activity.user.name, activity.user.url %> <%= describe activity %></p> |
| 9 | - <%= button_to_remote(:delete, content_tag(:span, _('Remove')), :url =>{:action => 'remove_activity', :activity_id => activity.id}, :update => "profile-activity-item-#{activity.id}") if logged_in? && current_person == @profile %> | |
| 9 | + <%= button_to_remote(:delete, content_tag(:span, _('Remove')), :url =>{:action => 'remove_activity', :activity_id => activity.id}, :update => "profile-activity-item-#{activity.id}") if can_edit_profile %> | |
| 10 | 10 | </div> |
| 11 | 11 | <hr /> |
| 12 | 12 | </li> | ... | ... |
app/views/profile/_profile_network_activities.rhtml
| ... | ... | @@ -9,6 +9,7 @@ |
| 9 | 9 | <div class='profile-network-description'> |
| 10 | 10 | <p class='profile-network-time'><%= time_ago_as_sentence(activity.created_at) + ' ' + _('ago') %></p> |
| 11 | 11 | <p class='profile-network-text'><%= link_to activity.user.name, activity.user.url %> <%= describe activity %></p> |
| 12 | + <%= button_to_remote(:delete, content_tag(:span, _('Remove')), :url =>{:action => 'remove_notification', :activity_id => activity.id}, :update => "profile-network-item-#{activity.id}") if can_edit_profile %> | |
| 12 | 13 | <p class='profile-network-where'><%= _('In community %s') % link_to(activity.target.name, activity.target.url) if !profile.is_a?(Community) && activity.target.is_a?(Community) %></p> |
| 13 | 14 | </div> |
| 14 | 15 | <div id='profile-network-message-<%= activity.id%>' style='display:none;'> | ... | ... |
app/views/shared/block.rhtml
| 1 | 1 | <% if block.cacheable? && use_cache %> |
| 2 | 2 | <% cache_timeout(block.cache_key, block.timeout) do %> |
| 3 | - <%= display_block_content(block, main_content) %> | |
| 3 | + <%= display_block_content(block, user, main_content) %> | |
| 4 | 4 | <% end %> |
| 5 | 5 | <% else %> |
| 6 | - <%= display_block_content(block, main_content) %> | |
| 6 | + <%= display_block_content(block, user, main_content) %> | |
| 7 | 7 | <% end %> | ... | ... |
debian/changelog
| ... | ... | @@ -9,6 +9,29 @@ noosfero (0.36.0~1) unstable; urgency=low |
| 9 | 9 | |
| 10 | 10 | -- Antonio Terceiro <terceiro@colivre.coop.br> Sun, 27 Nov 2011 14:11:33 -0200 |
| 11 | 11 | |
| 12 | +noosfero (0.35.2) unstable; urgency=low | |
| 13 | + | |
| 14 | + * Bugfixes version release | |
| 15 | + | |
| 16 | + -- Daniela Soares Feitosa <daniela@colivre.coop.br> Fri, 02 Mar 2012 13:36:02 -0300 | |
| 17 | + | |
| 18 | +noosfero (0.35.2~1) unstable; urgency=low | |
| 19 | + | |
| 20 | + * Bugfixes version release | |
| 21 | + * Added missing Build dependencies to build in a clean chroot: rake, rails, | |
| 22 | + libferret-ruby, libwill-paginate-ruby, tango-icon-theme, rcov | |
| 23 | + * Noosfero needs a functioning MTA: added dependency on exim4 | | |
| 24 | + mail-transport-agent. | |
| 25 | + * /usr/share/dbconfig-common/scripts/noosfero/install/pgsql: run db:migrate | |
| 26 | + just after db:schema:load. | |
| 27 | + * etc/init.d/noosfero: forward fix for the Lenny → Squeeze upgrade. In | |
| 28 | + Squeeze, `rails` is an empty package that depends on rails-ruby1.8, but | |
| 29 | + rails-ruby1.8 is only unpacked *after* noosfero prerm runs. This way, the | |
| 30 | + initscript must be able to stop the services without any of the Rails | |
| 31 | + libraries available. | |
| 32 | + | |
| 33 | + -- Antonio Terceiro <terceiro@colivre.coop.br> Thu, 01 Mar 2012 14:37:15 -0300 | |
| 34 | + | |
| 12 | 35 | noosfero (0.35.1) unstable; urgency=low |
| 13 | 36 | |
| 14 | 37 | * Bugfixes version release | ... | ... |
debian/control
| ... | ... | @@ -3,7 +3,7 @@ Section: web |
| 3 | 3 | Priority: extra |
| 4 | 4 | Maintainer: Noosfero developers <noosfero-dev@listas.softwarelivre.org> |
| 5 | 5 | Uploaders: Antonio Terceiro <terceiro@colivre.coop.br> |
| 6 | -Build-Depends: debhelper (>= 7.0.50~), po4a, libgettext-ruby-util, libgettext-ruby1.8, libsqlite3-ruby1.8, | |
| 6 | +Build-Depends: debhelper (>= 7.0.50~), po4a, libgettext-ruby-util, libgettext-ruby1.8, libsqlite3-ruby1.8, rake, rails, libferret-ruby, libwill-paginate-ruby, tango-icon-theme, rcov | |
| 7 | 7 | Standards-Version: 3.8.4 |
| 8 | 8 | Homepage: http://noosfero.org/ |
| 9 | 9 | Vcs-Git: git://git.colivre.coop.br/noosfero.git |
| ... | ... | @@ -11,7 +11,7 @@ Vcs-Browser: http://git.colivre.coop.br/?p=noosfero.git |
| 11 | 11 | |
| 12 | 12 | Package: noosfero |
| 13 | 13 | Architecture: all |
| 14 | -Depends: rails (>= 2.3.5-1~), rails-ruby1.8 (>= 2.3.5-1~), ruby1.8, ruby, rake, libgettext-rails-ruby1.8, libsqlite3-ruby, libpgsql-ruby, libmysql-ruby, librmagick-ruby, libredcloth-ruby, libwill-paginate-ruby (>= 2.3.12-1~), iso-codes, libfeedparser-ruby, libferret-ruby, libdaemons-ruby, rcov, mongrel, mongrel-cluster, tango-icon-theme, libhpricot-ruby, iso-codes, memcached, debconf, dbconfig-common, postgresql, adduser, ${misc:Depends} | |
| 14 | +Depends: rails (>= 2.3.5-1~), rails-ruby1.8 (>= 2.3.5-1~), ruby1.8, ruby, rake, libgettext-rails-ruby1.8, libsqlite3-ruby, libpgsql-ruby, libmysql-ruby, librmagick-ruby, libredcloth-ruby, libwill-paginate-ruby (>= 2.3.12-1~), iso-codes, libfeedparser-ruby, libferret-ruby, libdaemons-ruby, rcov, mongrel, mongrel-cluster, tango-icon-theme, libhpricot-ruby, iso-codes, memcached, debconf, dbconfig-common, postgresql, adduser, exim4 | mail-transport-agent, ${misc:Depends} | |
| 15 | 15 | Recommends: postgresql-client |
| 16 | 16 | Description: free web-based platform for social networks |
| 17 | 17 | Noosfero is a web platform for social and solidarity economy networks with | ... | ... |
debian/dbinstall
| ... | ... | @@ -8,4 +8,5 @@ sed -i -e 's/adapter: pgsql/adapter: postgresql/' /etc/noosfero/database.yml |
| 8 | 8 | /etc/init.d/noosfero setup |
| 9 | 9 | |
| 10 | 10 | cd /usr/share/noosfero && su noosfero -c "rake db:schema:load RAILS_ENV=production" |
| 11 | +cd /usr/share/noosfero && su noosfero -c "rake db:migrate RAILS_ENV=production SCHEMA=/dev/null" | |
| 11 | 12 | cd /usr/share/noosfero && su noosfero -c "rake db:data:minimal RAILS_ENV=production" | ... | ... |
lib/noosfero.rb
script/production
| ... | ... | @@ -40,10 +40,34 @@ do_start() { |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | do_stop() { |
| 43 | - ruby -S thin -C config/thin.yml stop | |
| 44 | - ./script/delayed_job stop | |
| 45 | - ./script/feed-updater stop | |
| 46 | - ./script/ferret_server -e $RAILS_ENV stop | |
| 43 | + | |
| 44 | + # During Debian upgrades, it is possible that rails is not available (e.g. | |
| 45 | + # Lenny -> Squeeze), so the programs below might fail. If they do, we fall | |
| 46 | + # back to stopping the daemons by manually reading their PID files, killing | |
| 47 | + # them and wiping the PID files. | |
| 48 | + | |
| 49 | + ruby -S thin -C config/thin.yml stop || | |
| 50 | + stop_via_pid_file tmp/pids/thin.*.pid | |
| 51 | + | |
| 52 | + ./script/delayed_job stop || | |
| 53 | + stop_via_pid_file tmp/pids/delayed_job.pid | |
| 54 | + | |
| 55 | + ./script/feed-updater stop || | |
| 56 | + stop_via_pid_file tmp/pids/feed-updater.default.pid | |
| 57 | + | |
| 58 | + ./script/ferret_server -e $RAILS_ENV stop || | |
| 59 | + stop_via_pid_file tmp/pids/ferret.production.pid | |
| 60 | +} | |
| 61 | + | |
| 62 | +stop_via_pid_file() { | |
| 63 | + for pidfile in $@; do | |
| 64 | + if [ -e "$pidfile" ]; then | |
| 65 | + pid=$(cat $pidfile) | |
| 66 | + echo "Sentign TERM signal to stop $pid ..." | |
| 67 | + kill -TERM "$pid" | |
| 68 | + rm -f $pidfile | |
| 69 | + fi | |
| 70 | + done | |
| 47 | 71 | } |
| 48 | 72 | |
| 49 | 73 | environments_loop() { | ... | ... |
test/functional/profile_controller_test.rb
| ... | ... | @@ -1033,14 +1033,43 @@ class ProfileControllerTest < ActionController::TestCase |
| 1033 | 1033 | assert_redirected_to :controller => 'account', :action => 'login' |
| 1034 | 1034 | end |
| 1035 | 1035 | |
| 1036 | - should "not remove an activity of another user" do | |
| 1037 | - login_as(profile.identifier) | |
| 1038 | - p1 = fast_create(Person) | |
| 1039 | - at = fast_create(ActionTracker::Record, :user_id => p1.id) | |
| 1040 | - atn = fast_create(ActionTrackerNotification, :profile_id => p1.id, :action_tracker_id => at.id) | |
| 1041 | - count = ActionTrackerNotification.count | |
| 1042 | - post :remove_activity, :profile => profile.identifier, :activity_id => at.id | |
| 1043 | - assert_equal count, ActionTrackerNotification.count | |
| 1036 | + should "remove an activity of another person if user has permissions to edit it" do | |
| 1037 | + user = create_user('owner').person | |
| 1038 | + login_as(user.identifier) | |
| 1039 | + owner = create_user('owner').person | |
| 1040 | + activity = fast_create(ActionTracker::Record, :user_id => owner.id) | |
| 1041 | + @controller.stubs(:user).returns(user) | |
| 1042 | + @controller.stubs(:profile).returns(owner) | |
| 1043 | + | |
| 1044 | + assert_no_difference ActionTracker::Record, :count do | |
| 1045 | + post :remove_activity, :profile => owner.identifier, :activity_id => activity.id | |
| 1046 | + end | |
| 1047 | + | |
| 1048 | + owner.environment.add_admin(user) | |
| 1049 | + | |
| 1050 | + assert_difference ActionTracker::Record, :count, -1 do | |
| 1051 | + post :remove_activity, :profile => owner.identifier, :activity_id => activity.id | |
| 1052 | + end | |
| 1053 | + end | |
| 1054 | + | |
| 1055 | + should "remove a notification of another profile if user has permissions to edit it" do | |
| 1056 | + user = create_user('owner').person | |
| 1057 | + login_as(user.identifier) | |
| 1058 | + profile = fast_create(Profile) | |
| 1059 | + activity = fast_create(ActionTracker::Record, :user_id => user.id) | |
| 1060 | + fast_create(ActionTrackerNotification, :profile_id => profile.id, :action_tracker_id => activity.id) | |
| 1061 | + @controller.stubs(:user).returns(user) | |
| 1062 | + @controller.stubs(:profile).returns(profile) | |
| 1063 | + | |
| 1064 | + assert_no_difference ActionTrackerNotification, :count do | |
| 1065 | + post :remove_notification, :profile => profile.identifier, :activity_id => activity.id | |
| 1066 | + end | |
| 1067 | + | |
| 1068 | + profile.environment.add_admin(user) | |
| 1069 | + | |
| 1070 | + assert_difference ActionTrackerNotification, :count, -1 do | |
| 1071 | + post :remove_activity, :profile => profile.identifier, :activity_id => activity.id | |
| 1072 | + end | |
| 1044 | 1073 | end |
| 1045 | 1074 | |
| 1046 | 1075 | should "not show the scrap button on network activity if the user don't follow the user" do | ... | ... |
test/unit/blog_archives_block_test.rb
| ... | ... | @@ -157,4 +157,22 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase |
| 157 | 157 | end |
| 158 | 158 | end |
| 159 | 159 | |
| 160 | + should 'not count articles if the user can\'t see them' do | |
| 161 | + person = create_user('testuser').person | |
| 162 | + blog = fast_create(Blog, :profile_id => profile.id, :path => 'blog_path') | |
| 163 | + block = fast_create(BlogArchivesBlock) | |
| 164 | + | |
| 165 | + feed = mock() | |
| 166 | + feed.stubs(:url).returns('feed_url') | |
| 167 | + blog.stubs(:feed).returns(feed) | |
| 168 | + block.stubs(:blog).returns(blog) | |
| 169 | + block.stubs(:owner).returns(profile) | |
| 170 | + | |
| 171 | + public_post = fast_create(TextileArticle, :profile_id => profile.id, :parent_id => blog.id, :published => true, :published_at => Time.mktime(2012, 'jan')) | |
| 172 | + private_post = fast_create(TextileArticle, :profile_id => profile.id, :parent_id => blog.id, :published => false, :published_at => Time.mktime(2012, 'jan')) | |
| 173 | + | |
| 174 | + assert_match /January \(1\)/, block.content({:person => person}) | |
| 175 | + assert_match /January \(1\)/, block.content() | |
| 176 | + assert_match /January \(2\)/, block.content({:person => profile}) | |
| 177 | + end | |
| 160 | 178 | end | ... | ... |