1
0
Fork 1
mirror of https://akkoma.dev/AkkomaGang/akkoma.git synced 2024-11-18 02:49:18 +00:00

Add validation in Pleroma.List.create/2

This commit is contained in:
Egor Kislitsyn 2019-08-26 18:59:57 +07:00
parent 6dc24422dc
commit 3b1b631c2a
2 changed files with 18 additions and 7 deletions

View file

@ -109,15 +109,19 @@ def rename(%Pleroma.List{} = list, title) do
end end
def create(title, %User{} = creator) do def create(title, %User{} = creator) do
list = %Pleroma.List{user_id: creator.id, title: title} changeset = title_changeset(%Pleroma.List{user_id: creator.id}, %{title: title})
Repo.transaction(fn -> if changeset.valid? do
list = Repo.insert!(list) Repo.transaction(fn ->
list = Repo.insert!(changeset)
list list
|> change(ap_id: "#{creator.ap_id}/lists/#{list.id}") |> change(ap_id: "#{creator.ap_id}/lists/#{list.id}")
|> Repo.update!() |> Repo.update!()
end) end)
else
{:error, changeset}
end
end end
def follow(%Pleroma.List{following: following} = list, %User{} = followed) do def follow(%Pleroma.List{following: following} = list, %User{} = followed) do

View file

@ -15,6 +15,13 @@ test "creating a list" do
assert title == "title" assert title == "title"
end end
test "validates title" do
user = insert(:user)
assert {:error, changeset} = Pleroma.List.create("", user)
assert changeset.errors == [title: {"can't be blank", [validation: :required]}]
end
test "getting a list not belonging to the user" do test "getting a list not belonging to the user" do
user = insert(:user) user = insert(:user)
other_user = insert(:user) other_user = insert(:user)