fix(pastes): attempt getting a non-split version of the paste id
Signed-off-by: Amogh Lele <amolele@gmail.com>
This commit is contained in:
parent
94451e37d8
commit
4fcf5489da
@ -16,7 +16,13 @@ defmodule KetbinWeb.PageController do
|
||||
[head | tail] = String.split(id, ".")
|
||||
|
||||
# fetch paste from db
|
||||
paste = Pastes.get_paste!(head)
|
||||
paste =
|
||||
try do
|
||||
Pastes.get_paste!(head)
|
||||
rescue
|
||||
Ecto.NoResultsError ->
|
||||
Pastes.get_paste!(id)
|
||||
end
|
||||
|
||||
# paste is a url, redirect
|
||||
# regular paste, show content
|
||||
|
@ -98,7 +98,15 @@ defmodule KetbinWeb.UserAuth do
|
||||
|
||||
def owns_paste(%{params: %{"id" => id}, assigns: %{current_user: user}} = conn, _params) do
|
||||
[head | _tail] = String.split(id, ".")
|
||||
paste = Pastes.get_paste!(head)
|
||||
|
||||
paste =
|
||||
try do
|
||||
Pastes.get_paste!(head)
|
||||
rescue
|
||||
Ecto.NoResultsError ->
|
||||
Pastes.get_paste!(id)
|
||||
end
|
||||
|
||||
assign(conn, :show_edit, (user && user.id == paste.belongs_to) || false)
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user