From 8b9413c719e86d445abe50669e7c57af56c4479b Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Tue, 6 Jan 2026 14:25:50 -0500 Subject: [PATCH] backups: Arrange form for adding remote location - Group together related fields with borders. - Display errors on form and fields. Signed-off-by: James Valleroy --- plinth/modules/backups/forms.py | 8 +- .../static/backups_add_remote_repository.js | 4 +- .../backups_add_remote_repository.html | 177 +++++++++++++++--- .../modules/backups/tests/test_functional.py | 4 +- 4 files changed, 157 insertions(+), 36 deletions(-) diff --git a/plinth/modules/backups/forms.py b/plinth/modules/backups/forms.py index 3ccb62956..e118b7eeb 100644 --- a/plinth/modules/backups/forms.py +++ b/plinth/modules/backups/forms.py @@ -184,7 +184,7 @@ class EncryptedBackupsMixin(forms.Form): choices=[('repokey', _('Key in Repository')), ('none', _('None'))]) encryption_passphrase = forms.CharField( label=_('Passphrase'), - help_text=_('Passphrase; Only needed when using encryption.'), + help_text=_('Only needed when using encryption.'), widget=forms.PasswordInput(), required=False) confirm_encryption_passphrase = forms.CharField( label=_('Confirm Passphrase'), help_text=_('Repeat the passphrase.'), @@ -264,9 +264,9 @@ class AddRemoteRepositoryForm(EncryptedBackupsMixin, forms.Form): ('password_auth', _('Password-based Authentication'))]) ssh_password = forms.CharField( label=_('SSH server password'), widget=forms.PasswordInput(), - strip=True, help_text=_( - 'Password of the SSH Server. Required only for Password-based ' - 'Authentication.'), required=False) + strip=True, + help_text=_('Required only for password-based authentication.'), + required=False) field_order = ['repository', 'ssh_auth_type', 'ssh_password' ] + encryption_fields diff --git a/plinth/modules/backups/static/backups_add_remote_repository.js b/plinth/modules/backups/static/backups_add_remote_repository.js index 3377259e3..720a247e9 100644 --- a/plinth/modules/backups/static/backups_add_remote_repository.js +++ b/plinth/modules/backups/static/backups_add_remote_repository.js @@ -23,8 +23,8 @@ */ document.addEventListener('DOMContentLoaded', () => { - const keyAuth = document.getElementById('id_ssh_auth_type_0'); - const passwordAuth = document.getElementById('id_ssh_auth_type_1'); + const keyAuth = document.getElementById('id_ssh_auth_type_key'); + const passwordAuth = document.getElementById('id_ssh_auth_type_password'); const sshPasswordField = document.getElementById('id_ssh_password'); const encryptionType = document.getElementById('id_encryption'); const encryptionPassphraseField = document.getElementById('id_encryption_passphrase'); diff --git a/plinth/modules/backups/templates/backups_add_remote_repository.html b/plinth/modules/backups/templates/backups_add_remote_repository.html index 939195d3c..79754d225 100644 --- a/plinth/modules/backups/templates/backups_add_remote_repository.html +++ b/plinth/modules/backups/templates/backups_add_remote_repository.html @@ -17,36 +17,157 @@

{{ title }}

+ {% if form.non_field_errors %} +
+ × + {% for non_field_error in form.non_field_errors %} + {{ non_field_error }} + {% endfor %} +
+ {% endif %} + {% csrf_token %} -
-
-

{% trans "SSH Client Authentication Key"%}

-

- {% blocktrans trimmed %} - {{ box_name }} service has the following SSH client public key: - {% endblocktrans %} -

-
{{ ssh_client_public_key }}
-

- {% blocktrans trimmed %} - If this public key is added to the authorized keys list on the remote - machine, then SSH key authentication will be used instead of - password-based authentication. - {% endblocktrans %} -

-

- {% blocktrans trimmed %} - Otherwise, {{ box_name }} service will attempt to connect using the - password provided in the form below. If successful, then the public - key will be automatically added to the authorized keys list, so that - future connections do not need the password. - {% endblocktrans %} -

+
+ +
+ + {% for error in form.repository.errors %} + {{ error }} + {% endfor %} +

+ {{ form.repository.help_text|safe }} +

+
-
- {{ form|bootstrap }} +
+

{{ form.ssh_auth_type.label }}

+

+ {{ form.ssh_auth_type.help_text|safe }} +

+ {% for error in form.ssh_auth_type.errors %} + {{ error }} + {% endfor %} +
+
+ +
+ +
+

+ {% blocktrans trimmed %} + {{ box_name }} service has the following SSH client public key: + {% endblocktrans %} +

+
{{ ssh_client_public_key }}
+

+ {% blocktrans trimmed %} + The public key must be added to the authorized keys list on the + remote machine. + {% endblocktrans %} +

+
+
+ +
+
+ +
+ +

+ {% blocktrans trimmed %} + {{ box_name }} service will attempt to connect using the provided + password. If successful, then the public key will be automatically + added to the authorized keys list, so that future connections do + not need the password. + {% endblocktrans %} +

+ +
+ +
+ + {% for error in form.ssh_password.errors %} + {{ error }} + {% endfor %} +

+ {{ form.ssh_password.help_text|safe }} +

+
+
+
+
+ +
+
+ +
+ + {% for error in form.encryption.errors %} + {{ error }} + {% endfor %} +

+ {{ form.encryption.help_text|safe }} +

+
+
+ +
+ +
+ + {% for error in form.encryption_passphrase.errors %} + {{ error }} + {% endfor %} +

+ {{ form.encryption_passphrase.help_text|safe }} +

+
+
+ +
+ +
+ + {% for error in form.confirm_encryption_passphrase.errors %} + {{ error }} + {% endfor %} +

+ {{ form.confirm_encryption_passphrase.help_text|safe }} +

+
+
+
diff --git a/plinth/modules/backups/tests/test_functional.py b/plinth/modules/backups/tests/test_functional.py index 2747bf074..c268a35ce 100644 --- a/plinth/modules/backups/tests/test_functional.py +++ b/plinth/modules/backups/tests/test_functional.py @@ -232,10 +232,10 @@ def _add_remote_backup_location(browser, ssh_use_password=True): password = functional.get_password( functional.config['DEFAULT']['username']) if ssh_use_password: - browser.find_by_id('id_ssh_auth_type_1').first.check() + browser.find_by_id('id_ssh_auth_type_password').first.check() browser.find_by_name('ssh_password').fill(password) else: - browser.find_by_id('id_ssh_auth_type_0').first.check() + browser.find_by_id('id_ssh_auth_type_key').first.check() browser.choose('id_encryption', 'repokey') browser.find_by_name('encryption_passphrase').fill(password)