Merge branch 'fix-tags' into 'develop'

Fix tagging problems for existing instances.

See merge request pleroma/pleroma!562
This commit is contained in:
lambda 2018-12-17 19:38:24 +00:00
commit c6d5f189d9
3 changed files with 20 additions and 3 deletions

View file

@ -13,7 +13,6 @@ cache:
key: ${CI_COMMIT_REF_SLUG} key: ${CI_COMMIT_REF_SLUG}
paths: paths:
- deps - deps
- _build
stages: stages:
- lint - lint
- test - test

View file

@ -838,7 +838,7 @@ defmodule Pleroma.User do
do: tag(User.get_by_nickname(nickname), tags) do: tag(User.get_by_nickname(nickname), tags)
def tag(%User{} = user, tags), def tag(%User{} = user, tags),
do: update_tags(user, Enum.uniq(user.tags ++ normalize_tags(tags))) do: update_tags(user, Enum.uniq((user.tags || []) ++ normalize_tags(tags)))
def untag(user_identifiers, tags) when is_list(user_identifiers) do def untag(user_identifiers, tags) when is_list(user_identifiers) do
Repo.transaction(fn -> Repo.transaction(fn ->
@ -849,7 +849,8 @@ defmodule Pleroma.User do
def untag(nickname, tags) when is_binary(nickname), def untag(nickname, tags) when is_binary(nickname),
do: untag(User.get_by_nickname(nickname), tags) do: untag(User.get_by_nickname(nickname), tags)
def untag(%User{} = user, tags), do: update_tags(user, user.tags -- normalize_tags(tags)) def untag(%User{} = user, tags),
do: update_tags(user, (user.tags || []) -- normalize_tags(tags))
defp update_tags(%User{} = user, new_tags) do defp update_tags(%User{} = user, new_tags) do
{:ok, updated_user} = {:ok, updated_user} =

View file

@ -11,6 +11,23 @@ defmodule Pleroma.UserTest do
:ok :ok
end end
describe "when tags are nil" do
test "tagging a user" do
user = insert(:user, %{tags: nil})
user = User.tag(user, ["cool", "dude"])
assert "cool" in user.tags
assert "dude" in user.tags
end
test "untagging a user" do
user = insert(:user, %{tags: nil})
user = User.untag(user, ["cool", "dude"])
assert user.tags == []
end
end
test "ap_id returns the activity pub id for the user" do test "ap_id returns the activity pub id for the user" do
user = UserBuilder.build() user = UserBuilder.build()