[#1304] Moved all non-mutes / non-blocks fields from User.Info to User. WIP.

This commit is contained in:
Ivan Tashkinov 2019-10-16 21:59:21 +03:00
commit 10ff01acd9
88 changed files with 1069 additions and 1170 deletions

View file

@ -683,7 +683,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
test "it returns returns a uri if the user has 'hide_followers' set", %{conn: conn} do
user = insert(:user)
user_two = insert(:user, %{info: %{hide_followers: true}})
user_two = insert(:user, hide_followers: true)
User.follow(user, user_two)
result =
@ -696,7 +696,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
test "it returns a 403 error on pages, if the user has 'hide_followers' set and the request is not authenticated",
%{conn: conn} do
user = insert(:user, %{info: %{hide_followers: true}})
user = insert(:user, hide_followers: true)
result =
conn
@ -708,7 +708,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
test "it renders the page, if the user has 'hide_followers' set and the request is authenticated with the same user",
%{conn: conn} do
user = insert(:user, %{info: %{hide_followers: true}})
user = insert(:user, hide_followers: true)
other_user = insert(:user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
@ -764,7 +764,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
end
test "it returns a uri if the user has 'hide_follows' set", %{conn: conn} do
user = insert(:user, %{info: %{hide_follows: true}})
user = insert(:user, hide_follows: true)
user_two = insert(:user)
User.follow(user, user_two)
@ -778,7 +778,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
test "it returns a 403 error on pages, if the user has 'hide_follows' set and the request is not authenticated",
%{conn: conn} do
user = insert(:user, %{info: %{hide_follows: true}})
user = insert(:user, hide_follows: true)
result =
conn
@ -790,7 +790,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
test "it renders the page, if the user has 'hide_follows' set and the request is authenticated with the same user",
%{conn: conn} do
user = insert(:user, %{info: %{hide_follows: true}})
user = insert(:user, hide_follows: true)
other_user = insert(:user)
{:ok, user, _other_user, _activity} = CommonAPI.follow(user, other_user)

View file

@ -93,8 +93,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
{:ok, user} = ActivityPub.make_user_from_ap_id(user_id)
assert user.ap_id == user_id
assert user.nickname == "admin@mastodon.example.org"
assert user.info.source_data
assert user.info.ap_enabled
assert user.source_data
assert user.ap_enabled
assert user.follower_address == "http://mastodon.example.org/users/admin/followers"
end
@ -279,7 +279,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert activity.actor == user.ap_id
user = User.get_cached_by_id(user.id)
assert user.info.note_count == 0
assert user.note_count == 0
end
test "can be fetched into a timeline" do
@ -342,7 +342,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
})
user = User.get_cached_by_id(user.id)
assert user.info.note_count == 2
assert user.note_count == 2
end
test "increases replies count" do
@ -1009,7 +1009,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
end
test "decrements user note count only for public activities" do
user = insert(:user, info: %{note_count: 10})
user = insert(:user, note_count: 10)
{:ok, a1} =
CommonAPI.post(User.get_cached_by_id(user.id), %{
@ -1041,7 +1041,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
{:ok, _} = Object.normalize(a4) |> ActivityPub.delete()
user = User.get_cached_by_id(user.id)
assert user.info.note_count == 10
assert user.note_count == 10
end
test "it creates a delete activity and checks that it is also sent to users mentioned by the deleted object" do
@ -1305,9 +1305,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
following_address: "http://localhost:4001/users/masto_closed/following"
)
{:ok, info} = ActivityPub.fetch_follow_information_for_user(user)
assert info.hide_followers == true
assert info.hide_follows == false
{:ok, follow_info} = ActivityPub.fetch_follow_information_for_user(user)
assert follow_info.hide_followers == true
assert follow_info.hide_follows == false
end
test "detects hidden follows" do
@ -1328,9 +1328,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
following_address: "http://localhost:4001/users/masto_closed/following"
)
{:ok, info} = ActivityPub.fetch_follow_information_for_user(user)
assert info.hide_followers == false
assert info.hide_follows == true
{:ok, follow_info} = ActivityPub.fetch_follow_information_for_user(user)
assert follow_info.hide_followers == false
assert follow_info.hide_follows == true
end
end
end

