summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlain <lain@soykaf.club>2020-12-02 12:18:43 +0100
committerlain <lain@soykaf.club>2020-12-22 21:07:56 +0100
commita32e13e6c48493eae1d28200c49bfe113cc15758 (patch)
treed6786565dfd9d9e4be75e3dbc9943031d1832ecf
parentc10783087f9ed18ccd2cb42070c13c918ee12652 (diff)
User: Don't allow local users in remote changesets
-rw-r--r--lib/pleroma/user.ex13
-rw-r--r--test/pleroma/user_test.exs7
2 files changed, 20 insertions, 0 deletions
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index b56a5dfe2..f6ab4f666 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -461,7 +461,20 @@ defmodule Pleroma.User do
|> validate_format(:nickname, @email_regex)
|> validate_length(:bio, max: bio_limit)
|> validate_length(:name, max: name_limit)
+ |> validate_inclusion(:local, [true])
|> validate_fields(true)
+ |> validate_non_local()
+ end
+
+ defp validate_non_local(cng) do
+ local? = get_field(cng, :local)
+
+ if local? do
+ cng
+ |> add_error(:local, "User is local, can't update with this changeset.")
+ else
+ cng
+ end
end
def update_changeset(struct, params \\ %{}) do
diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs
index d8ac652af..52dcea0b3 100644
--- a/test/pleroma/user_test.exs
+++ b/test/pleroma/user_test.exs
@@ -877,6 +877,13 @@ defmodule Pleroma.UserTest do
refute cs.valid?
end)
end
+
+ test "it is invalid given a local user" do
+ user = insert(:user)
+ cs = User.remote_user_changeset(user, %{name: "tom from myspace"})
+
+ refute cs.valid?
+ end
end
describe "followers and friends" do