From f9e8a94106a715afae351b08399e2e35da9de07b Mon Sep 17 00:00:00 2001 From: Guy Sheffer Date: Wed, 22 Jul 2020 17:26:36 +0300 Subject: [PATCH 1/6] Add multiarch support to docker container, fixes https://git.pleroma.social/pleroma/pleroma-docker-compose/-/issues/2 --- .gitlab-ci.yml | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c9ab84892..816c05b1e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -285,10 +285,13 @@ docker: - export CI_VCS_REF=$CI_COMMIT_SHORT_SHA allow_failure: true script: - - docker build --cache-from $IMAGE_TAG_SLUG --build-arg VCS_REF=$CI_VCS_REF --build-arg BUILD_DATE=$CI_JOB_TIMESTAMP -t $IMAGE_TAG -t $IMAGE_TAG_SLUG -t $IMAGE_TAG_LATEST . - - docker push $IMAGE_TAG - - docker push $IMAGE_TAG_SLUG - - docker push $IMAGE_TAG_LATEST + - mkdir -p /root/.docker/cli-plugins + - wget https://github.com/docker/buildx/releases/download/v0.4.1/buildx-v0.4.1.linux-amd64 -O ~/.docker/cli-plugins/docker-buildx + - chmod +x ~/.docker/cli-plugins/docker-buildx + - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes + - docker buildx create --name mbuilder --driver docker-container --use + - docker buildx inspect --bootstrap + - docker buildx build --platform linux/amd64,linux/arm/v7 --push --cache-from $IMAGE_TAG_SLUG --build-arg VCS_REF=$CI_VCS_REF --build-arg BUILD_DATE=$CI_JOB_TIMESTAMP -t $IMAGE_TAG -t $IMAGE_TAG_SLUG -t $IMAGE_TAG_LATEST . tags: - dind only: @@ -303,10 +306,13 @@ docker-stable: before_script: *before-docker allow_failure: true script: - - docker build --cache-from $IMAGE_TAG_SLUG --build-arg VCS_REF=$CI_VCS_REF --build-arg BUILD_DATE=$CI_JOB_TIMESTAMP -t $IMAGE_TAG -t $IMAGE_TAG_SLUG -t $IMAGE_TAG_LATEST_STABLE . - - docker push $IMAGE_TAG - - docker push $IMAGE_TAG_SLUG - - docker push $IMAGE_TAG_LATEST_STABLE + - mkdir -p /root/.docker/cli-plugins + - wget https://github.com/docker/buildx/releases/download/v0.4.1/buildx-v0.4.1.linux-amd64 -O ~/.docker/cli-plugins/docker-buildx + - chmod +x ~/.docker/cli-plugins/docker-buildx + - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes + - docker buildx create --name mbuilder --driver docker-container --use + - docker buildx inspect --bootstrap + - docker buildx build --platform linux/amd64,linux/arm/v7 --push --cache-from $IMAGE_TAG_SLUG --build-arg VCS_REF=$CI_VCS_REF --build-arg BUILD_DATE=$CI_JOB_TIMESTAMP -t $IMAGE_TAG -t $IMAGE_TAG_SLUG -t $IMAGE_TAG_LATEST_STABLE . tags: - dind only: @@ -321,9 +327,14 @@ docker-release: before_script: *before-docker allow_failure: true script: - - docker build --cache-from $IMAGE_TAG_SLUG --build-arg VCS_REF=$CI_VCS_REF --build-arg BUILD_DATE=$CI_JOB_TIMESTAMP -t $IMAGE_TAG -t $IMAGE_TAG_SLUG . - - docker push $IMAGE_TAG - - docker push $IMAGE_TAG_SLUG + script: + - mkdir -p /root/.docker/cli-plugins + - wget https://github.com/docker/buildx/releases/download/v0.4.1/buildx-v0.4.1.linux-amd64 -O ~/.docker/cli-plugins/docker-buildx + - chmod +x ~/.docker/cli-plugins/docker-buildx + - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes + - docker buildx create --name mbuilder --driver docker-container --use + - docker buildx inspect --bootstrap + - docker buildx build --platform linux/amd64,linux/arm/v7 --push --cache-from $IMAGE_TAG_SLUG --build-arg VCS_REF=$CI_VCS_REF --build-arg BUILD_DATE=$CI_JOB_TIMESTAMP -t $IMAGE_TAG -t $IMAGE_TAG_SLUG . tags: - dind only: From 0c4e855663fec52f8f98fe8fa8597e5268502c97 Mon Sep 17 00:00:00 2001 From: Guy Sheffer Date: Thu, 6 Aug 2020 09:50:10 +0300 Subject: [PATCH 2/6] Add checksum to docker buildx, add aarch/arm64 to the list of platforms --- .gitlab-ci.yml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 816c05b1e..5e6245459 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -278,6 +278,8 @@ docker: IMAGE_TAG_SLUG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG IMAGE_TAG_LATEST: $CI_REGISTRY_IMAGE:latest IMAGE_TAG_LATEST_STABLE: $CI_REGISTRY_IMAGE:latest-stable + DOCKER_BUILDX_URL: https://github.com/docker/buildx/releases/download/v0.4.1/buildx-v0.4.1.linux-amd64 + DOCKER_BUILDX_HASH: 71a7d01439aa8c165a25b59c44d3f016fddbd98b before_script: &before-docker - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - docker pull $IMAGE_TAG_SLUG || true @@ -286,12 +288,13 @@ docker: allow_failure: true script: - mkdir -p /root/.docker/cli-plugins - - wget https://github.com/docker/buildx/releases/download/v0.4.1/buildx-v0.4.1.linux-amd64 -O ~/.docker/cli-plugins/docker-buildx + - wget "${DOCKER_BUILDX_URL}" -O ~/.docker/cli-plugins/docker-buildx + - echo "${DOCKER_BUILDX_HASH} /root/.docker/cli-plugins/docker-buildx" | sha1sum -c - chmod +x ~/.docker/cli-plugins/docker-buildx - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes - docker buildx create --name mbuilder --driver docker-container --use - docker buildx inspect --bootstrap - - docker buildx build --platform linux/amd64,linux/arm/v7 --push --cache-from $IMAGE_TAG_SLUG --build-arg VCS_REF=$CI_VCS_REF --build-arg BUILD_DATE=$CI_JOB_TIMESTAMP -t $IMAGE_TAG -t $IMAGE_TAG_SLUG -t $IMAGE_TAG_LATEST . + - docker buildx build --platform linux/amd64,linux/arm/v7,linux/arm64/v8 --push --cache-from $IMAGE_TAG_SLUG --build-arg VCS_REF=$CI_VCS_REF --build-arg BUILD_DATE=$CI_JOB_TIMESTAMP -t $IMAGE_TAG -t $IMAGE_TAG_SLUG -t $IMAGE_TAG_LATEST . tags: - dind only: @@ -307,12 +310,13 @@ docker-stable: allow_failure: true script: - mkdir -p /root/.docker/cli-plugins - - wget https://github.com/docker/buildx/releases/download/v0.4.1/buildx-v0.4.1.linux-amd64 -O ~/.docker/cli-plugins/docker-buildx + - wget "${DOCKER_BUILDX_URL}" -O ~/.docker/cli-plugins/docker-buildx + - echo "${DOCKER_BUILDX_HASH} /root/.docker/cli-plugins/docker-buildx" | sha1sum -c - chmod +x ~/.docker/cli-plugins/docker-buildx - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes - docker buildx create --name mbuilder --driver docker-container --use - docker buildx inspect --bootstrap - - docker buildx build --platform linux/amd64,linux/arm/v7 --push --cache-from $IMAGE_TAG_SLUG --build-arg VCS_REF=$CI_VCS_REF --build-arg BUILD_DATE=$CI_JOB_TIMESTAMP -t $IMAGE_TAG -t $IMAGE_TAG_SLUG -t $IMAGE_TAG_LATEST_STABLE . + - docker buildx build --platform linux/amd64,linux/arm/v7,linux/arm64/v8 --push --cache-from $IMAGE_TAG_SLUG --build-arg VCS_REF=$CI_VCS_REF --build-arg BUILD_DATE=$CI_JOB_TIMESTAMP -t $IMAGE_TAG -t $IMAGE_TAG_SLUG -t $IMAGE_TAG_LATEST_STABLE . tags: - dind only: @@ -329,12 +333,13 @@ docker-release: script: script: - mkdir -p /root/.docker/cli-plugins - - wget https://github.com/docker/buildx/releases/download/v0.4.1/buildx-v0.4.1.linux-amd64 -O ~/.docker/cli-plugins/docker-buildx + - wget "${DOCKER_BUILDX_URL}" -O ~/.docker/cli-plugins/docker-buildx + - echo "${DOCKER_BUILDX_HASH} /root/.docker/cli-plugins/docker-buildx" | sha1sum -c - chmod +x ~/.docker/cli-plugins/docker-buildx - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes - docker buildx create --name mbuilder --driver docker-container --use - docker buildx inspect --bootstrap - - docker buildx build --platform linux/amd64,linux/arm/v7 --push --cache-from $IMAGE_TAG_SLUG --build-arg VCS_REF=$CI_VCS_REF --build-arg BUILD_DATE=$CI_JOB_TIMESTAMP -t $IMAGE_TAG -t $IMAGE_TAG_SLUG . + - docker buildx build --platform linux/amd64,linux/arm/v7,linux/arm64/v8 --push --cache-from $IMAGE_TAG_SLUG --build-arg VCS_REF=$CI_VCS_REF --build-arg BUILD_DATE=$CI_JOB_TIMESTAMP -t $IMAGE_TAG -t $IMAGE_TAG_SLUG . tags: - dind only: From 0865f36965f1583085af3a424dbbc89de724fd33 Mon Sep 17 00:00:00 2001 From: Sergey Suprunenko Date: Sat, 15 Aug 2020 15:27:41 +0200 Subject: [PATCH 3/6] Mark notifications about statuses from muted users as read automatically --- lib/pleroma/notification.ex | 6 ++++++ test/notification_test.exs | 6 +++++- test/web/mastodon_api/views/notification_view_test.exs | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index 0b171563b..b4719896e 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -441,6 +441,7 @@ def create_notification(%Activity{} = activity, %User{} = user, do_send \\ true) |> Multi.insert(:notification, %Notification{ user_id: user.id, activity: activity, + seen: mark_as_read?(activity, user), type: type_from_activity(activity) }) |> Marker.multi_set_last_read_id(user, "notifications") @@ -634,6 +635,11 @@ def skip?(:filtered, activity, user) do def skip?(_, _, _), do: false + def mark_as_read?(activity, target_user) do + user = Activity.user_actor(activity) + User.mutes_user?(target_user, user) + end + def for_user_and_activity(user, activity) do from(n in __MODULE__, where: n.user_id == ^user.id, diff --git a/test/notification_test.exs b/test/notification_test.exs index 8243cfd34..93f4761da 100644 --- a/test/notification_test.exs +++ b/test/notification_test.exs @@ -217,7 +217,10 @@ test "it creates a notification for the user if the user mutes the activity auth muter = Repo.get(User, muter.id) {:ok, activity} = CommonAPI.post(muted, %{status: "Hi @#{muter.nickname}"}) - assert Notification.create_notification(activity, muter) + notification = Notification.create_notification(activity, muter) + + assert notification.id + assert notification.seen end test "notification created if user is muted without notifications" do @@ -1012,6 +1015,7 @@ test "it returns notifications for muted user without notifications", %{user: us [notification] = Notification.for_user(user) assert notification.activity.object + assert notification.seen end test "it doesn't return notifications for muted user with notifications", %{user: user} do diff --git a/test/web/mastodon_api/views/notification_view_test.exs b/test/web/mastodon_api/views/notification_view_test.exs index 8e0e58538..2f6a808f1 100644 --- a/test/web/mastodon_api/views/notification_view_test.exs +++ b/test/web/mastodon_api/views/notification_view_test.exs @@ -219,7 +219,7 @@ test "muted notification" do expected = %{ id: to_string(notification.id), - pleroma: %{is_seen: false, is_muted: true}, + pleroma: %{is_seen: true, is_muted: true}, type: "favourite", account: AccountView.render("show.json", %{user: another_user, for: user}), status: StatusView.render("show.json", %{activity: create_activity, for: user}), From 25c69e271a3ea6687805e0bd0d4b902cda06e364 Mon Sep 17 00:00:00 2001 From: Sergey Suprunenko Date: Mon, 17 Aug 2020 00:07:23 +0200 Subject: [PATCH 4/6] Make notifications about new statuses from muted threads read --- CHANGELOG.md | 1 + lib/pleroma/notification.ex | 3 ++- lib/pleroma/web/common_api/common_api.ex | 2 +- test/notification_test.exs | 7 ++++++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8e80eb3c..c462833d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). contents has been renamed to `hide_notification_contents` - Mastodon API: Added `pleroma.metadata.post_formats` to /api/v1/instance - Mastodon API (legacy): Allow query parameters for `/api/v1/domain_blocks`, e.g. `/api/v1/domain_blocks?domain=badposters.zone` +- Mastodon API: Make notifications about statuses from muted users and threads read automatically - Pleroma API: `/api/pleroma/captcha` responses now include `seconds_valid` with an integer value. diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index b4719896e..c1825f810 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -15,6 +15,7 @@ defmodule Pleroma.Notification do alias Pleroma.Repo alias Pleroma.ThreadMute alias Pleroma.User + alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI.Utils alias Pleroma.Web.Push alias Pleroma.Web.Streamer @@ -637,7 +638,7 @@ def skip?(_, _, _), do: false def mark_as_read?(activity, target_user) do user = Activity.user_actor(activity) - User.mutes_user?(target_user, user) + User.mutes_user?(target_user, user) || CommonAPI.thread_muted?(target_user, activity) end def for_user_and_activity(user, activity) do diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index a8141b28f..5ad2b91c2 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -465,7 +465,7 @@ def remove_mute(user, activity) do end def thread_muted?(%User{id: user_id}, %{data: %{"context" => context}}) - when is_binary("context") do + when is_binary(context) do ThreadMute.exists?(user_id, context) end diff --git a/test/notification_test.exs b/test/notification_test.exs index 93f4761da..a09b08675 100644 --- a/test/notification_test.exs +++ b/test/notification_test.exs @@ -246,7 +246,10 @@ test "it creates a notification for an activity from a muted thread" do in_reply_to_status_id: activity.id }) - assert Notification.create_notification(activity, muter) + notification = Notification.create_notification(activity, muter) + + assert notification.id + assert notification.seen end test "it disables notifications from strangers" do @@ -320,6 +323,7 @@ test "it creates notifications if content matches with a not irreversible filter {:ok, [notification]} = Notification.create_notifications(status) assert notification + refute notification.seen end test "it creates notifications when someone likes user's status with a filtered word" do @@ -333,6 +337,7 @@ test "it creates notifications when someone likes user's status with a filtered {:ok, [notification]} = Notification.create_notifications(activity_two) assert notification + refute notification.seen end end From 112bec52252108de57e708ed47cf43abd9f3b2f1 Mon Sep 17 00:00:00 2001 From: lain Date: Tue, 25 Aug 2020 17:35:59 +0200 Subject: [PATCH 5/6] Webfinger: Handle bogus ids better. --- lib/pleroma/web/web_finger/web_finger.ex | 24 ++++++++++++++---------- test/web/web_finger/web_finger_test.exs | 5 +++++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex index 71ccf251a..c4051e63e 100644 --- a/lib/pleroma/web/web_finger/web_finger.ex +++ b/lib/pleroma/web/web_finger/web_finger.ex @@ -149,6 +149,18 @@ def find_lrdd_template(domain) do end end + defp get_address_from_domain(domain, encoded_account) when is_binary(domain) do + case find_lrdd_template(domain) do + {:ok, template} -> + String.replace(template, "{uri}", encoded_account) + + _ -> + "https://#{domain}/.well-known/webfinger?resource=#{encoded_account}" + end + end + + defp get_address_from_domain(_, _), do: nil + @spec finger(String.t()) :: {:ok, map()} | {:error, any()} def finger(account) do account = String.trim_leading(account, "@") @@ -163,16 +175,8 @@ def finger(account) do encoded_account = URI.encode("acct:#{account}") - address = - case find_lrdd_template(domain) do - {:ok, template} -> - String.replace(template, "{uri}", encoded_account) - - _ -> - "https://#{domain}/.well-known/webfinger?resource=#{encoded_account}" - end - - with response <- + with address when is_binary(address) <- get_address_from_domain(domain, encoded_account), + response <- HTTP.get( address, [{"accept", "application/xrd+xml,application/jrd+json"}] diff --git a/test/web/web_finger/web_finger_test.exs b/test/web/web_finger/web_finger_test.exs index f4884e0a2..96fc0bbaa 100644 --- a/test/web/web_finger/web_finger_test.exs +++ b/test/web/web_finger/web_finger_test.exs @@ -40,6 +40,11 @@ test "works for ap_ids" do end describe "fingering" do + test "returns error for nonsensical input" do + assert {:error, _} = WebFinger.finger("bliblablu") + assert {:error, _} = WebFinger.finger("pleroma.social") + end + test "returns error when fails parse xml or json" do user = "invalid_content@social.heldscal.la" assert {:error, %Jason.DecodeError{}} = WebFinger.finger(user) From dcd06488e02408f7e9b459d1da4be2669db0969d Mon Sep 17 00:00:00 2001 From: rinpatch Date: Wed, 26 Aug 2020 07:08:02 +0300 Subject: [PATCH 6/6] release MR template: add a note about merging stable changes back to develop --- .gitlab/merge_request_templates/Release.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab/merge_request_templates/Release.md b/.gitlab/merge_request_templates/Release.md index 237f74e00..b2c772696 100644 --- a/.gitlab/merge_request_templates/Release.md +++ b/.gitlab/merge_request_templates/Release.md @@ -3,3 +3,4 @@ * [ ] Compile a changelog * [ ] Create an MR with an announcement to pleroma.social * [ ] Tag the release +* [ ] Merge `stable` into `develop` (in case the fixes are already in develop, use `git merge -s ours --no-commit` and manually merge the changelogs)