forked from AkkomaGang/akkoma
user: add is_internal_user? helper function
This commit is contained in:
parent
0a6f6e1b5b
commit
62e5ff624e
2 changed files with 21 additions and 0 deletions
|
@ -1410,4 +1410,8 @@ defp put_password_hash(
|
||||||
end
|
end
|
||||||
|
|
||||||
defp put_password_hash(changeset), do: changeset
|
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
|
end
|
||||||
|
|
|
@ -1310,4 +1310,21 @@ test "without args", %{user: user} do
|
||||||
assert following == 0
|
assert following == 0
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue