mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-30 14:57:59 +01:00
load topic correctly
This commit is contained in:
parent
68472cf412
commit
6a741d1b2c
1 changed files with 10 additions and 2 deletions
|
@ -6,9 +6,17 @@ defmodule PhilomenaWeb.TopicController do
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
plug :load_and_authorize_resource, model: Forum, id_name: "forum_id", id_field: "short_name", persisted: true
|
plug :load_and_authorize_resource, model: Forum, id_name: "forum_id", id_field: "short_name", persisted: true
|
||||||
plug :load_and_authorize_resource, model: Topic, id_name: "id", id_field: "slug", preload: :user
|
|
||||||
|
|
||||||
def show(conn, %{"id" => _id}) do
|
def show(conn, %{"id" => slug}) do
|
||||||
|
forum = conn.assigns.forum
|
||||||
|
topic =
|
||||||
|
Topic
|
||||||
|
|> where(forum_id: ^forum.id, slug: ^slug, hidden_from_users: false)
|
||||||
|
|> preload(:user)
|
||||||
|
|> Repo.one()
|
||||||
|
|
||||||
|
conn = conn |> assign(:topic, topic)
|
||||||
|
|
||||||
posts =
|
posts =
|
||||||
Post
|
Post
|
||||||
|> where(topic_id: ^conn.assigns.topic.id)
|
|> where(topic_id: ^conn.assigns.topic.id)
|
||||||
|
|
Loading…
Reference in a new issue