From b56a997aef54b04d9de403324126f40c53a2ba6c Mon Sep 17 00:00:00 2001 From: aignatov-bio Date: Mon, 4 Nov 2019 14:53:59 +0100 Subject: [PATCH 1/2] Fix team import for user with avatars --- app/services/team_importer.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/services/team_importer.rb b/app/services/team_importer.rb index edf6e3df7..866d15cdc 100644 --- a/app/services/team_importer.rb +++ b/app/services/team_importer.rb @@ -373,12 +373,13 @@ class TeamImporter user.password = user_json['user']['encrypted_password'] user.current_team_id = team.id user.invited_by_id = @user_mappings[user.invited_by_id] - if user_json['user']['avatar'] - avatar_path = File.join(@import_dir, 'avatars', orig_user_id.to_s, - user_json['user']['avatar']['filename']) - File.open(avatar_path) { |f| user.avatar = f } if File.exist?(avatar_path) - end user.save! + if user_json['user']['avatar'] + avatar_filename = user_json['user']['avatar']['filename'] + avatar_path = File.join(@import_dir, 'avatars', orig_user_id.to_s, avatar_filename) + avatar = File.open(avatar_path) + user.avatar.attach(io: avatar, filename: avatar_filename) + end @user_counter += 1 user.update_attribute('encrypted_password', user_json['user']['encrypted_password']) From e4a39bbbe4c2487b41dd474c7859de3affa4218e Mon Sep 17 00:00:00 2001 From: aignatov-bio Date: Wed, 6 Nov 2019 14:41:51 +0100 Subject: [PATCH 2/2] Add check for files --- app/services/team_importer.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/services/team_importer.rb b/app/services/team_importer.rb index 866d15cdc..854ce2b5c 100644 --- a/app/services/team_importer.rb +++ b/app/services/team_importer.rb @@ -377,8 +377,10 @@ class TeamImporter if user_json['user']['avatar'] avatar_filename = user_json['user']['avatar']['filename'] avatar_path = File.join(@import_dir, 'avatars', orig_user_id.to_s, avatar_filename) - avatar = File.open(avatar_path) - user.avatar.attach(io: avatar, filename: avatar_filename) + if File.exist?(avatar_path) + avatar = File.open(avatar_path) + user.avatar.attach(io: avatar, filename: avatar_filename) + end end @user_counter += 1 user.update_attribute('encrypted_password',