Merge remote-tracking branch 'upstream/develop' into neckbeard

This commit is contained in:
Your New SJW Waifu 2022-07-13 11:26:14 -05:00
commit 745d0f6d1c
9 changed files with 119 additions and 13 deletions

View File

@ -187,6 +187,7 @@ config :pleroma, :instance,
email: "example@example.com",
notify_email: "noreply@example.com",
description: "Pleroma: An efficient and flexible fediverse server",
short_description: "",
background_image: "/images/city.jpg",
instance_thumbnail: "/instance/thumbnail.jpeg",
limit: 5_000,

View File

@ -536,6 +536,15 @@ config :pleroma, :config_description, [
"Very cool instance"
]
},
%{
key: :short_description,
type: :string,
description:
"Shorter version of instance description. It can be seen on `/api/v1/instance`",
suggestions: [
"Cool instance"
]
},
%{
key: :limit,
type: :integer,

View File

@ -18,6 +18,7 @@ To add configuration to your config file, you can copy it from the base config.
* `email`: Email used to reach an Administrator/Moderator of the instance.
* `notify_email`: Email used for notifications.
* `description`: The instances description, can be seen in nodeinfo and ``/api/v1/instance``.
* `short_description`: Shorter version of instance description, can be seen on ``/api/v1/instance``.
* `limit`: Posts character limit (CW/Subject included in the counter).
* `description_limit`: The character limit for image descriptions.
* `remote_limit`: Hard character limit beyond which remote posts will be dropped.

View File

@ -706,7 +706,7 @@ defmodule Pleroma.User do
])
|> validate_required([:name, :nickname])
|> unique_constraint(:nickname)
|> validate_exclusion(:nickname, Config.get([User, :restricted_nicknames]))
|> validate_not_restricted_nickname(:nickname)
|> validate_format(:nickname, local_nickname_regex())
|> put_ap_id()
|> unique_constraint(:ap_id)
@ -754,17 +754,9 @@ defmodule Pleroma.User do
|> validate_confirmation(:password)
|> unique_constraint(:email)
|> validate_format(:email, @email_regex)
|> validate_change(:email, fn :email, email ->
valid? =
Config.get([User, :email_blacklist])
|> Enum.all?(fn blacklisted_domain ->
!String.ends_with?(email, ["@" <> blacklisted_domain, "." <> blacklisted_domain])
end)
if valid?, do: [], else: [email: "Invalid email"]
end)
|> validate_email_not_in_blacklisted_domain(:email)
|> unique_constraint(:nickname)
|> validate_exclusion(:nickname, Config.get([User, :restricted_nicknames]))
|> validate_not_restricted_nickname(:nickname)
|> validate_format(:nickname, local_nickname_regex())
|> validate_length(:bio, max: bio_limit)
|> validate_length(:name, min: 1, max: name_limit)
@ -778,6 +770,35 @@ defmodule Pleroma.User do
|> put_following_and_follower_and_featured_address()
end
def validate_not_restricted_nickname(changeset, field) do
validate_change(changeset, field, fn _, value ->
valid? =
Config.get([User, :restricted_nicknames])
|> Enum.all?(fn restricted_nickname ->
String.downcase(value) != String.downcase(restricted_nickname)
end)
if valid?, do: [], else: [nickname: "Invalid nickname"]
end)
end
def validate_email_not_in_blacklisted_domain(changeset, field) do
validate_change(changeset, field, fn _, value ->
valid? =
Config.get([User, :email_blacklist])
|> Enum.all?(fn blacklisted_domain ->
blacklisted_domain_downcase = String.downcase(blacklisted_domain)
!String.ends_with?(String.downcase(value), [
"@" <> blacklisted_domain_downcase,
"." <> blacklisted_domain_downcase
])
end)
if valid?, do: [], else: [email: "Invalid email"]
end)
end
def maybe_validate_required_email(changeset, true), do: changeset
def maybe_validate_required_email(changeset, _) do

