This commit is contained in:
byte[] 2019-10-03 19:58:54 -04:00
parent 1349f41f99
commit 86ffbfdb5b
9 changed files with 41 additions and 20 deletions

View file

@ -25,6 +25,9 @@ config :bcrypt_elixir,
config :elastix,
json_codec: Jason
config :canary,
repo: Philomena.Repo
# Configures the endpoint
config :philomena, PhilomenaWeb.Endpoint,
url: [host: "localhost"],

View file

@ -8,7 +8,7 @@ defmodule Philomena.Images.Elasticsearch do
}
},
mappings: %{
_doc: %{
image: %{
_all: %{enabled: false},
dynamic: false,
properties: %{
@ -76,6 +76,10 @@ defmodule Philomena.Images.Elasticsearch do
}
end
# preload([
# :user, :deleter, :gallery_interactions, :upvoters, :downvoters, :favers,
# :hiders, tags: [:aliases, :aliased_tag]
# ])
def as_json(image) do
%{
id: image.id,

View file

@ -35,7 +35,7 @@ defmodule Philomena.Tags do
** (Ecto.NoResultsError)
"""
def get_tag!(id), do: Repo.get!(Tag, id)
def get_tag!(slug), do: Repo.get_by!(Tag, slug: slug)
@doc """
Creates a tag.

View file

@ -12,8 +12,8 @@ defimpl Canada.Can, for: [Atom, Philomena.Users.User] do
when action in [:new, :create, :index],
do: true
def can?(_user, :read, %Image{hidden_from_users: true}), do: false
def can?(_user, :read, %Image{hidden_from_users: false}), do: true
def can?(_user, :show, %Image{hidden_from_users: true}), do: false
def can?(_user, :show, %Image{hidden_from_users: false}), do: true
# Otherwise...
def can?(_user, _action, _model), do: false

View file

@ -23,6 +23,7 @@ defmodule PhilomenaWeb do
import Plug.Conn
import PhilomenaWeb.Gettext
import Canary.Plugs
alias PhilomenaWeb.Router.Helpers, as: Routes
alias PhilomenaWeb.Plugs.ImageFilter
end

View file

@ -1,10 +1,11 @@
defmodule PhilomenaWeb.ImageController do
use PhilomenaWeb, :controller
alias Philomena.{Images, Images.Image}
alias Philomena.{Images.Image}
import Ecto.Query
plug ImageFilter
plug :load_and_authorize_resource, model: Image, only: :show, preload: :tags
def index(conn, _params) do
query = conn.assigns.compiled_filter
@ -21,8 +22,7 @@ defmodule PhilomenaWeb.ImageController do
render(conn, "index.html", images: images)
end
def show(conn, %{"id" => id}) do
image = Images.get_image!(id)
render(conn, "show.html", image: image)
def show(conn, %{"id" => _id}) do
render(conn, "show.html", image: conn.assigns.image)
end
end

View file

@ -1,15 +1,35 @@
defmodule PhilomenaWeb.TagController do
use PhilomenaWeb, :controller
alias Philomena.Tags
alias Philomena.{Images.Image, Tags}
import Ecto.Query
plug ImageFilter
def index(conn, _params) do
tags = Tags.list_tags()
render(conn, "index.html", tags: tags)
end
def show(conn, %{"id" => id}) do
tag = Tags.get_tag!(id)
render(conn, "show.html", tag: tag)
def show(conn, %{"id" => slug}) do
tag = Tags.get_tag!(slug)
query = conn.assigns.compiled_filter
images =
Image.search_records(
%{
query: %{
bool: %{
must_not: query,
must: %{term: %{"namespaced_tags.name": tag.name}}
}
},
sort: %{created_at: :desc}
},
Image |> preload(:tags)
)
render(conn, "show.html", tag: tag, images: images)
end
end

View file

@ -1,8 +0,0 @@
<h1>Show Tag</h1>
<ul>
</ul>
<span><%= link "Edit", to: Routes.tag_path(@conn, :edit, @tag) %></span>
<span><%= link "Back", to: Routes.tag_path(@conn, :index) %></span>

View file

@ -0,0 +1 @@
= render PhilomenaWeb.ImageView, "index.html", images: @images