Refactor a bit, include doc count

This commit is contained in:
shamoon 2025-03-26 14:27:52 -07:00
parent 5a834a5eca
commit 186ceaba90
4 changed files with 13 additions and 7 deletions

View File

@ -1,6 +1,7 @@
from django.conf import settings as django_settings
from django.contrib.auth.models import User
from documents.models import Document
from paperless.config import GeneralConfig
@ -26,8 +27,9 @@ def settings(request):
"domain": getattr(django_settings, "PAPERLESS_URL", request.get_host()),
"APP_TITLE": app_title,
"APP_LOGO": app_logo,
"HAS_USERS": User.objects.exclude(
"FIRST_INSTALL": User.objects.exclude(
username__in=["consumer", "AnonymousUser"],
).count()
> 0,
== 0
and Document.objects.count() == 0,
}

View File

@ -15,7 +15,7 @@
{% endblock form_top_content %}
{% block form_content %}
{% if not HAS_USERS %}
{% if FIRST_INSTALL %}
<script type="text/javascript">
// forward to the signup page if no users exist
window.location.href = "{{ signup_url }}";

View File

@ -6,7 +6,7 @@
{% endblock head_title %}
{% block form_top_content %}
{% if HAS_USERS %}
{% if not FIRST_INSTALL %}
<p>
{% blocktrans %}Already have an account? <a href="{{ login_url }}">Sign in</a>{% endblocktrans %}
</p>
@ -14,7 +14,7 @@
{% endblock form_top_content %}
{% block form_content %}
{% if not HAS_USERS %}
{% if FIRST_INSTALL %}
<p>
{% blocktrans %}Note: This is the first user account for this installation and will be granted superuser privileges.{% endblocktrans %}
</p>
@ -49,7 +49,7 @@
{% endblock form_content %}
{% block after_form_content %}
{% if HAS_USERS %}
{% if not FIRST_INSTALL %}
{% load allauth socialaccount %}
{% get_providers as socialaccount_providers %}
{% if socialaccount_providers %}

View File

@ -10,6 +10,7 @@ from django.contrib.auth.models import User
from django.forms import ValidationError
from django.urls import reverse
from documents.models import Document
from paperless.signals import handle_social_account_updated
logger = logging.getLogger("paperless.auth")
@ -24,8 +25,9 @@ class CustomAccountAdapter(DefaultAccountAdapter):
if (
User.objects.exclude(username__in=["consumer", "AnonymousUser"]).count()
== 0
and Document.objects.count() == 0
):
# If there are no users, allow signups
# I.e. a fresh install, allow signups
return True
allow_signups = super().is_open_for_signup(request)
# Override with setting, otherwise default to super.
@ -83,7 +85,9 @@ class CustomAccountAdapter(DefaultAccountAdapter):
if (
User.objects.exclude(username__in=["consumer", "AnonymousUser"]).count()
== 0
and Document.objects.count() == 0
):
# I.e. a fresh install, make the user a superuser
logger.debug(f"Creating initial superuser `{user}`")
user.is_superuser = True
user.is_staff = True