Commit 074fa790 authored by Maksim's avatar Maksim

fix compile warnings

parent cf85a9ae
defmodule Mix.Tasks.Pleroma.Common do defmodule Mix.Tasks.Pleroma.Common do
@shortdoc "Common functions to be reused in mix tasks" @doc "Common functions to be reused in mix tasks"
def start_pleroma do def start_pleroma do
Mix.Task.run("app.start") Mix.Task.run("app.start")
end end
......
defmodule Mix.Tasks.Pleroma.Instance do defmodule Mix.Tasks.Pleroma.Instance do
use Mix.Task use Mix.Task
alias Pleroma.{Repo, User}
alias Mix.Tasks.Pleroma.Common alias Mix.Tasks.Pleroma.Common
@shortdoc "Manages Pleroma instance" @shortdoc "Manages Pleroma instance"
......
...@@ -22,7 +22,7 @@ defmodule Mix.Tasks.Pleroma.Relay do ...@@ -22,7 +22,7 @@ defmodule Mix.Tasks.Pleroma.Relay do
def run(["follow", target]) do def run(["follow", target]) do
Common.start_pleroma() Common.start_pleroma()
with {:ok, activity} <- Relay.follow(target) do with {:ok, _activity} <- Relay.follow(target) do
# put this task to sleep to allow the genserver to push out the messages # put this task to sleep to allow the genserver to push out the messages
:timer.sleep(500) :timer.sleep(500)
else else
...@@ -33,7 +33,7 @@ def run(["follow", target]) do ...@@ -33,7 +33,7 @@ def run(["follow", target]) do
def run(["unfollow", target]) do def run(["unfollow", target]) do
Common.start_pleroma() Common.start_pleroma()
with {:ok, activity} <- Relay.unfollow(target) do with {:ok, _activity} <- Relay.unfollow(target) do
# put this task to sleep to allow the genserver to push out the messages # put this task to sleep to allow the genserver to push out the messages
:timer.sleep(500) :timer.sleep(500)
else else
......
defmodule Mix.Tasks.Pleroma.Uploads do defmodule Mix.Tasks.Pleroma.Uploads do
use Mix.Task use Mix.Task
import Mix.Ecto alias Pleroma.{Upload, Uploaders.Local}
alias Pleroma.{Upload, Uploaders.Local, Uploaders.S3}
alias Mix.Tasks.Pleroma.Common alias Mix.Tasks.Pleroma.Common
require Logger require Logger
@log_every 50 @log_every 50
@shortdoc "Migrate uploads from local to remote storage" @shortdoc "Migrate uploads from local to remote storage"
@longdoc """ @doc """
Manages uploads Manages uploads
## Migrate uploads from local to remote storage ## Migrate uploads from local to remote storage
""" """
def run(["migrate_local", target_uploader | args]) do def run(["migrate_local", target_uploader | args]) do
delete? = Enum.member?(args, "--delete") delete? = Enum.member?(args, "--delete")
Common.start_pleroma() Common.start_pleroma()
...@@ -59,7 +57,7 @@ def run(["migrate_local", target_uploader | args]) do ...@@ -59,7 +57,7 @@ def run(["migrate_local", target_uploader | args]) do
File.exists?(root_path) -> File.exists?(root_path) ->
file = Path.basename(id) file = Path.basename(id)
[hash, ext] = String.split(id, ".") [hash, _ext] = String.split(id, ".")
{%Pleroma.Upload{id: hash, name: file, path: file, tempfile: root_path}, root_path} {%Pleroma.Upload{id: hash, name: file, path: file, tempfile: root_path}, root_path}
true -> true ->
......
...@@ -20,7 +20,7 @@ defmodule Mix.Tasks.Pleroma.User do ...@@ -20,7 +20,7 @@ defmodule Mix.Tasks.Pleroma.User do
- `--admin`/`--no-admin` - whether the user is an admin - `--admin`/`--no-admin` - whether the user is an admin
## Generate an invite link. ## Generate an invite link.
mix pleroma.user invite mix pleroma.user invite
## Delete the user's account. ## Delete the user's account.
...@@ -32,7 +32,7 @@ defmodule Mix.Tasks.Pleroma.User do ...@@ -32,7 +32,7 @@ defmodule Mix.Tasks.Pleroma.User do
mix pleroma.user toggle_activated NICKNAME mix pleroma.user toggle_activated NICKNAME
## Unsubscribe local users from user's account and deactivate it ## Unsubscribe local users from user's account and deactivate it
mix pleroma.user unsubscribe NICKNAME mix pleroma.user unsubscribe NICKNAME
## Create a password reset link. ## Create a password reset link.
...@@ -235,6 +235,26 @@ def run(["set", nickname | rest]) do ...@@ -235,6 +235,26 @@ def run(["set", nickname | rest]) do
end end
end end
def run(["invite"]) do
Common.start_pleroma()
with {:ok, token} <- Pleroma.UserInviteToken.create_token() do
Mix.shell().info("Generated user invite token")
url =
Pleroma.Web.Router.Helpers.redirect_url(
Pleroma.Web.Endpoint,
:registration_page,
token.token
)
IO.puts(url)
else
_ ->
Mix.shell().error("Could not create invite token.")
end
end
defp set_moderator(user, value) do defp set_moderator(user, value) do
info_cng = User.Info.admin_api_update(user.info, %{is_moderator: value}) info_cng = User.Info.admin_api_update(user.info, %{is_moderator: value})
...@@ -270,24 +290,4 @@ defp set_locked(user, value) do ...@@ -270,24 +290,4 @@ defp set_locked(user, value) do
Mix.shell().info("Locked status of #{user.nickname}: #{user.info.locked}") Mix.shell().info("Locked status of #{user.nickname}: #{user.info.locked}")
end end
def run(["invite"]) do
Common.start_pleroma()
with {:ok, token} <- Pleroma.UserInviteToken.create_token() do
Mix.shell().info("Generated user invite token")
url =
Pleroma.Web.Router.Helpers.redirect_url(
Pleroma.Web.Endpoint,
:registration_page,
token.token
)
IO.puts(url)
else
_ ->
Mix.shell().error("Could not create invite token.")
end
end
end end
...@@ -15,7 +15,6 @@ def user_agent() do ...@@ -15,7 +15,6 @@ def user_agent() do
# See http://elixir-lang.org/docs/stable/elixir/Application.html # See http://elixir-lang.org/docs/stable/elixir/Application.html
# for more information on OTP Applications # for more information on OTP Applications
@env Mix.env()
def start(_type, _args) do def start(_type, _args) do
import Cachex.Spec import Cachex.Spec
......
...@@ -165,7 +165,7 @@ defp load_from_file(file) do ...@@ -165,7 +165,7 @@ defp load_from_file(file) do
defp load_from_file_stream(stream) do defp load_from_file_stream(stream) do
stream stream
|> Stream.map(&String.strip/1) |> Stream.map(&String.trim/1)
|> Stream.map(fn line -> |> Stream.map(fn line ->
case String.split(line, ~r/,\s*/) do case String.split(line, ~r/,\s*/) do
[name, file] -> {name, file} [name, file] -> {name, file}
......
defmodule Pleroma.Filter do defmodule Pleroma.Filter do
use Ecto.Schema use Ecto.Schema
import Ecto.{Changeset, Query} import Ecto.{Changeset, Query}
alias Pleroma.{User, Repo, Activity} alias Pleroma.{User, Repo}
schema "filters" do schema "filters" do
belongs_to(:user, Pleroma.User) belongs_to(:user, User)
field(:filter_id, :integer) field(:filter_id, :integer)
field(:hide, :boolean, default: false) field(:hide, :boolean, default: false)
field(:whole_word, :boolean, default: true) field(:whole_word, :boolean, default: true)
...@@ -26,7 +26,7 @@ def get(id, %{id: user_id} = _user) do ...@@ -26,7 +26,7 @@ def get(id, %{id: user_id} = _user) do
Repo.one(query) Repo.one(query)
end end
def get_filters(%Pleroma.User{id: user_id} = user) do def get_filters(%User{id: user_id} = _user) do
query = query =
from( from(
f in Pleroma.Filter, f in Pleroma.Filter,
...@@ -38,9 +38,9 @@ def get_filters(%Pleroma.User{id: user_id} = user) do ...@@ -38,9 +38,9 @@ def get_filters(%Pleroma.User{id: user_id} = user) do
def create(%Pleroma.Filter{user_id: user_id, filter_id: nil} = filter) do def create(%Pleroma.Filter{user_id: user_id, filter_id: nil} = filter) do
# If filter_id wasn't given, use the max filter_id for this user plus 1. # If filter_id wasn't given, use the max filter_id for this user plus 1.
# XXX This could result in a race condition if a user tries to add two # XXX This could result in a race condition if a user tries to add two
# different filters for their account from two different clients at the # different filters for their account from two different clients at the
# same time, but that should be unlikely. # same time, but that should be unlikely.
max_id_query = max_id_query =
from( from(
......
...@@ -166,7 +166,7 @@ def scrub_attribute("img", {"src", "http" <> target}) do ...@@ -166,7 +166,7 @@ def scrub_attribute("img", {"src", "http" <> target}) do
{"src", media_url} {"src", media_url}
end end
def scrub_attribute(tag, attribute), do: attribute def scrub_attribute(_tag, attribute), do: attribute
def scrub({"img", attributes, children}) do def scrub({"img", attributes, children}) do
attributes = attributes =
...@@ -177,9 +177,9 @@ def scrub({"img", attributes, children}) do ...@@ -177,9 +177,9 @@ def scrub({"img", attributes, children}) do
{"img", attributes, children} {"img", attributes, children}
end end
def scrub({:comment, children}), do: "" def scrub({:comment, _children}), do: ""
def scrub({tag, attributes, children}), do: {tag, attributes, children} def scrub({tag, attributes, children}), do: {tag, attributes, children}
def scrub({tag, children}), do: children def scrub({_tag, children}), do: children
def scrub(text), do: text def scrub(text), do: text
end end
...@@ -25,7 +25,7 @@ def new(opts \\ []) do ...@@ -25,7 +25,7 @@ def new(opts \\ []) do
# fetch Hackney options # fetch Hackney options
# #
defp hackney_options(opts \\ []) do defp hackney_options(opts) do
options = Keyword.get(opts, :adapter, []) options = Keyword.get(opts, :adapter, [])
@hackney_options ++ options @hackney_options ++ options
end end
......
...@@ -23,7 +23,7 @@ def follow_changeset(list, attrs \\ %{}) do ...@@ -23,7 +23,7 @@ def follow_changeset(list, attrs \\ %{}) do
|> validate_required([:following]) |> validate_required([:following])
end end
def for_user(user, opts) do def for_user(user, _opts) do
query = query =
from( from(
l in Pleroma.List, l in Pleroma.List,
...@@ -46,7 +46,7 @@ def get(id, %{id: user_id} = _user) do ...@@ -46,7 +46,7 @@ def get(id, %{id: user_id} = _user) do
Repo.one(query) Repo.one(query)
end end
def get_following(%Pleroma.List{following: following} = list) do def get_following(%Pleroma.List{following: following} = _list) do
q = q =
from( from(
u in User, u in User,
......
...@@ -33,10 +33,10 @@ def bin_mime_type(<<head::binary-size(@read_bytes), _::binary>>) do ...@@ -33,10 +33,10 @@ def bin_mime_type(<<head::binary-size(@read_bytes), _::binary>>) do
{:ok, check_mime_type(head)} {:ok, check_mime_type(head)}
end end
def mime_type(<<_::binary>>), do: {:ok, @default}
def bin_mime_type(_), do: :error def bin_mime_type(_), do: :error
def mime_type(<<_::binary>>), do: {:ok, @default}
defp fix_extension(filename, content_type) do defp fix_extension(filename, content_type) do
parts = String.split(filename, ".") parts = String.split(filename, ".")
......
...@@ -118,7 +118,7 @@ def create_notification(%Activity{} = activity, %User{} = user) do ...@@ -118,7 +118,7 @@ def create_notification(%Activity{} = activity, %User{} = user) do
def get_notified_from_activity(activity, local_only \\ true) def get_notified_from_activity(activity, local_only \\ true)
def get_notified_from_activity( def get_notified_from_activity(
%Activity{data: %{"to" => _, "type" => type} = data} = activity, %Activity{data: %{"to" => _, "type" => type} = _data} = activity,
local_only local_only
) )
when type in ["Create", "Like", "Announce", "Follow"] do when type in ["Create", "Like", "Announce", "Follow"] do
...@@ -131,18 +131,18 @@ def get_notified_from_activity( ...@@ -131,18 +131,18 @@ def get_notified_from_activity(
User.get_users_from_set(recipients, local_only) User.get_users_from_set(recipients, local_only)
end end
def get_notified_from_activity(_, local_only), do: [] def get_notified_from_activity(_, _local_only), do: []
defp maybe_notify_to_recipients( defp maybe_notify_to_recipients(
recipients, recipients,
%Activity{data: %{"to" => to, "type" => type}} = activity %Activity{data: %{"to" => to, "type" => _type}} = _activity
) do ) do
recipients ++ to recipients ++ to
end end
defp maybe_notify_mentioned_recipients( defp maybe_notify_mentioned_recipients(
recipients, recipients,
%Activity{data: %{"to" => to, "type" => type} = data} = activity %Activity{data: %{"to" => _to, "type" => type} = data} = _activity
) )
when type == "Create" do when type == "Create" do
object = Object.normalize(data["object"]) object = Object.normalize(data["object"])
......
...@@ -26,14 +26,7 @@ def call( ...@@ -26,14 +26,7 @@ def call(
end end
end end
def call( def call(%{assigns: %{auth_credentials: %{password: _}}} = conn, _) do
%{
assigns: %{
auth_credentials: %{password: password}
}
} = conn,
_
) do
Pbkdf2.dummy_checkpw() Pbkdf2.dummy_checkpw()
conn conn
end end
......
...@@ -5,7 +5,7 @@ def init(options) do ...@@ -5,7 +5,7 @@ def init(options) do
options options
end end
def call(conn, opts) do def call(conn, _opts) do
with ["Basic " <> header] <- get_req_header(conn, "authorization"), with ["Basic " <> header] <- get_req_header(conn, "authorization"),
{:ok, userinfo} <- Base.decode64(header), {:ok, userinfo} <- Base.decode64(header),
[username, password] <- String.split(userinfo, ":", parts: 2) do [username, password] <- String.split(userinfo, ":", parts: 2) do
......
...@@ -5,7 +5,7 @@ def init(options) do ...@@ -5,7 +5,7 @@ def init(options) do
options options
end end
def call(conn, opts) do def call(conn, _opts) do
if Keyword.get(Application.get_env(:pleroma, :instance), :federating) do if Keyword.get(Application.get_env(:pleroma, :instance), :federating) do
conn conn
else else
......
...@@ -4,11 +4,11 @@ defmodule Pleroma.Plugs.HTTPSecurityPlug do ...@@ -4,11 +4,11 @@ defmodule Pleroma.Plugs.HTTPSecurityPlug do
def init(opts), do: opts def init(opts), do: opts
def call(conn, options) do def call(conn, _options) do
if Config.get([:http_security, :enabled]) do if Config.get([:http_security, :enabled]) do
conn = conn
merge_resp_headers(conn, headers()) |> merge_resp_headers(headers())
|> maybe_send_sts_header(Config.get([:http_security, :sts])) |> maybe_send_sts_header(Config.get([:http_security, :sts]))
else else
conn conn
end end
...@@ -42,7 +42,7 @@ defp csp_string do ...@@ -42,7 +42,7 @@ defp csp_string do
"script-src 'self'", "script-src 'self'",
"connect-src 'self' " <> String.replace(Pleroma.Web.Endpoint.static_url(), "http", "ws"), "connect-src 'self' " <> String.replace(Pleroma.Web.Endpoint.static_url(), "http", "ws"),
"manifest-src 'self'", "manifest-src 'self'",
if @protocol == "https" do if protocol == "https" do
"upgrade-insecure-requests" "upgrade-insecure-requests"
end end
] ]
......
defmodule Pleroma.Plugs.SessionAuthenticationPlug do defmodule Pleroma.Plugs.SessionAuthenticationPlug do
import Plug.Conn import Plug.Conn
alias Pleroma.User
def init(options) do def init(options) do
options options
......
...@@ -8,10 +8,6 @@ defmodule Pleroma.Plugs.UploadedMedia do ...@@ -8,10 +8,6 @@ defmodule Pleroma.Plugs.UploadedMedia do
@behaviour Plug @behaviour Plug
# no slashes # no slashes
@path "media" @path "media"
@cache_control %{
default: "public, max-age=1209600",
error: "public, must-revalidate, max-age=160"
}
def init(_opts) do def init(_opts) do
static_plug_opts = static_plug_opts =
......
...@@ -7,7 +7,7 @@ def init(options) do ...@@ -7,7 +7,7 @@ def init(options) do
options options
end end
def call(conn, options) do def call(conn, _options) do
with %{auth_credentials: %{username: username}} <- conn.assigns, with %{auth_credentials: %{username: username}} <- conn.assigns,
{:ok, %User{} = user} <- user_fetcher(username) do {:ok, %User{} = user} <- user_fetcher(username) do
conn conn
......
...@@ -85,7 +85,9 @@ defmodule Pleroma.ReverseProxy do ...@@ -85,7 +85,9 @@ defmodule Pleroma.ReverseProxy do
| {:redirect_on_failure, boolean()} | {:redirect_on_failure, boolean()}
@spec call(Plug.Conn.t(), url :: String.t(), [option()]) :: Plug.Conn.t() @spec call(Plug.Conn.t(), url :: String.t(), [option()]) :: Plug.Conn.t()
def call(conn = %{method: method}, url, opts \\ []) when method in @methods do def call(_conn, _url, _opts \\ [])
def call(conn = %{method: method}, url, opts) when method in @methods do
hackney_opts = hackney_opts =
@default_hackney_options @default_hackney_options
|> Keyword.merge(Keyword.get(opts, :http, [])) |> Keyword.merge(Keyword.get(opts, :http, []))
...@@ -240,24 +242,23 @@ defp put_resp_headers(conn, headers) do ...@@ -240,24 +242,23 @@ defp put_resp_headers(conn, headers) do
end end
defp build_req_headers(headers, opts) do defp build_req_headers(headers, opts) do
headers = headers
headers |> downcase_headers()
|> downcase_headers() |> Enum.filter(fn {k, _} -> k in @keep_req_headers end)
|> Enum.filter(fn {k, _} -> k in @keep_req_headers end) |> (fn headers ->
|> (fn headers -> headers = headers ++ Keyword.get(opts, :req_headers, [])
headers = headers ++ Keyword.get(opts, :req_headers, [])
if Keyword.get(opts, :keep_user_agent, false) do
if Keyword.get(opts, :keep_user_agent, false) do List.keystore(
List.keystore( headers,
headers, "user-agent",
"user-agent", 0,
0, {"user-agent", Pleroma.Application.user_agent()}
{"user-agent", Pleroma.Application.user_agent()} )
) else
else headers
headers end
end end).()
end).()
end end
defp build_resp_headers(headers, opts) do defp build_resp_headers(headers, opts) do
...@@ -268,7 +269,7 @@ defp build_resp_headers(headers, opts) do ...@@ -268,7 +269,7 @@ defp build_resp_headers(headers, opts) do
|> (fn headers -> headers ++ Keyword.get(opts, :resp_headers, []) end).() |> (fn headers -> headers ++ Keyword.get(opts, :resp_headers, []) end).()
end end
defp build_resp_cache_headers(headers, opts) do defp build_resp_cache_headers(headers, _opts) do
has_cache? = Enum.any?(headers, fn {k, _} -> k in @resp_cache_headers end) has_cache? = Enum.any?(headers, fn {k, _} -> k in @resp_cache_headers end)
if has_cache? do if has_cache? do
......
...@@ -128,19 +128,18 @@ defp get_opts(opts) do ...@@ -128,19 +128,18 @@ defp get_opts(opts) do
opts opts
end end
opts = if Pleroma.Config.get([:instance, :dedupe_media]) == true &&
if Pleroma.Config.get([:instance, :dedupe_media]) == true && !Enum.member?(opts.filters, Pleroma.Upload.Filter.Dedupe) do
!Enum.member?(opts.filters, Pleroma.Upload.Filter.Dedupe) do Logger.warn("""
Logger.warn(""" Pleroma: configuration `:instance, :dedupe_media` is deprecated, please instead set:
Pleroma: configuration `:instance, :dedupe_media` is deprecated, please instead set:
:pleroma, Pleroma.Upload, [filters: [Pleroma.Upload.Filter.Dedupe]] :pleroma, Pleroma.Upload, [filters: [Pleroma.Upload.Filter.Dedupe]]
""")