From: Ariadne Conill Date: Wed, 17 Jul 2019 17:12:42 +0000 (+0000) Subject: user: add is_internal_user? helper function X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=62e5ff624e1984b48eecaf2a6c14ad092013a13e;p=akkoma user: add is_internal_user? helper function --- 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