View file

@ -35,7 +35,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
test "it allows posts without links" do
user = insert(:user)
assert user.info.note_count == 0
assert user.note_count == 0
message =
@linkless_message
@ -47,7 +47,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
test "it disallows posts with links" do
user = insert(:user)
assert user.info.note_count == 0
assert user.note_count == 0
message =
@linkful_message
@ -59,9 +59,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
describe "with old user" do
test "it allows posts without links" do
user = insert(:user, info: %{note_count: 1})
user = insert(:user, note_count: 1)
assert user.info.note_count == 1
assert user.note_count == 1
message =
@linkless_message
@ -71,9 +71,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
end
test "it allows posts with links" do
user = insert(:user, info: %{note_count: 1})
user = insert(:user, note_count: 1)
assert user.info.note_count == 1
assert user.note_count == 1
message =
@linkful_message
@ -85,9 +85,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
describe "with followed new user" do
test "it allows posts without links" do
user = insert(:user, info: %{follower_count: 1})
user = insert(:user, follower_count: 1)
assert user.info.follower_count == 1
assert user.follower_count == 1
message =
@linkless_message
@ -97,9 +97,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
end
test "it allows posts with links" do
user = insert(:user, info: %{follower_count: 1})
user = insert(:user, follower_count: 1)
assert user.info.follower_count == 1
assert user.follower_count == 1
message =
@linkful_message
@ -133,7 +133,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
describe "with contentless-objects" do
test "it does not reject them or error out" do
user = insert(:user, info: %{note_count: 1})
user = insert(:user, note_count: 1)
message =
@response_message

View file

