🔧 chore(utils.py): refactor setup_superuser and teardown_superuser functions to improve readability and remove unnecessary code duplication
🔧 chore(utils.py): update teardown_superuser function to only remove default superuser if AUTO_LOGIN is set to False
This commit is contained in:
parent
34c624ad82
commit
f060155fe6
1 changed files with 8 additions and 3 deletions
|
|
@ -102,6 +102,9 @@ def get_or_create_super_user(session: Session, username, password, is_default):
|
|||
def setup_superuser(settings_service, session: Session):
|
||||
if settings_service.auth_settings.AUTO_LOGIN:
|
||||
logger.debug("AUTO_LOGIN is set to True. Creating default superuser.")
|
||||
else:
|
||||
# Remove the default superuser if it exists
|
||||
teardown_superuser(settings_service, session)
|
||||
|
||||
username = settings_service.auth_settings.SUPERUSER
|
||||
password = settings_service.auth_settings.SUPERUSER_PASSWORD
|
||||
|
|
@ -132,10 +135,12 @@ def teardown_superuser(settings_service, session):
|
|||
# If AUTO_LOGIN is True, we will remove the default superuser
|
||||
# from the database.
|
||||
|
||||
if settings_service.auth_settings.AUTO_LOGIN:
|
||||
if not settings_service.auth_settings.AUTO_LOGIN:
|
||||
try:
|
||||
logger.debug("AUTO_LOGIN is set to True. Removing default superuser.")
|
||||
username = settings_service.auth_settings.SUPERUSER
|
||||
logger.debug(
|
||||
"AUTO_LOGIN is set to False. Removing default superuser if exists."
|
||||
)
|
||||
username = DEFAULT_SUPERUSER
|
||||
from langflow.services.database.models.user.user import User
|
||||
|
||||
user = session.query(User).filter(User.username == username).first()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue