Skip to content

Instantly share code, notes, and snippets.

@thebrianemory
Last active January 17, 2018 20:29
Show Gist options
  • Save thebrianemory/0ce111d78182bbbae1623c85d1b739bf to your computer and use it in GitHub Desktop.
Save thebrianemory/0ce111d78182bbbae1623c85d1b739bf to your computer and use it in GitHub Desktop.
defmodule CatcastsWeb.VideoController do
use CatcastsWeb, :controller
alias Catcasts.Videos
alias Catcasts.Videos.{Video, YoutubeData}
plug :check_video_owner when action in [:delete]
... # Code removed for readability
defp check_video_owner(conn, _params) do
%{params: %{"id" => video_id}} = conn
if Catcasts.Repo.get(Video, video_id).user_id == conn.assigns.user.id do
conn
else
conn
|> put_flash(:error, "You cannot do that")
|> redirect(to: video_path(conn, :index))
|> halt()
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment