From 8a24bef2e3d5b119fa628273612d0807220e290f Mon Sep 17 00:00:00 2001 From: Jeremy Kescher Date: Sun, 4 Dec 2022 22:12:02 +0100 Subject: [PATCH 01/18] Fix Redis warnings regarding version 5.0.0 --- app/lib/delivery_failure_tracker.rb | 2 +- app/lib/feed_manager.rb | 16 ++++++++-------- app/lib/vacuum/statuses_vacuum.rb | 2 +- .../follow_recommendation_suppression.rb | 4 ++-- app/models/trends/base.rb | 2 +- app/services/batched_remove_status_service.rb | 18 +++++++++--------- app/workers/scheduler/indexing_scheduler.rb | 2 +- lib/chewy/strategy/mastodon.rb | 2 +- lib/mastodon/feeds_cli.rb | 4 ++-- spec/lib/delivery_failure_tracker_spec.rb | 2 +- spec/lib/vacuum/feeds_vacuum_spec.rb | 2 +- 11 files changed, 28 insertions(+), 28 deletions(-) diff --git a/app/lib/delivery_failure_tracker.rb b/app/lib/delivery_failure_tracker.rb index 66c1fd8c00..e27f29129f 100644 --- a/app/lib/delivery_failure_tracker.rb +++ b/app/lib/delivery_failure_tracker.rb @@ -10,7 +10,7 @@ class DeliveryFailureTracker end def track_failure! - redis.sadd(exhausted_deliveries_key, today) + redis.sadd?(exhausted_deliveries_key, today) UnavailableDomain.create(domain: @host) if reached_failure_threshold? end diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb index 9fe9ec346d..8dc4a8c96e 100644 --- a/app/lib/feed_manager.rb +++ b/app/lib/feed_manager.rb @@ -322,24 +322,24 @@ class FeedManager def clean_feeds!(type, ids) reblogged_id_sets = {} - redis.pipelined do + redis.pipelined do |pipeline| ids.each do |feed_id| - redis.del(key(type, feed_id)) + pipeline.del(key(type, feed_id)) reblog_key = key(type, feed_id, 'reblogs') # We collect a future for this: we don't block while getting # it, but we can iterate over it later. - reblogged_id_sets[feed_id] = redis.zrange(reblog_key, 0, -1) - redis.del(reblog_key) + reblogged_id_sets[feed_id] = pipeline.zrange(reblog_key, 0, -1) + pipeline.del(reblog_key) end end # Remove all of the reblog tracking keys we just removed the # references to. - redis.pipelined do + redis.pipelined do |pipeline| reblogged_id_sets.each do |feed_id, future| future.value.each do |reblogged_id| reblog_set_key = key(type, feed_id, "reblogs:#{reblogged_id}") - redis.del(reblog_set_key) + pipeline.del(reblog_set_key) end end end @@ -519,7 +519,7 @@ class FeedManager # REBLOG_FALLOFF most recent statuses, so we note that this # is an "extra" reblog, by storing it in reblog_set_key. reblog_set_key = key(timeline_type, account_id, "reblogs:#{status.reblog_of_id}") - redis.sadd(reblog_set_key, status.id) + redis.sadd?(reblog_set_key, status.id) return false end else @@ -556,7 +556,7 @@ class FeedManager # 2. Remove reblog from set of this status's reblogs. reblog_set_key = key(timeline_type, account_id, "reblogs:#{status.reblog_of_id}") - redis.srem(reblog_set_key, status.id) + redis.srem?(reblog_set_key, status.id) redis.zrem(reblog_key, status.reblog_of_id) # 3. Re-insert another reblog or original into the feed if one # remains in the set. We could pick a random element, but this diff --git a/app/lib/vacuum/statuses_vacuum.rb b/app/lib/vacuum/statuses_vacuum.rb index d1c4e71973..e6237374be 100644 --- a/app/lib/vacuum/statuses_vacuum.rb +++ b/app/lib/vacuum/statuses_vacuum.rb @@ -42,6 +42,6 @@ class Vacuum::StatusesVacuum end def remove_from_search_index(status_ids) - with_redis { |redis| redis.sadd('chewy:queue:StatusesIndex', status_ids) } + with_redis { |redis| redis.sadd?('chewy:queue:StatusesIndex', status_ids) } end end diff --git a/app/models/follow_recommendation_suppression.rb b/app/models/follow_recommendation_suppression.rb index 170506b853..3b503c9c70 100644 --- a/app/models/follow_recommendation_suppression.rb +++ b/app/models/follow_recommendation_suppression.rb @@ -19,9 +19,9 @@ class FollowRecommendationSuppression < ApplicationRecord private def remove_follow_recommendations - redis.pipelined do + redis.pipelined do |pipeline| I18n.available_locales.each do |locale| - redis.zrem("follow_recommendations:#{locale}", account_id) + pipeline.zrem("follow_recommendations:#{locale}", account_id) end end end diff --git a/app/models/trends/base.rb b/app/models/trends/base.rb index a189f11f23..3d4f01049f 100644 --- a/app/models/trends/base.rb +++ b/app/models/trends/base.rb @@ -60,7 +60,7 @@ class Trends::Base end def record_used_id(id, at_time = Time.now.utc) - redis.sadd(used_key(at_time), id) + redis.sadd?(used_key(at_time), id) redis.expire(used_key(at_time), 1.day.seconds) end diff --git a/app/services/batched_remove_status_service.rb b/app/services/batched_remove_status_service.rb index 2b649ee222..4f68fc6c44 100644 --- a/app/services/batched_remove_status_service.rb +++ b/app/services/batched_remove_status_service.rb @@ -48,9 +48,9 @@ class BatchedRemoveStatusService < BaseService # Cannot be batched @status_id_cutoff = Mastodon::Snowflake.id_at(2.weeks.ago) - redis.pipelined do + redis.pipelined do |pipeline| statuses.each do |status| - unpush_from_public_timelines(status) + unpush_from_public_timelines(pipeline, status) end end end @@ -73,22 +73,22 @@ class BatchedRemoveStatusService < BaseService end end - def unpush_from_public_timelines(status) + def unpush_from_public_timelines(pipeline, status) return unless status.public_visibility? && status.id > @status_id_cutoff payload = Oj.dump(event: :delete, payload: status.id.to_s) - redis.publish('timeline:public', payload) - redis.publish(status.local? ? 'timeline:public:local' : 'timeline:public:remote', payload) + pipeline.publish('timeline:public', payload) + pipeline.publish(status.local? ? 'timeline:public:local' : 'timeline:public:remote', payload) if status.media_attachments.any? - redis.publish('timeline:public:media', payload) - redis.publish(status.local? ? 'timeline:public:local:media' : 'timeline:public:remote:media', payload) + pipeline.publish('timeline:public:media', payload) + pipeline.publish(status.local? ? 'timeline:public:local:media' : 'timeline:public:remote:media', payload) end status.tags.map { |tag| tag.name.mb_chars.downcase }.each do |hashtag| - redis.publish("timeline:hashtag:#{hashtag}", payload) - redis.publish("timeline:hashtag:#{hashtag}:local", payload) if status.local? + pipeline.publish("timeline:hashtag:#{hashtag}", payload) + pipeline.publish("timeline:hashtag:#{hashtag}:local", payload) if status.local? end end diff --git a/app/workers/scheduler/indexing_scheduler.rb b/app/workers/scheduler/indexing_scheduler.rb index c423966297..d0c5c8f861 100644 --- a/app/workers/scheduler/indexing_scheduler.rb +++ b/app/workers/scheduler/indexing_scheduler.rb @@ -16,7 +16,7 @@ class Scheduler::IndexingScheduler type.import!(ids) redis.pipelined do |pipeline| - ids.each { |id| pipeline.srem("chewy:queue:#{type.name}", id) } + ids.each { |id| pipeline.srem?("chewy:queue:#{type.name}", id) } end end end diff --git a/lib/chewy/strategy/mastodon.rb b/lib/chewy/strategy/mastodon.rb index ee8b921865..0be98f6a35 100644 --- a/lib/chewy/strategy/mastodon.rb +++ b/lib/chewy/strategy/mastodon.rb @@ -17,7 +17,7 @@ module Chewy RedisConfiguration.with do |redis| redis.pipelined do |pipeline| @stash.each do |type, ids| - pipeline.sadd("chewy:queue:#{type.name}", ids) + pipeline.sadd?("chewy:queue:#{type.name}", ids) end end end diff --git a/lib/mastodon/feeds_cli.rb b/lib/mastodon/feeds_cli.rb index 428d63a446..ebdb6fee47 100644 --- a/lib/mastodon/feeds_cli.rb +++ b/lib/mastodon/feeds_cli.rb @@ -54,8 +54,8 @@ module Mastodon def clear keys = redis.keys('feed:*') - redis.pipelined do - keys.each { |key| redis.del(key) } + redis.pipelined do |pipeline| + keys.each { |key| pipeline.del(key) } end say('OK', :green) diff --git a/spec/lib/delivery_failure_tracker_spec.rb b/spec/lib/delivery_failure_tracker_spec.rb index c8179ebd91..dee9e39bf2 100644 --- a/spec/lib/delivery_failure_tracker_spec.rb +++ b/spec/lib/delivery_failure_tracker_spec.rb @@ -22,7 +22,7 @@ describe DeliveryFailureTracker do describe '#track_failure!' do it 'marks URL as unavailable after 7 days of being called' do - 6.times { |i| redis.sadd('exhausted_deliveries:example.com', i) } + 6.times { |i| redis.sadd?('exhausted_deliveries:example.com', i) } subject.track_failure! expect(subject.days).to eq 7 diff --git a/spec/lib/vacuum/feeds_vacuum_spec.rb b/spec/lib/vacuum/feeds_vacuum_spec.rb index 0aec26740f..438eaa6b45 100644 --- a/spec/lib/vacuum/feeds_vacuum_spec.rb +++ b/spec/lib/vacuum/feeds_vacuum_spec.rb @@ -11,7 +11,7 @@ RSpec.describe Vacuum::FeedsVacuum do redis.zadd(feed_key_for(inactive_user), 1, 1) redis.zadd(feed_key_for(active_user), 1, 1) redis.zadd(feed_key_for(inactive_user, 'reblogs'), 2, 2) - redis.sadd(feed_key_for(inactive_user, 'reblogs:2'), 3) + redis.sadd?(feed_key_for(inactive_user, 'reblogs:2'), 3) subject.perform end From 66a70ebb6e64c97dd9e0b2ffaeaa33aad3a28beb Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 6 Dec 2022 23:38:03 +0100 Subject: [PATCH 02/18] Fix pre-4.0 admin action logs (#22091) * Fix BackfillAdminActionLogs post-deployment migration * Improve migration tests * Backfill admin action logs again --- ...221101190723_backfill_admin_action_logs.rb | 29 ++-- ...114142_backfill_admin_action_logs_again.rb | 153 ++++++++++++++++++ db/schema.rb | 2 +- lib/tasks/tests.rake | 14 +- 4 files changed, 182 insertions(+), 16 deletions(-) create mode 100644 db/post_migrate/20221206114142_backfill_admin_action_logs_again.rb diff --git a/db/post_migrate/20221101190723_backfill_admin_action_logs.rb b/db/post_migrate/20221101190723_backfill_admin_action_logs.rb index 9a64d17150..48ef1e6e31 100644 --- a/db/post_migrate/20221101190723_backfill_admin_action_logs.rb +++ b/db/post_migrate/20221101190723_backfill_admin_action_logs.rb @@ -79,69 +79,72 @@ class BackfillAdminActionLogs < ActiveRecord::Migration[6.1] safety_assured do AdminActionLog.includes(:account).where(target_type: 'Account', human_identifier: nil).find_each do |log| next if log.account.nil? - log.update(human_identifier: log.account.acct) + log.update_attribute('human_identifier', log.account.acct) end AdminActionLog.includes(user: :account).where(target_type: 'User', human_identifier: nil).find_each do |log| next if log.user.nil? - log.update(human_identifier: log.user.account.acct, route_param: log.user.account_id) + log.update_attribute('human_identifier', log.user.account.acct) + log.update_attribute('route_param', log.user.account_id) end Admin::ActionLog.where(target_type: 'Report', human_identifier: nil).in_batches.update_all('human_identifier = target_id::text') AdminActionLog.includes(:domain_block).where(target_type: 'DomainBlock').find_each do |log| next if log.domain_block.nil? - log.update(human_identifier: log.domain_block.domain) + log.update_attribute('human_identifier', log.domain_block.domain) end AdminActionLog.includes(:domain_allow).where(target_type: 'DomainAllow').find_each do |log| next if log.domain_allow.nil? - log.update(human_identifier: log.domain_allow.domain) + log.update_attribute('human_identifier', log.domain_allow.domain) end AdminActionLog.includes(:email_domain_block).where(target_type: 'EmailDomainBlock').find_each do |log| next if log.email_domain_block.nil? - log.update(human_identifier: log.email_domain_block.domain) + log.update_attribute('human_identifier', log.email_domain_block.domain) end AdminActionLog.includes(:unavailable_domain).where(target_type: 'UnavailableDomain').find_each do |log| next if log.unavailable_domain.nil? - log.update(human_identifier: log.unavailable_domain.domain) + log.update_attribute('human_identifier', log.unavailable_domain.domain) end AdminActionLog.includes(status: :account).where(target_type: 'Status', human_identifier: nil).find_each do |log| next if log.status.nil? - log.update(human_identifier: log.status.account.acct, permalink: log.status.uri) + log.update_attribute('human_identifier', log.status.account.acct) + log.update_attribute('permalink', log.status.uri) end AdminActionLog.includes(account_warning: :account).where(target_type: 'AccountWarning', human_identifier: nil).find_each do |log| next if log.account_warning.nil? - log.update(human_identifier: log.account_warning.account.acct) + log.update_attribute('human_identifier', log.account_warning.account.acct) end AdminActionLog.includes(:announcement).where(target_type: 'Announcement', human_identifier: nil).find_each do |log| next if log.announcement.nil? - log.update(human_identifier: log.announcement.text) + log.update_attribute('human_identifier', log.announcement.text) end AdminActionLog.includes(:ip_block).where(target_type: 'IpBlock', human_identifier: nil).find_each do |log| next if log.ip_block.nil? - log.update(human_identifier: "#{log.ip_block.ip}/#{log.ip_block.ip.prefix}") + log.update_attribute('human_identifier', "#{log.ip_block.ip}/#{log.ip_block.ip.prefix}") end AdminActionLog.includes(:custom_emoji).where(target_type: 'CustomEmoji', human_identifier: nil).find_each do |log| next if log.custom_emoji.nil? - log.update(human_identifier: log.custom_emoji.shortcode) + log.update_attribute('human_identifier', log.custom_emoji.shortcode) end AdminActionLog.includes(:canonical_email_block).where(target_type: 'CanonicalEmailBlock', human_identifier: nil).find_each do |log| next if log.canonical_email_block.nil? - log.update(human_identifier: log.canonical_email_block.canonical_email_hash) + log.update_attribute('human_identifier', log.canonical_email_block.canonical_email_hash) end AdminActionLog.includes(appeal: :account).where(target_type: 'Appeal', human_identifier: nil).find_each do |log| next if log.appeal.nil? - log.update(human_identifier: log.appeal.account.acct, route_param: log.appeal.account_warning_id) + log.update_attribute('human_identifier', log.appeal.account.acct) + log.update_attribute('route_param', log.appeal.account_warning_id) end end end diff --git a/db/post_migrate/20221206114142_backfill_admin_action_logs_again.rb b/db/post_migrate/20221206114142_backfill_admin_action_logs_again.rb new file mode 100644 index 0000000000..279053ab94 --- /dev/null +++ b/db/post_migrate/20221206114142_backfill_admin_action_logs_again.rb @@ -0,0 +1,153 @@ +# frozen_string_literal: true + +class BackfillAdminActionLogsAgain < ActiveRecord::Migration[6.1] + disable_ddl_transaction! + + class Account < ApplicationRecord + # Dummy class, to make migration possible across version changes + has_one :user, inverse_of: :account + + def local? + domain.nil? + end + + def acct + local? ? username : "#{username}@#{domain}" + end + end + + class User < ApplicationRecord + # Dummy class, to make migration possible across version changes + belongs_to :account + end + + class Status < ApplicationRecord + include RoutingHelper + + # Dummy class, to make migration possible across version changes + belongs_to :account + + def local? + attributes['local'] || attributes['uri'].nil? + end + + def uri + local? ? activity_account_status_url(account, self) : attributes['uri'] + end + end + + class DomainBlock < ApplicationRecord; end + class DomainAllow < ApplicationRecord; end + class EmailDomainBlock < ApplicationRecord; end + class UnavailableDomain < ApplicationRecord; end + + class AccountWarning < ApplicationRecord + # Dummy class, to make migration possible across version changes + belongs_to :account + end + + class Announcement < ApplicationRecord; end + class IpBlock < ApplicationRecord; end + class CustomEmoji < ApplicationRecord; end + class CanonicalEmailBlock < ApplicationRecord; end + + class Appeal < ApplicationRecord + # Dummy class, to make migration possible across version changes + belongs_to :account + end + + class AdminActionLog < ApplicationRecord + # Dummy class, to make migration possible across version changes + + # Cannot use usual polymorphic support because of namespacing issues + belongs_to :status, foreign_key: :target_id + belongs_to :account, foreign_key: :target_id + belongs_to :user, foreign_key: :user_id + belongs_to :domain_block, foreign_key: :target_id + belongs_to :domain_allow, foreign_key: :target_id + belongs_to :email_domain_block, foreign_key: :target_id + belongs_to :unavailable_domain, foreign_key: :target_id + belongs_to :account_warning, foreign_key: :target_id + belongs_to :announcement, foreign_key: :target_id + belongs_to :ip_block, foreign_key: :target_id + belongs_to :custom_emoji, foreign_key: :target_id + belongs_to :canonical_email_block, foreign_key: :target_id + belongs_to :appeal, foreign_key: :target_id + end + + def up + safety_assured do + AdminActionLog.includes(:account).where(target_type: 'Account', human_identifier: nil).find_each do |log| + next if log.account.nil? + log.update_attribute('human_identifier', log.account.acct) + end + + AdminActionLog.includes(user: :account).where(target_type: 'User', human_identifier: nil).find_each do |log| + next if log.user.nil? + log.update_attribute('human_identifier', log.user.account.acct) + log.update_attribute('route_param', log.user.account_id) + end + + Admin::ActionLog.where(target_type: 'Report', human_identifier: nil).in_batches.update_all('human_identifier = target_id::text') + + AdminActionLog.includes(:domain_block).where(target_type: 'DomainBlock').find_each do |log| + next if log.domain_block.nil? + log.update_attribute('human_identifier', log.domain_block.domain) + end + + AdminActionLog.includes(:domain_allow).where(target_type: 'DomainAllow').find_each do |log| + next if log.domain_allow.nil? + log.update_attribute('human_identifier', log.domain_allow.domain) + end + + AdminActionLog.includes(:email_domain_block).where(target_type: 'EmailDomainBlock').find_each do |log| + next if log.email_domain_block.nil? + log.update_attribute('human_identifier', log.email_domain_block.domain) + end + + AdminActionLog.includes(:unavailable_domain).where(target_type: 'UnavailableDomain').find_each do |log| + next if log.unavailable_domain.nil? + log.update_attribute('human_identifier', log.unavailable_domain.domain) + end + + AdminActionLog.includes(status: :account).where(target_type: 'Status', human_identifier: nil).find_each do |log| + next if log.status.nil? + log.update_attribute('human_identifier', log.status.account.acct) + log.update_attribute('permalink', log.status.uri) + end + + AdminActionLog.includes(account_warning: :account).where(target_type: 'AccountWarning', human_identifier: nil).find_each do |log| + next if log.account_warning.nil? + log.update_attribute('human_identifier', log.account_warning.account.acct) + end + + AdminActionLog.includes(:announcement).where(target_type: 'Announcement', human_identifier: nil).find_each do |log| + next if log.announcement.nil? + log.update_attribute('human_identifier', log.announcement.text) + end + + AdminActionLog.includes(:ip_block).where(target_type: 'IpBlock', human_identifier: nil).find_each do |log| + next if log.ip_block.nil? + log.update_attribute('human_identifier', "#{log.ip_block.ip}/#{log.ip_block.ip.prefix}") + end + + AdminActionLog.includes(:custom_emoji).where(target_type: 'CustomEmoji', human_identifier: nil).find_each do |log| + next if log.custom_emoji.nil? + log.update_attribute('human_identifier', log.custom_emoji.shortcode) + end + + AdminActionLog.includes(:canonical_email_block).where(target_type: 'CanonicalEmailBlock', human_identifier: nil).find_each do |log| + next if log.canonical_email_block.nil? + log.update_attribute('human_identifier', log.canonical_email_block.canonical_email_hash) + end + + AdminActionLog.includes(appeal: :account).where(target_type: 'Appeal', human_identifier: nil).find_each do |log| + next if log.appeal.nil? + log.update_attribute('human_identifier', log.appeal.account.acct) + log.update_attribute('route_param', log.appeal.account_warning_id) + end + end + end + + def down; end +end diff --git a/db/schema.rb b/db/schema.rb index 09d07fcca6..704cef1228 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_11_04_133904) do +ActiveRecord::Schema.define(version: 2022_12_06_114142) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" diff --git a/lib/tasks/tests.rake b/lib/tasks/tests.rake index 96d2f71127..1dd25abb9b 100644 --- a/lib/tasks/tests.rake +++ b/lib/tasks/tests.rake @@ -43,6 +43,16 @@ namespace :tests do puts 'CustomFilterKeyword records not created as expected' exit(1) end + + unless Admin::ActionLog.find_by(target_type: 'DomainBlock', target_id: 1).human_identifier == 'example.org' + puts 'Admin::ActionLog domain block records not updated as expected' + exit(1) + end + + unless Admin::ActionLog.find_by(target_type: 'EmailDomainBlock', target_id: 1).human_identifier == 'example.org' + puts 'Admin::ActionLog email domain block records not updated as expected' + exit(1) + end end desc 'Populate the database with test data for 2.4.3' @@ -84,8 +94,8 @@ namespace :tests do VALUES (1, 'destroy', 'Account', 1, now(), now()), (1, 'destroy', 'User', 1, now(), now()), - (1, 'destroy', 'DomainBlock', 1312, now(), now()), - (1, 'destroy', 'EmailDomainBlock', 1312, now(), now()), + (1, 'destroy', 'DomainBlock', 1, now(), now()), + (1, 'destroy', 'EmailDomainBlock', 1, now(), now()), (1, 'destroy', 'Status', 1, now(), now()), (1, 'destroy', 'CustomEmoji', 3, now(), now()); SQL From 33f06a4ae72176623c57ad3b203aac999ebb2b93 Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Tue, 6 Dec 2022 17:54:02 -0500 Subject: [PATCH 03/18] Fix the top border of verified account fields (#22006) --- app/javascript/styles/mastodon/components.scss | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/javascript/styles/mastodon/components.scss b/app/javascript/styles/mastodon/components.scss index 45b1ac5010..79a9a4bd7d 100644 --- a/app/javascript/styles/mastodon/components.scss +++ b/app/javascript/styles/mastodon/components.scss @@ -7138,10 +7138,12 @@ noscript { .verified { border: 1px solid rgba($valid-value-color, 0.5); + margin-top: -1px; &:first-child { border-top-left-radius: 4px; border-top-right-radius: 4px; + margin-top: 0; } &:last-child { From f80c3d40e81b0955e4d5d1df76a2eb9efe1e711a Mon Sep 17 00:00:00 2001 From: Mikhail Paulyshka Date: Wed, 7 Dec 2022 02:00:56 +0300 Subject: [PATCH 04/18] enable be locale (#22022) It already has 80+% completion, which is enough for everyday use. Test instance runs on https://meowstodon.net/ --- config/application.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/config/application.rb b/config/application.rb index 6fa3654d8c..83124cfdac 100644 --- a/config/application.rb +++ b/config/application.rb @@ -71,6 +71,7 @@ module Mastodon :af, :ar, :ast, + :be, :bg, :bn, :br, From 69137f4a90874442cc5fefdf86dad7c4a4884bdc Mon Sep 17 00:00:00 2001 From: Claire Date: Wed, 7 Dec 2022 00:10:53 +0100 Subject: [PATCH 05/18] Fix irreversible and whole_word parameters handling in /api/v1/filters (#21988) Fixes #21965 --- app/controllers/api/v1/filters_controller.rb | 6 ++--- app/models/custom_filter.rb | 2 +- .../api/v1/filters_controller_spec.rb | 26 ++++++++++++++++--- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/v1/filters_controller.rb b/app/controllers/api/v1/filters_controller.rb index 149139b40a..772791b255 100644 --- a/app/controllers/api/v1/filters_controller.rb +++ b/app/controllers/api/v1/filters_controller.rb @@ -13,7 +13,7 @@ class Api::V1::FiltersController < Api::BaseController def create ApplicationRecord.transaction do - filter_category = current_account.custom_filters.create!(resource_params) + filter_category = current_account.custom_filters.create!(filter_params) @filter = filter_category.keywords.create!(keyword_params) end @@ -52,11 +52,11 @@ class Api::V1::FiltersController < Api::BaseController end def resource_params - params.permit(:phrase, :expires_in, :irreversible, context: []) + params.permit(:phrase, :expires_in, :irreversible, :whole_word, context: []) end def filter_params - resource_params.slice(:expires_in, :irreversible, :context) + resource_params.slice(:phrase, :expires_in, :irreversible, :context) end def keyword_params diff --git a/app/models/custom_filter.rb b/app/models/custom_filter.rb index da2a914934..5a4a974be4 100644 --- a/app/models/custom_filter.rb +++ b/app/models/custom_filter.rb @@ -54,7 +54,7 @@ class CustomFilter < ApplicationRecord end def irreversible=(value) - self.action = value ? :hide : :warn + self.action = ActiveModel::Type::Boolean.new.cast(value) ? :hide : :warn end def irreversible? diff --git a/spec/controllers/api/v1/filters_controller_spec.rb b/spec/controllers/api/v1/filters_controller_spec.rb index af1951f0ba..8acb46a007 100644 --- a/spec/controllers/api/v1/filters_controller_spec.rb +++ b/spec/controllers/api/v1/filters_controller_spec.rb @@ -22,9 +22,11 @@ RSpec.describe Api::V1::FiltersController, type: :controller do describe 'POST #create' do let(:scopes) { 'write:filters' } + let(:irreversible) { true } + let(:whole_word) { false } before do - post :create, params: { phrase: 'magic', context: %w(home), irreversible: true } + post :create, params: { phrase: 'magic', context: %w(home), irreversible: irreversible, whole_word: whole_word } end it 'returns http success' do @@ -34,11 +36,29 @@ RSpec.describe Api::V1::FiltersController, type: :controller do it 'creates a filter' do filter = user.account.custom_filters.first expect(filter).to_not be_nil - expect(filter.keywords.pluck(:keyword)).to eq ['magic'] + expect(filter.keywords.pluck(:keyword, :whole_word)).to eq [['magic', whole_word]] expect(filter.context).to eq %w(home) - expect(filter.irreversible?).to be true + expect(filter.irreversible?).to be irreversible expect(filter.expires_at).to be_nil end + + context 'with different parameters' do + let(:irreversible) { false } + let(:whole_word) { true } + + it 'returns http success' do + expect(response).to have_http_status(200) + end + + it 'creates a filter' do + filter = user.account.custom_filters.first + expect(filter).to_not be_nil + expect(filter.keywords.pluck(:keyword, :whole_word)).to eq [['magic', whole_word]] + expect(filter.context).to eq %w(home) + expect(filter.irreversible?).to be irreversible + expect(filter.expires_at).to be_nil + end + end end describe 'GET #show' do From 98a9347dd735f1d7040175d243b8af8ac3a4ebca Mon Sep 17 00:00:00 2001 From: Jonathan Hawkes Date: Tue, 6 Dec 2022 19:13:14 -0400 Subject: [PATCH 06/18] Update Ubuntu, Node versions, dependencies (#22075) --- Vagrantfile | 71 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 27 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 3e73d9e470..880cc18495 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -3,16 +3,14 @@ ENV["PORT"] ||= "3000" -$provision = <