From 62e5ff624e1984b48eecaf2a6c14ad092013a13e Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Wed, 17 Jul 2019 17:12:42 +0000 Subject: [PATCH] user: add is_internal_user? helper function --- lib/pleroma/user.ex | 4 ++++ test/user_test.exs | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 463bb9ad4..c91fbb68a 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -1410,4 +1410,8 @@ defmodule Pleroma.User do end defp put_password_hash(changeset), do: changeset + + def is_internal_user?(%User{nickname: nil}), do: true + def is_internal_user?(%User{local: true, nickname: "internal." <> _}), do: true + def is_internal_user?(_), do: false end diff --git a/test/user_test.exs b/test/user_test.exs index 264b7a40e..908f72a0e 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -1310,4 +1310,21 @@ defmodule Pleroma.UserTest do assert following == 0 end end + + describe "is_internal_user?/1" do + test "non-internal user returns false" do + user = insert(:user) + refute User.is_internal_user?(user) + end + + test "user with no nickname returns true" do + user = insert(:user, %{nickname: nil}) + assert User.is_internal_user?(user) + end + + test "user with internal-prefixed nickname returns true" do + user = insert(:user, %{nickname: "internal.test"}) + assert User.is_internal_user?(user) + end + end end -- 2.45.2