Birthdays: birth_date --> birthday

This commit is contained in:
Alex Gleason 2022-01-22 13:21:55 -06:00
parent 74cf0f0355
commit 66e8c6f90f
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
19 changed files with 92 additions and 92 deletions

View file

@ -25,8 +25,8 @@ 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 `birth_date` and `show_birth_date` field in `/api/v1/accounts/update_credentials`.
- Configuration: Add `birth_date_required` and `birth_date_min_age` settings to provide a way to require users to enter their birth date.
- 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

View file

@ -260,8 +260,8 @@
profile_directory: true,
privileged_staff: false,
max_endorsed_users: 20,
birth_date_required: false,
birth_date_min_age: 0
birthday_required: false,
birthday_min_age: 0
config :pleroma, :welcome,
direct_message: [

View file

@ -959,12 +959,12 @@
"Let moderators access sensitive data (e.g. updating user credentials, get password reset token, delete users, index and read private statuses and chats)"
},
%{
key: :birth_date_required,
key: :birthday_required,
type: :boolean,
description: "Require users to provide birth day."
},
%{
key: :birth_date_min_age,
key: :birthday_min_age,
type: :integer,
description:
"Min age for users to create account. Only makes sense if birth date is required."

View file

@ -154,8 +154,8 @@ defmodule Pleroma.User do
field(:pinned_objects, :map, default: %{})
field(:is_suggested, :boolean, default: false)
field(:last_status_at, :naive_datetime)
field(:birth_date, :date)
field(:hide_birth_date, :boolean, default: false)
field(:birthday, :date)
field(:hide_birthday, :boolean, default: false)
embeds_one(
:notification_settings,
@ -473,7 +473,7 @@ def remote_user_changeset(struct \\ %User{local: false}, params) do
:also_known_as,
:accepts_chat_messages,
:pinned_objects,
:birth_date
:birthday
]
)
|> cast(params, [:name], empty_values: [])
@ -535,8 +535,8 @@ def update_changeset(struct, params \\ %{}) do
:actor_type,
:accepts_chat_messages,
:disclose_client,
:birth_date,
:hide_birth_date
:birthday,
:hide_birthday
]
)
|> validate_min_age()
@ -745,7 +745,7 @@ def register_changeset(struct, params \\ %{}, opts \\ []) do
:emoji,
:accepts_chat_messages,
:registration_reason,
:birth_date
:birthday
])
|> validate_required([:name, :nickname, :password, :password_confirmation])
|> validate_confirmation(:password)
@ -767,7 +767,7 @@ def register_changeset(struct, params \\ %{}, opts \\ []) 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_birth_date
|> maybe_validate_required_birthday
|> validate_min_age()
|> put_password_hash
|> put_ap_id()
@ -785,9 +785,9 @@ def maybe_validate_required_email(changeset, _) do
end
end
defp maybe_validate_required_birth_date(changeset) do
if Config.get([:instance, :birth_date_required]) do
validate_required(changeset, [:birth_date])
defp maybe_validate_required_birthday(changeset) do
if Config.get([:instance, :birthday_required]) do
validate_required(changeset, [:birthday])
else
changeset
end
@ -795,13 +795,13 @@ defp maybe_validate_required_birth_date(changeset) do
defp validate_min_age(changeset) do
changeset
|> validate_change(:birth_date, fn :birth_date, birth_date ->
|> validate_change(:birthday, fn :birthday, birthday ->
valid? =
Date.utc_today()
|> Date.diff(birth_date) >=
Config.get([:instance, :birth_date_min_age])
|> Date.diff(birthday) >=
Config.get([:instance, :birthday_min_age])
if valid?, do: [], else: [birth_date: "Invalid birth date"]
if valid?, do: [], else: [birthday: "Invalid age"]
end)
end
@ -2589,8 +2589,8 @@ def get_friends_birthdays_query(%User{} = user, day, month) do
User.Query.build(%{
friends: user,
deactivated: false,
birth_day: day,
birth_month: month
birthday_day: day,
birthday_month: month
})
end
end

View file

@ -60,8 +60,8 @@ defmodule Pleroma.User.Query do
select: term(),
limit: pos_integer(),
actor_types: [String.t()],
birth_day: pos_integer(),
birth_month: pos_integer()
birthday_day: pos_integer(),
birthday_month: pos_integer()
}
| map()
@ -232,18 +232,18 @@ defp compose_query({:internal, false}, query) do
|> where([u], not like(u.nickname, "internal.%"))
end
defp compose_query({:birth_day, day}, query) do
defp compose_query({:birthday_day, day}, query) do
query
|> where([u], u.hide_birth_date == false)
|> where([u], not is_nil(u.birth_date))
|> where([u], fragment("date_part('day', ?)", u.birth_date) == ^day)
|> 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({:birth_month, month}, query) do
defp compose_query({:birthday_month, month}, query) do
query
|> where([u], u.hide_birth_date == false)
|> where([u], not is_nil(u.birth_date))
|> where([u], fragment("date_part('month', ?)", u.birth_date) == ^month)
|> 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

