From 06875bc11d2272fa277ce43eda07bed6726657b7 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Sun, 17 Nov 2019 13:18:21 -0500 Subject: [PATCH] consistensize plug naming scheme --- lib/philomena/images.ex | 2 +- lib/philomena/topics.ex | 2 +- lib/philomena_web.ex | 1 - .../controllers/conversation_controller.ex | 2 +- lib/philomena_web/controllers/filter_controller.ex | 2 +- .../controllers/image/comment_controller.ex | 6 +++--- .../controllers/image/fave_controller.ex | 4 ++-- .../controllers/image/hide_controller.ex | 4 ++-- .../controllers/image/subscription_controller.ex | 2 +- .../controllers/image/vote_controller.ex | 4 ++-- .../controllers/registration/totp_controller.ex | 2 +- .../controllers/session/totp_controller.ex | 2 +- .../controllers/topic/subscription_controller.ex | 12 ++++++------ lib/philomena_web/endpoint.ex | 6 +++--- lib/philomena_web/plugs/canary_map_plug.ex | 2 +- .../plugs/{current_ban.ex => current_ban_plug.ex} | 4 ++-- .../{current_filter.ex => current_filter_plug.ex} | 2 +- lib/philomena_web/plugs/ensure_user_enabled_plug.ex | 4 ++-- ...r_banned_users.ex => filter_banned_users_plug.ex} | 6 +++--- .../plugs/{image_filter.ex => image_filter_plug.ex} | 2 +- .../plugs/{pagination.ex => pagination_plug.ex} | 2 +- .../plugs/{referrer.ex => referrer_plug.ex} | 4 ++-- .../plugs/{reload_user.ex => reload_user_plug.ex} | 2 +- .../plugs/{render_time.ex => render_time_plug.ex} | 2 +- .../plugs/{require_user.ex => require_user_plug.ex} | 2 +- lib/philomena_web/plugs/totp_plug.ex | 2 +- lib/philomena_web/router.ex | 12 ++++++------ 27 files changed, 48 insertions(+), 49 deletions(-) rename lib/philomena_web/plugs/{current_ban.ex => current_ban_plug.ex} (86%) rename lib/philomena_web/plugs/{current_filter.ex => current_filter_plug.ex} (93%) rename lib/philomena_web/plugs/{filter_banned_users.ex => filter_banned_users_plug.ex} (80%) rename lib/philomena_web/plugs/{image_filter.ex => image_filter_plug.ex} (92%) rename lib/philomena_web/plugs/{pagination.ex => pagination_plug.ex} (94%) rename lib/philomena_web/plugs/{referrer.ex => referrer_plug.ex} (85%) rename lib/philomena_web/plugs/{reload_user.ex => reload_user_plug.ex} (89%) rename lib/philomena_web/plugs/{render_time.ex => render_time_plug.ex} (79%) rename lib/philomena_web/plugs/{require_user.ex => require_user_plug.ex} (89%) diff --git a/lib/philomena/images.ex b/lib/philomena/images.ex index 4b22c2a0..d0705e73 100644 --- a/lib/philomena/images.ex +++ b/lib/philomena/images.ex @@ -122,7 +122,7 @@ defmodule Philomena.Images do alias Philomena.Images.Subscription - def subscribed?(image, nil), do: false + def subscribed?(_image, nil), do: false def subscribed?(image, user) do Subscription |> where(image_id: ^image.id, user_id: ^user.id) diff --git a/lib/philomena/topics.ex b/lib/philomena/topics.ex index 6ef51b34..a63b3b3b 100644 --- a/lib/philomena/topics.ex +++ b/lib/philomena/topics.ex @@ -104,7 +104,7 @@ defmodule Philomena.Topics do alias Philomena.Topics.Subscription - def subscribed?(topic, nil), do: false + def subscribed?(_topic, nil), do: false def subscribed?(topic, user) do Subscription |> where(topic_id: ^topic.id, user_id: ^user.id) diff --git a/lib/philomena_web.ex b/lib/philomena_web.ex index 7b33057f..24c39e3b 100644 --- a/lib/philomena_web.ex +++ b/lib/philomena_web.ex @@ -25,7 +25,6 @@ defmodule PhilomenaWeb do import PhilomenaWeb.Gettext import Canary.Plugs alias PhilomenaWeb.Router.Helpers, as: Routes - alias PhilomenaWeb.Plugs.RequireUser end end diff --git a/lib/philomena_web/controllers/conversation_controller.ex b/lib/philomena_web/controllers/conversation_controller.ex index f8fe080d..d4ffb4d9 100644 --- a/lib/philomena_web/controllers/conversation_controller.ex +++ b/lib/philomena_web/controllers/conversation_controller.ex @@ -6,7 +6,7 @@ defmodule PhilomenaWeb.ConversationController do alias Philomena.Repo 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] def index(conn, _params) do diff --git a/lib/philomena_web/controllers/filter_controller.ex b/lib/philomena_web/controllers/filter_controller.ex index 338171f4..36c571f3 100644 --- a/lib/philomena_web/controllers/filter_controller.ex +++ b/lib/philomena_web/controllers/filter_controller.ex @@ -6,7 +6,7 @@ defmodule PhilomenaWeb.FilterController do import Ecto.Query 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 user = conn.assigns.current_user diff --git a/lib/philomena_web/controllers/image/comment_controller.ex b/lib/philomena_web/controllers/image/comment_controller.ex index f6caaa5a..9f49afca 100644 --- a/lib/philomena_web/controllers/image/comment_controller.ex +++ b/lib/philomena_web/controllers/image/comment_controller.ex @@ -7,14 +7,14 @@ defmodule PhilomenaWeb.Image.CommentController do alias Philomena.Repo 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 # 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 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 comment = diff --git a/lib/philomena_web/controllers/image/fave_controller.ex b/lib/philomena_web/controllers/image/fave_controller.ex index aa39b9bb..c36eab8b 100644 --- a/lib/philomena_web/controllers/image/fave_controller.ex +++ b/lib/philomena_web/controllers/image/fave_controller.ex @@ -6,8 +6,8 @@ defmodule PhilomenaWeb.Image.FaveController do alias Philomena.Repo alias Ecto.Multi - plug PhilomenaWeb.Plugs.FilterBannedUsers - plug PhilomenaWeb.Plugs.CanaryMapPlug, create: :vote, delete: :vote + plug PhilomenaWeb.FilterBannedUsersPlug + plug PhilomenaWeb.CanaryMapPlug, create: :vote, delete: :vote plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true def create(conn, _params) do diff --git a/lib/philomena_web/controllers/image/hide_controller.ex b/lib/philomena_web/controllers/image/hide_controller.ex index d1e532c1..642723e9 100644 --- a/lib/philomena_web/controllers/image/hide_controller.ex +++ b/lib/philomena_web/controllers/image/hide_controller.ex @@ -6,8 +6,8 @@ defmodule PhilomenaWeb.Image.HideController do alias Philomena.Repo alias Ecto.Multi - plug PhilomenaWeb.Plugs.FilterBannedUsers - plug PhilomenaWeb.Plugs.CanaryMapPlug, create: :vote, delete: :vote + plug PhilomenaWeb.FilterBannedUsersPlug + plug PhilomenaWeb.CanaryMapPlug, create: :vote, delete: :vote plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true def create(conn, _params) do diff --git a/lib/philomena_web/controllers/image/subscription_controller.ex b/lib/philomena_web/controllers/image/subscription_controller.ex index 5cc33e06..d7f077b8 100644 --- a/lib/philomena_web/controllers/image/subscription_controller.ex +++ b/lib/philomena_web/controllers/image/subscription_controller.ex @@ -4,7 +4,7 @@ defmodule PhilomenaWeb.Image.SubscriptionController do alias Philomena.Images.Image 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 def create(conn, _params) do diff --git a/lib/philomena_web/controllers/image/vote_controller.ex b/lib/philomena_web/controllers/image/vote_controller.ex index eaf3031b..8b9da65a 100644 --- a/lib/philomena_web/controllers/image/vote_controller.ex +++ b/lib/philomena_web/controllers/image/vote_controller.ex @@ -6,8 +6,8 @@ defmodule PhilomenaWeb.Image.VoteController do alias Philomena.Repo alias Ecto.Multi - plug PhilomenaWeb.Plugs.FilterBannedUsers - plug PhilomenaWeb.Plugs.CanaryMapPlug, create: :vote, delete: :vote + plug PhilomenaWeb.FilterBannedUsersPlug + plug PhilomenaWeb.CanaryMapPlug, create: :vote, delete: :vote plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true def create(conn, params) do diff --git a/lib/philomena_web/controllers/registration/totp_controller.ex b/lib/philomena_web/controllers/registration/totp_controller.ex index ececa83e..d3aaede6 100644 --- a/lib/philomena_web/controllers/registration/totp_controller.ex +++ b/lib/philomena_web/controllers/registration/totp_controller.ex @@ -39,7 +39,7 @@ defmodule PhilomenaWeb.Registration.TotpController do {:ok, user} -> 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) |> redirect(to: Routes.registration_totp_path(conn, :edit)) end diff --git a/lib/philomena_web/controllers/session/totp_controller.ex b/lib/philomena_web/controllers/session/totp_controller.ex index 8b48a19a..05d3dabd 100644 --- a/lib/philomena_web/controllers/session/totp_controller.ex +++ b/lib/philomena_web/controllers/session/totp_controller.ex @@ -27,7 +27,7 @@ defmodule PhilomenaWeb.Session.TotpController do {:ok, user} -> conn - |> PhilomenaWeb.Plugs.TotpPlug.update_valid_totp_at_for_session(user) + |> PhilomenaWeb.TotpPlug.update_valid_totp_at_for_session(user) |> redirect(to: "/") end end diff --git a/lib/philomena_web/controllers/topic/subscription_controller.ex b/lib/philomena_web/controllers/topic/subscription_controller.ex index d399bf82..d46280a8 100644 --- a/lib/philomena_web/controllers/topic/subscription_controller.ex +++ b/lib/philomena_web/controllers/topic/subscription_controller.ex @@ -5,7 +5,7 @@ defmodule PhilomenaWeb.Topic.SubscriptionController do alias Philomena.Repo 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 def create(conn, %{"topic_id" => slug}) do @@ -36,10 +36,10 @@ defmodule PhilomenaWeb.Topic.SubscriptionController do defp load_topic(conn, slug) do forum = conn.assigns.forum - topic = - Topic - |> where(forum_id: ^forum.id, slug: ^slug, hidden_from_users: false) - |> preload(:user) - |> Repo.one() + + Topic + |> where(forum_id: ^forum.id, slug: ^slug, hidden_from_users: false) + |> preload(:user) + |> Repo.one() end end \ No newline at end of file diff --git a/lib/philomena_web/endpoint.ex b/lib/philomena_web/endpoint.ex index 22ae9a93..725b0290 100644 --- a/lib/philomena_web/endpoint.ex +++ b/lib/philomena_web/endpoint.ex @@ -49,8 +49,8 @@ defmodule PhilomenaWeb.Endpoint do plug Pow.Plug.Session, otp_app: :philomena plug PowPersistentSession.Plug.Cookie, otp_app: :philomena - plug PhilomenaWeb.Plugs.ReloadUser - plug PhilomenaWeb.Plugs.RenderTime - plug PhilomenaWeb.Plugs.Referrer + plug PhilomenaWeb.ReloadUserPlug + plug PhilomenaWeb.RenderTimePlug + plug PhilomenaWeb.ReferrerPlug plug PhilomenaWeb.Router end diff --git a/lib/philomena_web/plugs/canary_map_plug.ex b/lib/philomena_web/plugs/canary_map_plug.ex index 660ca6d4..7372b6a6 100644 --- a/lib/philomena_web/plugs/canary_map_plug.ex +++ b/lib/philomena_web/plugs/canary_map_plug.ex @@ -1,4 +1,4 @@ -defmodule PhilomenaWeb.Plugs.CanaryMapPlug do +defmodule PhilomenaWeb.CanaryMapPlug do import Plug.Conn def init(opts), do: opts diff --git a/lib/philomena_web/plugs/current_ban.ex b/lib/philomena_web/plugs/current_ban_plug.ex similarity index 86% rename from lib/philomena_web/plugs/current_ban.ex rename to lib/philomena_web/plugs/current_ban_plug.ex index c9acc682..4dccde3f 100644 --- a/lib/philomena_web/plugs/current_ban.ex +++ b/lib/philomena_web/plugs/current_ban_plug.ex @@ -1,10 +1,10 @@ -defmodule PhilomenaWeb.Plugs.CurrentBan do +defmodule PhilomenaWeb.CurrentBanPlug do @moduledoc """ This plug loads the ban for the current user. ## Example - plug PhilomenaWeb.Plugs.CurrentBan + plug PhilomenaWeb.CurrentBanPlug """ alias Philomena.Bans alias Plug.Conn diff --git a/lib/philomena_web/plugs/current_filter.ex b/lib/philomena_web/plugs/current_filter_plug.ex similarity index 93% rename from lib/philomena_web/plugs/current_filter.ex rename to lib/philomena_web/plugs/current_filter_plug.ex index 416d2e96..7072a0ab 100644 --- a/lib/philomena_web/plugs/current_filter.ex +++ b/lib/philomena_web/plugs/current_filter_plug.ex @@ -1,4 +1,4 @@ -defmodule PhilomenaWeb.Plugs.CurrentFilter do +defmodule PhilomenaWeb.CurrentFilterPlug do import Plug.Conn alias Philomena.{Filters, Filters.Filter} diff --git a/lib/philomena_web/plugs/ensure_user_enabled_plug.ex b/lib/philomena_web/plugs/ensure_user_enabled_plug.ex index fdc48d4a..0f14baf1 100644 --- a/lib/philomena_web/plugs/ensure_user_enabled_plug.ex +++ b/lib/philomena_web/plugs/ensure_user_enabled_plug.ex @@ -1,10 +1,10 @@ -defmodule PhilomenaWeb.Plugs.EnsureUserEnabledPlug do +defmodule PhilomenaWeb.EnsureUserEnabledPlug do @moduledoc """ This plug ensures that a user is enabled. ## Example - plug PhilomenaWeb.Plugs.EnsureUserEnabledPlug + plug PhilomenaWeb.EnsureUserEnabledPlug """ alias PhilomenaWeb.Router.Helpers, as: Routes alias Phoenix.Controller diff --git a/lib/philomena_web/plugs/filter_banned_users.ex b/lib/philomena_web/plugs/filter_banned_users_plug.ex similarity index 80% rename from lib/philomena_web/plugs/filter_banned_users.ex rename to lib/philomena_web/plugs/filter_banned_users_plug.ex index f5b820ae..5b92a9ef 100644 --- a/lib/philomena_web/plugs/filter_banned_users.ex +++ b/lib/philomena_web/plugs/filter_banned_users_plug.ex @@ -1,11 +1,11 @@ -defmodule PhilomenaWeb.Plugs.FilterBannedUsers do +defmodule PhilomenaWeb.FilterBannedUsersPlug do @moduledoc """ 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 - plug PhilomenaWeb.Plugs.FilterBannedUsers + plug PhilomenaWeb.FilterBannedUsersPlug """ alias Phoenix.Controller alias Plug.Conn diff --git a/lib/philomena_web/plugs/image_filter.ex b/lib/philomena_web/plugs/image_filter_plug.ex similarity index 92% rename from lib/philomena_web/plugs/image_filter.ex rename to lib/philomena_web/plugs/image_filter_plug.ex index ce0f50a9..f9844ce7 100644 --- a/lib/philomena_web/plugs/image_filter.ex +++ b/lib/philomena_web/plugs/image_filter_plug.ex @@ -1,4 +1,4 @@ -defmodule PhilomenaWeb.Plugs.ImageFilter do +defmodule PhilomenaWeb.ImageFilterPlug do import Plug.Conn import Search.String diff --git a/lib/philomena_web/plugs/pagination.ex b/lib/philomena_web/plugs/pagination_plug.ex similarity index 94% rename from lib/philomena_web/plugs/pagination.ex rename to lib/philomena_web/plugs/pagination_plug.ex index 3389fcf4..71930e0f 100644 --- a/lib/philomena_web/plugs/pagination.ex +++ b/lib/philomena_web/plugs/pagination_plug.ex @@ -1,4 +1,4 @@ -defmodule PhilomenaWeb.Plugs.Pagination do +defmodule PhilomenaWeb.PaginationPlug do import Plug.Conn # No options diff --git a/lib/philomena_web/plugs/referrer.ex b/lib/philomena_web/plugs/referrer_plug.ex similarity index 85% rename from lib/philomena_web/plugs/referrer.ex rename to lib/philomena_web/plugs/referrer_plug.ex index 23f37530..e46fbc03 100644 --- a/lib/philomena_web/plugs/referrer.ex +++ b/lib/philomena_web/plugs/referrer_plug.ex @@ -1,11 +1,11 @@ -defmodule PhilomenaWeb.Plugs.Referrer do +defmodule PhilomenaWeb.ReferrerPlug do @moduledoc """ This plug assigns the HTTP Referer, if it exists. Note the misspelling in the standard. ## Example - plug PhilomenaWeb.Plugs.Referrer + plug PhilomenaWeb.ReferrerPlug """ alias Plug.Conn diff --git a/lib/philomena_web/plugs/reload_user.ex b/lib/philomena_web/plugs/reload_user_plug.ex similarity index 89% rename from lib/philomena_web/plugs/reload_user.ex rename to lib/philomena_web/plugs/reload_user_plug.ex index a3ee8975..2324899c 100644 --- a/lib/philomena_web/plugs/reload_user.ex +++ b/lib/philomena_web/plugs/reload_user_plug.ex @@ -1,4 +1,4 @@ -defmodule PhilomenaWeb.Plugs.ReloadUser do +defmodule PhilomenaWeb.ReloadUserPlug do alias Pow.Plug alias Philomena.Users.User alias Philomena.Repo diff --git a/lib/philomena_web/plugs/render_time.ex b/lib/philomena_web/plugs/render_time_plug.ex similarity index 79% rename from lib/philomena_web/plugs/render_time.ex rename to lib/philomena_web/plugs/render_time_plug.ex index 2705d73f..97c699ab 100644 --- a/lib/philomena_web/plugs/render_time.ex +++ b/lib/philomena_web/plugs/render_time_plug.ex @@ -1,4 +1,4 @@ -defmodule PhilomenaWeb.Plugs.RenderTime do +defmodule PhilomenaWeb.RenderTimePlug do import Plug.Conn # No options diff --git a/lib/philomena_web/plugs/require_user.ex b/lib/philomena_web/plugs/require_user_plug.ex similarity index 89% rename from lib/philomena_web/plugs/require_user.ex rename to lib/philomena_web/plugs/require_user_plug.ex index 88aac28a..681ad99c 100644 --- a/lib/philomena_web/plugs/require_user.ex +++ b/lib/philomena_web/plugs/require_user_plug.ex @@ -1,4 +1,4 @@ -defmodule PhilomenaWeb.Plugs.RequireUser do +defmodule PhilomenaWeb.RequireUserPlug do import Phoenix.Controller import Plug.Conn import Pow.Plug diff --git a/lib/philomena_web/plugs/totp_plug.ex b/lib/philomena_web/plugs/totp_plug.ex index ae3a8fe8..283419bf 100644 --- a/lib/philomena_web/plugs/totp_plug.ex +++ b/lib/philomena_web/plugs/totp_plug.ex @@ -1,4 +1,4 @@ -defmodule PhilomenaWeb.Plugs.TotpPlug do +defmodule PhilomenaWeb.TotpPlug do @moduledoc """ This plug ensures that a user session has a valid TOTP. diff --git a/lib/philomena_web/router.ex b/lib/philomena_web/router.ex index cb7d8435..66bb3358 100644 --- a/lib/philomena_web/router.ex +++ b/lib/philomena_web/router.ex @@ -9,11 +9,11 @@ defmodule PhilomenaWeb.Router do plug :fetch_flash plug :protect_from_forgery plug :put_secure_browser_headers - plug PhilomenaWeb.Plugs.CurrentFilter - plug PhilomenaWeb.Plugs.ImageFilter - plug PhilomenaWeb.Plugs.Pagination - plug PhilomenaWeb.Plugs.EnsureUserEnabledPlug - plug PhilomenaWeb.Plugs.CurrentBan + plug PhilomenaWeb.CurrentFilterPlug + plug PhilomenaWeb.ImageFilterPlug + plug PhilomenaWeb.PaginationPlug + plug PhilomenaWeb.EnsureUserEnabledPlug + plug PhilomenaWeb.CurrentBanPlug end pipeline :api do @@ -21,7 +21,7 @@ defmodule PhilomenaWeb.Router do end pipeline :ensure_totp do - plug PhilomenaWeb.Plugs.TotpPlug + plug PhilomenaWeb.TotpPlug end pipeline :protected do