mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-23 08:36:29 +00:00
User: Don't allow local users in remote changesets
This commit is contained in:
parent
57d0379b89
commit
222312900e
2 changed files with 20 additions and 0 deletions
|
@ -472,7 +472,20 @@ defmodule Pleroma.User do
|
||||||
|> validate_format(:nickname, @email_regex)
|
|> validate_format(:nickname, @email_regex)
|
||||||
|> validate_length(:bio, max: bio_limit)
|
|> validate_length(:bio, max: bio_limit)
|
||||||
|> validate_length(:name, max: name_limit)
|
|> validate_length(:name, max: name_limit)
|
||||||
|
|> validate_inclusion(:local, [true])
|
||||||
|> validate_fields(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
|
end
|
||||||
|
|
||||||
def update_changeset(struct, params \\ %{}) do
|
def update_changeset(struct, params \\ %{}) do
|
||||||
|
|
|
@ -895,6 +895,13 @@ defmodule Pleroma.UserTest do
|
||||||
refute cs.valid?
|
refute cs.valid?
|
||||||
end)
|
end)
|
||||||
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
|
end
|
||||||
|
|
||||||
describe "followers and friends" do
|
describe "followers and friends" do
|
||||||
|
|
Loading…
Reference in a new issue