consistensize plug naming scheme

This commit is contained in:
byte[] 2019-11-17 13:18:21 -05:00
parent f9bdda08a7
commit 06875bc11d
27 changed files with 48 additions and 49 deletions

View file

@ -122,7 +122,7 @@ defmodule Philomena.Images do
alias Philomena.Images.Subscription alias Philomena.Images.Subscription
def subscribed?(image, nil), do: false def subscribed?(_image, nil), do: false
def subscribed?(image, user) do def subscribed?(image, user) do
Subscription Subscription
|> where(image_id: ^image.id, user_id: ^user.id) |> where(image_id: ^image.id, user_id: ^user.id)

View file

@ -104,7 +104,7 @@ defmodule Philomena.Topics do
alias Philomena.Topics.Subscription alias Philomena.Topics.Subscription
def subscribed?(topic, nil), do: false def subscribed?(_topic, nil), do: false
def subscribed?(topic, user) do def subscribed?(topic, user) do
Subscription Subscription
|> where(topic_id: ^topic.id, user_id: ^user.id) |> where(topic_id: ^topic.id, user_id: ^user.id)

View file

@ -25,7 +25,6 @@ defmodule PhilomenaWeb do
import PhilomenaWeb.Gettext import PhilomenaWeb.Gettext
import Canary.Plugs import Canary.Plugs
alias PhilomenaWeb.Router.Helpers, as: Routes alias PhilomenaWeb.Router.Helpers, as: Routes
alias PhilomenaWeb.Plugs.RequireUser
end end
end end

View file

@ -6,7 +6,7 @@ defmodule PhilomenaWeb.ConversationController do
alias Philomena.Repo alias Philomena.Repo
import Ecto.Query import Ecto.Query
plug PhilomenaWeb.Plugs.FilterBannedUsers when action in [:new, :create] plug PhilomenaWeb.FilterBannedUsersPlug when action in [:new, :create]
plug :load_and_authorize_resource, model: Conversation, id_field: "slug", only: :show, preload: [:to, :from] plug :load_and_authorize_resource, model: Conversation, id_field: "slug", only: :show, preload: [:to, :from]
def index(conn, _params) do def index(conn, _params) do

View file

@ -6,7 +6,7 @@ defmodule PhilomenaWeb.FilterController do
import Ecto.Query import Ecto.Query
plug :load_and_authorize_resource, model: Filter, except: [:index], preload: :user plug :load_and_authorize_resource, model: Filter, except: [:index], preload: :user
plug RequireUser when action not in [:index, :show] plug PhilomenaWeb.RequireUserPlug when action not in [:index, :show]
def index(conn, _params) do def index(conn, _params) do
user = conn.assigns.current_user user = conn.assigns.current_user

View file

@ -7,14 +7,14 @@ defmodule PhilomenaWeb.Image.CommentController do
alias Philomena.Repo alias Philomena.Repo
import Ecto.Query import Ecto.Query
plug PhilomenaWeb.Plugs.CanaryMapPlug, create: :show, edit: :show, update: :show plug PhilomenaWeb.CanaryMapPlug, create: :show, edit: :show, update: :show
plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true
# Undo the previous private parameter screwery # Undo the previous private parameter screwery
plug PhilomenaWeb.Plugs.CanaryMapPlug, create: :create, edit: :edit, update: :update plug PhilomenaWeb.CanaryMapPlug, create: :create, edit: :edit, update: :update
plug :load_and_authorize_resource, model: Comment, only: [:show], preload: [:image, user: [awards: :badge]] plug :load_and_authorize_resource, model: Comment, only: [:show], preload: [:image, user: [awards: :badge]]
plug PhilomenaWeb.Plugs.FilterBannedUsers when action in [:create, :edit, :update] plug PhilomenaWeb.FilterBannedUsersPlug when action in [:create, :edit, :update]
def index(conn, %{"comment_id" => comment_id}) do def index(conn, %{"comment_id" => comment_id}) do
comment = comment =

View file

@ -6,8 +6,8 @@ defmodule PhilomenaWeb.Image.FaveController do
alias Philomena.Repo alias Philomena.Repo
alias Ecto.Multi alias Ecto.Multi
plug PhilomenaWeb.Plugs.FilterBannedUsers plug PhilomenaWeb.FilterBannedUsersPlug
plug PhilomenaWeb.Plugs.CanaryMapPlug, create: :vote, delete: :vote plug PhilomenaWeb.CanaryMapPlug, create: :vote, delete: :vote
plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true
def create(conn, _params) do def create(conn, _params) do

View file

@ -6,8 +6,8 @@ defmodule PhilomenaWeb.Image.HideController do
alias Philomena.Repo alias Philomena.Repo
alias Ecto.Multi alias Ecto.Multi
plug PhilomenaWeb.Plugs.FilterBannedUsers plug PhilomenaWeb.FilterBannedUsersPlug
plug PhilomenaWeb.Plugs.CanaryMapPlug, create: :vote, delete: :vote plug PhilomenaWeb.CanaryMapPlug, create: :vote, delete: :vote
plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true
def create(conn, _params) do def create(conn, _params) do

