Don't allow empty feed URLs
This commit is contained in:
parent
b559bd9dc3
commit
9c1bbbbf23
|
@ -36,20 +36,38 @@ defmodule FrenzyWeb.FeedController do
|
||||||
end
|
end
|
||||||
|
|
||||||
def create(conn, %{"feed" => %{"group_id" => group_id, "feed_url" => feed_url}}) do
|
def create(conn, %{"feed" => %{"group_id" => group_id, "feed_url" => feed_url}}) do
|
||||||
|
user = conn.assigns[:user]
|
||||||
group = Repo.get(Group, group_id)
|
group = Repo.get(Group, group_id)
|
||||||
|
feed_url = feed_url |> String.trim()
|
||||||
|
|
||||||
changeset =
|
cond do
|
||||||
Ecto.build_assoc(group, :feeds, %{
|
group != nil && group.user_id == user.id ->
|
||||||
feed_url: feed_url,
|
if String.length(feed_url) > 0 do
|
||||||
filter: %Filter{
|
changeset =
|
||||||
mode: "reject",
|
Ecto.build_assoc(group, :feeds, %{
|
||||||
score: 0
|
feed_url: feed_url,
|
||||||
}
|
filter: %Filter{
|
||||||
})
|
mode: "reject",
|
||||||
|
score: 0
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
{:ok, feed} = Repo.insert(changeset)
|
{:ok, feed} = Repo.insert(changeset)
|
||||||
|
|
||||||
redirect(conn, to: Routes.group_path(Endpoint, :show, group_id))
|
conn
|
||||||
|
|> put_flash(:info, "Feed created")
|
||||||
|
|> redirect(to: Routes.group_path(Endpoint, :show, group_id))
|
||||||
|
else
|
||||||
|
conn
|
||||||
|
|> put_flash(:error, "Feed URL must not be empty")
|
||||||
|
|> redirect(to: Routes.group_path(Endpoint, :show, group_id))
|
||||||
|
end
|
||||||
|
|
||||||
|
true ->
|
||||||
|
conn
|
||||||
|
|> put_flash(:error, "Invalid group")
|
||||||
|
|> redirect(to: Routes.group_path(Endpoint, :index))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit(conn, _params) do
|
def edit(conn, _params) do
|
||||||
|
|
Loading…
Reference in New Issue