Compare commits

..

4 Commits

2 changed files with 27 additions and 26 deletions
+17 -16
View File
@@ -1984,7 +1984,7 @@ def _upload_student_cards_excel():
if not current_permissions['actions'].get('can_manage_user', False):
flash('Ihnen fehlen die nötigen Berechtigungen, um diese Aktion auszuführen.', 'error')
return redirect(url_for('library'))
return redirect(url_for('library_view'))
if not cfg.MODULES.is_enabled('student_cards'):
flash('Schülerausweis-Modul ist deaktiviert.', 'error')
@@ -3653,7 +3653,7 @@ def api_library_item_update(item_id):
if not current_permissions['actions'].get('can_edit', False):
flash('Ihnen fehlen die nötigen Berechtigungen, um diese Aktion auszuführen.', 'error')
return redirect(url_for('library'))
return redirect(url_for('library_view'))
if not cfg.MODULES.is_enabled('library'):
return jsonify({'ok': False, 'message': 'Bibliotheks-Modul ist deaktiviert.'}), 403
@@ -3886,7 +3886,7 @@ def student_cards_admin():
if not current_permissions['actions'].get('can_manage_users', False):
flash('Ihnen fehlen die nötigen Berechtigungen, um diese Aktion auszuführen.', 'error')
return redirect(url_for('library'))
return redirect(url_for('library_view'))
if not cfg.MODULES.is_enabled('student_cards'):
flash('Schülerausweis-Modul ist deaktiviert.', 'error')
return redirect(url_for('home_admin'))
@@ -4031,7 +4031,7 @@ def student_cards_print():
if not current_permissions['actions'].get('can_manage_users', False):
flash('Ihnen fehlen die nötigen Berechtigungen, um diese Aktion auszuführen.', 'error')
return redirect(url_for('library'))
return redirect(url_for('library_view'))
if not cfg.MODULES.is_enabled('student_cards'):
flash('Schülerausweis-Modul ist deaktiviert.', 'error')
return redirect(url_for('home_admin'))
@@ -4065,7 +4065,7 @@ def student_card_barcode_print():
if not current_permissions['actions'].get('can_manage_users', False):
flash('Ihnen fehlen die nötigen Berechtigungen, um diese Aktion auszuführen.', 'error')
return redirect(url_for('library'))
return redirect(url_for('library_view'))
if not cfg.MODULES.is_enabled('student_cards'):
flash('Schülerausweis-Modul ist deaktiviert.', 'error')
return redirect(url_for('home_admin'))
@@ -4098,7 +4098,7 @@ def student_card_barcode_download():
if not current_permissions['actions'].get('can_manage_users', False):
flash('Ihnen fehlen die nötigen Berechtigungen, um diese Aktion auszuführen.', 'error')
return redirect(url_for('library'))
return redirect(url_for('library_view'))
if not cfg.MODULES.is_enabled('student_cards'):
flash('Schülerausweis-Modul ist deaktiviert.', 'error')
return redirect(url_for('home_admin'))
@@ -4282,7 +4282,7 @@ def student_card_single_barcode_download(card_id):
if not current_permissions['actions'].get('can_manage_users', False):
flash('Ihnen fehlen die nötigen Berechtigungen, um diese Aktion auszuführen.', 'error')
return redirect(url_for('library'))
return redirect(url_for('library_view'))
if not cfg.MODULES.is_enabled('student_cards'):
flash('Schülerausweis-Modul ist deaktiviert.', 'error')
return redirect(url_for('home_admin'))
@@ -6366,7 +6366,7 @@ def delete_item(id):
if not cfg.MODULES.is_enabled('inventory'):
flash('Bibliotheks-Modul ist deaktiviert.', 'error')
return redirect(url_for('library'))
return redirect(url_for('library_view'))
# Resolve all related item ids (grouped variants) and load their data
group_item_ids = it.get_group_item_ids(id)
@@ -6504,7 +6504,7 @@ def bulk_delete_items():
if not cfg.MODULES.is_enabled('inventory'):
flash('Bibliotheks-Modul ist deaktiviert.', 'error')
return redirect(url_for('library'))
return redirect(url_for('library_view'))
payload = request.get_json(silent=True) or {}
item_ids = payload.get('item_ids') or request.form.getlist('item_ids')
@@ -6569,7 +6569,7 @@ def edit_item(id):
if not cfg.MODULES.is_enabled('inventory'):
flash('Bibliotheks-Modul ist deaktiviert.', 'error')
return redirect(url_for('library'))
return redirect(url_for('library_view'))
# Strip whitespace from all text fields
name = sanitize_form_value(request.form.get('name'))
@@ -6699,7 +6699,7 @@ def update_group():
if not current_permissions['actions'].get('can_edit', False):
flash('Ihnen fehlen die nötigen Berechtigungen, um diese Aktion (Löschen) auszuführen.', 'error')
return redirect(url_for('library'))
return redirect(url_for('library_view'))
data = request.get_json()
series_group_id = data.get('series_group_id')
@@ -7047,9 +7047,10 @@ def ausleihen(id):
if current_permissions['actions'].get('can_borrow') and not is_library_item:
if student_card_id:
student_user = us.get_user_by_student_card(student_card_id)
app.logger.debug(f"Borrowing on behalf of student card {student_card_id}: found user {student_user}")
if not student_user:
flash('Keine Schülerin/kein Schüler mit dieser Ausweis-ID gefunden.', 'error')
return redirect(url_for('library'))
return redirect(url_for('library_view'))
effective_borrower = student_user.get('Username') or student_user.get('username') or username
if borrow_duration_days is None:
try:
@@ -7915,7 +7916,7 @@ def register():
name = (request.form.get('name') or '').strip()
last_name = (request.form.get('last-name') or '').strip()
# Generate a username from the first 2 letters of first and last name.
# Generate a username from the first 3 letters of first and last name.
username = us.build_unique_username_from_name(name, last_name)
permission_preset = (request.form.get('permission_preset') or 'standard_user').strip()
@@ -9086,7 +9087,7 @@ def library_item_invoices(item_id):
if not current_permissions['pages'].get('library_loans_admin', False):
flash('Ihnen fehlen die nötigen Berechtigungen, um diese Aktion auszuführen.', 'error')
return redirect(url_for('library'))
return redirect(url_for('library_view'))
client = None
try:
@@ -9993,7 +9994,7 @@ def fetch_book_info(isbn):
if not current_permissions['actions'].get('can_insert', False):
flash('Ihnen fehlen die nötigen Berechtigungen, um diese Aktion auszuführen.', 'error')
return redirect(url_for('library'))
return redirect(url_for('library_view'))
if not cfg.MODULES.is_enabled('library'):
return jsonify({"error": "Bibliotheks-Modul ist deaktiviert."}), 403
@@ -10044,7 +10045,7 @@ def download_book_cover():
if not current_permissions['actions'].get('can_insert', False):
flash('Ihnen fehlen die nötigen Berechtigungen, um diese Aktion auszuführen.', 'error')
return redirect(url_for('library'))
return redirect(url_for('library_view'))
if not cfg.MODULES.is_enabled('library'):
return jsonify({"error": "Bibliotheks-Modul ist deaktiviert."}), 403
+10 -10
View File
@@ -97,18 +97,18 @@ def build_name_synonym(first_name, last_name=''):
last = _clean_name_fragment(last_name)
if first and last:
return (first[:2] + last[:2]).title()
return (first[:3] + last[:3]).title()
combined = (first + last)
if not combined:
return 'User'
return combined[:4].title()
return combined[:6].title()
def build_username_from_name(first_name, last_name=''):
"""
Build a deterministic username abbreviation from first and last name.
Uses 2 letters from each name and stores it lowercase.
Uses 3 letters from each name and stores it lowercase.
Args:
first_name (str): First name
@@ -123,12 +123,12 @@ def build_username_from_name(first_name, last_name=''):
def build_unique_username_from_name(first_name, last_name=''):
"""
Build a unique username from the first 2 letters of the first name and
the first 2 letters of the last name.
Build a unique username from the first 3 letters of the first name and
the first 3 letters of the last name.
"""
first = _clean_name_fragment(first_name)
last = _clean_name_fragment(last_name)
base_username = (first[:2] + last[:2]).lower()
base_username = (first[:3] + last[:3]).lower()
if not base_username:
base_username = 'user'
@@ -594,8 +594,8 @@ def student_card_exists(student_card_id):
return False
client = MongoClient(cfg.MONGODB_HOST, cfg.MONGODB_PORT)
db = _get_tenant_db(client)
users = db['users']
exists = users.find_one({'StudentCardId': normalized}) is not None
users = db['student_cards']
exists = users.find_one({'SchülerName': normalized}) is not None
client.close()
return exists
@@ -607,8 +607,8 @@ def get_user_by_student_card(student_card_id):
return None
client = MongoClient(cfg.MONGODB_HOST, cfg.MONGODB_PORT)
db = _get_tenant_db(client)
users = db['users']
found_user = users.find_one({'StudentCardId': normalized})
users = db['student_cards']
found_user = users.find_one({'SchülerName': normalized})
client.close()
return found_user