Merge branch 'develop' into api

This commit is contained in:
Jonne Haß
2020-01-14 11:59:56 +01:00
250 changed files with 2476 additions and 1272 deletions

View File

@@ -0,0 +1,13 @@
# frozen_string_literal: true
class AddDeviseTwoFactorToUsers < ActiveRecord::Migration[5.1]
def change
change_table :users, bulk: true do |t|
t.string :encrypted_otp_secret
t.string :encrypted_otp_secret_iv
t.string :encrypted_otp_secret_salt
t.integer :consumed_timestep
t.boolean :otp_required_for_login
end
end
end

View File

@@ -0,0 +1,7 @@
# frozen_string_literal: true
class AddTwoFactorBackupableToUser < ActiveRecord::Migration[5.1]
def change
add_column :users, :otp_backup_codes, :text
end
end

View File

@@ -0,0 +1,11 @@
# frozen_string_literal: true
class FixMissingRemotePhotoFields < ActiveRecord::Migration[5.1]
def up
Photo.where(remote_photo_path: nil).each do |photo|
photo.write_attribute(:unprocessed_image, photo.read_attribute(:processed_image))
photo.update_remote_path
photo.save!
end
end
end

View File

@@ -0,0 +1,52 @@
# frozen_string_literal: true
class DecryptTwoFactorSecret < ActiveRecord::Migration[5.1]
class User < ApplicationRecord
end
def up
add_column :users, :plain_otp_secret, :string
key = twofa_encryption_key
decrypt_existing_secrets(key) if key
change_table :users, bulk: true do |t|
t.remove :encrypted_otp_secret
t.remove :encrypted_otp_secret_iv
t.remove :encrypted_otp_secret_salt
end
end
def down
raise ActiveRecord::IrreversibleMigration
end
private
def twofa_encryption_key
if AppConfig.heroku?
ENV["TWOFA_ENCRYPTION_KEY"]
else
key_file = File.expand_path("../../config/initializers/twofa_encryption_key.rb", File.dirname(__FILE__))
if File.exist? key_file
require key_file
File.delete(key_file)
return Diaspora::Application.config.twofa_encryption_key
end
end
end
def decrypt_existing_secrets(key)
User.where.not(encrypted_otp_secret: nil).each do |user|
user.plain_otp_secret = Encryptor.decrypt(
value: user.encrypted_otp_secret.unpack("m").first,
key: key,
iv: user.encrypted_otp_secret_iv.unpack("m").first,
salt: user.encrypted_otp_secret_salt.slice(1..-1).unpack("m").first
)
user.save!
end
end
end

View File

@@ -0,0 +1,14 @@
# frozen_string_literal: true
class PhotosRemoveCommentCount < ActiveRecord::Migration[5.1]
class Comment < ApplicationRecord
end
def change
remove_column :photos, :comments_count, :integer
reversible do |change|
change.up { Comment.where(commentable_type: "Photo").delete_all }
end
end
end

View File

@@ -0,0 +1,9 @@
# frozen_string_literal: true
class FixPendingProfilePhotos < ActiveRecord::Migration[5.1]
def up
Photo.where(pending: true).each do |photo|
photo.update(pending: false) if Profile.where(image_url: photo.url(:thumb_large)).exists?
end
end
end

View File

@@ -0,0 +1,10 @@
# frozen_string_literal: true
class RemoveChat < ActiveRecord::Migration[5.1]
def up
remove_column :aspects, :chat_enabled
drop_table :chat_contacts
drop_table :chat_fragments
drop_table :chat_offline_messages
end
end