View file

@ -1501,8 +1501,8 @@ defp object_to_user_data(data) do
nil
end
birth_date =
if data["vcard:bday"] do
birthday =
if is_binary(data["vcard:bday"]) do
case Date.from_iso8601(data["vcard:bday"]) do
{:ok, date} -> date
{:error, _} -> nil
@ -1534,7 +1534,7 @@ defp object_to_user_data(data) do
shared_inbox: shared_inbox,
accepts_chat_messages: accepts_chat_messages,
pinned_objects: pinned_objects,
birth_date: birth_date
birthday: birthday
}
# nickname can be nil because of virtual actors

View file

@ -92,9 +92,9 @@ def render("user.json", %{user: user}) do
%{}
end
birth_date =
if !user.hide_birth_date,
do: user.birth_date,
birthday =
if !user.hide_birthday,
do: user.birthday,
else: nil
%{
@ -122,7 +122,7 @@ def render("user.json", %{user: user}) do
"discoverable" => user.is_discoverable,
"capabilities" => capabilities,
"alsoKnownAs" => user.also_known_as,
"vcard:bday" => birth_date
"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))

View file

@ -544,10 +544,10 @@ defp create_request do
nullable: true,
description: "Invite token required when the registrations aren't public"
},
birth_date: %Schema{
birthday: %Schema{
type: :string,
nullable: true,
description: "User's birth date",
description: "User's birthday",
format: :date
}
},
@ -727,16 +727,16 @@ defp update_credentials_request do
"Discovery (listing, indexing) of this account by external services (search bots etc.) is allowed."
},
actor_type: ActorType,
birth_date: %Schema{
birthday: %Schema{
type: :string,
nullable: true,
description: "User's birth date",
description: "User's birthday",
format: :date
},
hide_birth_date: %Schema{
hide_birthday: %Schema{
allOf: [BooleanLike],
nullable: true,
description: "User's birth date will be hidden"
description: "User's birthday will be hidden"
}
},
example: %{
@ -758,8 +758,8 @@ defp update_credentials_request do
also_known_as: ["https://foo.bar/users/foo"],
discoverable: false,
actor_type: "Person",
hide_birth_date: true,
birth_date: "2001-02-12"
hide_birthday: true,
birthday: "2001-02-12"
}
}
end

View file

@ -47,14 +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},
birth_date: %Schema{type: :string, nullable: true, format: :date},
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_birth_date: %Schema{type: :boolean, nullable: true},
hide_birthday: %Schema{type: :boolean, nullable: true},
hide_favorites: %Schema{type: :boolean},
hide_followers_count: %Schema{
type: :boolean,
@ -205,7 +205,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
"settings_store" => %{
"pleroma-fe" => %{}
},
"birth_date" => "2001-02-12"
"birthday" => "2001-02-12"
},
"source" => %{
"fields" => [],

View file

@ -192,7 +192,7 @@ def update_credentials(%{assigns: %{user: user}, body_params: params} = conn, _p
:allow_following_move,
:also_known_as,
:accepts_chat_messages,
:hide_birth_date
:hide_birthday
]
|> Enum.reduce(%{}, fn key, acc ->
Maps.put_if_present(acc, key, params[key], &{:ok, Params.truthy_param?(&1)})
@ -220,7 +220,7 @@ def update_credentials(%{assigns: %{user: user}, body_params: params} = conn, _p
|> 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(:birth_date, params[:birth_date])
|> Maps.put_if_present(:birthday, params[:birthday])
# What happens here:
#

View file

@ -298,8 +298,8 @@ defp do_render("show.json", %{user: user} = opts) do
background_image: image_url(user.background) |> MediaProxy.url(),
accepts_chat_messages: user.accepts_chat_messages,
favicon: favicon,
birth_date: user.birth_date,
hide_birth_date: user.hide_birth_date
birthday: user.birthday,
hide_birthday: user.hide_birthday
}
}
|> maybe_put_role(user, opts[:for])
@ -313,7 +313,7 @@ defp do_render("show.json", %{user: user} = opts) 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_birth_date(user, opts[:for])
|> maybe_hide_birthday(user, opts[:for])
end
defp username_from_nickname(string) when is_binary(string) do
@ -435,21 +435,21 @@ defp maybe_put_email_address(data, %User{id: user_id}, %User{id: user_id} = user
defp maybe_put_email_address(data, _, _), do: data
defp maybe_hide_birth_date(data, %User{id: user_id}, %User{id: user_id}) do
defp maybe_hide_birthday(data, %User{id: user_id}, %User{id: user_id}) do
data
end
defp maybe_hide_birth_date(data, %User{hide_birth_date: true}, _) do
defp maybe_hide_birthday(data, %User{hide_birthday: true}, _) do
data
|> Kernel.pop_in([:pleroma, :birth_date])
|> Kernel.pop_in([:pleroma, :birthday])
|> elem(1)
|> Kernel.pop_in([:pleroma, :hide_birth_date])
|> Kernel.pop_in([:pleroma, :hide_birthday])
|> elem(1)
end
defp maybe_hide_birth_date(data, _, _) do
defp maybe_hide_birthday(data, _, _) do
data
|> Kernel.pop_in([:pleroma, :hide_birth_date])
|> Kernel.pop_in([:pleroma, :hide_birthday])
|> elem(1)
end

View file

@ -47,8 +47,8 @@ def render("show.json", _) do
fields_limits: fields_limits(),
post_formats: Config.get([:instance, :allowed_post_formats]),
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])
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)

View file

@ -20,7 +20,7 @@ def register_user(params, opts \\ []) do
|> Map.put(:name, Map.get(params, :fullname, params[:username]))
|> Map.put(:password_confirmation, params[:password])
|> Map.put(:registration_reason, params[:reason])
|> Map.put(:birth_date, params[:birth_date])
|> Map.put(:birthday, params[:birthday])
if Pleroma.Config.get([:instance, :registrations_open]) do
create_user(params, opts)

View file

@ -3,8 +3,8 @@ defmodule Pleroma.Repo.Migrations.AddBirthDateToUsers do
def change do
alter table(:users) do
add_if_not_exists(:birth_date, :date)
add_if_not_exists(:hide_birth_date, :boolean, default: false, null: false)
add_if_not_exists(:birthday, :date)
add_if_not_exists(:hide_birthday, :boolean, default: false, null: false)
end
end
end

View file

@ -755,7 +755,7 @@ test "it restricts length of registration reason" do
end
end
describe "user registration, with :birth_date_required and :birth_date_min_age" do
describe "user registration, with :birthday_required and :birthday_min_age" do
@full_user_data %{
bio: "A guy",
name: "my name",
@ -766,17 +766,17 @@ test "it restricts length of registration reason" do
}
setup do
clear_config([:instance, :birth_date_required], true)
clear_config([:instance, :birth_date_min_age], 18 * 365)
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()
birth_date = Date.add(today, -19 * 365)
birthday = Date.add(today, -19 * 365)
params =
@full_user_data
|> Map.put(:birth_date, birth_date)
|> Map.put(:birthday, birthday)
changeset = User.register_changeset(%User{}, params)
@ -791,11 +791,11 @@ test "it fails when birth date is not provided" do
test "it fails when provided invalid birth date" do
today = Date.utc_today()
birth_date = Date.add(today, -17 * 365)
birthday = Date.add(today, -17 * 365)
params =
@full_user_data
|> Map.put(:birth_date, birth_date)
|> Map.put(:birthday, birthday)
changeset = User.register_changeset(%User{}, params)