@ -27,7 +27,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
test "it returns sharedInbox for messages involving as:Public in to" do
user =
insert(:user, %{
info: %{source_data: %{"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}}}
source_data: %{"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}}
})
activity = %Activity{
@ -40,7 +40,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
test "it returns sharedInbox for messages involving as:Public in cc" do
user =
insert(:user, %{
info: %{source_data: %{"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}}}
source_data: %{"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}}
})
activity = %Activity{
@ -53,7 +53,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
test "it returns sharedInbox for messages involving multiple recipients in to" do
user =
insert(:user, %{
info: %{source_data: %{"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}}}
source_data: %{"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}}
})
user_two = insert(:user)
@ -69,7 +69,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
test "it returns sharedInbox for messages involving multiple recipients in cc" do
user =
insert(:user, %{
info: %{source_data: %{"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}}}
source_data: %{"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}}
})
user_two = insert(:user)
@ -84,14 +84,12 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
test "it returns sharedInbox for messages involving multiple recipients in total" do
user =
insert(:user, %{
info: %{
source_data: %{
"inbox" => "http://example.com/personal-inbox",
"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}
}
insert(:user,
source_data: %{
"inbox" => "http://example.com/personal-inbox",
"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}
}
})
)
user_two = insert(:user)
@ -104,14 +102,12 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
test "it returns inbox for messages involving single recipients in total" do
user =
insert(:user, %{
info: %{
source_data: %{
"inbox" => "http://example.com/personal-inbox",
"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}
}
insert(:user,
source_data: %{
"inbox" => "http://example.com/personal-inbox",
"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}
}
})
)
activity = %Activity{
data: %{"to" => [user.ap_id], "cc" => []}
@ -241,10 +237,8 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
follower =
insert(:user,
local: false,
info: %{
ap_enabled: true,
source_data: %{"inbox" => "https://domain.com/users/nick1/inbox"}
}
source_data: %{"inbox" => "https://domain.com/users/nick1/inbox"},
ap_enabled: true
)
actor = insert(:user, follower_address: follower.ap_id)
@ -278,19 +272,15 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
fetcher =
insert(:user,
local: false,
info: %{
ap_enabled: true,
source_data: %{"inbox" => "https://domain.com/users/nick1/inbox"}
}
source_data: %{"inbox" => "https://domain.com/users/nick1/inbox"},
ap_enabled: true
)
another_fetcher =
insert(:user,
local: false,
info: %{
ap_enabled: true,
source_data: %{"inbox" => "https://domain2.com/users/nick1/inbox"}
}
source_data: %{"inbox" => "https://domain2.com/users/nick1/inbox"},
ap_enabled: true
)
actor = insert(:user)

View file

@ -58,7 +58,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
end
test "with locked accounts, it does not create a follow or an accept" do
user = insert(:user, info: %{locked: true})
user = insert(:user, locked: true)
data =
File.read!("test/fixtures/mastodon-follow-activity.json")

View file

@ -148,7 +148,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
user = User.get_cached_by_ap_id(object_data["actor"])
assert user.info.note_count == 1
assert user.note_count == 1
end
test "it works for incoming notices with hashtags" do
@ -585,7 +585,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
}
]
assert user.info.banner["url"] == [
assert user.banner["url"] == [
%{
"href" =>
"https://cd.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
@ -604,7 +604,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
user = User.get_cached_by_ap_id(activity.actor)
assert User.Info.fields(user.info) == [
assert User.fields(user) == [
%{"name" => "foo", "value" => "bar"},
%{"name" => "foo1", "value" => "bar1"}
]
@ -625,7 +625,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
user = User.get_cached_by_ap_id(user.ap_id)
assert User.Info.fields(user.info) == [
assert User.fields(user) == [
%{"name" => "foo", "value" => "updated"},
%{"name" => "foo1", "value" => "updated"}
]
@ -643,7 +643,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
user = User.get_cached_by_ap_id(user.ap_id)
assert User.Info.fields(user.info) == [
assert User.fields(user) == [
%{"name" => "foo", "value" => "updated"},
%{"name" => "foo1", "value" => "updated"}
]
@ -654,7 +654,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
user = User.get_cached_by_ap_id(user.ap_id)
assert User.Info.fields(user.info) == []
assert User.fields(user) == []
end
test "it works for incoming update activities which lock the account" do
@ -677,7 +677,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(update_data)
user = User.get_cached_by_ap_id(data["actor"])
assert user.info.locked == true
assert user.locked == true
end
test "it works for incoming deletes" do
@ -918,7 +918,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
test "it works for incoming accepts which were orphaned" do
follower = insert(:user)
followed = insert(:user, %{info: %User.Info{locked: true}})
followed = insert(:user, locked: true)
{:ok, follow_activity} = ActivityPub.follow(follower, followed)
@ -940,7 +940,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
test "it works for incoming accepts which are referenced by IRI only" do
follower = insert(:user)
followed = insert(:user, %{info: %User.Info{locked: true}})
followed = insert(:user, locked: true)
{:ok, follow_activity} = ActivityPub.follow(follower, followed)
@ -960,7 +960,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
test "it fails for incoming accepts which cannot be correlated" do
follower = insert(:user)
followed = insert(:user, %{info: %User.Info{locked: true}})
followed = insert(:user, locked: true)
accept_data =
File.read!("test/fixtures/mastodon-accept-activity.json")
@ -979,7 +979,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
test "it fails for incoming rejects which cannot be correlated" do
follower = insert(:user)
followed = insert(:user, %{info: %User.Info{locked: true}})
followed = insert(:user, locked: true)
accept_data =
File.read!("test/fixtures/mastodon-reject-activity.json")
@ -998,7 +998,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
test "it works for incoming rejects which are orphaned" do
follower = insert(:user)
followed = insert(:user, %{info: %User.Info{locked: true}})
followed = insert(:user, locked: true)
{:ok, follower} = User.follow(follower, followed)
{:ok, _follow_activity} = ActivityPub.follow(follower, followed)
@ -1024,7 +1024,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
test "it works for incoming rejects which are referenced by IRI only" do
follower = insert(:user)
followed = insert(:user, %{info: %User.Info{locked: true}})
followed = insert(:user, locked: true)
{:ok, follower} = User.follow(follower, followed)
{:ok, follow_activity} = ActivityPub.follow(follower, followed)
@ -1326,18 +1326,18 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert "http://localhost:4001/users/rye@niu.moe/followers" in activity.recipients
user = User.get_cached_by_id(user.id)
assert user.info.note_count == 1
assert user.note_count == 1
{:ok, user} = Transmogrifier.upgrade_user_from_ap_id("https://niu.moe/users/rye")
ObanHelpers.perform_all()
assert user.info.ap_enabled
assert user.info.note_count == 1
assert user.ap_enabled
assert user.note_count == 1
assert user.follower_address == "https://niu.moe/users/rye/followers"
assert user.following_address == "https://niu.moe/users/rye/following"
user = User.get_cached_by_id(user.id)
assert user.info.note_count == 1
assert user.note_count == 1
activity = Activity.get_by_id(activity.id)
assert user.follower_address in activity.recipients
@ -1358,7 +1358,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
"https://cdn.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
}
]
} = user.info.banner
} = user.banner
refute "..." in activity.recipients

View file

@ -297,7 +297,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
describe "update_follow_state_for_all/2" do
test "updates the state of all Follow activities with the same actor and object" do
user = insert(:user, info: %{locked: true})
user = insert(:user, locked: true)
follower = insert(:user)
{:ok, follow_activity} = ActivityPub.follow(follower, user)
@ -321,7 +321,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
describe "update_follow_state/2" do
test "updates the state of the given follow activity" do
user = insert(:user, info: %{locked: true})
user = insert(:user, locked: true)
follower = insert(:user)
{:ok, follow_activity} = ActivityPub.follow(follower, user)

View file

@ -29,7 +29,7 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
{:ok, user} =
insert(:user)
|> User.upgrade_changeset(%{info: %{fields: fields}})
|> User.upgrade_changeset(%{fields: fields})
|> User.update_and_set_cache()
assert %{
@ -38,7 +38,7 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
end
test "Renders with emoji tags" do
user = insert(:user, %{info: %{emoji: [%{"bib" => "/test"}]}})
user = insert(:user, emoji: [%{"bib" => "/test"}])
assert %{
"tag" => [
@ -64,9 +64,7 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
user =
insert(:user,
avatar: %{"url" => [%{"href" => "https://someurl"}]},
info: %{
banner: %{"url" => [%{"href" => "https://somebanner"}]}
}
banner: %{"url" => [%{"href" => "https://somebanner"}]}
)
{:ok, user} = User.ensure_keys_present(user)
@ -121,8 +119,7 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
other_user = insert(:user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user})
info = Map.merge(user.info, %{hide_followers_count: true, hide_followers: true})
user = Map.put(user, :info, info)
user = Map.merge(user, %{hide_followers_count: true, hide_followers: true})
assert %{"totalItems" => 0} = UserView.render("followers.json", %{user: user})
end
@ -131,8 +128,7 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
other_user = insert(:user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user})
info = Map.merge(user.info, %{hide_followers_count: false, hide_followers: true})
user = Map.put(user, :info, info)
user = Map.merge(user, %{hide_followers_count: false, hide_followers: true})
assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user})
end
end
@ -143,8 +139,7 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
other_user = insert(:user)
{:ok, user, _other_user, _activity} = CommonAPI.follow(user, other_user)
assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user})
info = Map.merge(user.info, %{hide_follows_count: true, hide_follows: true})
user = Map.put(user, :info, info)
user = Map.merge(user, %{hide_follows_count: true, hide_follows: true})
assert %{"totalItems" => 0} = UserView.render("following.json", %{user: user})
end
@ -153,8 +148,7 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
other_user = insert(:user)
{:ok, user, _other_user, _activity} = CommonAPI.follow(user, other_user)
assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user})
info = Map.merge(user.info, %{hide_follows_count: false, hide_follows: true})
user = Map.put(user, :info, info)
user = Map.merge(user, %{hide_follows_count: false, hide_follows: true})
assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user})
end
end