View file

@ -4,7 +4,7 @@ defmodule PhilomenaWeb.Image.SubscriptionController do
alias Philomena.Images.Image alias Philomena.Images.Image
alias Philomena.Images alias Philomena.Images
plug PhilomenaWeb.Plugs.CanaryMapPlug, create: :show, delete: :show plug PhilomenaWeb.CanaryMapPlug, create: :show, delete: :show
plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true
def create(conn, _params) do def create(conn, _params) do

View file

@ -6,8 +6,8 @@ defmodule PhilomenaWeb.Image.VoteController do
alias Philomena.Repo alias Philomena.Repo
alias Ecto.Multi alias Ecto.Multi
plug PhilomenaWeb.Plugs.FilterBannedUsers plug PhilomenaWeb.FilterBannedUsersPlug
plug PhilomenaWeb.Plugs.CanaryMapPlug, create: :vote, delete: :vote plug PhilomenaWeb.CanaryMapPlug, create: :vote, delete: :vote
plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true
def create(conn, params) do def create(conn, params) do

View file

@ -39,7 +39,7 @@ defmodule PhilomenaWeb.Registration.TotpController do
{:ok, user} -> {:ok, user} ->
conn conn
|> PhilomenaWeb.Plugs.TotpPlug.update_valid_totp_at_for_session(user) |> PhilomenaWeb.TotpPlug.update_valid_totp_at_for_session(user)
|> put_flash(:totp_backup_codes, backup_codes) |> put_flash(:totp_backup_codes, backup_codes)
|> redirect(to: Routes.registration_totp_path(conn, :edit)) |> redirect(to: Routes.registration_totp_path(conn, :edit))
end end

View file

@ -27,7 +27,7 @@ defmodule PhilomenaWeb.Session.TotpController do
{:ok, user} -> {:ok, user} ->
conn conn
|> PhilomenaWeb.Plugs.TotpPlug.update_valid_totp_at_for_session(user) |> PhilomenaWeb.TotpPlug.update_valid_totp_at_for_session(user)
|> redirect(to: "/") |> redirect(to: "/")
end end
end end

View file

@ -5,7 +5,7 @@ defmodule PhilomenaWeb.Topic.SubscriptionController do
alias Philomena.Repo alias Philomena.Repo
import Ecto.Query import Ecto.Query
plug PhilomenaWeb.Plugs.CanaryMapPlug, create: :show, delete: :show plug PhilomenaWeb.CanaryMapPlug, create: :show, delete: :show
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
def create(conn, %{"topic_id" => slug}) do def create(conn, %{"topic_id" => slug}) do
@ -36,10 +36,10 @@ defmodule PhilomenaWeb.Topic.SubscriptionController do
defp load_topic(conn, slug) do defp load_topic(conn, slug) do
forum = conn.assigns.forum forum = conn.assigns.forum
topic =
Topic Topic
|> where(forum_id: ^forum.id, slug: ^slug, hidden_from_users: false) |> where(forum_id: ^forum.id, slug: ^slug, hidden_from_users: false)
|> preload(:user) |> preload(:user)
|> Repo.one() |> Repo.one()
end end
end end

View file

@ -49,8 +49,8 @@ defmodule PhilomenaWeb.Endpoint do
plug Pow.Plug.Session, otp_app: :philomena plug Pow.Plug.Session, otp_app: :philomena
plug PowPersistentSession.Plug.Cookie, otp_app: :philomena plug PowPersistentSession.Plug.Cookie, otp_app: :philomena
plug PhilomenaWeb.Plugs.ReloadUser plug PhilomenaWeb.ReloadUserPlug
plug PhilomenaWeb.Plugs.RenderTime plug PhilomenaWeb.RenderTimePlug
plug PhilomenaWeb.Plugs.Referrer plug PhilomenaWeb.ReferrerPlug
plug PhilomenaWeb.Router plug PhilomenaWeb.Router
end end

View file

@ -1,4 +1,4 @@
defmodule PhilomenaWeb.Plugs.CanaryMapPlug do defmodule PhilomenaWeb.CanaryMapPlug do
import Plug.Conn import Plug.Conn
def init(opts), do: opts def init(opts), do: opts

View file

@ -1,10 +1,10 @@
defmodule PhilomenaWeb.Plugs.CurrentBan do defmodule PhilomenaWeb.CurrentBanPlug do
@moduledoc """ @moduledoc """
This plug loads the ban for the current user. This plug loads the ban for the current user.
## Example ## Example
plug PhilomenaWeb.Plugs.CurrentBan plug PhilomenaWeb.CurrentBanPlug
""" """
alias Philomena.Bans alias Philomena.Bans
alias Plug.Conn alias Plug.Conn

View file

