Veiko Aasa f12e634bc9
users: Delete or move home folder when user is deleted or renamed
On user deletion, user's home folder is also deleted. Admins have an
option to avoid deleting user's home by inactivating the user instead.

This commit also removes user deletion buttons from the user's list
page and adds this option to the user edit page. The user's edit form
asks for a confirmation if the user deletion is requested. This change
also means that the confirmation password is now required to delete a user.

Also:
  - Add a simple username validation to the privileged actions.
  - Functional tests: Create a fixture to login as an admin before every test.
  - Functional tests: Add a test to check that SSH passwordless login works
    after user is renamed to validate correct SSH related path permissions.
  - Privileged tests: Add `test_` prefix to the generated random string which
    makes easier to check and cleanup created home folders.
  - Minor quote fixes.

Tests performed in stable and testing containers:
  - Run all the users module tests twice, no failures in tests.
  - When user is the last admin, both "Active" and "Delete user"
    checkboxes are disabled.

Closes #2451.

[sunil]

- Refactor the JS code:

  - Ensure that DOM elements are lookup after DOM content is loaded.

  - Styling changes. Reduce the number of globals, name the global names
  somewhat more unique.

  - Click the button instead of submitting the form to disable the button.

- Template changes:

  - Add a body for the confirmation dialog to talk about disabling the user and
  deleting the home directory.

  - Change the label of the confirm button to make it more
  explicit (recommendation from many UX guides).

  - Styling.

- Functional tests:

  - Fix visibility checking of an element to use the correct splinter API.

  - Simplify clicking the edit user link.

- Minor update to form checkbox help text.

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2024-10-23 21:13:25 -07:00

73 lines
2.1 KiB
HTML

{% extends "base.html" %}
{% comment %}
# SPDX-License-Identifier: AGPL-3.0-or-later
{% endcomment %}
{% load bootstrap %}
{% load i18n %}
{% load static %}
{% block content %}
<h3>
{% blocktrans trimmed with username=object.username %}
Edit User <em>{{ username }}</em>
{% endblocktrans %}
</h3>
<p>
{% url 'users:change_password' object.username as change_password_url %}
{% blocktrans trimmed %}
Use the <a href='{{ change_password_url }}'>change password form
</a> to change the password.
{% endblocktrans %}
</p>
<form class="form form-update" method="post">
{% csrf_token %}
{{ form|bootstrap }}
<input type="submit" class="btn btn-primary"
value="{% trans "Save Changes" %}"/>
</form>
<div id="user-delete-confirm-dialog" class="modal" tabindex="-1"
role="dialog">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">
{% blocktrans trimmed with username=object.username %}
Delete user <em>{{ username }}</em> and all the user's files?
{% endblocktrans %}
</h5>
<button type="button" class="close" data-dismiss="modal"
aria-label="{% trans 'Close' %}">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
{% blocktrans trimmed %}
Deleting a user account also removes all the files user's home
directory. If you wish to keep these files, disable the user account
instead.
{% endblocktrans %}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger confirm">
{% trans "Delete user and files" %}
</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">
{% trans "Cancel" %}
</button>
</div>
</div>
</div>
</div>
{% endblock %}
{% block page_js %}
<script type="text/javascript" src="{% static 'users/users.js' %}"></script>
{% endblock %}