mirror of
https://github.com/YunoHost-Apps/django_example_ynh.git
synced 2024-09-03 18:26:21 +02:00
Add '__ADMIN_EMAIL__' to config_panel.toml settings
This commit is contained in:
parent
9b4805a56d
commit
768ed7f24a
8 changed files with 41 additions and 10 deletions
|
@ -11,6 +11,8 @@
|
|||
|
||||
from pathlib import Path as __Path
|
||||
|
||||
from django.core.validators import EmailValidator as __EmailValidator
|
||||
|
||||
from django_yunohost_integration.base_settings import * # noqa
|
||||
from django_yunohost_integration.secret_key import get_or_create_secret as __get_or_create_secret
|
||||
|
||||
|
@ -32,8 +34,9 @@ PATH_URL = PATH_URL.strip('/')
|
|||
|
||||
DEBUG_ENABLED = '__DEBUG_ENABLED__'
|
||||
LOG_LEVEL = '__LOG_LEVEL__'
|
||||
|
||||
ADMIN_EMAIL = '__ADMIN_EMAIL__'
|
||||
# -----------------------------------------------------------------------------
|
||||
# Use/convert/validate config_panel.toml settings:
|
||||
|
||||
DEBUG = bool(int(DEBUG_ENABLED))
|
||||
assert LOG_LEVEL in (
|
||||
|
@ -43,6 +46,7 @@ assert LOG_LEVEL in (
|
|||
'ERROR',
|
||||
'CRITICAL',
|
||||
), f'Invalid LOG_LEVEL: {LOG_LEVEL!r}'
|
||||
__EmailValidator(message='ADMIN_EMAIL from config panel is not valid!')(ADMIN_EMAIL)
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
|
@ -56,7 +60,7 @@ SECRET_KEY = __get_or_create_secret(FINALPATH / 'secret.txt') # /opt/yunohost/$
|
|||
# -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
ADMINS = (('__ADMIN__', '__ADMINMAIL__'),)
|
||||
ADMINS = (('__ADMIN__', ADMIN_EMAIL),)
|
||||
|
||||
MANAGERS = ADMINS
|
||||
|
||||
|
@ -87,7 +91,7 @@ SERVER_EMAIL = 'noreply@__DOMAIN__'
|
|||
|
||||
# Default email address to use for various automated correspondence from
|
||||
# the site managers. Used for registration emails.
|
||||
DEFAULT_FROM_EMAIL = '__ADMINMAIL__'
|
||||
DEFAULT_FROM_EMAIL = ADMIN_EMAIL
|
||||
|
||||
# List of URLs your site is supposed to serve
|
||||
ALLOWED_HOSTS = ['__DOMAIN__']
|
||||
|
|
|
@ -7,6 +7,13 @@ services = ["__APP__"]
|
|||
[main.config]
|
||||
name = "Configuration Options"
|
||||
|
||||
[main.config.admin_email]
|
||||
ask = "ADMIN email"
|
||||
type = "string"
|
||||
help = "EMail address for error emails."
|
||||
default = "root@localhost"
|
||||
bind = "admin_email:__FINALPATH__/settings.py"
|
||||
|
||||
[main.config.debug_enabled]
|
||||
ask = "DEBUG mode"
|
||||
type = "boolean"
|
||||
|
|
|
@ -21,6 +21,9 @@ debug_enabled="0"
|
|||
# 'log_level' -> '__LOG_LEVEL__' -> settings.LOG_LEVEL
|
||||
log_level="WARNING"
|
||||
|
||||
# 'admin_email' -> '__ADMIN_EMAIL__' add in settings.ADMINS
|
||||
admin_email="${admin}@${domain}"
|
||||
|
||||
#=================================================
|
||||
# SET CONSTANTS
|
||||
#=================================================
|
||||
|
@ -30,8 +33,6 @@ final_path=/opt/yunohost/$app
|
|||
log_path=/var/log/$app
|
||||
log_file="${log_path}/django_example_ynh.log"
|
||||
|
||||
adminmail=$(ynh_user_get_info --username=$admin --key=mail)
|
||||
|
||||
#=================================================
|
||||
# COMMON VARIABLES
|
||||
#=================================================
|
||||
|
|
|
@ -31,9 +31,15 @@ log_path=$(ynh_app_setting_get --app="$app" --key=log_path)
|
|||
|
||||
port=$(ynh_app_setting_get --app="$app" --key=port)
|
||||
db_pwd=$(ynh_app_setting_get --app="$app" --key=psqlpwd)
|
||||
admin_mail=$(ynh_user_get_info "$admin" mail)
|
||||
redis_db=$(ynh_app_setting_get --app="$app" --key=redis_db)
|
||||
|
||||
#-------------------------------------------------
|
||||
# config_panel.toml settings:
|
||||
|
||||
debug_enabled=$(ynh_app_setting_get --app="$app" --key=debug_enabled)
|
||||
log_level=$(ynh_app_setting_get --app="$app" --key=log_level)
|
||||
admin_email=$(ynh_app_setting_get --app="$app" --key=admin_email)
|
||||
|
||||
#=================================================
|
||||
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||
#=================================================
|
||||
|
|
|
@ -55,7 +55,6 @@ port=$(ynh_find_port --port=8000)
|
|||
ynh_app_setting_set --app="$app" --key=port --value="$port"
|
||||
|
||||
db_pwd=$(ynh_app_setting_get --app="$app" --key=psqlpwd)
|
||||
admin_mail=$(ynh_user_get_info --username="$admin" --key=mail)
|
||||
|
||||
redis_db=$(ynh_redis_get_free_db)
|
||||
ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db"
|
||||
|
@ -65,6 +64,7 @@ ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db"
|
|||
|
||||
ynh_app_setting_set --app="$app" --key=debug_enabled --value="$debug_enabled"
|
||||
ynh_app_setting_set --app="$app" --key=log_level --value="$log_level"
|
||||
ynh_app_setting_set --app="$app" --key=admin_email --value="$admin_email"
|
||||
|
||||
#=================================================
|
||||
# STANDARD MODIFICATIONS
|
||||
|
@ -167,7 +167,7 @@ cd "$final_path" || exit
|
|||
./manage.py collectstatic --no-input
|
||||
|
||||
# Create/update Django superuser (set unusable password, because auth done via SSOwat):
|
||||
./manage.py create_superuser --username="$admin" --email="$admin_mail"
|
||||
./manage.py create_superuser --username="$admin" --email="$(ynh_user_get_info "$admin" mail)"
|
||||
|
||||
# Check the configuration
|
||||
# This may fail in some cases with errors, etc., but the app works and the user can fix issues later.
|
||||
|
|
|
@ -26,7 +26,6 @@ db_pwd=$(ynh_app_setting_get --app="$app" --key=psqlpwd)
|
|||
db_name=$(ynh_sanitize_dbid --db_name="$app")
|
||||
db_user=$db_name
|
||||
|
||||
admin_mail=$(ynh_user_get_info "$admin" mail)
|
||||
redis_db=$(ynh_app_setting_get --app="$app" --key=redis_db)
|
||||
|
||||
#-------------------------------------------------
|
||||
|
@ -44,6 +43,12 @@ if [ -z "$log_level" ]; then
|
|||
ynh_app_setting_set --app="$app" --key=log_level --value="$log_level"
|
||||
fi
|
||||
|
||||
admin_email=$(ynh_app_setting_get --app="$app" --key=admin_email)
|
||||
if [ -z "$admin_email" ]; then
|
||||
admin_email="root@localhost"
|
||||
ynh_app_setting_set --app="$app" --key=admin_email --value="$admin_email"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||
#=================================================
|
||||
|
@ -158,7 +163,7 @@ cd "$final_path" || exit
|
|||
./manage.py collectstatic --no-input
|
||||
|
||||
# Create/update Django superuser (set unusable password, because auth done via SSOwat):
|
||||
./manage.py create_superuser --username="$admin" --email="$admin_mail"
|
||||
./manage.py create_superuser --username="$admin" --email="$(ynh_user_get_info "$admin" mail)"
|
||||
|
||||
# Check the configuration
|
||||
# This may fail in some cases with errors, etc., but the app works and the user can fix issues later.
|
||||
|
|
|
@ -28,6 +28,8 @@ def pytest_configure():
|
|||
runserver=False,
|
||||
extra_replacements={
|
||||
'__DEBUG_ENABLED__': '0',
|
||||
'__LOG_LEVEL__': 'INFO',
|
||||
'__ADMIN_EMAIL__': 'foo-bar@test.tld',
|
||||
},
|
||||
)
|
||||
print('Local test files created here:')
|
||||
|
|
|
@ -27,6 +27,12 @@ class DjangoYnhTestCase(HtmlAssertionMixin, TestCase):
|
|||
|
||||
assert settings.ROOT_URLCONF == 'urls'
|
||||
|
||||
def test_config_panel_settings(self):
|
||||
# config_panel.toml settings, set via tests.conftest.pytest_configure():
|
||||
assert settings.DEBUG_ENABLED == '0' and settings.DEBUG is False
|
||||
assert settings.LOG_LEVEL == 'INFO'
|
||||
assert settings.ADMIN_EMAIL == 'foo-bar@test.tld'
|
||||
|
||||
def test_urls(self):
|
||||
assert reverse('admin:index') == '/app_path/'
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue