Birthdays: hide_birthday -> show_birthday
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
aaa9314f4c
commit
0266bc3c96
@ -28,7 +28,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||||||
- Added `/manifest.json` for progressive web apps.
|
- Added `/manifest.json` for progressive web apps.
|
||||||
- MastoAPI: Support for `birthday` and `show_birthday` field in `/api/v1/accounts/update_credentials`.
|
- 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.
|
- 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
|
- PleromaAPI: Add `GET /api/v1/pleroma/birthdays` API endpoint
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Subscription(Bell) Notifications: Don't create from Pipeline Ingested replies
|
- Subscription(Bell) Notifications: Don't create from Pipeline Ingested replies
|
||||||
|
@ -155,7 +155,7 @@ defmodule Pleroma.User do
|
|||||||
field(:is_suggested, :boolean, default: false)
|
field(:is_suggested, :boolean, default: false)
|
||||||
field(:last_status_at, :naive_datetime)
|
field(:last_status_at, :naive_datetime)
|
||||||
field(:birthday, :date)
|
field(:birthday, :date)
|
||||||
field(:hide_birthday, :boolean, default: false)
|
field(:show_birthday, :boolean, default: false)
|
||||||
|
|
||||||
embeds_one(
|
embeds_one(
|
||||||
:notification_settings,
|
:notification_settings,
|
||||||
@ -473,7 +473,8 @@ defmodule Pleroma.User do
|
|||||||
:also_known_as,
|
:also_known_as,
|
||||||
:accepts_chat_messages,
|
:accepts_chat_messages,
|
||||||
:pinned_objects,
|
:pinned_objects,
|
||||||
:birthday
|
:birthday,
|
||||||
|
:show_birthday
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|> cast(params, [:name], empty_values: [])
|
|> cast(params, [:name], empty_values: [])
|
||||||
@ -536,7 +537,7 @@ defmodule Pleroma.User do
|
|||||||
:accepts_chat_messages,
|
:accepts_chat_messages,
|
||||||
:disclose_client,
|
:disclose_client,
|
||||||
:birthday,
|
:birthday,
|
||||||
:hide_birthday
|
:show_birthday
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|> validate_min_age()
|
|> validate_min_age()
|
||||||
|
@ -234,14 +234,14 @@ defmodule Pleroma.User.Query do
|
|||||||
|
|
||||||
defp compose_query({:birthday_day, day}, query) do
|
defp compose_query({:birthday_day, day}, query) do
|
||||||
query
|
query
|
||||||
|> where([u], u.hide_birthday == false)
|
|> where([u], u.show_birthday == true)
|
||||||
|> where([u], not is_nil(u.birthday))
|
|> where([u], not is_nil(u.birthday))
|
||||||
|> where([u], fragment("date_part('day', ?)", u.birthday) == ^day)
|
|> where([u], fragment("date_part('day', ?)", u.birthday) == ^day)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp compose_query({:birthday_month, month}, query) do
|
defp compose_query({:birthday_month, month}, query) do
|
||||||
query
|
query
|
||||||
|> where([u], u.hide_birthday == false)
|
|> where([u], u.show_birthday == true)
|
||||||
|> where([u], not is_nil(u.birthday))
|
|> where([u], not is_nil(u.birthday))
|
||||||
|> where([u], fragment("date_part('month', ?)", u.birthday) == ^month)
|
|> where([u], fragment("date_part('month', ?)", u.birthday) == ^month)
|
||||||
end
|
end
|
||||||
|
@ -1511,6 +1511,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
show_birthday = !!birthday
|
||||||
|
|
||||||
user_data = %{
|
user_data = %{
|
||||||
ap_id: data["id"],
|
ap_id: data["id"],
|
||||||
uri: get_actor_url(data["url"]),
|
uri: get_actor_url(data["url"]),
|
||||||
@ -1534,7 +1536,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||||||
shared_inbox: shared_inbox,
|
shared_inbox: shared_inbox,
|
||||||
accepts_chat_messages: accepts_chat_messages,
|
accepts_chat_messages: accepts_chat_messages,
|
||||||
pinned_objects: pinned_objects,
|
pinned_objects: pinned_objects,
|
||||||
birthday: birthday
|
birthday: birthday,
|
||||||
|
show_birthday: show_birthday
|
||||||
}
|
}
|
||||||
|
|
||||||
# nickname can be nil because of virtual actors
|
# nickname can be nil because of virtual actors
|
||||||
|
@ -93,7 +93,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do
|
|||||||
end
|
end
|
||||||
|
|
||||||
birthday =
|
birthday =
|
||||||
if !user.hide_birthday,
|
if user.show_birthday,
|
||||||
do: user.birthday,
|
do: user.birthday,
|
||||||
else: nil
|
else: nil
|
||||||
|
|
||||||
|
@ -733,10 +733,10 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
|||||||
description: "User's birthday",
|
description: "User's birthday",
|
||||||
format: :date
|
format: :date
|
||||||
},
|
},
|
||||||
hide_birthday: %Schema{
|
show_birthday: %Schema{
|
||||||
allOf: [BooleanLike],
|
allOf: [BooleanLike],
|
||||||
nullable: true,
|
nullable: true,
|
||||||
description: "User's birthday will be hidden"
|
description: "User's birthday will be visible"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
example: %{
|
example: %{
|
||||||
@ -758,7 +758,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
|||||||
also_known_as: ["https://foo.bar/users/foo"],
|
also_known_as: ["https://foo.bar/users/foo"],
|
||||||
discoverable: false,
|
discoverable: false,
|
||||||
actor_type: "Person",
|
actor_type: "Person",
|
||||||
hide_birthday: true,
|
show_birthday: false,
|
||||||
birthday: "2001-02-12"
|
birthday: "2001-02-12"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
|
|||||||
description:
|
description:
|
||||||
"whether the user account is waiting on email confirmation to be activated"
|
"whether the user account is waiting on email confirmation to be activated"
|
||||||
},
|
},
|
||||||
hide_birthday: %Schema{type: :boolean, nullable: true},
|
show_birthday: %Schema{type: :boolean, nullable: true},
|
||||||
hide_favorites: %Schema{type: :boolean},
|
hide_favorites: %Schema{type: :boolean},
|
||||||
hide_followers_count: %Schema{
|
hide_followers_count: %Schema{
|
||||||
type: :boolean,
|
type: :boolean,
|
||||||
|
@ -192,7 +192,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
|
|||||||
:allow_following_move,
|
:allow_following_move,
|
||||||
:also_known_as,
|
:also_known_as,
|
||||||
:accepts_chat_messages,
|
:accepts_chat_messages,
|
||||||
:hide_birthday
|
:show_birthday
|
||||||
]
|
]
|
||||||
|> Enum.reduce(%{}, fn key, acc ->
|
|> Enum.reduce(%{}, fn key, acc ->
|
||||||
Maps.put_if_present(acc, key, params[key], &{:ok, Params.truthy_param?(&1)})
|
Maps.put_if_present(acc, key, params[key], &{:ok, Params.truthy_param?(&1)})
|
||||||
|
@ -298,8 +298,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||||||
background_image: image_url(user.background) |> MediaProxy.url(),
|
background_image: image_url(user.background) |> MediaProxy.url(),
|
||||||
accepts_chat_messages: user.accepts_chat_messages,
|
accepts_chat_messages: user.accepts_chat_messages,
|
||||||
favicon: favicon,
|
favicon: favicon,
|
||||||
birthday: user.birthday,
|
birthday: user.birthday
|
||||||
hide_birthday: user.hide_birthday
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|> maybe_put_role(user, opts[:for])
|
|> maybe_put_role(user, opts[:for])
|
||||||
@ -313,7 +312,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||||||
|> maybe_put_unread_conversation_count(user, opts[:for])
|
|> maybe_put_unread_conversation_count(user, opts[:for])
|
||||||
|> maybe_put_unread_notification_count(user, opts[:for])
|
|> maybe_put_unread_notification_count(user, opts[:for])
|
||||||
|> maybe_put_email_address(user, opts[:for])
|
|> maybe_put_email_address(user, opts[:for])
|
||||||
|> maybe_hide_birthday(user, opts[:for])
|
|> maybe_show_birthday(user, opts[:for])
|
||||||
end
|
end
|
||||||
|
|
||||||
defp username_from_nickname(string) when is_binary(string) do
|
defp username_from_nickname(string) when is_binary(string) do
|
||||||
@ -347,6 +346,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||||||
|> Kernel.put_in([:source, :privacy], user.default_scope)
|
|> Kernel.put_in([:source, :privacy], user.default_scope)
|
||||||
|> Kernel.put_in([:source, :pleroma, :show_role], user.show_role)
|
|> Kernel.put_in([:source, :pleroma, :show_role], user.show_role)
|
||||||
|> Kernel.put_in([:source, :pleroma, :no_rich_text], user.no_rich_text)
|
|> Kernel.put_in([:source, :pleroma, :no_rich_text], user.no_rich_text)
|
||||||
|
|> Kernel.put_in([:source, :pleroma, :show_birthday], user.show_birthday)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp maybe_put_settings(data, _, _, _), do: data
|
defp maybe_put_settings(data, _, _, _), do: data
|
||||||
@ -435,22 +435,18 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||||||
|
|
||||||
defp maybe_put_email_address(data, _, _), do: data
|
defp maybe_put_email_address(data, _, _), do: data
|
||||||
|
|
||||||
defp maybe_hide_birthday(data, %User{id: user_id}, %User{id: user_id}) do
|
defp maybe_show_birthday(data, %User{id: user_id} = user, %User{id: user_id}) do
|
||||||
data
|
data
|
||||||
|
|> Kernel.put_in([:pleroma, :birthday], user.birthday)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp maybe_hide_birthday(data, %User{hide_birthday: true}, _) do
|
defp maybe_show_birthday(data, %User{show_birthday: true} = user, _) do
|
||||||
data
|
data
|
||||||
|> Kernel.pop_in([:pleroma, :birthday])
|
|> Kernel.put_in([:pleroma, :birthday], user.birthday)
|
||||||
|> elem(1)
|
|
||||||
|> Kernel.pop_in([:pleroma, :hide_birthday])
|
|
||||||
|> elem(1)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp maybe_hide_birthday(data, _, _) do
|
defp maybe_show_birthday(data, _, _) do
|
||||||
data
|
data
|
||||||
|> Kernel.pop_in([:pleroma, :hide_birthday])
|
|
||||||
|> elem(1)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp image_url(%{"url" => [%{"href" => href} | _]}), do: href
|
defp image_url(%{"url" => [%{"href" => href} | _]}), do: href
|
||||||
|
@ -143,7 +143,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountController do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc "GET /api/v1/pleroma/birthday_reminders"
|
@doc "GET /api/v1/pleroma/birthdays"
|
||||||
def birthdays(%{assigns: %{user: %User{} = user}} = conn, %{day: day, month: month} = _params) do
|
def birthdays(%{assigns: %{user: %User{} = user}} = conn, %{day: day, month: month} = _params) do
|
||||||
birthdays =
|
birthdays =
|
||||||
User.get_friends_birthdays_query(user, day, month)
|
User.get_friends_birthdays_query(user, day, month)
|
||||||
|
@ -449,7 +449,7 @@ defmodule Pleroma.Web.Router do
|
|||||||
post("/accounts/:id/subscribe", AccountController, :subscribe)
|
post("/accounts/:id/subscribe", AccountController, :subscribe)
|
||||||
post("/accounts/:id/unsubscribe", AccountController, :unsubscribe)
|
post("/accounts/:id/unsubscribe", AccountController, :unsubscribe)
|
||||||
|
|
||||||
get("/birthday_reminders", AccountController, :birthdays)
|
get("/birthdays", AccountController, :birthdays)
|
||||||
end
|
end
|
||||||
|
|
||||||
post("/accounts/confirmation_resend", AccountController, :confirmation_resend)
|
post("/accounts/confirmation_resend", AccountController, :confirmation_resend)
|
||||||
|
@ -4,7 +4,7 @@ defmodule Pleroma.Repo.Migrations.AddBirthDateToUsers do
|
|||||||
def change do
|
def change do
|
||||||
alter table(:users) do
|
alter table(:users) do
|
||||||
add_if_not_exists(:birthday, :date)
|
add_if_not_exists(:birthday, :date)
|
||||||
add_if_not_exists(:hide_birthday, :boolean, default: false, null: false)
|
add_if_not_exists(:show_birthday, :boolean, default: false, null: false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -380,14 +380,14 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
|
|||||||
assert user_data["pleroma"]["birthday"] == "2001-02-12"
|
assert user_data["pleroma"]["birthday"] == "2001-02-12"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "updates the user's hide_birthday status", %{conn: conn} do
|
test "updates the user's show_birthday status", %{conn: conn} do
|
||||||
res =
|
res =
|
||||||
patch(conn, "/api/v1/accounts/update_credentials", %{
|
patch(conn, "/api/v1/accounts/update_credentials", %{
|
||||||
"hide_birthday" => true
|
"show_birthday" => true
|
||||||
})
|
})
|
||||||
|
|
||||||
assert user_data = json_response_and_validate_schema(res, 200)
|
assert user_data = json_response_and_validate_schema(res, 200)
|
||||||
assert user_data["pleroma"]["hide_birthday"] == true
|
assert user_data["pleroma"]["source"]["show_birthday"] == true
|
||||||
end
|
end
|
||||||
|
|
||||||
test "emojis in fields labels", %{conn: conn} do
|
test "emojis in fields labels", %{conn: conn} do
|
||||||
|
@ -312,12 +312,14 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||||||
%{id: id1} =
|
%{id: id1} =
|
||||||
user1 =
|
user1 =
|
||||||
insert(:user, %{
|
insert(:user, %{
|
||||||
birthday: "2001-02-12"
|
birthday: "2001-02-12",
|
||||||
|
show_birthday: true
|
||||||
})
|
})
|
||||||
|
|
||||||
user2 =
|
user2 =
|
||||||
insert(:user, %{
|
insert(:user, %{
|
||||||
birthday: "2001-02-14"
|
birthday: "2001-02-14",
|
||||||
|
show_birthday: true
|
||||||
})
|
})
|
||||||
|
|
||||||
user3 = insert(:user)
|
user3 = insert(:user)
|
||||||
@ -328,7 +330,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||||||
|
|
||||||
[%{"id" => ^id1}] =
|
[%{"id" => ^id1}] =
|
||||||
conn
|
conn
|
||||||
|> get("/api/v1/pleroma/birthday_reminders?day=12&month=2")
|
|> get("/api/v1/pleroma/birthdays?day=12&month=2")
|
||||||
|> json_response_and_validate_schema(:ok)
|
|> json_response_and_validate_schema(:ok)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -338,14 +340,14 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||||||
user1 =
|
user1 =
|
||||||
insert(:user, %{
|
insert(:user, %{
|
||||||
birthday: "2001-02-12",
|
birthday: "2001-02-12",
|
||||||
hide_birthday: true
|
show_birthday: false
|
||||||
})
|
})
|
||||||
|
|
||||||
%{id: id2} =
|
%{id: id2} =
|
||||||
user2 =
|
user2 =
|
||||||
insert(:user, %{
|
insert(:user, %{
|
||||||
birthday: "2001-02-12",
|
birthday: "2001-02-12",
|
||||||
hide_birthday: false
|
show_birthday: true
|
||||||
})
|
})
|
||||||
|
|
||||||
CommonAPI.follow(user, user1)
|
CommonAPI.follow(user, user1)
|
||||||
@ -353,7 +355,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||||||
|
|
||||||
[%{"id" => ^id2}] =
|
[%{"id" => ^id2}] =
|
||||||
conn
|
conn
|
||||||
|> get("/api/v1/pleroma/birthday_reminders?day=12&month=2")
|
|> get("/api/v1/pleroma/birthdays?day=12&month=2")
|
||||||
|> json_response_and_validate_schema(:ok)
|
|> json_response_and_validate_schema(:ok)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user