fix(usermanager): generate static images on launch

This commit is contained in:
Julian Lobbes 2022-11-20 21:50:04 +01:00
parent a082af09c3
commit 8e9777353e
4 changed files with 38 additions and 6 deletions

View File

@ -45,6 +45,5 @@ def create_app(test_config=None):
app.add_url_rule('/', endpoint='index')
# TODO create OUs
# TODO create static files
return app

View File

@ -17,6 +17,7 @@ function removeUserFromFormField(username) {
}
}
formField.value = JSON.stringify(newMembersList);
adjustLastMemberButtonState();
};
function addUserToFormField(username) {
@ -24,6 +25,7 @@ function addUserToFormField(username) {
let oldMembersList = JSON.parse(formField.value);
oldMembersList.push(username);
formField.value = JSON.stringify(oldMembersList);
adjustLastMemberButtonState();
};
class MemberEntry extends AbstractUserEntry {
@ -68,9 +70,9 @@ function createRemovedMemberRow(username) {
let newTableDataButton = document.createElement("td");
let newTableButton = document.createElement("button");
newTableButton.type = "button";
newTableButton.className = "toggleMembershipButton btn btn-outline-light";
newTableButton.className = "toggleMembershipButton inProgress btn btn-outline-light";
newTableButton.disabled = true;
newTableButton.textContent = "Being removed...";
newTableButton.textContent = "Will be removed";
newTableDataButton.appendChild(newTableButton);
newTableRow.appendChild(newTableDataButton);
};
@ -101,13 +103,31 @@ function createAddedMemberRow(username) {
let newTableDataButton = document.createElement("td");
let newTableButton = document.createElement("button");
newTableButton.type = "button";
newTableButton.className = "toggleMembershipButton btn btn-outline-light";
newTableButton.className = "toggleMembershipButton inProgress btn btn-outline-light";
newTableButton.disabled = true;
newTableButton.textContent = "Being added...";
newTableButton.textContent = "Will be added";
newTableDataButton.appendChild(newTableButton);
newTableRow.appendChild(newTableDataButton);
};
/**
* If there is only one member in the group member table, disables that member's
* remove button.
* If there is more than one member, activates the removal button.
*/
function adjustLastMemberButtonState() {
memberRows = membersTable.querySelectorAll(".userEntry");
if (memberRows.length == 1) {
memberRows[0].querySelector(".toggleMembershipButton").disabled = true;
} else {
for (let button of membersTable.querySelectorAll(".toggleMembershipButton")) {
if (!button.className.includes("inProgress")) {
button.disabled = false;
}
}
}
}
const membersTable = document.getElementById("groupMembers");
const nonMembersTable = document.getElementById("groupNonMembers");
let memberEntries = new Set();
@ -120,3 +140,4 @@ for (let userEntry of document.body.querySelectorAll(".userEntry")) {
nonMemberEntries.add(new NonMemberEntry(userEntry.id, userEntry));
}
}
adjustLastMemberButtonState();

View File

@ -4,6 +4,8 @@
<div class="row">
<div class="col">
<h1>Editing group: {{ groupname }}</h1>
<p class="text-muted">Add or remove members from <i>{{ groupname }}</i> here. Hit the <kbd>Apply</kbd> button to save your changes.</p>
<p class="text-muted">Note that Groups must always have at least one member.</p>
</div>
</div>
<div class="row">
@ -80,5 +82,5 @@
</form>
</div>
</div>
<script src="{{ url_for('static', filename='js/groupEdit.js') }}"></script>
<script src="{{ url_for('static', filename='js/group_edit.js') }}"></script>
{% endblock content %}

View File

@ -23,6 +23,16 @@ from lumi2.exceptions import InvalidStringFormatException, InvalidImageException
bp = Blueprint('usermanager', __name__)
@bp.before_app_first_request
def _init_static_images():
conn = ldap.get_connection()
users = ldap.get_users(conn)
conn.unbind()
for user in users:
user._generate_static_images()
@bp.route('/')
def index():
"""Home page view."""