Don't allow empty feed URLs
This commit is contained in:
parent
b559bd9dc3
commit
9c1bbbbf23
|
@ -36,8 +36,13 @@ 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()
|
||||||
|
|
||||||
|
cond do
|
||||||
|
group != nil && group.user_id == user.id ->
|
||||||
|
if String.length(feed_url) > 0 do
|
||||||
changeset =
|
changeset =
|
||||||
Ecto.build_assoc(group, :feeds, %{
|
Ecto.build_assoc(group, :feeds, %{
|
||||||
feed_url: feed_url,
|
feed_url: feed_url,
|
||||||
|
@ -49,7 +54,20 @@ defmodule FrenzyWeb.FeedController do
|
||||||
|
|
||||||
{: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