field(:follower_count, :integer, default: 0)
field(:following_count, :integer, default: 0)
field(:is_locked, :boolean, default: false)
- field(:confirmation_pending, :boolean, default: false)
+ field(:is_confirmed, :boolean, default: true)
field(:password_reset_pending, :boolean, default: false)
- field(:approval_pending, :boolean, default: false)
+ field(:is_approved, :boolean, default: true)
field(:registration_reason, :string, default: nil)
field(:confirmation_token, :string, default: nil)
field(:default_scope, :string, default: "public")
@spec account_status(User.t()) :: account_status()
def account_status(%User{deactivated: true}), do: :deactivated
def account_status(%User{password_reset_pending: true}), do: :password_reset_pending
- def account_status(%User{local: true, approval_pending: true}), do: :approval_pending
+ def account_status(%User{local: true, is_approved: false}), do: :approval_pending
- def account_status(%User{local: true, confirmation_pending: true}) do
+ def account_status(%User{local: true, is_confirmed: false}) do
if Config.get([:instance, :account_activation_required]) do
:confirmation_pending
else
reason_limit = Config.get([:instance, :registration_reason_length], 500)
params = Map.put_new(params, :accepts_chat_messages, true)
- need_confirmation? =
- if is_nil(opts[:need_confirmation]) do
- Config.get([:instance, :account_activation_required])
+ confirmed? =
+ if is_nil(opts[:confirmed]) do
+ !Config.get([:instance, :account_activation_required])
else
- opts[:need_confirmation]
+ opts[:confirmed]
end
- need_approval? =
- if is_nil(opts[:need_approval]) do
- Config.get([:instance, :account_approval_required])
+ approved? =
+ if is_nil(opts[:approved]) do
+ !Config.get([:instance, :account_approval_required])
else
- opts[:need_approval]
+ opts[:approved]
end
struct
- |> confirmation_changeset(need_confirmation: need_confirmation?)
+ |> confirmation_changeset(set_confirmation: confirmed?)
- |> approval_changeset(need_approval: need_approval?)
+ |> approval_changeset(set_approval: approved?)
|> cast(params, [
:bio,
:raw_bio,
end
end
- def post_register_action(%User{is_approved: true, confirmation_pending: false} = user) do
- def post_register_action(%User{approval_pending: false, is_confirmed: true} = user) do
++ def post_register_action(%User{is_approved: true, is_confirmed: true} = user) do
with {:ok, user} <- autofollow_users(user),
{:ok, _} <- autofollowing_users(user),
{:ok, user} <- set_cache(user),
follower_count: 0,
following_count: 0,
is_locked: false,
- confirmation_pending: false,
+ is_confirmed: true,
password_reset_pending: false,
- approval_pending: false,
+ is_approved: true,
registration_reason: nil,
confirmation_token: nil,
domain_blocks: [],
"local" => user.local,
"roles" => User.roles(user),
"tags" => user.tags || [],
- "confirmation_pending" => user.confirmation_pending,
+ "is_confirmed" => user.is_confirmed,
- "approval_pending" => user.approval_pending,
+ "is_approved" => user.is_approved,
"url" => user.uri || user.ap_id,
"registration_reason" => user.registration_reason,
"actor_type" => user.actor_type
end)
end
- test "sends approval emails when `approval_pending: true`" do
+ test "sends approval emails when `is_approved: false`" do
admin = insert(:user, is_admin: true)
- user = insert(:user, confirmation_pending: true, is_approved: false)
- user = insert(:user, is_confirmed: false, approval_pending: true)
++ user = insert(:user, is_confirmed: false, is_approved: false)
User.confirm(user)
ObanHelpers.perform_all()
end
test "confirming a confirmed user does not trigger post-register actions" do
- user = insert(:user, confirmation_pending: false, is_approved: false)
- user = insert(:user, is_confirmed: true, approval_pending: true)
++ user = insert(:user, is_confirmed: true, is_approved: false)
User.confirm(user)
ObanHelpers.perform_all()
follower_count: 9,
following_count: 9001,
is_locked: true,
- confirmation_pending: true,
+ is_confirmed: false,
password_reset_pending: true,
- approval_pending: true,
+ is_approved: false,
registration_reason: "ahhhhh",
confirmation_token: "qqqq",
domain_blocks: ["lain.com"],
follower_count: 0,
following_count: 0,
is_locked: false,
- confirmation_pending: false,
+ is_confirmed: true,
password_reset_pending: false,
- approval_pending: false,
+ is_approved: true,
registration_reason: nil,
confirmation_token: nil,
domain_blocks: [],
end
test "returns :approval_pending for unapproved user" do
- user = insert(:user, local: true, approval_pending: true)
+ user = insert(:user, local: true, is_approved: false)
assert User.account_status(user) == :approval_pending
- user = insert(:user, local: true, confirmation_pending: true, is_approved: false)
- user = insert(:user, local: true, is_confirmed: false, approval_pending: true)
++ user = insert(:user, local: true, is_confirmed: false, is_approved: false)
assert User.account_status(user) == :approval_pending
end
end
end
test "only unconfirmed users", %{conn: conn} do
- sad_user = insert(:user, nickname: "sadboy", confirmation_pending: true)
- old_user = insert(:user, nickname: "oldboy", confirmation_pending: true)
+ sad_user = insert(:user, nickname: "sadboy", is_confirmed: false)
+ old_user = insert(:user, nickname: "oldboy", is_confirmed: false)
- insert(:user, nickname: "happyboy", approval_pending: false)
+ insert(:user, nickname: "happyboy", is_approved: true)
- insert(:user, confirmation_pending: false)
+ insert(:user, is_confirmed: true)
result =
conn
users =
Enum.map([old_user, sad_user], fn user ->
user_response(user, %{
- "confirmation_pending" => true,
+ "is_confirmed" => false,
- "approval_pending" => false
+ "is_approved" => true
})
end)
|> Enum.sort_by(& &1["nickname"])
"tags" => [],
"avatar" => User.avatar_url(user) |> MediaProxy.url(),
"display_name" => HTML.strip_tags(user.name || user.nickname),
- "confirmation_pending" => false,
+ "is_confirmed" => true,
- "approval_pending" => false,
+ "is_approved" => true,
"url" => user.ap_id,
"registration_reason" => nil,
"actor_type" => "Person"
user = Repo.preload(token_from_db, :user).user
assert user
- refute user.confirmation_pending
+ assert user.is_confirmed
- refute user.approval_pending
+ assert user.is_approved
end
test "registers but does not log in with :account_activation_required", %{conn: conn} do