summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarcin mikołajczak <git@mkljczk.pl>2022-01-18 18:02:01 +0100
committermarcin mikołajczak <git@mkljczk.pl>2022-01-18 18:18:38 +0100
commit397f67fef8658000be26fd3b9bd86f5968fcaf52 (patch)
tree4e1db1caa5e57c92325ec8c7bc4d655ff7e3063d
parentb108b0565076d677a90ff38ec8926e1f3153b7f6 (diff)
Format code, expose instance configuration related to birth dates
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
-rw-r--r--config/description.exs3
-rw-r--r--lib/pleroma/user.ex3
-rw-r--r--lib/pleroma/web/api_spec/operations/account_operation.ex2
-rw-r--r--lib/pleroma/web/api_spec/schemas/account.ex2
-rw-r--r--lib/pleroma/web/mastodon_api/views/instance_view.ex4
-rw-r--r--lib/pleroma/web/pleroma_api/controllers/account_controller.ex12
-rw-r--r--test/pleroma/web/mastodon_api/views/account_view_test.exs2
7 files changed, 16 insertions, 12 deletions
diff --git a/config/description.exs b/config/description.exs
index 9a5242820..867112b8e 100644
--- a/config/description.exs
+++ b/config/description.exs
@@ -966,7 +966,8 @@ config :pleroma, :config_description, [
%{
key: :birth_date_min_age,
type: :integer,
- description: "Min age for users to create account. Only makes sense if birth date is required."
+ description:
+ "Min age for users to create account. Only makes sense if birth date is required."
}
]
},
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index ca9986e28..cb7740292 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -157,7 +157,6 @@ defmodule Pleroma.User do
field(:birth_date, :date)
field(:hide_birth_date, :boolean, default: false)
-
embeds_one(
:notification_settings,
Pleroma.User.NotificationSetting,
@@ -799,7 +798,7 @@ defmodule Pleroma.User do
valid? =
Date.utc_today()
|> Date.diff(birth_date) >=
- Config.get([:instance, :birth_date_min_age])
+ Config.get([:instance, :birth_date_min_age])
if valid?, do: [], else: [birth_date: "Invalid birth date"]
end)
diff --git a/lib/pleroma/web/api_spec/operations/account_operation.ex b/lib/pleroma/web/api_spec/operations/account_operation.ex
index dc2019b67..e0ef45027 100644
--- a/lib/pleroma/web/api_spec/operations/account_operation.ex
+++ b/lib/pleroma/web/api_spec/operations/account_operation.ex
@@ -549,7 +549,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
nullable: true,
description: "User's birth date",
format: :date
- },
+ }
},
example: %{
"username" => "cofe",
diff --git a/lib/pleroma/web/api_spec/schemas/account.ex b/lib/pleroma/web/api_spec/schemas/account.ex
index 66c900b76..a20964342 100644
--- a/lib/pleroma/web/api_spec/schemas/account.ex
+++ b/lib/pleroma/web/api_spec/schemas/account.ex
@@ -47,7 +47,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
description: "whether the user allows automatically follow moved following accounts"
},
background_image: %Schema{type: :string, nullable: true, format: :uri},
- birth_date: %Schema{type: :string, format: :date},
+ birth_date: %Schema{type: :string, nullable: true, format: :date},
chat_token: %Schema{type: :string},
is_confirmed: %Schema{
type: :boolean,
diff --git a/lib/pleroma/web/mastodon_api/views/instance_view.ex b/lib/pleroma/web/mastodon_api/views/instance_view.ex
index 8e657ee0f..f7c76f06b 100644
--- a/lib/pleroma/web/mastodon_api/views/instance_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/instance_view.ex
@@ -46,7 +46,9 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
federation: federation(),
fields_limits: fields_limits(),
post_formats: Config.get([:instance, :allowed_post_formats]),
- privileged_staff: Config.get([:instance, :privileged_staff])
+ privileged_staff: Config.get([:instance, :privileged_staff]),
+ birth_date_required: Config.get([:instance, :birth_date_required]),
+ birth_date_min_age: Config.get([:instance, :birth_date_min_age])
},
stats: %{mau: Pleroma.User.active_user_count()},
vapid_public_key: Keyword.get(Pleroma.Web.Push.vapid_config(), :public_key)
diff --git a/lib/pleroma/web/pleroma_api/controllers/account_controller.ex b/lib/pleroma/web/pleroma_api/controllers/account_controller.ex
index ca6c9c3a2..4a833275e 100644
--- a/lib/pleroma/web/pleroma_api/controllers/account_controller.ex
+++ b/lib/pleroma/web/pleroma_api/controllers/account_controller.ex
@@ -149,11 +149,11 @@ defmodule Pleroma.Web.PleromaAPI.AccountController do
User.Query.build(%{friends: user, deactivated: false, birth_day: day, birth_month: month})
|> Pleroma.Repo.all()
- conn
- |> render("index.json",
- for: user,
- users: birthdays,
- as: :user
- )
+ conn
+ |> render("index.json",
+ for: user,
+ users: birthdays,
+ as: :user
+ )
end
end
diff --git a/test/pleroma/web/mastodon_api/views/account_view_test.exs b/test/pleroma/web/mastodon_api/views/account_view_test.exs
index c23ffb966..da8761355 100644
--- a/test/pleroma/web/mastodon_api/views/account_view_test.exs
+++ b/test/pleroma/web/mastodon_api/views/account_view_test.exs
@@ -79,6 +79,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
ap_id: user.ap_id,
also_known_as: ["https://shitposter.zone/users/shp"],
background_image: "https://example.com/images/asuka_hospital.png",
+ birth_date: nil,
favicon: nil,
is_confirmed: true,
tags: [],
@@ -181,6 +182,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
ap_id: user.ap_id,
also_known_as: [],
background_image: nil,
+ birth_date: nil,
favicon: nil,
is_confirmed: true,
tags: [],