Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge upstream changes up to 0a2110b9af52005798251dc9d245a66dd5dd20fa #2714

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 7 additions & 1 deletion db/migrate/20160905150353_create_media_attachments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion db/migrate/20170330164118_add_attachment_data_to_imports.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 7 additions & 1 deletion db/migrate/20170901141119_truncate_preview_cards.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ def up
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
Expand Down
8 changes: 7 additions & 1 deletion db/migrate/20170913000752_create_site_uploads.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion db/migrate/20170917153509_create_custom_emojis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ def change
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ def up
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}" }

Expand All @@ -36,4 +42,22 @@ def down
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
72 changes: 72 additions & 0 deletions spec/system/filters_spec.rb
Original file line number Diff line number Diff line change
@@ -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