Merge branch 'refactor/user' into 'develop'
Simplify updating user's `info` See merge request pleroma/pleroma!1712
This commit is contained in:
commit
48a82c4609
13 changed files with 307 additions and 524 deletions
|
|
@ -77,12 +77,10 @@ defmodule Mix.Tasks.Pleroma.DatabaseTest do
|
|||
assert length(following) == 2
|
||||
assert info.follower_count == 0
|
||||
|
||||
info_cng = Ecto.Changeset.change(info, %{follower_count: 3})
|
||||
|
||||
{:ok, user} =
|
||||
user
|
||||
|> Ecto.Changeset.change(%{following: following ++ following})
|
||||
|> Ecto.Changeset.put_embed(:info, info_cng)
|
||||
|> User.change_info(&Ecto.Changeset.change(&1, %{follower_count: 3}))
|
||||
|> Repo.update()
|
||||
|
||||
assert length(user.following) == 4
|
||||
|
|
|
|||
|
|
@ -74,8 +74,8 @@ defmodule Pleroma.UserTest do
|
|||
CommonAPI.follow(follower, unlocked)
|
||||
CommonAPI.follow(follower, locked)
|
||||
|
||||
assert {:ok, []} = User.get_follow_requests(unlocked)
|
||||
assert {:ok, [activity]} = User.get_follow_requests(locked)
|
||||
assert [] = User.get_follow_requests(unlocked)
|
||||
assert [activity] = User.get_follow_requests(locked)
|
||||
|
||||
assert activity
|
||||
end
|
||||
|
|
@ -90,7 +90,7 @@ defmodule Pleroma.UserTest do
|
|||
CommonAPI.follow(accepted_follower, locked)
|
||||
User.follow(accepted_follower, locked)
|
||||
|
||||
assert {:ok, [activity]} = User.get_follow_requests(locked)
|
||||
assert [activity] = User.get_follow_requests(locked)
|
||||
assert activity
|
||||
end
|
||||
|
||||
|
|
@ -99,10 +99,10 @@ defmodule Pleroma.UserTest do
|
|||
follower = insert(:user)
|
||||
|
||||
CommonAPI.follow(follower, followed)
|
||||
assert {:ok, [_activity]} = User.get_follow_requests(followed)
|
||||
assert [_activity] = User.get_follow_requests(followed)
|
||||
|
||||
{:ok, _follower} = User.block(followed, follower)
|
||||
assert {:ok, []} = User.get_follow_requests(followed)
|
||||
assert [] = User.get_follow_requests(followed)
|
||||
end
|
||||
|
||||
test "follow_all follows mutliple users" do
|
||||
|
|
@ -560,7 +560,7 @@ defmodule Pleroma.UserTest do
|
|||
|
||||
test "it enforces the fqn format for nicknames" do
|
||||
cs = User.remote_user_creation(%{@valid_remote | nickname: "bla"})
|
||||
assert cs.changes.local == false
|
||||
assert Ecto.Changeset.get_field(cs, :local) == false
|
||||
assert cs.changes.avatar
|
||||
refute cs.valid?
|
||||
end
|
||||
|
|
@ -584,7 +584,7 @@ defmodule Pleroma.UserTest do
|
|||
{:ok, follower_one} = User.follow(follower_one, user)
|
||||
{:ok, follower_two} = User.follow(follower_two, user)
|
||||
|
||||
{:ok, res} = User.get_followers(user)
|
||||
res = User.get_followers(user)
|
||||
|
||||
assert Enum.member?(res, follower_one)
|
||||
assert Enum.member?(res, follower_two)
|
||||
|
|
@ -600,7 +600,7 @@ defmodule Pleroma.UserTest do
|
|||
{:ok, user} = User.follow(user, followed_one)
|
||||
{:ok, user} = User.follow(user, followed_two)
|
||||
|
||||
{:ok, res} = User.get_friends(user)
|
||||
res = User.get_friends(user)
|
||||
|
||||
followed_one = User.get_cached_by_ap_id(followed_one.ap_id)
|
||||
followed_two = User.get_cached_by_ap_id(followed_two.ap_id)
|
||||
|
|
@ -975,7 +975,7 @@ defmodule Pleroma.UserTest do
|
|||
info = User.get_cached_user_info(user2)
|
||||
|
||||
assert info.follower_count == 0
|
||||
assert {:ok, []} = User.get_followers(user2)
|
||||
assert [] = User.get_followers(user2)
|
||||
end
|
||||
|
||||
test "hide a user from friends" do
|
||||
|
|
@ -991,7 +991,7 @@ defmodule Pleroma.UserTest do
|
|||
|
||||
assert info.following_count == 0
|
||||
assert User.following_count(user2) == 0
|
||||
assert {:ok, []} = User.get_friends(user2)
|
||||
assert [] = User.get_friends(user2)
|
||||
end
|
||||
|
||||
test "hide a user's statuses from timelines and notifications" do
|
||||
|
|
@ -1034,7 +1034,7 @@ defmodule Pleroma.UserTest do
|
|||
test ".delete_user_activities deletes all create activities", %{user: user} do
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "2hu"})
|
||||
|
||||
{:ok, _} = User.delete_user_activities(user)
|
||||
User.delete_user_activities(user)
|
||||
|
||||
# TODO: Remove favorites, repeats, delete activities.
|
||||
refute Activity.get_by_id(activity.id)
|
||||
|
|
@ -1707,4 +1707,22 @@ defmodule Pleroma.UserTest do
|
|||
assert password_reset_pending
|
||||
end
|
||||
end
|
||||
|
||||
test "change_info/2" do
|
||||
user = insert(:user)
|
||||
assert user.info.hide_follows == false
|
||||
|
||||
changeset = User.change_info(user, &User.Info.profile_update(&1, %{hide_follows: true}))
|
||||
assert changeset.changes.info.changes.hide_follows == true
|
||||
end
|
||||
|
||||
test "update_info/2" do
|
||||
user = insert(:user)
|
||||
assert user.info.hide_follows == false
|
||||
|
||||
assert {:ok, _} = User.update_info(user, &User.Info.profile_update(&1, %{hide_follows: true}))
|
||||
|
||||
assert %{info: %{hide_follows: true}} = Repo.get(User, user.id)
|
||||
assert {:ok, %{info: %{hide_follows: true}}} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2613,14 +2613,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
{:ok, _} = CommonAPI.post(user, %{"status" => "cofe"})
|
||||
|
||||
# Stats should count users with missing or nil `info.deactivated` value
|
||||
user = User.get_cached_by_id(user.id)
|
||||
info_change = Changeset.change(user.info, %{deactivated: nil})
|
||||
|
||||
{:ok, _user} =
|
||||
user
|
||||
|> Changeset.change()
|
||||
|> Changeset.put_embed(:info, info_change)
|
||||
|> User.update_and_set_cache()
|
||||
user.id
|
||||
|> User.get_cached_by_id()
|
||||
|> User.update_info(&Changeset.change(&1, %{deactivated: nil}))
|
||||
|
||||
Pleroma.Stats.force_update()
|
||||
|
||||
|
|
@ -3953,13 +3950,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|
||||
describe "POST /api/v1/pleroma/accounts/confirmation_resend" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
info_change = User.Info.confirmation_changeset(user.info, need_confirmation: true)
|
||||
|
||||
{:ok, user} =
|
||||
user
|
||||
|> Changeset.change()
|
||||
|> Changeset.put_embed(:info, info_change)
|
||||
insert(:user)
|
||||
|> User.change_info(&User.Info.confirmation_changeset(&1, need_confirmation: true))
|
||||
|> Repo.update()
|
||||
|
||||
assert user.info.confirmation_pending
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.OAuth.Authorization
|
||||
alias Pleroma.Web.OAuth.OAuthController
|
||||
alias Pleroma.Web.OAuth.Token
|
||||
|
|
@ -775,15 +776,11 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
|
||||
test "rejects token exchange for valid credentials belonging to unconfirmed user and confirmation is required" do
|
||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||
|
||||
password = "testpassword"
|
||||
user = insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt(password))
|
||||
info_change = Pleroma.User.Info.confirmation_changeset(user.info, need_confirmation: true)
|
||||
|
||||
{:ok, user} =
|
||||
user
|
||||
|> Ecto.Changeset.change()
|
||||
|> Ecto.Changeset.put_embed(:info, info_change)
|
||||
insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt(password))
|
||||
|> User.change_info(&User.Info.confirmation_changeset(&1, need_confirmation: true))
|
||||
|> Repo.update()
|
||||
|
||||
refute Pleroma.User.auth_active?(user)
|
||||
|
|
|
|||
|
|
@ -50,20 +50,16 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
assert response(conn, 200)
|
||||
end) =~ "[error]"
|
||||
|
||||
# Set a wrong magic-key for a user so it has to refetch
|
||||
salmon_user = User.get_cached_by_ap_id("http://gs.example.org:4040/index.php/user/1")
|
||||
|
||||
# Wrong key
|
||||
info_cng =
|
||||
User.Info.remote_user_creation(salmon_user.info, %{
|
||||
magic_key:
|
||||
"RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwrong1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
|
||||
})
|
||||
info = %{
|
||||
magic_key:
|
||||
"RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwrong1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
|
||||
}
|
||||
|
||||
salmon_user
|
||||
|> Ecto.Changeset.change()
|
||||
|> Ecto.Changeset.put_embed(:info, info_cng)
|
||||
|> User.update_and_set_cache()
|
||||
# Set a wrong magic-key for a user so it has to refetch
|
||||
"http://gs.example.org:4040/index.php/user/1"
|
||||
|> User.get_cached_by_ap_id()
|
||||
|> User.update_info(&User.Info.remote_user_creation(&1, info))
|
||||
|
||||
assert capture_log(fn ->
|
||||
conn =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue