forked from YokaiRick/akkoma
User deletion: Remove relationships.
This commit is contained in:
parent
a78ae2a685
commit
6df6ad0b42
2 changed files with 44 additions and 0 deletions
|
@ -339,4 +339,19 @@ def deactivate (%User{} = user) do
|
||||||
cs = User.info_changeset(user, %{info: new_info})
|
cs = User.info_changeset(user, %{info: new_info})
|
||||||
Repo.update(cs)
|
Repo.update(cs)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def delete (%User{} = user) do
|
||||||
|
{:ok, user} = User.deactivate(user)
|
||||||
|
|
||||||
|
# Remove all relationships
|
||||||
|
{:ok, followers } = User.get_followers(user)
|
||||||
|
followers
|
||||||
|
|> Enum.each(fn (follower) -> User.unfollow(follower, user) end)
|
||||||
|
|
||||||
|
{:ok, friends} = User.get_friends(user)
|
||||||
|
friends
|
||||||
|
|> Enum.each(fn (followed) -> User.unfollow(user, followed) end)
|
||||||
|
|
||||||
|
:ok
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -339,4 +339,33 @@ test ".deactivate deactivates a user" do
|
||||||
{:ok, user} = User.deactivate(user)
|
{:ok, user} = User.deactivate(user)
|
||||||
assert true == user.info["deactivated"]
|
assert true == user.info["deactivated"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test ".delete deactivates a user, all follow relationships and all create activities" do
|
||||||
|
user = insert(:user)
|
||||||
|
followed = insert(:user)
|
||||||
|
follower = insert(:user)
|
||||||
|
|
||||||
|
{:ok, user} = User.follow(user, followed)
|
||||||
|
{:ok, follower} = User.follow(follower, user)
|
||||||
|
|
||||||
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "2hu"})
|
||||||
|
{:ok, activity_two} = CommonAPI.post(follower, %{"status" => "3hu"})
|
||||||
|
|
||||||
|
{:ok, _, _} = CommonAPI.favorite(activity_two.id, user)
|
||||||
|
{:ok, _, _} = CommonAPI.favorite(activity.id, follower)
|
||||||
|
{:ok, _, _} = CommonAPI.repeat(activity.id, follower)
|
||||||
|
|
||||||
|
:ok = User.delete(user)
|
||||||
|
|
||||||
|
followed = Repo.get(User, followed.id)
|
||||||
|
follower = Repo.get(User, follower.id)
|
||||||
|
user = Repo.get(User, user.id)
|
||||||
|
|
||||||
|
assert user.info["deactivated"]
|
||||||
|
|
||||||
|
refute User.following?(user, followed)
|
||||||
|
refute User.following?(followed, follower)
|
||||||
|
|
||||||
|
# TODO: check for activities.
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue