From 90ec88d58b1342d812810fd91b8e6c3ee84d5a4e Mon Sep 17 00:00:00 2001 From: Claire Date: Mon, 14 Aug 2023 18:54:51 +0200 Subject: [PATCH] Add support for `indexable` attribute on remote actors (#26485) Co-authored-by: Eugen Rochko --- app/helpers/context_helper.rb | 1 + app/models/account.rb | 1 + .../activitypub/process_account_service.rb | 1 + .../20230814223300_add_indexable_to_accounts.rb | 17 +++++++++++++++++ db/schema.rb | 3 ++- 5 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20230814223300_add_indexable_to_accounts.rb diff --git a/app/helpers/context_helper.rb b/app/helpers/context_helper.rb index c23e8d028..d8fa9b92e 100644 --- a/app/helpers/context_helper.rb +++ b/app/helpers/context_helper.rb @@ -20,6 +20,7 @@ module ContextHelper focal_point: { 'toot' => 'http://joinmastodon.org/ns#', 'focalPoint' => { '@container' => '@list', '@id' => 'toot:focalPoint' } }, blurhash: { 'toot' => 'http://joinmastodon.org/ns#', 'blurhash' => 'toot:blurhash' }, discoverable: { 'toot' => 'http://joinmastodon.org/ns#', 'discoverable' => 'toot:discoverable' }, + indexable: { 'toot' => 'http://joinmastodon.org/ns#', 'indexable' => 'toot:indexable' }, voters_count: { 'toot' => 'http://joinmastodon.org/ns#', 'votersCount' => 'toot:votersCount' }, olm: { 'toot' => 'http://joinmastodon.org/ns#', 'Device' => 'toot:Device', 'Ed25519Signature' => 'toot:Ed25519Signature', 'Ed25519Key' => 'toot:Ed25519Key', 'Curve25519Key' => 'toot:Curve25519Key', 'EncryptedMessage' => 'toot:EncryptedMessage', 'publicKeyBase64' => 'toot:publicKeyBase64', 'deviceId' => 'toot:deviceId', diff --git a/app/models/account.rb b/app/models/account.rb index 1edc15972..ca8cd2b13 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -50,6 +50,7 @@ # trendable :boolean # reviewed_at :datetime # requested_review_at :datetime +# indexable :boolean default(FALSE), not null # class Account < ApplicationRecord diff --git a/app/services/activitypub/process_account_service.rb b/app/services/activitypub/process_account_service.rb index c116fab73..ae30e88a2 100644 --- a/app/services/activitypub/process_account_service.rb +++ b/app/services/activitypub/process_account_service.rb @@ -115,6 +115,7 @@ class ActivityPub::ProcessAccountService < BaseService @account.fields = property_values || {} @account.also_known_as = as_array(@json['alsoKnownAs'] || []).map { |item| value_or_id(item) } @account.discoverable = @json['discoverable'] || false + @account.indexable = @json['indexable'] || false end def set_fetchable_key! diff --git a/db/migrate/20230814223300_add_indexable_to_accounts.rb b/db/migrate/20230814223300_add_indexable_to_accounts.rb new file mode 100644 index 000000000..6729c05ef --- /dev/null +++ b/db/migrate/20230814223300_add_indexable_to_accounts.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require Rails.root.join('lib', 'mastodon', 'migration_helpers') + +class AddIndexableToAccounts < ActiveRecord::Migration[7.0] + include Mastodon::MigrationHelpers + + disable_ddl_transaction! + + def up + safety_assured { add_column_with_default :accounts, :indexable, :boolean, default: false, allow_null: false } + end + + def down + remove_column :accounts, :indexable + end +end diff --git a/db/schema.rb b/db/schema.rb index fc997f634..7cca196ea 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[7.0].define(version: 2023_08_11_103651) do +ActiveRecord::Schema[7.0].define(version: 2023_08_14_223300) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -185,6 +185,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_11_103651) do t.boolean "trendable" t.datetime "reviewed_at", precision: nil t.datetime "requested_review_at", precision: nil + t.boolean "indexable", default: false, null: false t.index "(((setweight(to_tsvector('simple'::regconfig, (display_name)::text), 'A'::\"char\") || setweight(to_tsvector('simple'::regconfig, (username)::text), 'B'::\"char\")) || setweight(to_tsvector('simple'::regconfig, (COALESCE(domain, ''::character varying))::text), 'C'::\"char\")))", name: "search_index", using: :gin t.index "lower((username)::text), COALESCE(lower((domain)::text), ''::text)", name: "index_accounts_on_username_and_domain_lower", unique: true t.index ["domain", "id"], name: "index_accounts_on_domain_and_id"