Merge branch 'release/0.5.0.0-RC' into develop

This commit is contained in:
Jonne Haß 2015-04-22 20:58:54 +02:00
commit 0bad6dba88
7 changed files with 23 additions and 21 deletions

View file

@ -140,7 +140,7 @@ class UsersController < ApplicationController
end end
def download_profile def download_profile
send_data File.open(current_user.export.path).read, type: :json, filename: current_user.export.filename redirect_to current_user.export.url
end end
def export_photos def export_photos

View file

@ -2,7 +2,7 @@
# licensed under the Affero General Public License version 3 or later. See # licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file. # the COPYRIGHT file.
class ExportedPhotos < CarrierWave::Uploader::Base class ExportedPhotos < SecureUploader
def store_dir def store_dir
"uploads/users" "uploads/users"
@ -12,10 +12,6 @@ class ExportedPhotos < CarrierWave::Uploader::Base
"#{model.username}_photos_#{secure_token}.zip" if original_filename.present? "#{model.username}_photos_#{secure_token}.zip" if original_filename.present?
end end
protected
def secure_token(bytes = 16)
var = :"@#{mounted_as}_secure_token"
model.instance_variable_get(var) or model.instance_variable_set(var, SecureRandom.urlsafe_base64(bytes))
end
end end

View file

@ -2,7 +2,7 @@
# licensed under the Affero General Public License version 3 or later. See # licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file. # the COPYRIGHT file.
class ExportedUser < CarrierWave::Uploader::Base class ExportedUser < SecureUploader
def store_dir def store_dir
"uploads/users" "uploads/users"
@ -13,7 +13,7 @@ class ExportedUser < CarrierWave::Uploader::Base
end end
def filename def filename
"#{model.username}_diaspora_data.json.gz" "#{model.username}_diaspora_data_#{secure_token}.json.gz"
end end
end end

View file

@ -0,0 +1,7 @@
class SecureUploader < CarrierWave::Uploader::Base
protected
def secure_token(bytes = 16)
var = :"@#{mounted_as}_secure_token"
model.instance_variable_get(var) or model.instance_variable_set(var, SecureRandom.urlsafe_base64(bytes))
end
end

View file

@ -179,9 +179,9 @@
= link_to t('.download_export'), download_profile_user_path, class: "btn btn-success" = link_to t('.download_export'), download_profile_user_path, class: "btn btn-success"
%h6 %h6
= t('.last_exported_at', timestamp: current_user.exported_at) = t('.last_exported_at', timestamp: current_user.exported_at)
= link_to t('.request_export_update'), export_profile_user_path, class: "btn" = link_to t(".request_export_update"), export_profile_user_path, method: :post, class: "btn"
- else - else
= link_to t('.request_export'), export_profile_user_path, :class => "btn" = link_to t(".request_export"), export_profile_user_path, method: :post, class: "btn"
- if current_user.exporting_photos - if current_user.exporting_photos
.small-horizontal-spacer .small-horizontal-spacer
@ -191,10 +191,10 @@
= link_to t('.download_export_photos'), download_photos_user_path, class: "btn btn-success" = link_to t('.download_export_photos'), download_photos_user_path, class: "btn btn-success"
%h6 %h6
= t('.last_exported_at', timestamp: current_user.exported_photos_at) = t('.last_exported_at', timestamp: current_user.exported_photos_at)
= link_to t('.request_export_photos_update'), export_photos_user_path, class: "btn" = link_to t(".request_export_photos_update"), export_photos_user_path, method: :post, class: "btn"
- else - else
.small-horizontal-spacer .small-horizontal-spacer
= link_to t('.request_export_photos'), export_photos_user_path, :class => "btn" = link_to t(".request_export_photos"), export_photos_user_path, method: :post, class: "btn"
.span6 .span6
%h3 %h3

View file

@ -101,9 +101,9 @@ Diaspora::Application.routes.draw do
resource :user, :only => [:edit, :update, :destroy], :shallow => true do resource :user, :only => [:edit, :update, :destroy], :shallow => true do
get :getting_started_completed get :getting_started_completed
get :export_profile post :export_profile
get :download_profile get :download_profile
get :export_photos post :export_photos
get :download_photos get :download_photos
end end

View file

@ -14,7 +14,7 @@ describe UsersController, :type => :controller do
describe '#export_profile' do describe '#export_profile' do
it 'queues an export job' do it 'queues an export job' do
expect(@user).to receive :queue_export expect(@user).to receive :queue_export
get :export_profile post :export_profile
expect(request.flash[:notice]).to eql(I18n.t('users.edit.export_in_progress')) expect(request.flash[:notice]).to eql(I18n.t('users.edit.export_in_progress'))
expect(response).to redirect_to(edit_user_path) expect(response).to redirect_to(edit_user_path)
end end
@ -24,15 +24,14 @@ describe UsersController, :type => :controller do
it "downloads a user's export file" do it "downloads a user's export file" do
@user.perform_export! @user.perform_export!
get :download_profile get :download_profile
parsed = JSON.parse(ActiveSupport::Gzip.decompress(response.body)) expect(response).to redirect_to(@user.export.url)
expect(parsed['user']['username']).to eq @user.username
end end
end end
describe '#export_photos' do describe '#export_photos' do
it 'queues an export photos job' do it 'queues an export photos job' do
expect(@user).to receive :queue_export_photos expect(@user).to receive :queue_export_photos
get :export_photos post :export_photos
expect(request.flash[:notice]).to eql(I18n.t('users.edit.export_photos_in_progress')) expect(request.flash[:notice]).to eql(I18n.t('users.edit.export_photos_in_progress'))
expect(response).to redirect_to(edit_user_path) expect(response).to redirect_to(edit_user_path)
end end