Birth dates, birthday reminders API, allow instance admins to require minimum age
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
84dcb55b0f
commit
b108b05650
16 changed files with 168 additions and 14 deletions
|
|
@ -1523,7 +1523,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,
|
||||
birth_date: data["vcard:bday"]
|
||||
}
|
||||
|
||||
# nickname can be nil because of virtual actors
|
||||
|
|
|
|||
|
|
@ -92,6 +92,11 @@ defmodule Pleroma.Web.ActivityPub.UserView do
|
|||
%{}
|
||||
end
|
||||
|
||||
birth_date =
|
||||
if !user.hide_birth_date,
|
||||
do: user.birth_date,
|
||||
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" => birth_date
|
||||
}
|
||||
|> Map.merge(maybe_make_image(&User.avatar_url/2, "icon", user))
|
||||
|> Map.merge(maybe_make_image(&User.banner_url/2, "image", user))
|
||||
|
|
|
|||
|
|
@ -543,7 +543,13 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
|||
type: :string,
|
||||
nullable: true,
|
||||
description: "Invite token required when the registrations aren't public"
|
||||
}
|
||||
},
|
||||
birth_date: %Schema{
|
||||
type: :string,
|
||||
nullable: true,
|
||||
description: "User's birth date",
|
||||
format: :date
|
||||
},
|
||||
},
|
||||
example: %{
|
||||
"username" => "cofe",
|
||||
|
|
@ -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,
|
||||
birth_date: %Schema{
|
||||
type: :string,
|
||||
nullable: true,
|
||||
description: "User's birth date",
|
||||
format: :date
|
||||
},
|
||||
hide_birth_date: %Schema{
|
||||
allOf: [BooleanLike],
|
||||
nullable: true,
|
||||
description: "User's birth date 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_birth_date: true,
|
||||
birth_date: "2001-02-12"
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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},
|
||||
birth_date: %Schema{type: :string, 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},
|
||||
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" => %{}
|
||||
}
|
||||
},
|
||||
"birth_date" => "2001-02-12"
|
||||
},
|
||||
"source" => %{
|
||||
"fields" => [],
|
||||
|
|
|
|||
|
|
@ -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_birth_date
|
||||
]
|
||||
|> 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(:birth_date, params[:birth_date])
|
||||
|
||||
# What happens here:
|
||||
#
|
||||
|
|
|
|||
|
|
@ -249,6 +249,11 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
nil
|
||||
end
|
||||
|
||||
birth_date =
|
||||
if !user.hide_birth_date or opts[:for] == user,
|
||||
do: user.birth_date,
|
||||
else: nil
|
||||
|
||||
%{
|
||||
id: to_string(user.id),
|
||||
username: username_from_nickname(user.nickname),
|
||||
|
|
@ -297,7 +302,8 @@ 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,
|
||||
birth_date: birth_date
|
||||
}
|
||||
}
|
||||
|> maybe_put_role(user, opts[:for])
|
||||
|
|
|
|||
|
|
@ -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.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
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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(:birth_date, params[:birth_date])
|
||||
|
||||
if Pleroma.Config.get([:instance, :registrations_open]) do
|
||||
create_user(params, opts)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue