Last active
January 17, 2018 20:29
-
-
Save thebrianemory/0ce111d78182bbbae1623c85d1b739bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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