Merge commit '0a2110b9af52005798251dc9d245a66dd5dd20fa' into glitch-soc/merge-upstream

main
Claire 2024-05-20 17:47:48 +02:00
commit 20fdf8e22c
10 changed files with 145 additions and 9 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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