Merge pull request #2195 from aignatov-bio/ai-sci-4051-fix-team-import-for-avatars

Fix team import for user with avatars [SCI-4051]
This commit is contained in:
aignatov-bio 2019-11-07 13:02:30 +01:00 committed by GitHub
commit 938ea259cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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'])