Skip to content

Commit cd1cfa3

Browse files
committed
Fixing review issues
1 parent 14743e1 commit cd1cfa3

File tree

7 files changed

+35
-20
lines changed

7 files changed

+35
-20
lines changed

app/controllers/users_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def copy_import_files(user_data)
252252
end
253253

254254
def copy_import_file(tmp_file)
255-
return if tmp_file.empty?
255+
return if tmp_file.blank?
256256

257257
file_path_to_save_to = Rails.root.join("public", "uploads", "users",
258258
"#{current_user.username}_#{tmp_file.original_filename}")

app/services/import_service.rb

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,35 @@
33
class ImportService
44
include Diaspora::Logging
55

6-
def import_by_user(user_name, import_parameters)
6+
def import_by_user(user, import_parameters)
77
profile_path = import_parameters["profile_path"]
88
photos_path = import_parameters["photos_path"]
99

10-
import_by_files(profile_path, photos_path, user_name)
10+
import_by_files(user, profile_path, photos_path)
1111
end
1212

13-
def import_by_files(path_to_profile, path_to_photos, username, opts={})
14-
user = User.find_by(username: username)
15-
raise ArgumentError, "Username #{username} should exist before uploading photos." if user.nil?
13+
def import_by_files(user, path_to_profile, path_to_photos, opts={})
14+
import_profile_if_present(opts, path_to_photos, path_to_profile, user.username)
1615

17-
if path_to_profile.present?
18-
logger.info "Import for profile #{username} at path #{path_to_profile} requested"
19-
import_user_profile(path_to_profile, username, opts.merge(photo_migration: path_to_photos.present?))
20-
end
16+
import_photos_if_present(path_to_photos, user)
17+
remove_import_files(path_to_profile, path_to_photos)
18+
end
19+
20+
private
2121

22+
def import_photos_if_present(path_to_photos, user)
2223
if path_to_photos.present?
23-
logger.info("Importing photos from import file for '#{username}' from #{path_to_photos}")
24+
logger.info("Importing photos from import file for '#{user.username}' from #{path_to_photos}")
2425
import_user_photos(user, path_to_photos)
2526
end
26-
remove_import_files(path_to_profile, path_to_photos)
2727
end
2828

29-
private
29+
def import_profile_if_present(opts, path_to_photos, path_to_profile, username)
30+
if path_to_profile.present?
31+
logger.info "Import for profile #{username} at path #{path_to_profile} requested"
32+
import_user_profile(path_to_profile, username, opts.merge(photo_migration: path_to_photos.present?))
33+
end
34+
end
3035

3136
def import_user_profile(path_to_profile, username, opts)
3237
raise ArgumentError, "Profile file not found at path: #{path_to_profile}" unless File.exist?(path_to_profile)

app/views/users/_edit.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@
238238
= t(".import.warning")
239239
.form-group
240240
.btn.btn-primary{id: "import_account", data: {toggle: "modal", target: "#importAccountModal"}}
241-
Import another account...
241+
= t(".import.account")
242242
= render "import_account_modal"
243243
.row
244244
.col-md-12

app/workers/import_user.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class ImportUser < ArchiveBase
66

77
def perform_archive_job(user_id, import_parameters)
88
user = User.find(user_id)
9-
ImportService.new.import_by_user(user.username, import_parameters)
9+
ImportService.new.import_by_user(user, import_parameters)
1010
end
1111
end
1212
end

config/locales/diaspora/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,7 @@ en:
13201320
To do this, first export your data and photos from the pod you want to move from. Then, import those data and photo archives into this account.
13211321
Your old account on the other pod will be deleted once this process has completed."
13221322
warning: "There is no way back; that account can’t be restored if you change your mind."
1323+
account: "Import another account..."
13231324

13241325
close_account:
13251326
dont_go: "Hey, please don’t go!"

lib/tasks/accounts.rake

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ namespace :accounts do
1010
process_arguments(args)
1111
start_time = Time.now.getlocal
1212
if args[:new_user_name].present? && (args[:archive_path].present? || args[:photos_path].present?)
13-
ImportService.new.import_by_files(args[:archive_path], args[:photos_path], args[:new_user_name],
14-
args.slice(:import_settings, :import_profile))
15-
puts "\n Migration completed in #{Time.now.getlocal - start_time} seconds. (Photos might still be processed in)"
13+
user = User.find_by(username: args[:new_username])
14+
if user.nil?
15+
puts("Username #{args[:new_username]} should exist before uploading photos.")
16+
else
17+
import_user(user, start_time, args)
18+
end
1619
else
1720
puts "Must set a user name and a archive file path or photos file path"
1821
end
@@ -49,4 +52,10 @@ namespace :accounts do
4952

5053
response[0] == "y"
5154
end
55+
56+
def import_user(user, start_time, args)
57+
ImportService.new.import_by_files(user, args[:archive_path], args[:photos_path],
58+
args.slice(:import_settings, :import_profile))
59+
puts "\n Migration completed in #{Time.now.getlocal - start_time} seconds. (Photos might still be processed in)"
60+
end
5261
end

spec/integration/import_service_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
it "imports the photo with the same name" do
2121
old_random_string = photo.random_string
2222

23-
inlined_jobs { ImportService.new.import_by_files(nil, photo_archive.current_path, user.username) }
23+
inlined_jobs { ImportService.new.import_by_files(user, nil, photo_archive.current_path) }
2424

2525
imported_photo = photo.reload
2626
expect(imported_photo.random_string).to include(old_random_string)
@@ -46,7 +46,7 @@
4646
dispatcher
4747
end
4848

49-
inlined_jobs { ImportService.new.import_by_files(nil, photo_archive_path, user.username) }
49+
inlined_jobs { ImportService.new.import_by_files(user, nil, photo_archive_path) }
5050

5151
imported_photo = photo.reload
5252
new_random_string = imported_photo.random_string

0 commit comments

Comments
 (0)