View File

@ -17,6 +17,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
uri: Pleroma.Web.Endpoint.url(),
title: Keyword.get(instance, :name),
description: Keyword.get(instance, :description),
short_description: Keyword.get(instance, :short_description),
version: "#{@mastodon_api_level} (compatible; #{Pleroma.Application.named_version()})",
email: Keyword.get(instance, :email),
urls: %{

View File

@ -7,5 +7,9 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowView do
import Phoenix.HTML.Form
alias Pleroma.Web.Gettext
defdelegate avatar_url(user), to: Pleroma.User
def avatar_url(user) do
user
|> Pleroma.User.avatar_url()
|> Pleroma.Web.MediaProxy.url()
end
end

View File

@ -618,9 +618,10 @@ defmodule Pleroma.UserTest do
end
test "it restricts certain nicknames" do
clear_config([User, :restricted_nicknames], ["about"])
[restricted_name | _] = Pleroma.Config.get([User, :restricted_nicknames])
assert is_bitstring(restricted_name)
assert is_binary(restricted_name)
params =
@full_user_data
@ -631,6 +632,23 @@ defmodule Pleroma.UserTest do
refute changeset.valid?
end
test "it is case-insensitive when restricting nicknames" do
clear_config([User, :restricted_nicknames], ["about"])
[restricted_name | _] = Pleroma.Config.get([User, :restricted_nicknames])
assert is_binary(restricted_name)
restricted_upcase_name = String.upcase(restricted_name)
params =
@full_user_data
|> Map.put(:nickname, restricted_upcase_name)
changeset = User.register_changeset(%User{}, params)
refute changeset.valid?
end
test "it blocks blacklisted email domains" do
clear_config([User, :email_blacklist], ["trolling.world"])
@ -639,6 +657,11 @@ defmodule Pleroma.UserTest do
changeset = User.register_changeset(%User{}, params)
refute changeset.valid?
# Block with case-insensitive match
params = Map.put(@full_user_data, :email, "troll@TrOlLing.wOrld")
changeset = User.register_changeset(%User{}, params)
refute changeset.valid?
# Block with subdomain match
params = Map.put(@full_user_data, :email, "troll@gnomes.trolling.world")
changeset = User.register_changeset(%User{}, params)

View File

@ -22,6 +22,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do
"uri" => _,
"title" => _,
"description" => _,
"short_description" => _,
"version" => _,
"email" => from_config_email,
"urls" => %{

View File

@ -410,4 +410,49 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
assert response =~ "Error following account"
end
end
describe "avatar url" do
test "without media proxy" do
clear_config([:media_proxy, :enabled], false)
user =
insert(:user, %{
local: false,
avatar: %{"url" => [%{"href" => "https://remote.org/avatar.png"}]}
})
avatar_url = Pleroma.Web.TwitterAPI.RemoteFollowView.avatar_url(user)
assert avatar_url == "https://remote.org/avatar.png"
end
test "with media proxy" do
clear_config([:media_proxy, :enabled], true)
user =
insert(:user, %{
local: false,
avatar: %{"url" => [%{"href" => "https://remote.org/avatar.png"}]}
})
avatar_url = Pleroma.Web.TwitterAPI.RemoteFollowView.avatar_url(user)
url = Pleroma.Web.Endpoint.url()
assert String.starts_with?(avatar_url, url)
end
test "local avatar is not proxied" do
clear_config([:media_proxy, :enabled], true)
user =
insert(:user, %{
local: true,
avatar: %{"url" => [%{"href" => "#{Pleroma.Web.Endpoint.url()}/localuser/avatar.png"}]}
})
avatar_url = Pleroma.Web.TwitterAPI.RemoteFollowView.avatar_url(user)
assert avatar_url == "#{Pleroma.Web.Endpoint.url()}/localuser/avatar.png"
end
end
end