View file

@ -1588,8 +1588,8 @@ test "returns an error if captcha is invalid", %{conn: conn} do
describe "create account with required birth date" do
setup %{conn: conn} do
clear_config([:instance, :birth_date_required], true)
clear_config([:instance, :birth_date_min_age], 18 * 365)
clear_config([:instance, :birthday_required], true)
clear_config([:instance, :birthday_min_age], 18 * 365)
app_token = insert(:oauth_token, user: nil)
@ -1602,7 +1602,7 @@ test "returns an error if captcha is invalid", %{conn: conn} do
end
test "creates an account if provided valid birth date", %{conn: conn} do
birth_date =
birthday =
Date.utc_today()
|> Date.add(-19 * 365)
|> Date.to_string()
@ -1612,7 +1612,7 @@ test "creates an account if provided valid birth date", %{conn: conn} do
email: "mkljczk@example.org",
password: "dupa.8",
agreement: true,
birth_date: birth_date
birthday: birthday
}
res =
@ -1635,7 +1635,7 @@ test "returns an error if missing birth date", %{conn: conn} do
|> post("/api/v1/accounts", params)
assert json_response_and_validate_schema(res, 400) == %{
"error" => "{\"birth_date\":[\"can't be blank\"]}"
"error" => "{\"birthday\":[\"can't be blank\"]}"
}
end
end

View file

@ -370,24 +370,24 @@ test "update fields", %{conn: conn} do
]
end
test "updates birth date", %{conn: conn, user: user} do
test "updates birth date", %{conn: conn} do
res =
patch(conn, "/api/v1/accounts/update_credentials", %{
"birth_date" => "2001-02-12"
"birthday" => "2001-02-12"
})
assert user_data = json_response_and_validate_schema(res, 200)
assert user_data["pleroma"]["birth_date"] == "2001-02-12"
assert user_data["pleroma"]["birthday"] == "2001-02-12"
end
test "updates the user's hide_birth_date status", %{conn: conn} do
test "updates the user's hide_birthday status", %{conn: conn} do
res =
patch(conn, "/api/v1/accounts/update_credentials", %{
"hide_birth_date" => true
"hide_birthday" => true
})
assert user_data = json_response_and_validate_schema(res, 200)
assert user_data["pleroma"]["hide_birth_date"] == true
assert user_data["pleroma"]["hide_birthday"] == true
end
test "emojis in fields labels", %{conn: conn} do

View file

@ -79,7 +79,7 @@ test "Represent a user account" 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,
birthday: nil,
favicon: nil,
is_confirmed: true,
tags: [],
@ -182,7 +182,7 @@ test "Represent a Service(bot) account" do
ap_id: user.ap_id,
also_known_as: [],
background_image: nil,
birth_date: nil,
birthday: nil,
favicon: nil,
is_confirmed: true,
tags: [],

View file

@ -312,12 +312,12 @@ test "returns a list of friends having birthday on specified day" do
%{id: id1} =
user1 =
insert(:user, %{
birth_date: "2001-02-12"
birthday: "2001-02-12"
})
user2 =
insert(:user, %{
birth_date: "2001-02-14"
birthday: "2001-02-14"
})
user3 = insert(:user)
@ -337,15 +337,15 @@ test "the list doesn't list friends with hidden birth date" do
user1 =
insert(:user, %{
birth_date: "2001-02-12",
hide_birth_date: true
birthday: "2001-02-12",
hide_birthday: true
})
%{id: id2} =
user2 =
insert(:user, %{
birth_date: "2001-02-12",
hide_birth_date: false
birthday: "2001-02-12",
hide_birthday: false
})
CommonAPI.follow(user, user1)