mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
consistensize plug naming scheme
This commit is contained in:
parent
f9bdda08a7
commit
06875bc11d
27 changed files with 48 additions and 49 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 =
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
defmodule PhilomenaWeb.Plugs.CanaryMapPlug do
|
||||
defmodule PhilomenaWeb.CanaryMapPlug do
|
||||
import Plug.Conn
|
||||
|
||||
def init(opts), do: opts
|
||||
|
|
|
@ -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
|
|
@ -1,4 +1,4 @@
|
|||
defmodule PhilomenaWeb.Plugs.CurrentFilter do
|
||||
defmodule PhilomenaWeb.CurrentFilterPlug do
|
||||
import Plug.Conn
|
||||
|
||||
alias Philomena.{Filters, Filters.Filter}
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -1,4 +1,4 @@
|
|||
defmodule PhilomenaWeb.Plugs.ImageFilter do
|
||||
defmodule PhilomenaWeb.ImageFilterPlug do
|
||||
import Plug.Conn
|
||||
import Search.String
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
defmodule PhilomenaWeb.Plugs.Pagination do
|
||||
defmodule PhilomenaWeb.PaginationPlug do
|
||||
import Plug.Conn
|
||||
|
||||
# No options
|
|
@ -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
|
|
@ -1,4 +1,4 @@
|
|||
defmodule PhilomenaWeb.Plugs.ReloadUser do
|
||||
defmodule PhilomenaWeb.ReloadUserPlug do
|
||||
alias Pow.Plug
|
||||
alias Philomena.Users.User
|
||||
alias Philomena.Repo
|
|
@ -1,4 +1,4 @@
|
|||
defmodule PhilomenaWeb.Plugs.RenderTime do
|
||||
defmodule PhilomenaWeb.RenderTimePlug do
|
||||
import Plug.Conn
|
||||
|
||||
# No options
|
|
@ -1,4 +1,4 @@
|
|||
defmodule PhilomenaWeb.Plugs.RequireUser do
|
||||
defmodule PhilomenaWeb.RequireUserPlug do
|
||||
import Phoenix.Controller
|
||||
import Plug.Conn
|
||||
import Pow.Plug
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue