diff --git a/app/services/team_importer.rb b/app/services/team_importer.rb index edf6e3df7..854ce2b5c 100644 --- a/app/services/team_importer.rb +++ b/app/services/team_importer.rb @@ -373,12 +373,15 @@ 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) + 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', user_json['user']['encrypted_password'])