From 8ad75f9ecf16641699248ac83acc9f4d0edeba88 Mon Sep 17 00:00:00 2001 From: lain Date: Fri, 1 Nov 2019 13:31:55 +0100 Subject: Migrations: Add migration to fill empty info fields and make them non-null. --- .../20190711042020_fix_and_secure_user_info_field.exs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 priv/repo/migrations/20190711042020_fix_and_secure_user_info_field.exs diff --git a/priv/repo/migrations/20190711042020_fix_and_secure_user_info_field.exs b/priv/repo/migrations/20190711042020_fix_and_secure_user_info_field.exs new file mode 100644 index 000000000..9602a8c41 --- /dev/null +++ b/priv/repo/migrations/20190711042020_fix_and_secure_user_info_field.exs @@ -0,0 +1,17 @@ +defmodule Pleroma.Repo.Migrations.FixAndSecureUserInfoField do + use Ecto.Migration + + def up do + execute("UPDATE users SET info = '{}'::jsonb WHERE info IS NULL") + + execute("ALTER TABLE users + ALTER COLUMN info SET NOT NULL + ") + end + + def down do + execute("ALTER TABLE users + ALTER COLUMN info DROP NOT NULL + ") + end +end -- cgit v1.2.3 From 5b34545b64872a649c605124d12a44ec9bb6031c Mon Sep 17 00:00:00 2001 From: lain Date: Fri, 1 Nov 2019 13:40:28 +0100 Subject: Changelog: Add information about user.info migration. --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e078d422..979a9ac52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## [1.1.4] - 2019-11-01 +### Fixed +- Added a migration that fills up empty user.info fields to prevent breakage after previous unsafe migrations. + ## [1.1.3] - 2019-10-25 ### Fixed - Blocked users showing up in notifications collapsed as if they were muted -- cgit v1.2.3 From d52f9c144f0a554abc8c1297f8375205e7bf9304 Mon Sep 17 00:00:00 2001 From: lain Date: Fri, 1 Nov 2019 13:40:58 +0100 Subject: Mixfile: Bump version. --- mix.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index fde6216d2..2f7ac0e80 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule Pleroma.Mixfile do def project do [ app: :pleroma, - version: version("1.1.3"), + version: version("1.1.4"), elixir: "~> 1.7", elixirc_paths: elixirc_paths(Mix.env()), compilers: [:phoenix, :gettext] ++ Mix.compilers(), -- cgit v1.2.3 From 6f5ac0819a7b4257239e2832a32a0fac4f98e407 Mon Sep 17 00:00:00 2001 From: lain Date: Fri, 1 Nov 2019 14:16:00 +0100 Subject: Tests: Fix tests failing because of info being null. --- test/support/builders/user_builder.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/support/builders/user_builder.ex b/test/support/builders/user_builder.ex index 6da16f71a..4bdaddc4a 100644 --- a/test/support/builders/user_builder.ex +++ b/test/support/builders/user_builder.ex @@ -10,7 +10,8 @@ def build(data \\ %{}) do password_hash: Comeonin.Pbkdf2.hashpwsalt("test"), bio: "A tester.", ap_id: "some id", - last_digest_emailed_at: NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second) + last_digest_emailed_at: NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second), + info: %{} } Map.merge(user, data) -- cgit v1.2.3 From 4bab9672ed3d2dd4c1c62b2e233e79b671526515 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Wed, 30 Oct 2019 12:59:14 +0300 Subject: Fix bookmark migration using a query with a schema This resulted in failures when updating from Pleroma <1.0 because of all the new fields that were added to the user schema. --- priv/repo/migrations/20190414125034_migrate_old_bookmarks.exs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/priv/repo/migrations/20190414125034_migrate_old_bookmarks.exs b/priv/repo/migrations/20190414125034_migrate_old_bookmarks.exs index ce4590954..c547d2642 100644 --- a/priv/repo/migrations/20190414125034_migrate_old_bookmarks.exs +++ b/priv/repo/migrations/20190414125034_migrate_old_bookmarks.exs @@ -8,10 +8,10 @@ defmodule Pleroma.Repo.Migrations.MigrateOldBookmarks do def up do query = - from(u in User, + from(u in "users", where: u.local == true, - where: fragment("array_length(bookmarks, 1)") > 0, - select: %{id: u.id, bookmarks: fragment("bookmarks")} + where: fragment("array_length(?, 1)", u.bookmarks) > 0, + select: %{id: u.id, bookmarks: u.bookmarks} ) Repo.stream(query) -- cgit v1.2.3 From 5f844fd3f2b35075bd3a90c71315c321fec6a6e8 Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 4 Nov 2019 15:38:28 +0100 Subject: Migrations: Add a fixup migration for the muted_notifications This sets info->muted_notifications to an emtpy array if it is explicitly set to null before. This can happen when safe_jsonb_set coalesces to a jsonb null, which will make ecto not use the default value of [] anymore because it has been explicitly overwritten. --- .../20191104143558_fix_null_muted_notification_fields.exs | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 priv/repo/migrations/20191104143558_fix_null_muted_notification_fields.exs diff --git a/priv/repo/migrations/20191104143558_fix_null_muted_notification_fields.exs b/priv/repo/migrations/20191104143558_fix_null_muted_notification_fields.exs new file mode 100644 index 000000000..e17e75983 --- /dev/null +++ b/priv/repo/migrations/20191104143558_fix_null_muted_notification_fields.exs @@ -0,0 +1,7 @@ +defmodule Pleroma.Repo.Migrations.FixNullMutedNotificationFields do + use Ecto.Migration + + def change do + execute("update users set info = safe_jsonb_set(info, '{muted_notifications}', '[]'::jsonb, true) where local = true and info->'muted_notifications' = 'null'::jsonb") + end +end -- cgit v1.2.3 From 6a151e7c7f90b0aea71580e613be4ddf5a4809f5 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Sun, 3 Nov 2019 09:05:12 -0600 Subject: streamer: use direct object for filter checks when there is no valid child object in an activity We call Object.normalize/1 to get the child object for situations like Announce. However, the check is flawed and immediately fails if Object.normalize/1 fails. Instead, we should use the activity itself in those cases to allow activities which never have a child object to pass through the filter. Closes #1291 --- lib/pleroma/web/streamer/worker.ex | 2 +- test/web/streamer/streamer_test.exs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/streamer/worker.ex b/lib/pleroma/web/streamer/worker.ex index 0ea224874..da7a5a6f2 100644 --- a/lib/pleroma/web/streamer/worker.ex +++ b/lib/pleroma/web/streamer/worker.ex @@ -136,7 +136,7 @@ defp should_send?(%User{} = user, %Activity{} = item) do recipients = MapSet.new(item.recipients) domain_blocks = Pleroma.Web.ActivityPub.MRF.subdomains_regex(user.info.domain_blocks) - with parent when not is_nil(parent) <- Object.normalize(item), + with parent <- Object.normalize(item) || item, true <- Enum.all?([blocks, mutes, reblog_mutes], &(item.actor not in &1)), true <- Enum.all?([blocks, mutes], &(parent.data["actor"] not in &1)), true <- MapSet.disjoint?(recipients, recipient_blocks), diff --git a/test/web/streamer/streamer_test.exs b/test/web/streamer/streamer_test.exs index 313567bfd..601f6df49 100644 --- a/test/web/streamer/streamer_test.exs +++ b/test/web/streamer/streamer_test.exs @@ -110,6 +110,24 @@ test "it doesn't send notify to the 'user:notification' stream' when a domain is Streamer.stream("user:notification", notif) Task.await(task) end + + test "it sends follow activities to the 'user:notification' stream", %{ + user: user + } do + user2 = insert(:user) + task = Task.async(fn -> assert_receive {:text, _}, 4_000 end) + + Streamer.add_socket( + "user:notification", + %{transport_pid: task.pid, assigns: %{user: user}} + ) + + {:ok, _follower, _followed, _activity} = CommonAPI.follow(user2, user) + + # We don't directly pipe the notification to the streamer as it's already + # generated as a side effect of CommonAPI.follow(). + Task.await(task) + end end test "it sends to public" do -- cgit v1.2.3 From 4388255eed40c436d5931c3d0d070f3c1c9aab83 Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 4 Nov 2019 18:13:37 +0100 Subject: Migrations: Don't copy over mutes unless there actually are some. --- .../migrations/20190711042024_copy_muted_to_muted_notifications.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/priv/repo/migrations/20190711042024_copy_muted_to_muted_notifications.exs b/priv/repo/migrations/20190711042024_copy_muted_to_muted_notifications.exs index a3c5b52de..c0d6b3a87 100644 --- a/priv/repo/migrations/20190711042024_copy_muted_to_muted_notifications.exs +++ b/priv/repo/migrations/20190711042024_copy_muted_to_muted_notifications.exs @@ -3,6 +3,6 @@ defmodule Pleroma.Repo.Migrations.CopyMutedToMutedNotifications do alias Pleroma.User def change do - execute("update users set info = safe_jsonb_set(info, '{muted_notifications}', info->'mutes', true) where local = true") + execute("update users set info = safe_jsonb_set(info, '{muted_notifications}', info->'mutes', true) where local = true and info->'mutes' is not null") end end -- cgit v1.2.3 From b7de4ad0828078ed5aa03d243319855ce3eb95f8 Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 4 Nov 2019 17:31:08 +0000 Subject: Apply suggestion to CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 979a9ac52..4f681704c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [1.1.4] - 2019-11-01 ### Fixed - Added a migration that fills up empty user.info fields to prevent breakage after previous unsafe migrations. +- Failure to migrate from pre-1.0.0 versions +- Mastodon API: Notification stream not including follow notifications ## [1.1.3] - 2019-10-25 ### Fixed -- cgit v1.2.3