@ -1,4 +1,4 @@
defmodule PhilomenaWeb.Plugs.CurrentFilter do defmodule PhilomenaWeb.CurrentFilterPlug do
import Plug.Conn import Plug.Conn
alias Philomena.{Filters, Filters.Filter} alias Philomena.{Filters, Filters.Filter}

View file

@ -1,10 +1,10 @@
defmodule PhilomenaWeb.Plugs.EnsureUserEnabledPlug do defmodule PhilomenaWeb.EnsureUserEnabledPlug do
@moduledoc """ @moduledoc """
This plug ensures that a user is enabled. This plug ensures that a user is enabled.
## Example ## Example
plug PhilomenaWeb.Plugs.EnsureUserEnabledPlug plug PhilomenaWeb.EnsureUserEnabledPlug
""" """
alias PhilomenaWeb.Router.Helpers, as: Routes alias PhilomenaWeb.Router.Helpers, as: Routes
alias Phoenix.Controller alias Phoenix.Controller

View file

@ -1,11 +1,11 @@
defmodule PhilomenaWeb.Plugs.FilterBannedUsers do defmodule PhilomenaWeb.FilterBannedUsersPlug do
@moduledoc """ @moduledoc """
This plug redirects back if there is a ban for the current user. This plug redirects back if there is a ban for the current user.
CurrentBan must also be plugged, and it must come after it. CurrentBanPlug must also be plugged, and this must come after it.
## Example ## Example
plug PhilomenaWeb.Plugs.FilterBannedUsers plug PhilomenaWeb.FilterBannedUsersPlug
""" """
alias Phoenix.Controller alias Phoenix.Controller
alias Plug.Conn alias Plug.Conn

View file

@ -1,4 +1,4 @@
defmodule PhilomenaWeb.Plugs.ImageFilter do defmodule PhilomenaWeb.ImageFilterPlug do
import Plug.Conn import Plug.Conn
import Search.String import Search.String

View file

@ -1,4 +1,4 @@
defmodule PhilomenaWeb.Plugs.Pagination do defmodule PhilomenaWeb.PaginationPlug do
import Plug.Conn import Plug.Conn
# No options # No options

View file

@ -1,11 +1,11 @@
defmodule PhilomenaWeb.Plugs.Referrer do defmodule PhilomenaWeb.ReferrerPlug do
@moduledoc """ @moduledoc """
This plug assigns the HTTP Referer, if it exists. Note the misspelling This plug assigns the HTTP Referer, if it exists. Note the misspelling
in the standard. in the standard.
## Example ## Example
plug PhilomenaWeb.Plugs.Referrer plug PhilomenaWeb.ReferrerPlug
""" """
alias Plug.Conn alias Plug.Conn

View file

@ -1,4 +1,4 @@
defmodule PhilomenaWeb.Plugs.ReloadUser do defmodule PhilomenaWeb.ReloadUserPlug do
alias Pow.Plug alias Pow.Plug
alias Philomena.Users.User alias Philomena.Users.User
alias Philomena.Repo alias Philomena.Repo

View file

@ -1,4 +1,4 @@
defmodule PhilomenaWeb.Plugs.RenderTime do defmodule PhilomenaWeb.RenderTimePlug do
import Plug.Conn import Plug.Conn
# No options # No options

View file

@ -1,4 +1,4 @@
defmodule PhilomenaWeb.Plugs.RequireUser do defmodule PhilomenaWeb.RequireUserPlug do
import Phoenix.Controller import Phoenix.Controller
import Plug.Conn import Plug.Conn
import Pow.Plug import Pow.Plug

View file

@ -1,4 +1,4 @@
defmodule PhilomenaWeb.Plugs.TotpPlug do defmodule PhilomenaWeb.TotpPlug do
@moduledoc """ @moduledoc """
This plug ensures that a user session has a valid TOTP. This plug ensures that a user session has a valid TOTP.

View file

@ -9,11 +9,11 @@ defmodule PhilomenaWeb.Router do
plug :fetch_flash plug :fetch_flash
plug :protect_from_forgery plug :protect_from_forgery
plug :put_secure_browser_headers plug :put_secure_browser_headers
plug PhilomenaWeb.Plugs.CurrentFilter plug PhilomenaWeb.CurrentFilterPlug
plug PhilomenaWeb.Plugs.ImageFilter plug PhilomenaWeb.ImageFilterPlug
plug PhilomenaWeb.Plugs.Pagination plug PhilomenaWeb.PaginationPlug
plug PhilomenaWeb.Plugs.EnsureUserEnabledPlug plug PhilomenaWeb.EnsureUserEnabledPlug
plug PhilomenaWeb.Plugs.CurrentBan plug PhilomenaWeb.CurrentBanPlug
end end
pipeline :api do pipeline :api do
@ -21,7 +21,7 @@ defmodule PhilomenaWeb.Router do
end end
pipeline :ensure_totp do pipeline :ensure_totp do
plug PhilomenaWeb.Plugs.TotpPlug plug PhilomenaWeb.TotpPlug
end end
pipeline :protected do pipeline :protected do