From cf42eba0f997aa8065beac853b79d993e8a2495b Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 6 Feb 2024 14:31:54 +0100 Subject: [PATCH 01/57] Update dependency brakeman to v6.1.2 (#29062) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 57ad96437..b76f449b2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -146,7 +146,7 @@ GEM blurhash (0.1.7) bootsnap (1.18.3) msgpack (~> 1.2) - brakeman (6.1.1) + brakeman (6.1.2) racc browser (5.3.1) brpoplpush-redis_script (0.1.3) From 93a5b3f9df7dcf1965525ee2a1202e5f1e07bf05 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 6 Feb 2024 08:33:42 -0500 Subject: [PATCH 02/57] Move status serializer chooser to private method (#29030) --- app/controllers/api/v1/statuses_controller.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/statuses_controller.rb b/app/controllers/api/v1/statuses_controller.rb index 064e7632a..702896db2 100644 --- a/app/controllers/api/v1/statuses_controller.rb +++ b/app/controllers/api/v1/statuses_controller.rb @@ -71,7 +71,7 @@ class Api::V1::StatusesController < Api::BaseController with_rate_limit: true ) - render json: @status, serializer: @status.is_a?(ScheduledStatus) ? REST::ScheduledStatusSerializer : REST::StatusSerializer + render json: @status, serializer: serializer_for_status rescue PostStatusService::UnexpectedMentionsError => e unexpected_accounts = ActiveModel::Serializer::CollectionSerializer.new( e.accounts, @@ -155,6 +155,10 @@ class Api::V1::StatusesController < Api::BaseController ) end + def serializer_for_status + @status.is_a?(ScheduledStatus) ? REST::ScheduledStatusSerializer : REST::StatusSerializer + end + def pagination_params(core_params) params.slice(:limit).permit(:limit).merge(core_params) end From 0df86d77fd5f57fc88cfd00a2cf2c265215a2839 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 6 Feb 2024 09:36:04 -0500 Subject: [PATCH 03/57] Reduce `RSpec/ExampleLength` in PostStatusService spec example (#29105) --- spec/services/post_status_service_spec.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/spec/services/post_status_service_spec.rb b/spec/services/post_status_service_spec.rb index 1e5c420a6..d10a82607 100644 --- a/spec/services/post_status_service_spec.rb +++ b/spec/services/post_status_service_spec.rb @@ -228,13 +228,7 @@ RSpec.describe PostStatusService, type: :service do subject.call( account, text: 'test status update', - media_ids: [ - Fabricate(:media_attachment, account: account), - Fabricate(:media_attachment, account: account), - Fabricate(:media_attachment, account: account), - Fabricate(:media_attachment, account: account), - Fabricate(:media_attachment, account: account), - ].map(&:id) + media_ids: Array.new(5) { Fabricate(:media_attachment, account: account) }.map(&:id) ) end.to raise_error( Mastodon::ValidationError, From 2f19ddd1fa1c14db1edaedc93f29bb4f66ab2cf0 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 6 Feb 2024 09:54:26 -0500 Subject: [PATCH 04/57] Move status serializer error handling to private method (#29031) --- app/controllers/api/v1/statuses_controller.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/v1/statuses_controller.rb b/app/controllers/api/v1/statuses_controller.rb index 702896db2..01c371876 100644 --- a/app/controllers/api/v1/statuses_controller.rb +++ b/app/controllers/api/v1/statuses_controller.rb @@ -73,11 +73,7 @@ class Api::V1::StatusesController < Api::BaseController render json: @status, serializer: serializer_for_status rescue PostStatusService::UnexpectedMentionsError => e - unexpected_accounts = ActiveModel::Serializer::CollectionSerializer.new( - e.accounts, - serializer: REST::AccountSerializer - ) - render json: { error: e.message, unexpected_accounts: unexpected_accounts }, status: 422 + render json: unexpected_accounts_error_json(e), status: 422 end def update @@ -159,6 +155,17 @@ class Api::V1::StatusesController < Api::BaseController @status.is_a?(ScheduledStatus) ? REST::ScheduledStatusSerializer : REST::StatusSerializer end + def unexpected_accounts_error_json(error) + { + error: error.message, + unexpected_accounts: serialized_accounts(error.accounts), + } + end + + def serialized_accounts(accounts) + ActiveModel::Serializer::CollectionSerializer.new(accounts, serializer: REST::AccountSerializer) + end + def pagination_params(core_params) params.slice(:limit).permit(:limit).merge(core_params) end From 64300e0fe344b9dee015e65423c327742db246af Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 6 Feb 2024 16:32:09 +0100 Subject: [PATCH 05/57] Fix self-destruct schedule not actually replacing initial schedule (#29049) --- config/initializers/sidekiq.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index 9a2743ed5..53b02edc4 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -26,6 +26,7 @@ Sidekiq.configure_server do |config| 'queue' => 'scheduler', }, } + SidekiqScheduler::Scheduler.instance.reload_schedule! end end From 1e0b0a3486cf04666b7cbd67a4a72cf7f8068c97 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 6 Feb 2024 11:42:25 -0500 Subject: [PATCH 06/57] Use SQL heredoc on long statement lines in migrations (#29112) --- ...0317193015_add_search_index_to_accounts.rb | 12 +++++++- ...5042_add_case_insensitive_index_to_tags.rb | 29 +++++++++++++++++-- ..._fix_canonical_email_blocks_foreign_key.rb | 17 +++++++++-- .../20220309213005_fix_reblog_deleted_at.rb | 11 ++++++- 4 files changed, 62 insertions(+), 7 deletions(-) diff --git a/db/migrate/20170317193015_add_search_index_to_accounts.rb b/db/migrate/20170317193015_add_search_index_to_accounts.rb index e29da61b1..0edc38154 100644 --- a/db/migrate/20170317193015_add_search_index_to_accounts.rb +++ b/db/migrate/20170317193015_add_search_index_to_accounts.rb @@ -2,7 +2,17 @@ class AddSearchIndexToAccounts < ActiveRecord::Migration[5.0] def up - execute 'CREATE INDEX search_index ON accounts USING gin((setweight(to_tsvector(\'simple\', accounts.display_name), \'A\') || setweight(to_tsvector(\'simple\', accounts.username), \'B\') || setweight(to_tsvector(\'simple\', coalesce(accounts.domain, \'\')), \'C\')));' + execute <<~SQL.squish + CREATE INDEX search_index + ON accounts + USING gin( + ( + setweight(to_tsvector('simple', accounts.display_name), 'A') || + setweight(to_tsvector('simple', accounts.username), 'B') || + setweight(to_tsvector('simple', coalesce(accounts.domain, '')), 'C') + ) + ) + SQL end def down diff --git a/db/migrate/20190726175042_add_case_insensitive_index_to_tags.rb b/db/migrate/20190726175042_add_case_insensitive_index_to_tags.rb index f2d3aa8ee..02f073e14 100644 --- a/db/migrate/20190726175042_add_case_insensitive_index_to_tags.rb +++ b/db/migrate/20190726175042_add_case_insensitive_index_to_tags.rb @@ -9,9 +9,32 @@ class AddCaseInsensitiveIndexToTags < ActiveRecord::Migration[5.2] redundant_tag_ids = row['ids'].split(',')[1..] safety_assured do - execute "UPDATE accounts_tags AS t0 SET tag_id = #{canonical_tag_id} WHERE tag_id IN (#{redundant_tag_ids.join(', ')}) AND NOT EXISTS (SELECT t1.tag_id FROM accounts_tags AS t1 WHERE t1.tag_id = #{canonical_tag_id} AND t1.account_id = t0.account_id)" - execute "UPDATE statuses_tags AS t0 SET tag_id = #{canonical_tag_id} WHERE tag_id IN (#{redundant_tag_ids.join(', ')}) AND NOT EXISTS (SELECT t1.tag_id FROM statuses_tags AS t1 WHERE t1.tag_id = #{canonical_tag_id} AND t1.status_id = t0.status_id)" - execute "UPDATE featured_tags AS t0 SET tag_id = #{canonical_tag_id} WHERE tag_id IN (#{redundant_tag_ids.join(', ')}) AND NOT EXISTS (SELECT t1.tag_id FROM featured_tags AS t1 WHERE t1.tag_id = #{canonical_tag_id} AND t1.account_id = t0.account_id)" + execute <<~SQL.squish + UPDATE accounts_tags + AS t0 + SET tag_id = #{canonical_tag_id} + WHERE + tag_id IN (#{redundant_tag_ids.join(', ')}) + AND NOT EXISTS (SELECT t1.tag_id FROM accounts_tags AS t1 WHERE t1.tag_id = #{canonical_tag_id} AND t1.account_id = t0.account_id) + SQL + + execute <<~SQL.squish + UPDATE statuses_tags + AS t0 + SET tag_id = #{canonical_tag_id} + WHERE + tag_id IN (#{redundant_tag_ids.join(', ')}) + AND NOT EXISTS (SELECT t1.tag_id FROM statuses_tags AS t1 WHERE t1.tag_id = #{canonical_tag_id} AND t1.status_id = t0.status_id) + SQL + + execute <<~SQL.squish + UPDATE featured_tags + AS t0 + SET tag_id = #{canonical_tag_id} + WHERE + tag_id IN (#{redundant_tag_ids.join(', ')}) + AND NOT EXISTS (SELECT t1.tag_id FROM featured_tags AS t1 WHERE t1.tag_id = #{canonical_tag_id} AND t1.account_id = t0.account_id) + SQL end Tag.where(id: redundant_tag_ids).in_batches.delete_all diff --git a/db/migrate/20210630000137_fix_canonical_email_blocks_foreign_key.rb b/db/migrate/20210630000137_fix_canonical_email_blocks_foreign_key.rb index 9b475966b..90a1b1a5c 100644 --- a/db/migrate/20210630000137_fix_canonical_email_blocks_foreign_key.rb +++ b/db/migrate/20210630000137_fix_canonical_email_blocks_foreign_key.rb @@ -3,13 +3,26 @@ class FixCanonicalEmailBlocksForeignKey < ActiveRecord::Migration[6.1] def up safety_assured do - execute 'ALTER TABLE canonical_email_blocks DROP CONSTRAINT fk_rails_1ecb262096, ADD CONSTRAINT fk_rails_1ecb262096 FOREIGN KEY (reference_account_id) REFERENCES accounts(id) ON DELETE CASCADE;' + execute <<~SQL.squish + ALTER TABLE canonical_email_blocks + DROP CONSTRAINT fk_rails_1ecb262096, + ADD CONSTRAINT fk_rails_1ecb262096 + FOREIGN KEY (reference_account_id) + REFERENCES accounts(id) + ON DELETE CASCADE + SQL end end def down safety_assured do - execute 'ALTER TABLE canonical_email_blocks DROP CONSTRAINT fk_rails_1ecb262096, ADD CONSTRAINT fk_rails_1ecb262096 FOREIGN KEY (reference_account_id) REFERENCES accounts(id);' + execute <<~SQL.squish + ALTER TABLE canonical_email_blocks + DROP CONSTRAINT fk_rails_1ecb262096, + ADD CONSTRAINT fk_rails_1ecb262096 + FOREIGN KEY (reference_account_id) + REFERENCES accounts(id) + SQL end end end diff --git a/db/migrate/20220309213005_fix_reblog_deleted_at.rb b/db/migrate/20220309213005_fix_reblog_deleted_at.rb index e3474beeb..7fb9bff26 100644 --- a/db/migrate/20220309213005_fix_reblog_deleted_at.rb +++ b/db/migrate/20220309213005_fix_reblog_deleted_at.rb @@ -4,7 +4,16 @@ class FixReblogDeletedAt < ActiveRecord::Migration[6.1] disable_ddl_transaction! def up - safety_assured { execute 'UPDATE statuses s SET deleted_at = r.deleted_at FROM statuses r WHERE s.reblog_of_id = r.id AND r.deleted_at IS NOT NULL' } + safety_assured do + execute <<~SQL.squish + UPDATE statuses s + SET deleted_at = r.deleted_at + FROM statuses r + WHERE + s.reblog_of_id = r.id + AND r.deleted_at IS NOT NULL + SQL + end end def down; end From 7ee93b74317c0b51516146fbe32e72cd9bbb151c Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 6 Feb 2024 18:10:17 +0100 Subject: [PATCH 07/57] Change `source` attribute of `Suggestion` entity in `/api/v2/suggestions` back to a string (#29108) --- .../components/inline_follow_suggestions.jsx | 8 ++++---- app/models/account_suggestions.rb | 4 ++-- app/models/account_suggestions/suggestion.rb | 2 +- app/serializers/rest/suggestion_serializer.rb | 15 +++++++++++++- spec/requests/api/v2/suggestions_spec.rb | 20 ++++++++++++++++++- .../rest/suggestion_serializer_spec.rb | 2 +- 6 files changed, 41 insertions(+), 10 deletions(-) diff --git a/app/javascript/mastodon/features/home_timeline/components/inline_follow_suggestions.jsx b/app/javascript/mastodon/features/home_timeline/components/inline_follow_suggestions.jsx index ac414d04d..f76526e04 100644 --- a/app/javascript/mastodon/features/home_timeline/components/inline_follow_suggestions.jsx +++ b/app/javascript/mastodon/features/home_timeline/components/inline_follow_suggestions.jsx @@ -59,7 +59,7 @@ Source.propTypes = { id: PropTypes.oneOf(['friends_of_friends', 'similar_to_recently_followed', 'featured', 'most_followed', 'most_interactions']), }; -const Card = ({ id, source }) => { +const Card = ({ id, sources }) => { const intl = useIntl(); const account = useSelector(state => state.getIn(['accounts', id])); const relationship = useSelector(state => state.getIn(['relationships', id])); @@ -89,7 +89,7 @@ const Card = ({ id, source }) => {
- {firstVerifiedField ? : } + {firstVerifiedField ? : }