From e4763cd459d36b2fcd22e2e4abd3a2a326a21f5f Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 17 Dec 2018 20:12:01 +0100 Subject: [PATCH 1/2] Fix tagging problems for existing instances. --- lib/pleroma/user.ex | 5 +++-- test/user_test.exs | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 49928bc13..3ad1ab87a 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -838,7 +838,7 @@ defmodule Pleroma.User do do: tag(User.get_by_nickname(nickname), 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 Repo.transaction(fn -> @@ -849,7 +849,8 @@ defmodule Pleroma.User do def untag(nickname, tags) when is_binary(nickname), 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 {:ok, updated_user} = diff --git a/test/user_test.exs b/test/user_test.exs index 9baa5ef24..1e73770df 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -11,6 +11,23 @@ defmodule Pleroma.UserTest do :ok 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 user = UserBuilder.build() From 0f67c1d487e65c851bafbf53e9ca744db9d84def Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 17 Dec 2018 20:26:48 +0100 Subject: [PATCH 2/2] don't re-use build --- .gitlab-ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7c240d9f1..8ea652086 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -13,7 +13,6 @@ cache: key: ${CI_COMMIT_REF_SLUG} paths: - deps - - _build stages: - lint - test