mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-22 22:49:25 +00:00
Merge branch 'revert-4d3655c4' into 'develop'
Revert "Merge branch 'spc-fix-3' into 'develop'" See merge request pleroma/pleroma!745
This commit is contained in:
commit
bd89cdbe31
|
@ -1,113 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Object
|
||||
import Ecto.Query
|
||||
|
||||
defmodule Pleroma.SpcFixes do
|
||||
def upgrade_users do
|
||||
query =
|
||||
from(u in User,
|
||||
where: fragment("? like ?", u.ap_id, "https://shitposter.club/user/%")
|
||||
)
|
||||
|
||||
{:ok, file} = File.read("lib/pleroma/spc_fixes/users_conversion.txt")
|
||||
|
||||
# Mapping of old ap_id to new ap_id and vice reversa
|
||||
mapping =
|
||||
file
|
||||
|> String.trim()
|
||||
|> String.split("\n")
|
||||
|> Enum.map(fn line ->
|
||||
line
|
||||
|> String.split("\t")
|
||||
end)
|
||||
|> Enum.reduce(%{}, fn [_id, old_ap_id, new_ap_id], acc ->
|
||||
acc
|
||||
|> Map.put(String.trim(old_ap_id), String.trim(new_ap_id))
|
||||
|> Map.put(String.trim(new_ap_id), String.trim(old_ap_id))
|
||||
end)
|
||||
|
||||
# First, refetch all the old users.
|
||||
_old_users =
|
||||
query
|
||||
|> Repo.all()
|
||||
|> Enum.each(fn user ->
|
||||
with ap_id when is_binary(ap_id) <- mapping[user.ap_id] do
|
||||
# This fetches and updates the user.
|
||||
User.get_or_fetch_by_ap_id(ap_id)
|
||||
end
|
||||
end)
|
||||
|
||||
# Now, fix follow relationships.
|
||||
query =
|
||||
from(u in User,
|
||||
where: fragment("? like ?", u.ap_id, "https://shitposter.club/users/%")
|
||||
)
|
||||
|
||||
query
|
||||
|> Repo.all()
|
||||
|> Enum.each(fn user ->
|
||||
old_follower_address = User.ap_followers(user)
|
||||
|
||||
# Fix users
|
||||
query =
|
||||
from(u in User,
|
||||
where: ^old_follower_address in u.following,
|
||||
update: [
|
||||
push: [following: ^user.follower_address]
|
||||
]
|
||||
)
|
||||
|
||||
Repo.update_all(query, [])
|
||||
|
||||
# Fix activities
|
||||
query =
|
||||
from(a in Activity,
|
||||
where: fragment("?->>'actor' = ?", a.data, ^mapping[user.ap_id]),
|
||||
update: [
|
||||
set: [
|
||||
data:
|
||||
fragment(
|
||||
"jsonb_set(jsonb_set(?, '{actor}', ?), '{to}', (?->'to')::jsonb || ?)",
|
||||
a.data,
|
||||
^user.ap_id,
|
||||
a.data,
|
||||
^[user.follower_address]
|
||||
),
|
||||
actor: ^user.ap_id
|
||||
],
|
||||
push: [
|
||||
recipients: ^user.follower_address
|
||||
]
|
||||
]
|
||||
)
|
||||
|
||||
Repo.update_all(query, [])
|
||||
|
||||
# Fix objects
|
||||
query =
|
||||
from(a in Object,
|
||||
where: fragment("?->>'actor' = ?", a.data, ^mapping[user.ap_id]),
|
||||
update: [
|
||||
set: [
|
||||
data:
|
||||
fragment(
|
||||
"jsonb_set(jsonb_set(?, '{actor}', ?), '{to}', (?->'to')::jsonb || ?)",
|
||||
a.data,
|
||||
^user.ap_id,
|
||||
a.data,
|
||||
^[user.follower_address]
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
|
||||
Repo.update_all(query, [])
|
||||
end)
|
||||
end
|
||||
end
|
File diff suppressed because it is too large
Load diff
|
@ -1,10 +0,0 @@
|
|||
defmodule Pleroma.Repo.Migrations.FixSPCUsers do
|
||||
use Ecto.Migration
|
||||
|
||||
def up do
|
||||
Pleroma.SpcFixes.upgrade_users()
|
||||
end
|
||||
|
||||
def down do
|
||||
end
|
||||
end
|
1
test/fixtures/zep.json
vendored
1
test/fixtures/zep.json
vendored
|
@ -1 +0,0 @@
|
|||
{"url":"https://shitposter.club/users/zep","type":"Person","tag":[],"summary":"The Zeptar Show on anonradio.net","publicKey":{"publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsdkm3pQxYTW7rVVUQBJ0\nc+J7pUI623gohi2fwM05ZenYVysRIw0Mm6GYvDsCO6DHywi97pG4EBABEQNyagLS\njIDTrLR1GU0K4dnPgaZ7fIkXvMN+d2NNe0LoIw0wX23sw+L+D+U5l0AJ+3LqDC9s\nwucLz4uYokcrl8yxGFYHWjpRYqy/WVuk8986Hm1Mov4j8AWWV5VLl1yYcbQthSuw\nDXL5yMqwiLPn+Vhc4Pb216IhwIl+k9/tfdsnyAlCiasvUQ8Cigde0AJC0sqnUQhy\nJ4gSftvyW5ejYYebNWg09Afjq3I8k0gj1fGks0pY9IJr2a2H+eqCA//YI8z1XHvE\nlwIDAQAB\n-----END PUBLIC KEY-----\n\n","owner":"https://shitposter.club/users/zep","id":"https://shitposter.club/users/zep#main-key"},"preferredUsername":"zep","outbox":"https://shitposter.club/users/zep/outbox","name":"DJ Zep","manuallyApprovesFollowers":false,"inbox":"https://shitposter.club/users/zep/inbox","image":{"url":"https://shitposter.club/media/13946026-15ba-40e1-9cad-ba3a7aeb47e1/13946026-15ba-40e1-9cad-ba3a7aeb47e1.jpeg","type":"Image"},"id":"https://shitposter.club/users/zep","icon":{"url":"https://shitposter.club/media/83650c2f-7f31-98f5-acee-69a486c94173/83650c2f-7f31-98f5-acee-69a486c94173.jpeg","type":"Image"},"following":"https://shitposter.club/users/zep/following","followers":"https://shitposter.club/users/zep/followers","endpoints":{"sharedInbox":"https://shitposter.club/inbox"},"@context":["https://www.w3.org/ns/activitystreams","https://shitposter.club/schemas/litepub-0.1.jsonld"]}
|
|
@ -1,72 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.SpcFixesTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.SpcFixes
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Object
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
test "resets the ap_id and follower_address of old spc users" do
|
||||
Tesla.Mock.mock(fn
|
||||
%{url: "https://shitposter.club/users/zep"} ->
|
||||
%Tesla.Env{status: 200, body: File.read!("test/fixtures/zep.json")}
|
||||
|
||||
%{url: nil} ->
|
||||
nil
|
||||
end)
|
||||
|
||||
user =
|
||||
insert(:user, %{
|
||||
local: false,
|
||||
ap_id: "https://shitposter.club/user/4962",
|
||||
follower_address: User.ap_followers(%User{nickname: "zep@shitposter.club"}),
|
||||
info: %{topic: "ignore"},
|
||||
nickname: "zep@shitposter.club"
|
||||
})
|
||||
|
||||
other_user = insert(:user)
|
||||
{:ok, other_user} = User.follow(other_user, user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "blabla"})
|
||||
{:ok, _other_activity} = CommonAPI.post(other_user, %{"status" => "blabla"})
|
||||
|
||||
assert User.following?(other_user, user)
|
||||
assert [activity] == ActivityPub.fetch_activities(other_user.following)
|
||||
|
||||
SpcFixes.upgrade_users()
|
||||
|
||||
user = Pleroma.Repo.get(User, user.id)
|
||||
other_user = Pleroma.Repo.get(User, other_user.id)
|
||||
|
||||
assert user.ap_id == "https://shitposter.club/users/zep"
|
||||
assert user.follower_address == "https://shitposter.club/users/zep/followers"
|
||||
|
||||
aid = activity.id
|
||||
# Activites and following are correctly stitched.
|
||||
assert User.following?(other_user, user)
|
||||
assert [%{id: ^aid}] = ActivityPub.fetch_activities(other_user.following)
|
||||
|
||||
third_user = insert(:user)
|
||||
{:ok, third_user} = User.follow(third_user, user)
|
||||
assert [%{id: ^aid}] = ActivityPub.fetch_activities(third_user.following)
|
||||
|
||||
activity = Repo.get(Activity, aid)
|
||||
|
||||
assert activity.data["actor"] == user.ap_id
|
||||
assert user.follower_address in activity.recipients
|
||||
assert user.follower_address in activity.data["to"]
|
||||
|
||||
object = Object.get_by_ap_id(activity.data["object"]["id"])
|
||||
|
||||
assert object.data["actor"] == user.ap_id
|
||||
assert user.follower_address in object.data["to"]
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue