Don't allow empty feed URLs

This commit is contained in:
Shadowfacts 2019-08-31 15:09:40 -04:00
parent b559bd9dc3
commit 9c1bbbbf23
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 28 additions and 10 deletions

View File

@ -36,8 +36,13 @@ defmodule FrenzyWeb.FeedController do
end
def create(conn, %{"feed" => %{"group_id" => group_id, "feed_url" => feed_url}}) do
user = conn.assigns[:user]
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 =
Ecto.build_assoc(group, :feeds, %{
feed_url: feed_url,
@ -49,7 +54,20 @@ defmodule FrenzyWeb.FeedController do
{: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
def edit(conn, _params) do