diff --git a/db/migrate/20160227230233_add_attachment_avatar_to_accounts.rb b/db/migrate/20160227230233_add_attachment_avatar_to_accounts.rb index 3666abf1cc..534df25eed 100644 --- a/db/migrate/20160227230233_add_attachment_avatar_to_accounts.rb +++ b/db/migrate/20160227230233_add_attachment_avatar_to_accounts.rb @@ -3,7 +3,11 @@ class AddAttachmentAvatarToAccounts < ActiveRecord::Migration[4.2] def self.up change_table :accounts do |t| - t.attachment :avatar + # The following corresponds to `t.attachment :avatar` in an older version of Paperclip + t.string :avatar_file_name + t.string :avatar_content_type + t.integer :avatar_file_size + t.datetime :avatar_updated_at end end diff --git a/db/migrate/20160312193225_add_attachment_header_to_accounts.rb b/db/migrate/20160312193225_add_attachment_header_to_accounts.rb index 37108fc189..b481fc5290 100644 --- a/db/migrate/20160312193225_add_attachment_header_to_accounts.rb +++ b/db/migrate/20160312193225_add_attachment_header_to_accounts.rb @@ -3,7 +3,11 @@ class AddAttachmentHeaderToAccounts < ActiveRecord::Migration[4.2] def self.up change_table :accounts do |t| - t.attachment :header + # The following corresponds to `t.attachment :header` in an older version of Paperclip + t.string :header_file_name + t.string :header_content_type + t.integer :header_file_size + t.datetime :header_updated_at end end diff --git a/db/migrate/20160905150353_create_media_attachments.rb b/db/migrate/20160905150353_create_media_attachments.rb index 3903a7b9a1..92680db9f3 100644 --- a/db/migrate/20160905150353_create_media_attachments.rb +++ b/db/migrate/20160905150353_create_media_attachments.rb @@ -4,7 +4,13 @@ class CreateMediaAttachments < ActiveRecord::Migration[5.0] def change create_table :media_attachments do |t| t.integer :status_id, null: true, default: nil - t.attachment :file + + # The following corresponds to `t.attachment :file` in an older version of Paperclip + t.string :file_file_name + t.string :file_content_type + t.integer :file_file_size + t.datetime :file_updated_at + t.string :remote_url, null: false, default: '' t.integer :account_id diff --git a/db/migrate/20170330164118_add_attachment_data_to_imports.rb b/db/migrate/20170330164118_add_attachment_data_to_imports.rb index 908d4da96a..0daaa9d02e 100644 --- a/db/migrate/20170330164118_add_attachment_data_to_imports.rb +++ b/db/migrate/20170330164118_add_attachment_data_to_imports.rb @@ -3,7 +3,11 @@ class AddAttachmentDataToImports < ActiveRecord::Migration[4.2] def self.up change_table :imports do |t| - t.attachment :data + # The following corresponds to `t.attachment :data` in an older version of Paperclip + t.string :data_file_name + t.string :data_content_type + t.integer :data_file_size + t.datetime :data_updated_at end end diff --git a/db/migrate/20170901141119_truncate_preview_cards.rb b/db/migrate/20170901141119_truncate_preview_cards.rb index b4ba8c45ea..f251841f2e 100644 --- a/db/migrate/20170901141119_truncate_preview_cards.rb +++ b/db/migrate/20170901141119_truncate_preview_cards.rb @@ -8,7 +8,13 @@ class TruncatePreviewCards < ActiveRecord::Migration[5.1] t.string :url, default: '', null: false, index: { unique: true } t.string :title, default: '', null: false t.string :description, default: '', null: false - t.attachment :image + + # The following corresponds to `t.attachment :image` in an older version of Paperclip + t.string :image_file_name + t.string :image_content_type + t.integer :image_file_size + t.datetime :image_updated_at + t.integer :type, default: 0, null: false t.text :html, default: '', null: false t.string :author_name, default: '', null: false diff --git a/db/migrate/20170913000752_create_site_uploads.rb b/db/migrate/20170913000752_create_site_uploads.rb index 43a793806f..16a95ea013 100644 --- a/db/migrate/20170913000752_create_site_uploads.rb +++ b/db/migrate/20170913000752_create_site_uploads.rb @@ -4,7 +4,13 @@ class CreateSiteUploads < ActiveRecord::Migration[5.1] def change create_table :site_uploads do |t| t.string :var, default: '', null: false, index: { unique: true } - t.attachment :file + + # The following corresponds to `t.attachment :file` in an older version of Paperclip + t.string :file_file_name + t.string :file_content_type + t.integer :file_file_size + t.datetime :file_updated_at + t.json :meta t.timestamps end diff --git a/db/migrate/20170917153509_create_custom_emojis.rb b/db/migrate/20170917153509_create_custom_emojis.rb index 984fcd2181..dedc8cde80 100644 --- a/db/migrate/20170917153509_create_custom_emojis.rb +++ b/db/migrate/20170917153509_create_custom_emojis.rb @@ -5,7 +5,12 @@ class CreateCustomEmojis < ActiveRecord::Migration[5.1] create_table :custom_emojis do |t| t.string :shortcode, null: false, default: '' t.string :domain - t.attachment :image + + # The following corresponds to `t.attachment :image` in an older version of Paperclip + t.string :image_file_name + t.string :image_content_type + t.integer :image_file_size + t.datetime :image_updated_at t.timestamps end diff --git a/db/migrate/20200627125810_add_thumbnail_columns_to_media_attachments.rb b/db/migrate/20200627125810_add_thumbnail_columns_to_media_attachments.rb index a3c6b55fd2..c11a24e8b5 100644 --- a/db/migrate/20200627125810_add_thumbnail_columns_to_media_attachments.rb +++ b/db/migrate/20200627125810_add_thumbnail_columns_to_media_attachments.rb @@ -2,7 +2,12 @@ class AddThumbnailColumnsToMediaAttachments < ActiveRecord::Migration[5.2] def up - add_attachment :media_attachments, :thumbnail + # The following corresponds to `add_attachment :media_attachments, :thumbnail` in an older version of Paperclip + add_column :media_attachments, :thumbnail_file_name, :string + add_column :media_attachments, :thumbnail_content_type, :string + add_column :media_attachments, :thumbnail_file_size, :integer + add_column :media_attachments, :thumbnail_updated_at, :datetime + add_column :media_attachments, :thumbnail_remote_url, :string end diff --git a/db/post_migrate/20240307180905_migrate_devise_two_factor_secrets.rb b/db/post_migrate/20240307180905_migrate_devise_two_factor_secrets.rb index 360e4806da..6194cf9ee3 100644 --- a/db/post_migrate/20240307180905_migrate_devise_two_factor_secrets.rb +++ b/db/post_migrate/20240307180905_migrate_devise_two_factor_secrets.rb @@ -18,7 +18,13 @@ class MigrateDeviseTwoFactorSecrets < ActiveRecord::Migration[7.1] users_with_otp_enabled.find_each do |user| # Gets the new value on already-updated users # Falls back to legacy value on not-yet-migrated users - otp_secret = user.otp_secret + otp_secret = begin + user.otp_secret + rescue OpenSSL::OpenSSLError + next if ENV['MIGRATION_IGNORE_INVALID_OTP_SECRET'] == 'true' + + abort_with_decryption_error(user) + end Rails.logger.debug { "Processing #{user.email}" } @@ -36,4 +42,22 @@ class MigrateDeviseTwoFactorSecrets < ActiveRecord::Migration[7.1] def users_with_otp_enabled MigrationUser.where(otp_required_for_login: true, otp_secret: nil) end + + def abort_with_decryption_error(user) + abort <<~MESSAGE + + ERROR: Unable to decrypt OTP secret for user #{user.id}. + + This is most likely because you have changed the value of `OTP_SECRET` at some point in + time after the user configured 2FA. + + In this case, their OTP secret had already been lost with the change to `OTP_SECRET`, and + proceeding with this migration will not make the situation worse. + + Please double-check that you have not accidentally changed `OTP_SECRET` just for this + migration, and re-run the migration with `MIGRATION_IGNORE_INVALID_OTP_SECRET=true`. + + Migration aborted. + MESSAGE + end end diff --git a/spec/system/filters_spec.rb b/spec/system/filters_spec.rb new file mode 100644 index 0000000000..9d18e90460 --- /dev/null +++ b/spec/system/filters_spec.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe 'Filters' do + let(:user) { Fabricate(:user) } + let(:filter_title) { 'Filter of fun and games' } + + before { sign_in(user) } + + describe 'Creating a filter' do + it 'Populates a new filter from form' do + navigate_to_filters + + click_on I18n.t('filters.new.title') + fill_in_filter_form + expect(page).to have_content(filter_title) + end + end + + describe 'Editing an existing filter' do + let(:new_title) { 'Change title value' } + + before { Fabricate :custom_filter, account: user.account, title: filter_title } + + it 'Updates the saved filter' do + navigate_to_filters + + click_on filter_title + + fill_in filter_title_field, with: new_title + click_on I18n.t('generic.save_changes') + + expect(page).to have_content(new_title) + end + end + + describe 'Destroying an existing filter' do + before { Fabricate :custom_filter, account: user.account, title: filter_title } + + it 'Deletes the filter' do + navigate_to_filters + + expect(page).to have_content filter_title + expect do + click_on I18n.t('filters.index.delete') + end.to change(CustomFilter, :count).by(-1) + + expect(page).to_not have_content(filter_title) + end + end + + def navigate_to_filters + visit settings_path + + click_on I18n.t('filters.index.title') + expect(page).to have_content I18n.t('filters.index.title') + end + + def fill_in_filter_form + fill_in filter_title_field, with: filter_title + check I18n.t('filters.contexts.home') + within('.custom_filter_keywords_keyword') do + fill_in with: 'Keyword' + end + click_on I18n.t('filters.new.save') + end + + def filter_title_field + I18n.t('simple_form.labels.defaults.title') + end +end