From 7bc301e184afb95d8acd77294e2c23a6989ebc34 Mon Sep 17 00:00:00 2001 From: Claire Date: Wed, 23 Apr 2025 10:12:31 +0200 Subject: [PATCH 1/5] Make `Web::PushSubscription#user` and `Web::PushSubscription#access_token` relationships non-optional (#34498) Co-authored-by: Emelia Smith --- app/models/web/push_subscription.rb | 38 +++---------------- .../web/notification_serializer.rb | 2 +- ..._not_null_to_web_push_subscription_user.rb | 7 ++++ ..._not_null_to_web_push_subscription_user.rb | 19 ++++++++++ ...l_to_web_push_subscription_access_token.rb | 7 ++++ ...l_to_web_push_subscription_access_token.rb | 19 ++++++++++ db/schema.rb | 6 +-- .../web_push_subscription_fabricator.rb | 2 + .../api/v1/push/subscriptions_spec.rb | 3 +- 9 files changed, 66 insertions(+), 37 deletions(-) create mode 100644 db/migrate/20250422083912_add_not_null_to_web_push_subscription_user.rb create mode 100644 db/migrate/20250422084214_validate_add_not_null_to_web_push_subscription_user.rb create mode 100644 db/migrate/20250422085027_add_not_null_to_web_push_subscription_access_token.rb create mode 100644 db/migrate/20250422085303_validate_add_not_null_to_web_push_subscription_access_token.rb diff --git a/app/models/web/push_subscription.rb b/app/models/web/push_subscription.rb index 12d843cd09..25140598a5 100644 --- a/app/models/web/push_subscription.rb +++ b/app/models/web/push_subscription.rb @@ -12,13 +12,13 @@ # standard :boolean default(FALSE), not null # created_at :datetime not null # updated_at :datetime not null -# access_token_id :bigint(8) -# user_id :bigint(8) +# access_token_id :bigint(8) not null +# user_id :bigint(8) not null # class Web::PushSubscription < ApplicationRecord - belongs_to :user, optional: true - belongs_to :access_token, class_name: 'Doorkeeper::AccessToken', optional: true + belongs_to :user + belongs_to :access_token, class_name: 'Doorkeeper::AccessToken' has_one :session_activation, foreign_key: 'web_push_subscription_id', inverse_of: :web_push_subscription, dependent: nil @@ -28,7 +28,7 @@ class Web::PushSubscription < ApplicationRecord validates_with WebPushKeyValidator - delegate :locale, to: :associated_user + delegate :locale, to: :user generates_token_for :unsubscribe, expires_in: Web::PushNotificationWorker::TTL @@ -36,24 +36,8 @@ class Web::PushSubscription < ApplicationRecord policy_allows_notification?(notification) && alert_enabled_for_notification_type?(notification) end - def associated_user - return @associated_user if defined?(@associated_user) - - @associated_user = if user_id.nil? - session_activation.user - else - user - end - end - def associated_access_token - return @associated_access_token if defined?(@associated_access_token) - - @associated_access_token = if access_token_id.nil? - find_or_create_access_token.token - else - access_token.token - end + access_token.token end class << self @@ -65,16 +49,6 @@ class Web::PushSubscription < ApplicationRecord private - def find_or_create_access_token - Doorkeeper::AccessToken.find_or_create_for( - application: Doorkeeper::Application.find_by(superapp: true), - resource_owner: user_id || session_activation.user_id, - scopes: Doorkeeper::OAuth::Scopes.from_string('read write follow push'), - expires_in: Doorkeeper.configuration.access_token_expires_in, - use_refresh_token: Doorkeeper.configuration.refresh_token_enabled? - ) - end - def alert_enabled_for_notification_type?(notification) truthy?(data&.dig('alerts', notification.type.to_s)) end diff --git a/app/serializers/web/notification_serializer.rb b/app/serializers/web/notification_serializer.rb index fb2f7248a6..1c2b26bf5b 100644 --- a/app/serializers/web/notification_serializer.rb +++ b/app/serializers/web/notification_serializer.rb @@ -13,7 +13,7 @@ class Web::NotificationSerializer < ActiveModel::Serializer end def preferred_locale - current_push_subscription.associated_user&.locale || I18n.default_locale + current_push_subscription.user&.locale || I18n.default_locale end def notification_id diff --git a/db/migrate/20250422083912_add_not_null_to_web_push_subscription_user.rb b/db/migrate/20250422083912_add_not_null_to_web_push_subscription_user.rb new file mode 100644 index 0000000000..2af08edc40 --- /dev/null +++ b/db/migrate/20250422083912_add_not_null_to_web_push_subscription_user.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddNotNullToWebPushSubscriptionUser < ActiveRecord::Migration[8.0] + def change + add_check_constraint :web_push_subscriptions, 'user_id IS NOT NULL', name: 'web_push_subscriptions_user_id_null', validate: false + end +end diff --git a/db/migrate/20250422084214_validate_add_not_null_to_web_push_subscription_user.rb b/db/migrate/20250422084214_validate_add_not_null_to_web_push_subscription_user.rb new file mode 100644 index 0000000000..af1962a8fb --- /dev/null +++ b/db/migrate/20250422084214_validate_add_not_null_to_web_push_subscription_user.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class ValidateAddNotNullToWebPushSubscriptionUser < ActiveRecord::Migration[8.0] + def up + connection.execute(<<~SQL.squish) + DELETE FROM web_push_subscriptions + WHERE user_id IS NULL + SQL + + validate_check_constraint :web_push_subscriptions, name: 'web_push_subscriptions_user_id_null' + change_column_null :web_push_subscriptions, :user_id, false + remove_check_constraint :web_push_subscriptions, name: 'web_push_subscriptions_user_id_null' + end + + def down + add_check_constraint :web_push_subscriptions, 'user_id IS NOT NULL', name: 'web_push_subscriptions_user_id_null', validate: false + change_column_null :web_push_subscriptions, :user_id, true + end +end diff --git a/db/migrate/20250422085027_add_not_null_to_web_push_subscription_access_token.rb b/db/migrate/20250422085027_add_not_null_to_web_push_subscription_access_token.rb new file mode 100644 index 0000000000..167bc71b72 --- /dev/null +++ b/db/migrate/20250422085027_add_not_null_to_web_push_subscription_access_token.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddNotNullToWebPushSubscriptionAccessToken < ActiveRecord::Migration[8.0] + def change + add_check_constraint :web_push_subscriptions, 'access_token_id IS NOT NULL', name: 'web_push_subscriptions_access_token_id_null', validate: false + end +end diff --git a/db/migrate/20250422085303_validate_add_not_null_to_web_push_subscription_access_token.rb b/db/migrate/20250422085303_validate_add_not_null_to_web_push_subscription_access_token.rb new file mode 100644 index 0000000000..322d376667 --- /dev/null +++ b/db/migrate/20250422085303_validate_add_not_null_to_web_push_subscription_access_token.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class ValidateAddNotNullToWebPushSubscriptionAccessToken < ActiveRecord::Migration[8.0] + def up + connection.execute(<<~SQL.squish) + DELETE FROM web_push_subscriptions + WHERE access_token_id IS NULL + SQL + + validate_check_constraint :web_push_subscriptions, name: 'web_push_subscriptions_access_token_id_null' + change_column_null :web_push_subscriptions, :access_token_id, false + remove_check_constraint :web_push_subscriptions, name: 'web_push_subscriptions_access_token_id_null' + end + + def down + add_check_constraint :web_push_subscriptions, 'access_token_id IS NOT NULL', name: 'web_push_subscriptions_access_token_id_null', validate: false + change_column_null :web_push_subscriptions, :access_token_id, true + end +end diff --git a/db/schema.rb b/db/schema.rb index 6b1aa81bd0..0cabf8997c 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[8.0].define(version: 2025_04_11_095859) do +ActiveRecord::Schema[8.0].define(version: 2025_04_22_085303) do # These are extensions that must be enabled in order to support this database enable_extension "pg_catalog.plpgsql" @@ -1237,8 +1237,8 @@ ActiveRecord::Schema[8.0].define(version: 2025_04_11_095859) do t.json "data" t.datetime "created_at", precision: nil, null: false t.datetime "updated_at", precision: nil, null: false - t.bigint "access_token_id" - t.bigint "user_id" + t.bigint "access_token_id", null: false + t.bigint "user_id", null: false t.boolean "standard", default: false, null: false t.index ["access_token_id"], name: "index_web_push_subscriptions_on_access_token_id", where: "(access_token_id IS NOT NULL)" t.index ["user_id"], name: "index_web_push_subscriptions_on_user_id" diff --git a/spec/fabricators/web_push_subscription_fabricator.rb b/spec/fabricators/web_push_subscription_fabricator.rb index 6b4028342c..458aa8296e 100644 --- a/spec/fabricators/web_push_subscription_fabricator.rb +++ b/spec/fabricators/web_push_subscription_fabricator.rb @@ -8,4 +8,6 @@ Fabricator(:web_push_subscription, from: Web::PushSubscription) do Base64.urlsafe_encode64(ecdh_key) end key_auth { Base64.urlsafe_encode64(Random.new.bytes(16)) } + user { Fabricate(:user) } + access_token { |attrs| Fabricate.build(:accessible_access_token, resource_owner_id: attrs[:user].id) } end diff --git a/spec/requests/api/v1/push/subscriptions_spec.rb b/spec/requests/api/v1/push/subscriptions_spec.rb index 69adeb9b6f..359de9d95c 100644 --- a/spec/requests/api/v1/push/subscriptions_spec.rb +++ b/spec/requests/api/v1/push/subscriptions_spec.rb @@ -207,7 +207,8 @@ RSpec.describe 'API V1 Push Subscriptions' do Fabricate( :web_push_subscription, endpoint: create_payload[:subscription][:endpoint], - access_token_id: token.id + access_token: token, + user: user ) end end From b68c622a077a087c820823807236e82fd5daee88 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 23 Apr 2025 10:25:46 +0200 Subject: [PATCH 2/5] fix(deps): update dependency pg-connection-string to v2.8.1 (#34517) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index 4dd32a1d8a..80eb1a0503 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13287,9 +13287,9 @@ __metadata: linkType: hard "pg-connection-string@npm:^2.6.0, pg-connection-string@npm:^2.7.0": - version: 2.7.0 - resolution: "pg-connection-string@npm:2.7.0" - checksum: 10c0/50a1496a1c858f9495d78a2c7a66d93ef3602e718aff2953bb5738f3ea616d7f727f32fc20513c9bed127650cd14c1ddc7b458396f4000e689d4b64c65c5c51e + version: 2.8.1 + resolution: "pg-connection-string@npm:2.8.1" + checksum: 10c0/87cb519d97a5bdc756f71a6b051eea4d4887e2e102bc694ecda935fe636a037666a0444729b08c7a26c2e9e4b052b2b366af58492ccc49704bacd6876f946ce8 languageName: node linkType: hard From 577e407ffc9c217195283661fd7dfd5ac0fe0d30 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 23 Apr 2025 10:47:20 +0200 Subject: [PATCH 3/5] New Crowdin Translations (automated) (#34522) Co-authored-by: GitHub Actions --- app/javascript/mastodon/locales/de.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/javascript/mastodon/locales/de.json b/app/javascript/mastodon/locales/de.json index 4a86c46f28..e6eb25ec2d 100644 --- a/app/javascript/mastodon/locales/de.json +++ b/app/javascript/mastodon/locales/de.json @@ -56,8 +56,8 @@ "account.mute_notifications_short": "Benachrichtigungen stummschalten", "account.mute_short": "Stummschalten", "account.muted": "Stummgeschaltet", - "account.muting": "Wird stummgeschaltet", - "account.mutual": "Ihr folgt euch", + "account.muting": "Stummgeschaltet", + "account.mutual": "Ihr folgt einander", "account.no_bio": "Keine Beschreibung verfügbar.", "account.open_original_page": "Ursprüngliche Seite öffnen", "account.posts": "Beiträge", From ffc853c08694cc5f1ec37e42da9a00e9e6ede0ba Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 23 Apr 2025 10:53:29 +0200 Subject: [PATCH 4/5] fix(deps): update dependency pg to v8.15.1 (#34516) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- yarn.lock | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/yarn.lock b/yarn.lock index 80eb1a0503..cd7af4bf3d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13279,14 +13279,14 @@ __metadata: languageName: node linkType: hard -"pg-cloudflare@npm:^1.1.1": - version: 1.1.1 - resolution: "pg-cloudflare@npm:1.1.1" - checksum: 10c0/a68b957f755be6af813d68ccaf4c906a000fd2ecb362cd281220052cc9e2f6c26da3b88792742387008c30b3bf0d2fa3a0eff04aeb8af4414023c99ae78e07bd +"pg-cloudflare@npm:^1.2.0": + version: 1.2.0 + resolution: "pg-cloudflare@npm:1.2.0" + checksum: 10c0/d6f2d032aeab291b17d627b051aae85420aea86a3371895a77b55fec93e3dac05880fbf09e5de33486ad3a2e6d7d56a025a8aa66f0d5883984f9834e4cd6f6a4 languageName: node linkType: hard -"pg-connection-string@npm:^2.6.0, pg-connection-string@npm:^2.7.0": +"pg-connection-string@npm:^2.6.0, pg-connection-string@npm:^2.8.1": version: 2.8.1 resolution: "pg-connection-string@npm:2.8.1" checksum: 10c0/87cb519d97a5bdc756f71a6b051eea4d4887e2e102bc694ecda935fe636a037666a0444729b08c7a26c2e9e4b052b2b366af58492ccc49704bacd6876f946ce8 @@ -13307,19 +13307,19 @@ __metadata: languageName: node linkType: hard -"pg-pool@npm:^3.8.0": - version: 3.8.0 - resolution: "pg-pool@npm:3.8.0" +"pg-pool@npm:^3.9.1": + version: 3.9.1 + resolution: "pg-pool@npm:3.9.1" peerDependencies: pg: ">=8.0" - checksum: 10c0/c05287b0caafeab43807e6ad22d153c09c473dbeb5b2cea13b83102376e9a56f46b91fa9adf9d53885ce198280c6a95555390987c42b3858d1936d3e0cdc83aa + checksum: 10c0/2bbc0892ab7325486b7d5ad8ade59ec925476666ac3959cb4850814c5334bb2f1344258707f8d0445093b59dd6e94401508cebcee490d4827821549147a2ebd9 languageName: node linkType: hard -"pg-protocol@npm:*, pg-protocol@npm:^1.8.0": - version: 1.8.0 - resolution: "pg-protocol@npm:1.8.0" - checksum: 10c0/2be784955599d84b564795952cee52cc2b8eab0be43f74fc1061506353801e282c1d52c9e0691a9b72092c1f3fde370e9b181e80fef6bb82a9b8d1618bfa91e6 +"pg-protocol@npm:*, pg-protocol@npm:^1.9.0": + version: 1.9.0 + resolution: "pg-protocol@npm:1.9.0" + checksum: 10c0/c37e61d7fafa97f22eabf12de69863f42fdabb3671df9cc2623bd0ffd6bdedc212e7e8460ad2c721c8a08d8477b4f128a923bf2381905d68a23a532ec7517c77 languageName: node linkType: hard @@ -13352,13 +13352,13 @@ __metadata: linkType: hard "pg@npm:^8.5.0": - version: 8.14.1 - resolution: "pg@npm:8.14.1" + version: 8.15.1 + resolution: "pg@npm:8.15.1" dependencies: - pg-cloudflare: "npm:^1.1.1" - pg-connection-string: "npm:^2.7.0" - pg-pool: "npm:^3.8.0" - pg-protocol: "npm:^1.8.0" + pg-cloudflare: "npm:^1.2.0" + pg-connection-string: "npm:^2.8.1" + pg-pool: "npm:^3.9.1" + pg-protocol: "npm:^1.9.0" pg-types: "npm:^2.1.0" pgpass: "npm:1.x" peerDependencies: @@ -13369,7 +13369,7 @@ __metadata: peerDependenciesMeta: pg-native: optional: true - checksum: 10c0/221741cfcea4ab32c8b57bd60703bc36cfb5622dcac56c19e45f504ef8669f2f2e0429af8850f58079cfc89055da35b5a5e12de19e0505e3f61a4b4349388dcb + checksum: 10c0/c6e5fd9cd6af7fc3208e48f860fd9ec9f7bc20192e449b0b36b096a9d5889de50706c705f6996e51a765bd4b7331179d7ffb43528a141bb996ee6f2c8f994c9a languageName: node linkType: hard From ca4139be07fb0022fc8d915f48ff97c8389ac889 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 23 Apr 2025 11:50:42 +0200 Subject: [PATCH 5/5] chore(deps): update node.js to 22.15 (#34523) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- .nvmrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nvmrc b/.nvmrc index 744ca17ec0..5d621bb2fe 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -22.14 +22.15