summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md3
-rw-r--r--config/config.exs4
-rw-r--r--config/description.exs11
-rw-r--r--lib/pleroma/user.ex44
-rw-r--r--lib/pleroma/user/query.ex18
-rw-r--r--lib/pleroma/web/activity_pub/activity_pub.ex13
-rw-r--r--lib/pleroma/web/activity_pub/views/user_view.ex8
-rw-r--r--lib/pleroma/web/api_spec/operations/account_operation.ex23
-rw-r--r--lib/pleroma/web/api_spec/operations/pleroma_account_operation.ex29
-rw-r--r--lib/pleroma/web/api_spec/schemas/account.ex5
-rw-r--r--lib/pleroma/web/mastodon_api/controllers/account_controller.ex4
-rw-r--r--lib/pleroma/web/mastodon_api/views/account_view.ex23
-rw-r--r--lib/pleroma/web/mastodon_api/views/instance_view.ex4
-rw-r--r--lib/pleroma/web/pleroma_api/controllers/account_controller.ex19
-rw-r--r--lib/pleroma/web/router.ex2
-rw-r--r--lib/pleroma/web/twitter_api/twitter_api.ex1
-rw-r--r--priv/repo/migrations/29220116183110_add_birth_date_to_users.exs10
-rw-r--r--priv/static/schemas/litepub-0.1.jsonld3
-rw-r--r--test/pleroma/user_test.exs48
-rw-r--r--test/pleroma/web/mastodon_api/controllers/account_controller_test.exs54
-rw-r--r--test/pleroma/web/mastodon_api/update_credentials_test.exs20
-rw-r--r--test/pleroma/web/mastodon_api/views/account_view_test.exs2
-rw-r--r--test/pleroma/web/pleroma_api/controllers/account_controller_test.exs53
23 files changed, 387 insertions, 14 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6aaadca42..53cdc6e79 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,6 +26,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Ability to log slow Ecto queries by configuring `:pleroma, :telemetry, :slow_queries_logging`
- Added Phoenix LiveDashboard at `/phoenix/live_dashboard`
- Added `/manifest.json` for progressive web apps.
+- MastoAPI: Support for `birthday` and `show_birthday` field in `/api/v1/accounts/update_credentials`.
+- Configuration: Add `birthday_required` and `birthday_min_age` settings to provide a way to require users to enter their birth date.
+- PleromaAPI: Add `GET /api/v1/pleroma/birthday_reminders` API endpoint
### Fixed
- Subscription(Bell) Notifications: Don't create from Pipeline Ingested replies
diff --git a/config/config.exs b/config/config.exs
index 1385ce5de..cefc8a98f 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -259,7 +259,9 @@ config :pleroma, :instance,
password_reset_token_validity: 60 * 60 * 24,
profile_directory: true,
privileged_staff: false,
- max_endorsed_users: 20
+ max_endorsed_users: 20,
+ birthday_required: false,
+ birthday_min_age: 0
config :pleroma, :welcome,
direct_message: [
diff --git a/config/description.exs b/config/description.exs
index 644c60a63..3f66877e4 100644
--- a/config/description.exs
+++ b/config/description.exs
@@ -957,6 +957,17 @@ config :pleroma, :config_description, [
type: :boolean,
description:
"Let moderators access sensitive data (e.g. updating user credentials, get password reset token, delete users, index and read private statuses and chats)"
+ },
+ %{
+ key: :birthday_required,
+ type: :boolean,
+ description: "Require users to enter their birthday."
+ },
+ %{
+ key: :birthday_min_age,
+ type: :integer,
+ description:
+ "Minimum required age for users to create account. Only used if birthday is required."
}
]
},
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index bf5b6508b..8bb4fb204 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -154,6 +154,8 @@ defmodule Pleroma.User do
field(:pinned_objects, :map, default: %{})
field(:is_suggested, :boolean, default: false)
field(:last_status_at, :naive_datetime)
+ field(:birthday, :date)
+ field(:hide_birthday, :boolean, default: false)
embeds_one(
:notification_settings,
@@ -470,7 +472,8 @@ defmodule Pleroma.User do
:actor_type,
:also_known_as,
:accepts_chat_messages,
- :pinned_objects
+ :pinned_objects,
+ :birthday
]
)
|> cast(params, [:name], empty_values: [])
@@ -531,9 +534,12 @@ defmodule Pleroma.User do
:is_discoverable,
:actor_type,
:accepts_chat_messages,
- :disclose_client
+ :disclose_client,
+ :birthday,
+ :hide_birthday
]
)
+ |> validate_min_age()
|> unique_constraint(:nickname)
|> validate_format(:nickname, local_nickname_regex())
|> validate_length(:bio, max: bio_limit)
@@ -738,7 +744,8 @@ defmodule Pleroma.User do
:password_confirmation,
:emoji,
:accepts_chat_messages,
- :registration_reason
+ :registration_reason,
+ :birthday
])
|> validate_required([:name, :nickname, :password, :password_confirmation])
|> validate_confirmation(:password)
@@ -760,6 +767,8 @@ defmodule Pleroma.User do
|> validate_length(:name, min: 1, max: name_limit)
|> validate_length(:registration_reason, max: reason_limit)
|> maybe_validate_required_email(opts[:external])
+ |> maybe_validate_required_birthday
+ |> validate_min_age()
|> put_password_hash
|> put_ap_id()
|> unique_constraint(:ap_id)
@@ -776,6 +785,26 @@ defmodule Pleroma.User do
end
end
+ defp maybe_validate_required_birthday(changeset) do
+ if Config.get([:instance, :birthday_required]) do
+ validate_required(changeset, [:birthday])
+ else
+ changeset
+ end
+ end
+
+ defp validate_min_age(changeset) do
+ changeset
+ |> validate_change(:birthday, fn :birthday, birthday ->
+ valid? =
+ Date.utc_today()
+ |> Date.diff(birthday) >=
+ Config.get([:instance, :birthday_min_age])
+
+ if valid?, do: [], else: [birthday: "Invalid age"]
+ end)
+ end
+
defp put_ap_id(changeset) do
ap_id = ap_id(%User{nickname: get_field(changeset, :nickname)})
put_change(changeset, :ap_id, ap_id)
@@ -2559,4 +2588,13 @@ defmodule Pleroma.User do
_ -> {:error, user}
end
end
+
+ def get_friends_birthdays_query(%User{} = user, day, month) do
+ User.Query.build(%{
+ friends: user,
+ deactivated: false,
+ birthday_day: day,
+ birthday_month: month
+ })
+ end
end
diff --git a/lib/pleroma/user/query.ex b/lib/pleroma/user/query.ex
index bf78cb32d..dddfe07bf 100644
--- a/lib/pleroma/user/query.ex
+++ b/lib/pleroma/user/query.ex
@@ -59,7 +59,9 @@ defmodule Pleroma.User.Query do
order_by: term(),
select: term(),
limit: pos_integer(),
- actor_types: [String.t()]
+ actor_types: [String.t()],
+ birthday_day: pos_integer(),
+ birthday_month: pos_integer()
}
| map()
@@ -230,6 +232,20 @@ defmodule Pleroma.User.Query do
|> where([u], not like(u.nickname, "internal.%"))
end
+ defp compose_query({:birthday_day, day}, query) do
+ query
+ |> where([u], u.hide_birthday == false)
+ |> where([u], not is_nil(u.birthday))
+ |> where([u], fragment("date_part('day', ?)", u.birthday) == ^day)
+ end
+
+ defp compose_query({:birthday_month, month}, query) do
+ query
+ |> where([u], u.hide_birthday == false)
+ |> where([u], not is_nil(u.birthday))
+ |> where([u], fragment("date_part('month', ?)", u.birthday) == ^month)
+ end
+
defp compose_query(_unsupported_param, query), do: query
defp location_query(query, local) do
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
index 9ca44c532..7551dd56d 100644
--- a/lib/pleroma/web/activity_pub/activity_pub.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub.ex
@@ -1501,6 +1501,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
nil
end
+ birthday =
+ if is_binary(data["vcard:bday"]) do
+ case Date.from_iso8601(data["vcard:bday"]) do
+ {:ok, date} -> date
+ {:error, _} -> nil
+ end
+ else
+ nil
+ end
+
user_data = %{
ap_id: data["id"],
uri: get_actor_url(data["url"]),
@@ -1523,7 +1533,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
inbox: data["inbox"],
shared_inbox: shared_inbox,
accepts_chat_messages: accepts_chat_messages,
- pinned_objects: pinned_objects
+ pinned_objects: pinned_objects,
+ birthday: birthday
}
# nickname can be nil because of virtual actors
diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex
index 344da19d3..8ab516214 100644
--- a/lib/pleroma/web/activity_pub/views/user_view.ex
+++ b/lib/pleroma/web/activity_pub/views/user_view.ex
@@ -92,6 +92,11 @@ defmodule Pleroma.Web.ActivityPub.UserView do
%{}
end
+ birthday =
+ if !user.hide_birthday,
+ do: user.birthday,
+ else: nil
+
%{
"id" => user.ap_id,
"type" => user.actor_type,
@@ -116,7 +121,8 @@ defmodule Pleroma.Web.ActivityPub.UserView do
# Note: key name is indeed "discoverable" (not an error)
"discoverable" => user.is_discoverable,
"capabilities" => capabilities,
- "alsoKnownAs" => user.also_known_as
+ "alsoKnownAs" => user.also_known_as,
+ "vcard:bday" => birthday
}
|> Map.merge(maybe_make_image(&User.avatar_url/2, "icon", user))
|> Map.merge(maybe_make_image(&User.banner_url/2, "image", user))
diff --git a/lib/pleroma/web/api_spec/operations/account_operation.ex b/lib/pleroma/web/api_spec/operations/account_operation.ex
index 768d3c720..1b2bffa3e 100644
--- a/lib/pleroma/web/api_spec/operations/account_operation.ex
+++ b/lib/pleroma/web/api_spec/operations/account_operation.ex
@@ -543,6 +543,12 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
type: :string,
nullable: true,
description: "Invite token required when the registrations aren't public"
+ },
+ birthday: %Schema{
+ type: :string,
+ nullable: true,
+ description: "User's birthday",
+ format: :date
}
},
example: %{
@@ -720,7 +726,18 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
description:
"Discovery (listing, indexing) of this account by external services (search bots etc.) is allowed."
},
- actor_type: ActorType
+ actor_type: ActorType,
+ birthday: %Schema{
+ type: :string,
+ nullable: true,
+ description: "User's birthday",
+ format: :date
+ },
+ hide_birthday: %Schema{
+ allOf: [BooleanLike],
+ nullable: true,
+ description: "User's birthday will be hidden"
+ }
},
example: %{
bot: false,
@@ -740,7 +757,9 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
allow_following_move: false,
also_known_as: ["https://foo.bar/users/foo"],
discoverable: false,
- actor_type: "Person"
+ actor_type: "Person",
+ hide_birthday: true,
+ birthday: "2001-02-12"
}
}
end
diff --git a/lib/pleroma/web/api_spec/operations/pleroma_account_operation.ex b/lib/pleroma/web/api_spec/operations/pleroma_account_operation.ex
index ed0db173e..23201a4ba 100644
--- a/lib/pleroma/web/api_spec/operations/pleroma_account_operation.ex
+++ b/lib/pleroma/web/api_spec/operations/pleroma_account_operation.ex
@@ -4,6 +4,7 @@
defmodule Pleroma.Web.ApiSpec.PleromaAccountOperation do
alias OpenApiSpex.Operation
+ alias OpenApiSpex.Schema
alias Pleroma.Web.ApiSpec.AccountOperation
alias Pleroma.Web.ApiSpec.Schemas.AccountRelationship
alias Pleroma.Web.ApiSpec.Schemas.ApiError
@@ -112,6 +113,34 @@ defmodule Pleroma.Web.ApiSpec.PleromaAccountOperation do
}
end
+ def birthdays_operation do
+ %Operation{
+ tags: ["Retrieve account information"],
+ summary: "Birthday reminders",
+ description: "Birthday reminders about users you follow.",
+ operationId: "PleromaAPI.AccountController.birthdays",
+ parameters: [
+ Operation.parameter(
+ :day,
+ :query,
+ %Schema{type: :integer},
+ "Day of users' birthdays"
+ ),
+ Operation.parameter(
+ :month,
+ :query,
+ %Schema{type: :integer},
+ "Month of users' birthdays"
+ )
+ ],
+ security: [%{"oAuth" => ["read:accounts"]}],
+ responses: %{
+ 200 =>
+ Operation.response("Accounts", "application/json", AccountOperation.array_of_accounts())
+ }
+ }
+ end
+
defp id_param do
Operation.parameter(:id, :path, FlakeID, "Account ID",
example: "9umDrYheeY451cQnEe",
diff --git a/lib/pleroma/web/api_spec/schemas/account.ex b/lib/pleroma/web/api_spec/schemas/account.ex
index 548e70544..2113f0d31 100644
--- a/lib/pleroma/web/api_spec/schemas/account.ex
+++ b/lib/pleroma/web/api_spec/schemas/account.ex
@@ -47,12 +47,14 @@ 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},
+ birthday: %Schema{type: :string, nullable: true, format: :date},
chat_token: %Schema{type: :string},
is_confirmed: %Schema{
type: :boolean,
description:
"whether the user account is waiting on email confirmation to be activated"
},
+ hide_birthday: %Schema{type: :boolean, nullable: true},
hide_favorites: %Schema{type: :boolean},
hide_followers_count: %Schema{
type: :boolean,
@@ -202,7 +204,8 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
},
"settings_store" => %{
"pleroma-fe" => %{}
- }
+ },
+ "birthday" => "2001-02-12"
},
"source" => %{
"fields" => [],
diff --git a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex
index a90833bf0..60c9f7d69 100644
--- a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex
+++ b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex
@@ -191,7 +191,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
:skip_thread_containment,
:allow_following_move,
:also_known_as,
- :accepts_chat_messages
+ :accepts_chat_messages,
+ :hide_birthday
]
|> Enum.reduce(%{}, fn key, acc ->
Maps.put_if_present(acc, key, params[key], &{:ok, Params.truthy_param?(&1)})
@@ -219,6 +220,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
|> Maps.put_if_present(:is_locked, params[:locked])
# Note: param name is indeed :discoverable (not an error)
|> Maps.put_if_present(:is_discoverable, params[:discoverable])
+ |> Maps.put_if_present(:birthday, params[:birthday])
# What happens here:
#
diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex
index b964fdc54..e0137a112 100644
--- a/lib/pleroma/web/mastodon_api/views/account_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/account_view.ex
@@ -297,7 +297,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
skip_thread_containment: user.skip_thread_containment,
background_image: image_url(user.background) |> MediaProxy.url(),
accepts_chat_messages: user.accepts_chat_messages,
- favicon: favicon
+ favicon: favicon,
+ birthday: user.birthday,
+ hide_birthday: user.hide_birthday
}
}
|> maybe_put_role(user, opts[:for])
@@ -311,6 +313,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|> maybe_put_unread_conversation_count(user, opts[:for])
|> maybe_put_unread_notification_count(user, opts[:for])
|> maybe_put_email_address(user, opts[:for])
+ |> maybe_hide_birthday(user, opts[:for])
end
defp username_from_nickname(string) when is_binary(string) do
@@ -432,6 +435,24 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
defp maybe_put_email_address(data, _, _), do: data
+ defp maybe_hide_birthday(data, %User{id: user_id}, %User{id: user_id}) do
+ data
+ end
+
+ defp maybe_hide_birthday(data, %User{hide_birthday: true}, _) do
+ data
+ |> Kernel.pop_in([:pleroma, :birthday])
+ |> elem(1)
+ |> Kernel.pop_in([:pleroma, :hide_birthday])
+ |> elem(1)
+ end
+
+ defp maybe_hide_birthday(data, _, _) do
+ data
+ |> Kernel.pop_in([:pleroma, :hide_birthday])
+ |> elem(1)
+ end
+
defp image_url(%{"url" => [%{"href" => href} | _]}), do: href
defp image_url(_), do: nil
end
diff --git a/lib/pleroma/web/mastodon_api/views/instance_view.ex b/lib/pleroma/web/mastodon_api/views/instance_view.ex
index cbed5fba9..fa6c20a30 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]),
+ birthday_required: Config.get([:instance, :birthday_required]),
+ birthday_min_age: Config.get([:instance, :birthday_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 66a8d1c1c..20697fa46 100644
--- a/lib/pleroma/web/pleroma_api/controllers/account_controller.ex
+++ b/lib/pleroma/web/pleroma_api/controllers/account_controller.ex
@@ -51,6 +51,11 @@ defmodule Pleroma.Web.PleromaAPI.AccountController do
when action == :endorsements
)
+ plug(
+ OAuthScopesPlug,
+ %{scopes: ["read:accounts"]} when action == :birthdays
+ )
+
plug(RateLimiter, [name: :account_confirmation_resend] when action == :confirmation_resend)
plug(
@@ -137,4 +142,18 @@ defmodule Pleroma.Web.PleromaAPI.AccountController do
{:error, message} -> json_response(conn, :forbidden, %{error: message})
end
end
+
+ @doc "GET /api/v1/pleroma/birthday_reminders"
+ def birthdays(%{assigns: %{user: %User{} = user}} = conn, %{day: day, month: month} = _params) do
+ birthdays =
+ User.get_friends_birthdays_query(user, day, month)
+ |> Pleroma.Repo.all()
+
+ conn
+ |> render("index.json",
+ for: user,
+ users: birthdays,
+ as: :user
+ )
+ end
end
diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex
index 67c1a3e5c..2d896fdd4 100644
--- a/lib/pleroma/web/router.ex
+++ b/lib/pleroma/web/router.ex
@@ -448,6 +448,8 @@ defmodule Pleroma.Web.Router do
post("/accounts/:id/subscribe", AccountController, :subscribe)
post("/accounts/:id/unsubscribe", AccountController, :unsubscribe)
+
+ get("/birthday_reminders", AccountController, :birthdays)
end
post("/accounts/confirmation_resend", AccountController, :confirmation_resend)
diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex
index 76ca82d20..aa4dfb145 100644
--- a/lib/pleroma/web/twitter_api/twitter_api.ex
+++ b/lib/pleroma/web/twitter_api/twitter_api.ex
@@ -20,6 +20,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
|> Map.put(:name, Map.get(params, :fullname, params[:username]))
|> Map.put(:password_confirmation, params[:password])
|> Map.put(:registration_reason, params[:reason])
+ |> Map.put(:birthday, params[:birthday])
if Pleroma.Config.get([:instance, :registrations_open]) do
create_user(params, opts)
diff --git a/priv/repo/migrations/29220116183110_add_birth_date_to_users.exs b/priv/repo/migrations/29220116183110_add_birth_date_to_users.exs
new file mode 100644
index 000000000..be0ed2bbc
--- /dev/null
+++ b/priv/repo/migrations/29220116183110_add_birth_date_to_users.exs
@@ -0,0 +1,10 @@
+defmodule Pleroma.Repo.Migrations.AddBirthDateToUsers do
+ use Ecto.Migration
+
+ def change do
+ alter table(:users) do
+ add_if_not_exists(:birthday, :date)
+ add_if_not_exists(:hide_birthday, :boolean, default: false, null: false)
+ end
+ end
+end
diff --git a/priv/static/schemas/litepub-0.1.jsonld b/priv/static/schemas/litepub-0.1.jsonld
index e7722cf72..946099a6e 100644
--- a/priv/static/schemas/litepub-0.1.jsonld
+++ b/priv/static/schemas/litepub-0.1.jsonld
@@ -35,7 +35,8 @@
"alsoKnownAs": {
"@id": "as:alsoKnownAs",
"@type": "@id"
- }
+ },
+ "vcard": "http://www.w3.org/2006/vcard/ns#"
}
]
}
diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs
index 0345a9290..9a902e8b1 100644
--- a/test/pleroma/user_test.exs
+++ b/test/pleroma/user_test.exs
@@ -755,6 +755,54 @@ defmodule Pleroma.UserTest do
end
end
+ describe "user registration, with :birthday_required and :birthday_min_age" do
+ @full_user_data %{
+ bio: "A guy",
+ name: "my name",
+ nickname: "nick",
+ password: "test",
+ password_confirmation: "test",
+ email: "email@example.com"
+ }
+
+ setup do
+ clear_config([:instance, :birthday_required], true)
+ clear_config([:instance, :birthday_min_age], 18 * 365)
+ end
+
+ test "it passes when correct birth date is provided" do
+ today = Date.utc_today()
+ birthday = Date.add(today, -19 * 365)
+
+ params =
+ @full_user_data
+ |> Map.put(:birthday, birthday)
+
+ changeset = User.register_changeset(%User{}, params)
+
+ assert changeset.valid?
+ end
+
+ test "it fails when birth date is not provided" do
+ changeset = User.register_changeset(%User{}, @full_user_data)
+
+ refute changeset.valid?
+ end
+
+ test "it fails when provided invalid birth date" do
+ today = Date.utc_today()
+ birthday = Date.add(today, -17 * 365)
+
+ params =
+ @full_user_data
+ |> Map.put(:birthday, birthday)
+
+ changeset = User.register_changeset(%User{}, params)
+
+ refute changeset.valid?
+ end
+ end
+
describe "get_or_fetch/1" do
test "gets an existing user by nickname" do
user = insert(:user)
diff --git a/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs
index 9b07cd5c2..f272ed1ae 100644
--- a/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs
@@ -1608,6 +1608,60 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
end
end
+ describe "create account with required birth date" do
+ setup %{conn: conn} do
+ clear_config([:instance, :birthday_required], true)
+ clear_config([:instance, :birthday_min_age], 18 * 365)
+
+ app_token = insert(:oauth_token, user: nil)
+
+ conn =
+ conn
+ |> put_req_header("authorization", "Bearer " <> app_token.token)
+ |> put_req_header("content-type", "multipart/form-data")
+
+ [conn: conn]
+ end
+
+ test "creates an account if provided valid birth date", %{conn: conn} do
+ birthday =
+ Date.utc_today()
+ |> Date.add(-19 * 365)
+ |> Date.to_string()
+
+ params = %{
+ username: "mkljczk",
+ email: "mkljczk@example.org",
+ password: "dupa.8",
+ agreement: true,
+ birthday: birthday
+ }
+
+ res =
+ conn
+ |> post("/api/v1/accounts", params)
+
+ assert json_response_and_validate_schema(res, 200)
+ end
+
+ test "returns an error if missing birth date", %{conn: conn} do
+ params = %{
+ username: "mkljczk",
+ email: "mkljczk@example.org",
+ password: "dupa.8",
+ agreement: true
+ }
+
+ res =
+ conn
+ |> post("/api/v1/accounts", params)
+
+ assert json_response_and_validate_schema(res, 400) == %{
+ "error" => "{\"birthday\":[\"can't be blank\"]}"
+ }
+ end
+ end
+
describe "GET /api/v1/accounts/:id/lists - account_lists" do
test "returns lists to which the account belongs" do
%{user: user, conn: conn} = oauth_access(["read:lists"])
diff --git a/test/pleroma/web/mastodon_api/update_credentials_test.exs b/test/pleroma/web/mastodon_api/update_credentials_test.exs
index 1d2027899..5507a77b0 100644
--- a/test/pleroma/web/mastodon_api/update_credentials_test.exs
+++ b/test/pleroma/web/mastodon_api/update_credentials_test.exs
@@ -370,6 +370,26 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
]
end
+ test "updates birth date", %{conn: conn} do
+ res =
+ patch(conn, "/api/v1/accounts/update_credentials", %{
+ "birthday" => "2001-02-12"
+ })
+
+ assert user_data = json_response_and_validate_schema(res, 200)
+ assert user_data["pleroma"]["birthday"] == "2001-02-12"
+ end
+
+ test "updates the user's hide_birthday status", %{conn: conn} do
+ res =
+ patch(conn, "/api/v1/accounts/update_credentials", %{
+ "hide_birthday" => true
+ })
+
+ assert user_data = json_response_and_validate_schema(res, 200)
+ assert user_data["pleroma"]["hide_birthday"] == true
+ end
+
test "emojis in fields labels", %{conn: conn} do
fields = [
%{"name" => ":firefox:", "value" => "is best 2hu"},
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..329813994 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",
+ birthday: 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,
+ birthday: nil,
favicon: nil,
is_confirmed: true,
tags: [],
diff --git a/test/pleroma/web/pleroma_api/controllers/account_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/account_controller_test.exs
index d9aa8ce55..8f3e565ee 100644
--- a/test/pleroma/web/pleroma_api/controllers/account_controller_test.exs
+++ b/test/pleroma/web/pleroma_api/controllers/account_controller_test.exs
@@ -304,4 +304,57 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
assert json_response_and_validate_schema(conn, 404) == %{"error" => "Record not found"}
end
end
+
+ describe "birthday reminders" do
+ test "returns a list of friends having birthday on specified day" do
+ %{user: user, conn: conn} = oauth_access(["read:accounts"])
+
+ %{id: id1} =
+ user1 =
+ insert(:user, %{
+ birthday: "2001-02-12"
+ })
+
+ user2 =
+ insert(:user, %{
+ birthday: "2001-02-14"
+ })
+
+ user3 = insert(:user)
+
+ CommonAPI.follow(user, user1)
+ CommonAPI.follow(user, user2)
+ CommonAPI.follow(user, user3)
+
+ [%{"id" => ^id1}] =
+ conn
+ |> get("/api/v1/pleroma/birthday_reminders?day=12&month=2")
+ |> json_response_and_validate_schema(:ok)
+ end
+
+ test "the list doesn't list friends with hidden birth date" do
+ %{user: user, conn: conn} = oauth_access(["read:accounts"])
+
+ user1 =
+ insert(:user, %{
+ birthday: "2001-02-12",
+ hide_birthday: true
+ })
+
+ %{id: id2} =
+ user2 =
+ insert(:user, %{
+ birthday: "2001-02-12",
+ hide_birthday: false
+ })
+
+ CommonAPI.follow(user, user1)
+ CommonAPI.follow(user, user2)
+
+ [%{"id" => ^id2}] =
+ conn
+ |> get("/api/v1/pleroma/birthday_reminders?day=12&month=2")
+ |> json_response_and_validate_schema(:ok)
+ end
+ end
end