diff --git a/patches/noosfero/0001-Enhance-existing-backup-task-and-add-a-restore-one.patch b/patches/noosfero/0001-Enhance-existing-backup-task-and-add-a-restore-one.patch deleted file mode 100644 index e529ce9..0000000 --- a/patches/noosfero/0001-Enhance-existing-backup-task-and-add-a-restore-one.patch +++ /dev/null @@ -1,137 +0,0 @@ -From c1918dc6090c011a297bc470c04d4158410e61b8 Mon Sep 17 00:00:00 2001 -From: Antonio Terceiro -Date: Wed, 11 Feb 2015 19:55:30 -0200 -Subject: [PATCH] Enhance existing backup task and add a restore one - -- `rake backup` will now create a tarball with everything that needs to - be backed up (files + database dump) - -- `rake restore BACKUP=/path/to/(...).tar.gz` will restore that backup - over the current Noosfero instance. - -Multi-tenant setups are not supported yet. ---- - lib/tasks/backup.rake | 111 +++++++++++++++++++++++++++++++++++++++++++++++--- - 1 file changed, 105 insertions(+), 6 deletions(-) - -diff --git a/lib/tasks/backup.rake b/lib/tasks/backup.rake -index 849d4d6..7e64d17 100644 ---- a/lib/tasks/backup.rake -+++ b/lib/tasks/backup.rake -@@ -1,8 +1,107 @@ --desc "Creates a backup of the user files stored in public/" --task :backup do -- dirs = Dir.glob('public/images/[0-9][0-9][0-9][0-9]') + ['public/articles', 'public/thumbnails', 'public/user_themes'].select { |d| File.exists?(d) } -- tarball = 'backups/files-' + Time.now.strftime('%Y-%m-%d-%R') + '.tar' -+task :load_backup_config do -+ $config = YAML.load_file('config/database.yml') -+end -+ -+task :check_backup_support => :load_backup_config do -+ if $config['production']['adapter'] != 'postgresql' -+ fail("Only PostgreSQL is supported for backups at the moment") -+ end -+end -+ -+backup_dirs = [ -+ 'public/image_uploads', -+ 'public/articles', -+ 'public/thumbnails', -+ 'public/user_themes', -+] -+ -+desc "Creates a backup of the database and uploaded files" -+task :backup => :check_backup_support do -+ dirs = backup_dirs.select { |d| File.exists?(d) } -+ -+ backup_name = Time.now.strftime('%Y-%m-%d-%R') -+ backup_file = File.join('tmp/backup', backup_name) + '.tar.gz' -+ mkdir_p 'tmp/backup' -+ dump = File.join('tmp/backup', backup_name) + '.sql' -+ -+ database = $config['production']['database'] -+ sh "pg_dump #{database} > #{dump}" -+ -+ sh 'tar', 'caf', backup_file, dump, *dirs -+ rm_f dump -+ -+ puts "****************************************************" -+ puts "Backup in #{backup_file} !" -+ puts -+ puts "To restore, use:" -+ puts "$ rake restore BACKUP=#{backup_file}" -+ puts "****************************************************" -+end -+ -+def invalid_backup!(message, items=[]) -+ puts "E: #{message}" -+ items.each do |i| -+ puts "E: - #{i}" -+ end -+ puts "E: Is this a backup archive created by Noosfero with \`rake backup\`?" -+ exit 1 -+end -+ -+desc "Restores a backup created previousy with \`rake backup\`" -+task :restore => :check_backup_support do -+ backup = ENV["BACKUP"] -+ unless backup -+ puts "usage: rake restore BACKUP=/path/to/backup" -+ exit 1 -+ end -+ -+ files = `tar taf #{backup}`.split -+ -+ # validate files in the backup -+ invalid_files = [] -+ files.each do |f| -+ if f !~ /tmp\/backup\// && (backup_dirs.none? { |d| f =~ /^#{d}\// }) -+ invalid_files << f -+ end -+ end -+ if invalid_files.size > 0 -+ invalid_backup!("Invalid files found in the backup archive", invalid_files) -+ end -+ -+ # find database dump in the archive -+ dumps = files.select do |f| -+ File.dirname(f) == 'tmp/backup' && f =~ /\.sql$/ -+ end -+ if dumps.size == 0 -+ invalid_backup!("Could not find a database dump in the archive.") -+ elsif dumps.size > 1 -+ invalid_backup!("Multiple database dumps found in the archive:", dumps) -+ end -+ dump = dumps.first -+ -+ database = $config['production']['database'] -+ username = $config['production']['username'] -+ -+ puts "WARNING: backups should be restored to an empty database, otherwise" -+ puts "data from the backup may not be loaded properly." -+ puts -+ puts 'You can remove the existing database and create a new one with:' -+ puts -+ puts "$ sudo -u postgres dropdb #{database}" -+ puts "$ sudo -u postgres createdb #{database} --owner #{username}" -+ puts -+ print "Are you sure you want to continue (y/N)? " -+ response = $stdin.gets.strip -+ unless ['y', 'yes'].include?(response.downcase) -+ puts "*** ABORTED." -+ exit 1 -+ end -+ -+ sh 'tar', 'xaf', backup -+ sh "rails dbconsole production < #{dump}" -+ rm_f dump - -- mkdir_p(File.dirname(tarball)) -- sh('tar', 'cf', tarball, *dirs) -+ puts "****************************************************" -+ puts "Backup restored!" -+ puts "****************************************************" - end --- -2.1.4 - diff --git a/patches/noosfero/0001-Fix-backup-task.patch b/patches/noosfero/0001-Fix-backup-task.patch deleted file mode 100644 index 8da0085..0000000 --- a/patches/noosfero/0001-Fix-backup-task.patch +++ /dev/null @@ -1,52 +0,0 @@ -From 3b814b256441be6e0fc98cb1afa695c4f13d6849 Mon Sep 17 00:00:00 2001 -From: Athos Ribeiro -Date: Fri, 8 May 2015 15:13:40 -0300 -Subject: [PATCH] Fix backup task - -- Adds host option to the postgres commands where necessary. -- Passes -h option to tar when compressing in order to follow symlinks. - -Signed-off-by: Athos Ribeiro -Signed-off-by: Lucas Kanashiro ---- - lib/tasks/backup.rake | 10 ++++++---- - 1 file changed, 6 insertions(+), 4 deletions(-) - -diff --git a/lib/tasks/backup.rake b/lib/tasks/backup.rake -index 7e64d17..14b2418 100644 ---- a/lib/tasks/backup.rake -+++ b/lib/tasks/backup.rake -@@ -25,9 +25,10 @@ task :backup => :check_backup_support do - dump = File.join('tmp/backup', backup_name) + '.sql' - - database = $config['production']['database'] -- sh "pg_dump #{database} > #{dump}" -+ host = $config['production']['host'] -+ sh "pg_dump -h #{host} #{database} > #{dump}" - -- sh 'tar', 'caf', backup_file, dump, *dirs -+ sh 'tar', 'chaf', backup_file, dump, *dirs - rm_f dump - - puts "****************************************************" -@@ -81,14 +82,15 @@ task :restore => :check_backup_support do - - database = $config['production']['database'] - username = $config['production']['username'] -+ host = $config['production']['host'] - - puts "WARNING: backups should be restored to an empty database, otherwise" - puts "data from the backup may not be loaded properly." - puts - puts 'You can remove the existing database and create a new one with:' - puts -- puts "$ sudo -u postgres dropdb #{database}" -- puts "$ sudo -u postgres createdb #{database} --owner #{username}" -+ puts "$ sudo -u postgres dropdb -h #{host} #{database}" -+ puts "$ sudo -u postgres createdb -h #{host} #{database} --owner #{username}" - puts - print "Are you sure you want to continue (y/N)? " - response = $stdin.gets.strip --- -2.1.0 - diff --git a/patches/noosfero/0001-Use-as-placeholder-for-current-user-in-URLs.patch b/patches/noosfero/0001-Use-as-placeholder-for-current-user-in-URLs.patch deleted file mode 100644 index 8efc733..0000000 --- a/patches/noosfero/0001-Use-as-placeholder-for-current-user-in-URLs.patch +++ /dev/null @@ -1,196 +0,0 @@ -From 38e1a32782d0a2f5d66a936b707f307ceb13288f Mon Sep 17 00:00:00 2001 -From: David Carlos -Date: Thu, 12 Mar 2015 14:59:38 -0300 -Subject: [PATCH] Use ~ as placeholder for current user in URLs - -When the :profile parameter is '~', replace it with the identifier of -the currently logged-in user and redirect. This is useful for example -for adding direct links to the control panel of the current user in -documentation. - -Signed-off-by: Antonio Terceiro -Signed-off-by: Arthur Del Esposte -Signed-off-by: David Carlos -Signed-off-by: Gabriela Navarro ---- - app/controllers/application_controller.rb | 12 ++++++++ - config/routes.rb | 40 +++++++++++++------------- - lib/noosfero.rb | 6 ++++ - test/functional/application_controller_test.rb | 18 ++++++++++++ - test/integration/routing_test.rb | 4 +++ - 5 files changed, 60 insertions(+), 20 deletions(-) - -diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb -index 2bb0835..75fb3fd 100644 ---- a/app/controllers/application_controller.rb -+++ b/app/controllers/application_controller.rb -@@ -9,6 +9,7 @@ class ApplicationController < ActionController::Base - before_filter :allow_cross_domain_access - before_filter :login_required, :if => :private_environment? - before_filter :verify_members_whitelist, :if => [:private_environment?, :user] -+ before_filter :redirect_to_current_user - - def verify_members_whitelist - render_access_denied unless user.is_admin? || environment.in_whitelist?(user) -@@ -191,4 +192,15 @@ class ApplicationController < ActionController::Base - def private_environment? - @environment.enabled?(:restrict_to_members) - end -+ -+ def redirect_to_current_user -+ if params[:profile] == '~' -+ if logged_in? -+ redirect_to params.merge(:profile => user.identifier) -+ else -+ render_not_found -+ end -+ end -+ end -+ - end -diff --git a/config/routes.rb b/config/routes.rb -index f370954..a54ea19 100644 ---- a/config/routes.rb -+++ b/config/routes.rb -@@ -57,37 +57,37 @@ Noosfero::Application.routes.draw do - match 'search(/:action(/*category_path))', :controller => 'search' - - # events -- match 'profile/:profile/events_by_day', :controller => 'events', :action => 'events_by_day', :profile => /#{Noosfero.identifier_format}/ -- match 'profile/:profile/events_by_month', :controller => 'events', :action => 'events_by_month', :profile => /#{Noosfero.identifier_format}/ -- match 'profile/:profile/events/:year/:month/:day', :controller => 'events', :action => 'events', :year => /\d*/, :month => /\d*/, :day => /\d*/, :profile => /#{Noosfero.identifier_format}/ -- match 'profile/:profile/events/:year/:month', :controller => 'events', :action => 'events', :year => /\d*/, :month => /\d*/, :profile => /#{Noosfero.identifier_format}/ -- match 'profile/:profile/events', :controller => 'events', :action => 'events', :profile => /#{Noosfero.identifier_format}/ -+ match 'profile/:profile/events_by_day', :controller => 'events', :action => 'events_by_day', :profile => /#{Noosfero.identifier_format_in_url}/ -+ match 'profile/:profile/events_by_month', :controller => 'events', :action => 'events_by_month', :profile => /#{Noosfero.identifier_format_in_url}/ -+ match 'profile/:profile/events/:year/:month/:day', :controller => 'events', :action => 'events', :year => /\d*/, :month => /\d*/, :day => /\d*/, :profile => /#{Noosfero.identifier_format_in_url}/ -+ match 'profile/:profile/events/:year/:month', :controller => 'events', :action => 'events', :year => /\d*/, :month => /\d*/, :profile => /#{Noosfero.identifier_format_in_url}/ -+ match 'profile/:profile/events', :controller => 'events', :action => 'events', :profile => /#{Noosfero.identifier_format_in_url}/ - - # catalog -- match 'catalog/:profile', :controller => 'catalog', :action => 'index', :profile => /#{Noosfero.identifier_format}/, :as => :catalog -+ match 'catalog/:profile', :controller => 'catalog', :action => 'index', :profile => /#{Noosfero.identifier_format_in_url}/, :as => :catalog - - # invite -- match 'profile/:profile/invite/friends', :controller => 'invite', :action => 'invite_friends', :profile => /#{Noosfero.identifier_format}/ -- match 'profile/:profile/invite/:action', :controller => 'invite', :profile => /#{Noosfero.identifier_format}/ -+ match 'profile/:profile/invite/friends', :controller => 'invite', :action => 'invite_friends', :profile => /#{Noosfero.identifier_format_in_url}/ -+ match 'profile/:profile/invite/:action', :controller => 'invite', :profile => /#{Noosfero.identifier_format_in_url}/ - - # feeds per tag -- match 'profile/:profile/tags/:id/feed', :controller => 'profile', :action =>'tag_feed', :id => /.+/, :profile => /#{Noosfero.identifier_format}/, :as => :tag_feed -+ match 'profile/:profile/tags/:id/feed', :controller => 'profile', :action =>'tag_feed', :id => /.+/, :profile => /#{Noosfero.identifier_format_in_url}/, :as => :tag_feed - - # profile tags -- match 'profile/:profile/tags/:id', :controller => 'profile', :action => 'content_tagged', :id => /.+/, :profile => /#{Noosfero.identifier_format}/ -- match 'profile/:profile/tags(/:id)', :controller => 'profile', :action => 'tags', :profile => /#{Noosfero.identifier_format}/ -+ match 'profile/:profile/tags/:id', :controller => 'profile', :action => 'content_tagged', :id => /.+/, :profile => /#{Noosfero.identifier_format_in_url}/ -+ match 'profile/:profile/tags(/:id)', :controller => 'profile', :action => 'tags', :profile => /#{Noosfero.identifier_format_in_url}/ - - # profile search -- match 'profile/:profile/search', :controller => 'profile_search', :action => 'index', :profile => /#{Noosfero.identifier_format}/ -+ match 'profile/:profile/search', :controller => 'profile_search', :action => 'index', :profile => /#{Noosfero.identifier_format_in_url}/ - - # comments -- match 'profile/:profile/comment/:action/:id', :controller => 'comment', :profile => /#{Noosfero.identifier_format}/ -+ match 'profile/:profile/comment/:action/:id', :controller => 'comment', :profile => /#{Noosfero.identifier_format_in_url}/ - - # public profile information -- match 'profile/:profile(/:action(/:id))', :controller => 'profile', :action => 'index', :id => /[^\/]*/, :profile => /#{Noosfero.identifier_format}/, :as => :profile -+ match 'profile/:profile(/:action(/:id))', :controller => 'profile', :action => 'index', :id => /[^\/]*/, :profile => /#{Noosfero.identifier_format_in_url}/, :as => :profile - - # contact -- match 'contact/:profile/:action(/:id)', :controller => 'contact', :action => 'index', :id => /.*/, :profile => /#{Noosfero.identifier_format}/ -+ match 'contact/:profile/:action(/:id)', :controller => 'contact', :action => 'index', :id => /.*/, :profile => /#{Noosfero.identifier_format_in_url}/ - - # map balloon - match 'map_balloon/:action/:id', :controller => 'map_balloon', :id => /.*/ -@@ -99,8 +99,8 @@ Noosfero::Application.routes.draw do - ## Controllers that are profile-specific (for profile admins ) - ###################################################### - # profile customization - "My profile" -- match 'myprofile/:profile', :controller => 'profile_editor', :action => 'index', :profile => /#{Noosfero.identifier_format}/ -- match 'myprofile/:profile/:controller(/:action(/:id))', :controller => Noosfero.pattern_for_controllers_in_directory('my_profile'), :profile => /#{Noosfero.identifier_format}/, :as => :myprofile -+ match 'myprofile/:profile', :controller => 'profile_editor', :action => 'index', :profile => /#{Noosfero.identifier_format_in_url}/ -+ match 'myprofile/:profile/:controller(/:action(/:id))', :controller => Noosfero.pattern_for_controllers_in_directory('my_profile'), :profile => /#{Noosfero.identifier_format_in_url}/, :as => :myprofile - - - ###################################################### -@@ -128,14 +128,14 @@ Noosfero::Application.routes.draw do - # cache stuff - hack - match 'public/:action/:id', :controller => 'public' - -- match ':profile/*page/versions', :controller => 'content_viewer', :action => 'article_versions', :profile => /#{Noosfero.identifier_format}/, :constraints => EnvironmentDomainConstraint.new -+ match ':profile/*page/versions', :controller => 'content_viewer', :action => 'article_versions', :profile => /#{Noosfero.identifier_format_in_url}/, :constraints => EnvironmentDomainConstraint.new - match '*page/versions', :controller => 'content_viewer', :action => 'article_versions' - -- match ':profile/*page/versions_diff', :controller => 'content_viewer', :action => 'versions_diff', :profile => /#{Noosfero.identifier_format}/, :constraints => EnvironmentDomainConstraint.new -+ match ':profile/*page/versions_diff', :controller => 'content_viewer', :action => 'versions_diff', :profile => /#{Noosfero.identifier_format_in_url}/, :constraints => EnvironmentDomainConstraint.new - match '*page/versions_diff', :controller => 'content_viewer', :action => 'versions_diff' - - # match requests for profiles that don't have a custom domain -- match ':profile(/*page)', :controller => 'content_viewer', :action => 'view_page', :profile => /#{Noosfero.identifier_format}/, :constraints => EnvironmentDomainConstraint.new -+ match ':profile(/*page)', :controller => 'content_viewer', :action => 'view_page', :profile => /#{Noosfero.identifier_format_in_url}/, :constraints => EnvironmentDomainConstraint.new - - # match requests for content in domains hosted for profiles - match '/(*page)', :controller => 'content_viewer', :action => 'view_page' -diff --git a/lib/noosfero.rb b/lib/noosfero.rb -index d7ec786..b1ae492 100644 ---- a/lib/noosfero.rb -+++ b/lib/noosfero.rb -@@ -57,6 +57,12 @@ module Noosfero - '[a-z0-9][a-z0-9~.]*([_\-][a-z0-9~.]+)*' - end - -+ # All valid identifiers, plus ~ meaning "the current user". See -+ # ApplicationController#redirect_to_current_user -+ def self.identifier_format_in_url -+ "(#{identifier_format}|~)" -+ end -+ - def self.default_hostname - Environment.table_exists? && Environment.default ? Environment.default.default_hostname : 'localhost' - end -diff --git a/test/functional/application_controller_test.rb b/test/functional/application_controller_test.rb -index 1c4ca48..1a99752 100644 ---- a/test/functional/application_controller_test.rb -+++ b/test/functional/application_controller_test.rb -@@ -578,4 +578,22 @@ class ApplicationControllerTest < ActionController::TestCase - assert_response :success - end - -+ should "redirect to 404 if profile is '~' and user is not logged in" do -+ get :index, :profile => '~' -+ assert_response :missing -+ end -+ -+ should "redirect to action when profile is '~' " do -+ login_as('ze') -+ get :index, :profile => '~' -+ assert_response 302 -+ end -+ -+ should "substitute '~' by current user and redirect properly " do -+ login_as('ze') -+ profile = Profile.where(:identifier => 'ze').first -+ get :index, :profile => '~' -+ assert_redirected_to :controller => 'test', :action => 'index', :profile => profile.identifier -+ end -+ - end -diff --git a/test/integration/routing_test.rb b/test/integration/routing_test.rb -index 5a77eff..1c57323 100644 ---- a/test/integration/routing_test.rb -+++ b/test/integration/routing_test.rb -@@ -272,4 +272,8 @@ class RoutingTest < ActionController::IntegrationTest - assert_routing('/embed/block/12345', :controller => 'embed', :action => 'block', :id => '12345') - end - -+ should 'accept ~ as placeholder for current user' do -+ assert_routing('/profile/~', :controller => 'profile', :profile => '~', :action => 'index') -+ end -+ - end --- -2.1.4 - -- libgit2 0.21.2