+ error ->
+ Mix.shell().error("Could not create invite token: #{inspect(error)}")
+ end
+ end
+
+ def run(["invites"]) do
+ Common.start_pleroma()
+
+ Mix.shell().info("Invites list:")
+
+ UserInviteToken.list_invites()
+ |> Enum.each(fn invite ->
+ expire_info =
+ with expires_at when not is_nil(expires_at) <- invite.expires_at do
+ " | Expires at: #{Date.to_string(expires_at)}"
+ end
+
+ using_info =
+ with max_use when not is_nil(max_use) <- invite.max_use do
+ " | Max use: #{max_use} Left use: #{max_use - invite.uses}"
+ end
+
+ Mix.shell().info(
+ "ID: #{invite.id} | Token: #{invite.token} | Token type: #{invite.invite_type} | Used: #{
+ invite.used
+ }#{expire_info}#{using_info}"
+ )
+ end)
+ end
+
+ def run(["revoke_invite", token]) do
+ Common.start_pleroma()
+
+ with {:ok, invite} <- UserInviteToken.find_by_token(token),
+ {:ok, _} <- UserInviteToken.update_invite(invite, %{used: true}) do
+ Mix.shell().info("Invite for token #{token} was revoked.")
+ else
+ _ -> Mix.shell().error("No invite found with token #{token}")