|
|
|
@@ -25,9 +25,10 @@ Features:
|
|
|
|
|
- Booking and reservation of items
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from flask import Flask, render_template, request, redirect, url_for, session, flash, send_from_directory, get_flashed_messages, jsonify, Response, make_response, send_file
|
|
|
|
|
from flask import Flask, render_template, request, redirect, url_for, session, flash, send_from_directory, get_flashed_messages, jsonify, Response, make_response, send_file, abort
|
|
|
|
|
from werkzeug.utils import secure_filename
|
|
|
|
|
from werkzeug.middleware.proxy_fix import ProxyFix
|
|
|
|
|
from jinja2 import TemplateNotFound
|
|
|
|
|
import user as us
|
|
|
|
|
import items as it
|
|
|
|
|
import ausleihung as au
|
|
|
|
@@ -269,40 +270,6 @@ def _get_csrf_token():
|
|
|
|
|
def _is_csrf_exempt_request():
|
|
|
|
|
return request.method in {'GET', 'HEAD', 'OPTIONS', 'TRACE'}
|
|
|
|
|
|
|
|
|
|
def _is_library_module_path(path):
|
|
|
|
|
"""Return True when the current request path belongs to the library module."""
|
|
|
|
|
if not path:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
library_prefixes = (
|
|
|
|
|
'/library',
|
|
|
|
|
'/library_',
|
|
|
|
|
'/student_cards',
|
|
|
|
|
)
|
|
|
|
|
return path.startswith(library_prefixes)
|
|
|
|
|
|
|
|
|
|
def _is_inventory_module_path(path):
|
|
|
|
|
"""Return True when the current request path belongs to the inventory module."""
|
|
|
|
|
if not path:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
if path == '/' or path.startswith('/home'):
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
inventory_prefixes = (
|
|
|
|
|
'/scanner',
|
|
|
|
|
'/inventory',
|
|
|
|
|
'/upload_admin',
|
|
|
|
|
'/manage_filters',
|
|
|
|
|
'/manage_locations',
|
|
|
|
|
'/admin_borrowings',
|
|
|
|
|
'/admin_damaged_items',
|
|
|
|
|
'/admin/borrowings',
|
|
|
|
|
'/admin/damaged_items',
|
|
|
|
|
'/terminplan',
|
|
|
|
|
)
|
|
|
|
|
return path.startswith(inventory_prefixes)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.before_request
|
|
|
|
|
def _enforce_csrf_protection():
|
|
|
|
@@ -387,14 +354,28 @@ def _enforce_active_session_user():
|
|
|
|
|
@app.before_request
|
|
|
|
|
def _enforce_module_access():
|
|
|
|
|
endpoint = request.endpoint or ''
|
|
|
|
|
if endpoint == 'static' or endpoint.startswith('static') or request.path.startswith('/api/'):
|
|
|
|
|
if endpoint == 'static' or endpoint.startswith('static'):
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
if not cfg.LIBRARY_MODULE_ENABLED and _is_library_module_path(request.path):
|
|
|
|
|
return "Bibliotheks-Modul ist deaktiviert.", 403
|
|
|
|
|
|
|
|
|
|
if not cfg.INVENTORY_MODULE_ENABLED and _is_inventory_module_path(request.path):
|
|
|
|
|
return "Inventar-Modul ist deaktiviert.", 403
|
|
|
|
|
for name, matcher in cfg.MODULES._path_matchers.items():
|
|
|
|
|
if matcher(request.path) and not cfg.MODULES.is_enabled(name):
|
|
|
|
|
msg = {
|
|
|
|
|
'library': "Bibliotheks-Modul ist deaktiviert.",
|
|
|
|
|
'inventory': "Inventar-Modul ist deaktiviert.",
|
|
|
|
|
'student_cards': "Schülerausweis-Modul ist deaktiviert."
|
|
|
|
|
}.get(name, f"{name.capitalize()}-Modul ist deaktiviert.")
|
|
|
|
|
|
|
|
|
|
if request.path.startswith('/api/') or request.is_json:
|
|
|
|
|
return jsonify({'ok': False, 'message': msg}), 403
|
|
|
|
|
|
|
|
|
|
flash(msg, 'info')
|
|
|
|
|
|
|
|
|
|
if name != 'inventory' and cfg.MODULES.is_enabled('inventory'):
|
|
|
|
|
return redirect(url_for('home'))
|
|
|
|
|
elif name != 'library' and cfg.MODULES.is_enabled('library'):
|
|
|
|
|
return redirect(url_for('library_view'))
|
|
|
|
|
|
|
|
|
|
return redirect(url_for('my_borrowed_items'))
|
|
|
|
|
|
|
|
|
|
""" -----------------------------------------------------------After Request Handlers----------------------------------------------------------------------------- """
|
|
|
|
|
|
|
|
|
@@ -432,6 +413,26 @@ def _set_security_headers(response):
|
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.errorhandler(TemplateNotFound)
|
|
|
|
|
def handle_template_not_found(e):
|
|
|
|
|
"""Handle missing template files with a 404 response."""
|
|
|
|
|
app.logger.error(f"Template not found: {e.name}")
|
|
|
|
|
if request.is_json or request.path.startswith('/api/'):
|
|
|
|
|
return jsonify({'error': 'Template not found', 'status': 404}), 404
|
|
|
|
|
return abort(404)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.errorhandler(404)
|
|
|
|
|
def handle_not_found(e):
|
|
|
|
|
"""Handle 404 errors with a user-friendly response."""
|
|
|
|
|
app.logger.warning(f"404 Not Found: {request.path}")
|
|
|
|
|
if request.is_json or request.path.startswith('/api/'):
|
|
|
|
|
return jsonify({'error': 'Not found', 'status': 404}), 404
|
|
|
|
|
if 'username' in session:
|
|
|
|
|
return render_template('error.html', error_code=404, error_message='Seite nicht gefunden.'), 404
|
|
|
|
|
return redirect(url_for('login'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _csrf_error_response(message='CSRF token fehlt oder ist ungültig.'):
|
|
|
|
|
if request.is_json or request.path.startswith('/api/') or request.path in {'/download_book_cover', '/proxy_image', '/log_mobile_issue'}:
|
|
|
|
|
return jsonify({'error': message}), 400
|
|
|
|
@@ -440,24 +441,18 @@ def _csrf_error_response(message='CSRF token fehlt oder ist ungültig.'):
|
|
|
|
|
|
|
|
|
|
def _get_current_module(path):
|
|
|
|
|
"""Resolve the active UI module for navbar separation."""
|
|
|
|
|
|
|
|
|
|
if cfg.LIBRARY_MODULE_ENABLED and _is_library_module_path(path):
|
|
|
|
|
session['last_module'] = 'library'
|
|
|
|
|
return 'library'
|
|
|
|
|
if cfg.INVENTORY_MODULE_ENABLED and _is_inventory_module_path(path):
|
|
|
|
|
session['last_module'] = 'inventory'
|
|
|
|
|
return 'inventory'
|
|
|
|
|
mod = cfg.MODULES.get_module_for_path(path)
|
|
|
|
|
if mod:
|
|
|
|
|
session['last_module'] = mod
|
|
|
|
|
return mod
|
|
|
|
|
|
|
|
|
|
last_module = session.get('last_module')
|
|
|
|
|
if last_module == 'library' and cfg.LIBRARY_MODULE_ENABLED:
|
|
|
|
|
return 'library'
|
|
|
|
|
if last_module == 'inventory' and cfg.INVENTORY_MODULE_ENABLED:
|
|
|
|
|
return 'inventory'
|
|
|
|
|
if last_module and cfg.MODULES.is_enabled(last_module):
|
|
|
|
|
return last_module
|
|
|
|
|
|
|
|
|
|
# Default fallback: prefer inventory if enabled, otherwise library, else inventory
|
|
|
|
|
if cfg.INVENTORY_MODULE_ENABLED:
|
|
|
|
|
if cfg.MODULES.is_enabled('inventory'):
|
|
|
|
|
return 'inventory'
|
|
|
|
|
return 'library' if cfg.LIBRARY_MODULE_ENABLED else 'inventory'
|
|
|
|
|
return 'library' if cfg.MODULES.is_enabled('library') else 'inventory'
|
|
|
|
|
|
|
|
|
|
"""---------------------------------------------User Access Permissions----------------------------------------------------------------------------- """
|
|
|
|
|
|
|
|
|
@@ -1063,9 +1058,9 @@ def inject_version():
|
|
|
|
|
'csrf_token': csrf_token,
|
|
|
|
|
'CURRENT_MODULE': current_module,
|
|
|
|
|
'school_periods': SCHOOL_PERIODS,
|
|
|
|
|
'inventory_module_enabled': cfg.INVENTORY_MODULE_ENABLED,
|
|
|
|
|
'library_module_enabled': cfg.LIBRARY_MODULE_ENABLED,
|
|
|
|
|
'student_cards_module_enabled': cfg.STUDENT_CARDS_MODULE_ENABLED,
|
|
|
|
|
'inventory_module_enabled': cfg.MODULES.is_enabled('inventory'),
|
|
|
|
|
'library_module_enabled': cfg.MODULES.is_enabled('library'),
|
|
|
|
|
'student_cards_module_enabled': cfg.MODULES.is_enabled('student_cards'),
|
|
|
|
|
'is_admin': is_admin,
|
|
|
|
|
'unread_notification_count': unread_notification_count,
|
|
|
|
|
'current_permissions': current_permissions,
|
|
|
|
@@ -1750,7 +1745,7 @@ def _upload_student_cards_excel():
|
|
|
|
|
flash('Administratorrechte erforderlich.', 'error')
|
|
|
|
|
return redirect(url_for('home_admin'))
|
|
|
|
|
|
|
|
|
|
if not cfg.STUDENT_CARDS_MODULE_ENABLED:
|
|
|
|
|
if not cfg.MODULES.is_enabled('student_cards'):
|
|
|
|
|
flash('Schülerausweis-Modul ist deaktiviert.', 'error')
|
|
|
|
|
return redirect(url_for('home_admin'))
|
|
|
|
|
|
|
|
|
@@ -1945,7 +1940,7 @@ def _upload_excel_items(scope='inventory'):
|
|
|
|
|
fallback_route = 'library_admin' if is_library_scope else 'upload_admin'
|
|
|
|
|
|
|
|
|
|
if is_library_scope:
|
|
|
|
|
if not cfg.LIBRARY_MODULE_ENABLED:
|
|
|
|
|
if not cfg.MODULES.is_enabled('library'):
|
|
|
|
|
flash('Bibliotheks-Modul ist deaktiviert.', 'error')
|
|
|
|
|
return redirect(url_for('home'))
|
|
|
|
|
|
|
|
|
@@ -2643,8 +2638,8 @@ def home():
|
|
|
|
|
flash('Bitte mit registriertem Konto anmelden!', 'error')
|
|
|
|
|
return redirect(url_for('login'))
|
|
|
|
|
|
|
|
|
|
if not cfg.INVENTORY_MODULE_ENABLED:
|
|
|
|
|
if cfg.LIBRARY_MODULE_ENABLED:
|
|
|
|
|
if not cfg.MODULES.is_enabled('inventory'):
|
|
|
|
|
if cfg.MODULES.is_enabled('library'):
|
|
|
|
|
return redirect(url_for('library_view'))
|
|
|
|
|
else:
|
|
|
|
|
return "Weder Inventar- noch Bibliotheks-Modul sind aktiviert.", 403
|
|
|
|
@@ -2653,10 +2648,11 @@ def home():
|
|
|
|
|
return render_template(
|
|
|
|
|
'main.html',
|
|
|
|
|
username=session['username'],
|
|
|
|
|
library_module_enabled=cfg.LIBRARY_MODULE_ENABLED,
|
|
|
|
|
student_cards_module_enabled=cfg.STUDENT_CARDS_MODULE_ENABLED,
|
|
|
|
|
library_module_enabled=cfg.MODULES.is_enabled('library'),
|
|
|
|
|
student_cards_module_enabled=cfg.MODULES.is_enabled('student_cards'),
|
|
|
|
|
student_default_borrow_days=cfg.STUDENT_DEFAULT_BORROW_DAYS,
|
|
|
|
|
student_max_borrow_days=cfg.STUDENT_MAX_BORROW_DAYS
|
|
|
|
|
student_max_borrow_days=cfg.STUDENT_MAX_BORROW_DAYS,
|
|
|
|
|
open_item=request.args.get('open_item')
|
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
permissions = _get_current_user_permissions() or us.build_default_permission_payload('standard_user')
|
|
|
|
@@ -2682,8 +2678,8 @@ def home_admin():
|
|
|
|
|
flash('Ihnen ist es nicht gestattet auf dieser Internetanwendung, die eben besuchte Adrrese zu nutzen, versuchen sie es erneut nach dem sie sich mit einem berechtigten Nutzer angemeldet haben!', 'error')
|
|
|
|
|
return redirect(url_for('login'))
|
|
|
|
|
|
|
|
|
|
if not cfg.INVENTORY_MODULE_ENABLED:
|
|
|
|
|
if cfg.LIBRARY_MODULE_ENABLED:
|
|
|
|
|
if not cfg.MODULES.is_enabled('inventory'):
|
|
|
|
|
if cfg.MODULES.is_enabled('library'):
|
|
|
|
|
return redirect(url_for('library_admin'))
|
|
|
|
|
else:
|
|
|
|
|
return "Weder Inventar- noch Bibliotheks-Modul sind aktiviert.", 403
|
|
|
|
@@ -2694,11 +2690,12 @@ def home_admin():
|
|
|
|
|
return render_template(
|
|
|
|
|
'main_admin.html',
|
|
|
|
|
username=session['username'],
|
|
|
|
|
library_module_enabled=cfg.LIBRARY_MODULE_ENABLED,
|
|
|
|
|
student_cards_module_enabled=cfg.STUDENT_CARDS_MODULE_ENABLED,
|
|
|
|
|
library_module_enabled=cfg.MODULES.is_enabled('library'),
|
|
|
|
|
student_cards_module_enabled=cfg.MODULES.is_enabled('student_cards'),
|
|
|
|
|
student_default_borrow_days=cfg.STUDENT_DEFAULT_BORROW_DAYS,
|
|
|
|
|
student_max_borrow_days=cfg.STUDENT_MAX_BORROW_DAYS,
|
|
|
|
|
school_info=_get_school_info_for_export(),
|
|
|
|
|
open_item=request.args.get('open_item')
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -2713,8 +2710,8 @@ def tutorial_page():
|
|
|
|
|
'tutorial.html',
|
|
|
|
|
username=session['username'],
|
|
|
|
|
is_admin=us.check_admin(session['username']),
|
|
|
|
|
library_module_enabled=cfg.LIBRARY_MODULE_ENABLED,
|
|
|
|
|
student_cards_module_enabled=cfg.STUDENT_CARDS_MODULE_ENABLED,
|
|
|
|
|
library_module_enabled=cfg.MODULES.is_enabled('library'),
|
|
|
|
|
student_cards_module_enabled=cfg.MODULES.is_enabled('student_cards'),
|
|
|
|
|
student_default_borrow_days=cfg.STUDENT_DEFAULT_BORROW_DAYS,
|
|
|
|
|
student_max_borrow_days=cfg.STUDENT_MAX_BORROW_DAYS
|
|
|
|
|
)
|
|
|
|
@@ -2732,16 +2729,16 @@ def library_view():
|
|
|
|
|
if 'username' not in session:
|
|
|
|
|
flash('Bitte mit registriertem Konto anmelden!', 'error')
|
|
|
|
|
return redirect(url_for('login'))
|
|
|
|
|
if not cfg.LIBRARY_MODULE_ENABLED:
|
|
|
|
|
if not cfg.MODULES.is_enabled('library'):
|
|
|
|
|
flash('Bibliotheks-Modul ist deaktiviert.', 'error')
|
|
|
|
|
return redirect(url_for('home'))
|
|
|
|
|
|
|
|
|
|
return render_template(
|
|
|
|
|
'library_table.html',
|
|
|
|
|
username=session['username'],
|
|
|
|
|
library_module_enabled=cfg.LIBRARY_MODULE_ENABLED,
|
|
|
|
|
library_module_enabled=cfg.MODULES.is_enabled('library'),
|
|
|
|
|
is_admin=us.check_admin(session['username']),
|
|
|
|
|
student_cards_module_enabled=cfg.STUDENT_CARDS_MODULE_ENABLED,
|
|
|
|
|
student_cards_module_enabled=cfg.MODULES.is_enabled('student_cards'),
|
|
|
|
|
student_default_borrow_days=cfg.STUDENT_DEFAULT_BORROW_DAYS,
|
|
|
|
|
student_max_borrow_days=cfg.STUDENT_MAX_BORROW_DAYS
|
|
|
|
|
)
|
|
|
|
@@ -2756,7 +2753,7 @@ def library_loans_admin():
|
|
|
|
|
if not us.check_admin(session['username']):
|
|
|
|
|
flash('Ihnen ist es nicht gestattet auf dieser Internetanwendung, die eben besuchte Adrrese zu nutzen, versuchen sie es erneut nach dem sie sich mit einem berechtigten Nutzer angemeldet haben!', 'error')
|
|
|
|
|
return redirect(url_for('login'))
|
|
|
|
|
if not cfg.LIBRARY_MODULE_ENABLED:
|
|
|
|
|
if not cfg.MODULES.is_enabled('library'):
|
|
|
|
|
flash('Bibliotheks-Modul ist deaktiviert.', 'error')
|
|
|
|
|
return redirect(url_for('home_admin'))
|
|
|
|
|
|
|
|
|
@@ -2857,8 +2854,8 @@ def library_loans_admin():
|
|
|
|
|
'library_borrowings_admin.html',
|
|
|
|
|
loan_entries=loan_entries,
|
|
|
|
|
damaged_items=damaged_items,
|
|
|
|
|
library_module_enabled=cfg.LIBRARY_MODULE_ENABLED,
|
|
|
|
|
student_cards_module_enabled=cfg.STUDENT_CARDS_MODULE_ENABLED,
|
|
|
|
|
library_module_enabled=cfg.MODULES.is_enabled('library'),
|
|
|
|
|
student_cards_module_enabled=cfg.MODULES.is_enabled('student_cards'),
|
|
|
|
|
)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
app.logger.error(f"Error loading library loans admin view: {e}")
|
|
|
|
@@ -2993,9 +2990,9 @@ def api_library_scan_action():
|
|
|
|
|
"""
|
|
|
|
|
if 'username' not in session:
|
|
|
|
|
return jsonify({'ok': False, 'message': 'Nicht angemeldet.'}), 401
|
|
|
|
|
if not cfg.LIBRARY_MODULE_ENABLED:
|
|
|
|
|
if not cfg.MODULES.is_enabled('library'):
|
|
|
|
|
return jsonify({'ok': False, 'message': 'Bibliotheks-Modul ist deaktiviert.'}), 403
|
|
|
|
|
if not cfg.STUDENT_CARDS_MODULE_ENABLED:
|
|
|
|
|
if not cfg.MODULES.is_enabled('student_cards'):
|
|
|
|
|
return jsonify({'ok': False, 'message': 'Schülerausweis-Modul ist deaktiviert.'}), 403
|
|
|
|
|
|
|
|
|
|
payload = request.get_json(silent=True) or {}
|
|
|
|
@@ -3199,7 +3196,7 @@ def api_library_item_update(item_id):
|
|
|
|
|
return jsonify({'ok': False, 'message': 'Nicht angemeldet.'}), 401
|
|
|
|
|
if not us.check_admin(session['username']):
|
|
|
|
|
return jsonify({'ok': False, 'message': 'Administratorrechte erforderlich.'}), 403
|
|
|
|
|
if not cfg.LIBRARY_MODULE_ENABLED:
|
|
|
|
|
if not cfg.MODULES.is_enabled('library'):
|
|
|
|
|
return jsonify({'ok': False, 'message': 'Bibliotheks-Modul ist deaktiviert.'}), 403
|
|
|
|
|
|
|
|
|
|
payload = request.get_json(silent=True) or {}
|
|
|
|
@@ -3330,8 +3327,8 @@ def upload_admin():
|
|
|
|
|
'upload_admin.html',
|
|
|
|
|
username=session['username'],
|
|
|
|
|
duplicate_data=duplicate_data,
|
|
|
|
|
library_module_enabled=cfg.LIBRARY_MODULE_ENABLED,
|
|
|
|
|
student_cards_module_enabled=cfg.STUDENT_CARDS_MODULE_ENABLED,
|
|
|
|
|
library_module_enabled=cfg.MODULES.is_enabled('library'),
|
|
|
|
|
student_cards_module_enabled=cfg.MODULES.is_enabled('student_cards'),
|
|
|
|
|
show_library_features=False,
|
|
|
|
|
upload_mode='item',
|
|
|
|
|
page_title='Artikel hochladen',
|
|
|
|
@@ -3352,7 +3349,7 @@ def library_admin():
|
|
|
|
|
if not _action_access_allowed(permissions, 'can_insert'):
|
|
|
|
|
flash('Ihnen ist es nicht gestattet auf dieser Internetanwendung, die eben besuchte Adrrese zu nutzen, versuchen sie es erneut nach dem sie sich mit einem berechtigten Nutzer angemeldet haben!', 'error')
|
|
|
|
|
return redirect(url_for('login'))
|
|
|
|
|
if not cfg.LIBRARY_MODULE_ENABLED:
|
|
|
|
|
if not cfg.MODULES.is_enabled('library'):
|
|
|
|
|
flash('Bibliotheks-Modul ist deaktiviert.', 'error')
|
|
|
|
|
return redirect(url_for('home_admin'))
|
|
|
|
|
|
|
|
|
@@ -3396,8 +3393,8 @@ def library_admin():
|
|
|
|
|
'upload_admin.html',
|
|
|
|
|
username=session['username'],
|
|
|
|
|
duplicate_data=duplicate_data,
|
|
|
|
|
library_module_enabled=cfg.LIBRARY_MODULE_ENABLED,
|
|
|
|
|
student_cards_module_enabled=cfg.STUDENT_CARDS_MODULE_ENABLED,
|
|
|
|
|
library_module_enabled=cfg.MODULES.is_enabled('library'),
|
|
|
|
|
student_cards_module_enabled=cfg.MODULES.is_enabled('student_cards'),
|
|
|
|
|
show_library_features=True,
|
|
|
|
|
upload_mode='library',
|
|
|
|
|
page_title='Bücher hochladen',
|
|
|
|
@@ -3417,7 +3414,7 @@ def student_cards_admin():
|
|
|
|
|
if not us.check_admin(session['username']):
|
|
|
|
|
flash('Ihnen ist es nicht gestattet auf dieser Internetanwendung, die eben besuchte Adrrese zu nutzen, versuchen sie es erneut nach dem sie sich mit einem berechtigten Nutzer angemeldet haben!', 'error')
|
|
|
|
|
return redirect(url_for('login'))
|
|
|
|
|
if not cfg.STUDENT_CARDS_MODULE_ENABLED:
|
|
|
|
|
if not cfg.MODULES.is_enabled('student_cards'):
|
|
|
|
|
flash('Schülerausweis-Modul ist deaktiviert.', 'error')
|
|
|
|
|
return redirect(url_for('home_admin'))
|
|
|
|
|
|
|
|
|
@@ -3543,8 +3540,8 @@ def student_cards_admin():
|
|
|
|
|
edit_mode=edit_mode,
|
|
|
|
|
form_data=form_data,
|
|
|
|
|
config={'default': cfg.STUDENT_DEFAULT_BORROW_DAYS},
|
|
|
|
|
library_module_enabled=cfg.LIBRARY_MODULE_ENABLED,
|
|
|
|
|
student_cards_module_enabled=cfg.STUDENT_CARDS_MODULE_ENABLED
|
|
|
|
|
library_module_enabled=cfg.MODULES.is_enabled('library'),
|
|
|
|
|
student_cards_module_enabled=cfg.MODULES.is_enabled('student_cards')
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -3560,7 +3557,7 @@ def student_cards_print():
|
|
|
|
|
if not us.check_admin(session['username']):
|
|
|
|
|
flash('Ihnen ist es nicht gestattet auf dieser Internetanwendung, die eben besuchte Adrrese zu nutzen, versuchen sie es erneut nach dem sie sich mit einem berechtigten Nutzer angemeldet haben!', 'error')
|
|
|
|
|
return redirect(url_for('login'))
|
|
|
|
|
if not cfg.STUDENT_CARDS_MODULE_ENABLED:
|
|
|
|
|
if not cfg.MODULES.is_enabled('student_cards'):
|
|
|
|
|
flash('Schülerausweis-Modul ist deaktiviert.', 'error')
|
|
|
|
|
return redirect(url_for('home_admin'))
|
|
|
|
|
|
|
|
|
@@ -3592,7 +3589,7 @@ def student_card_barcode_print():
|
|
|
|
|
if not us.check_admin(session['username']):
|
|
|
|
|
flash('Ihnen ist es nicht gestattet auf dieser Internetanwendung, die eben besuchte Adrrese zu nutzen, versuchen sie es erneut nach dem sie sich mit einem berechtigten Nutzer angemeldet haben!', 'error')
|
|
|
|
|
return redirect(url_for('login'))
|
|
|
|
|
if not cfg.STUDENT_CARDS_MODULE_ENABLED:
|
|
|
|
|
if not cfg.MODULES.is_enabled('student_cards'):
|
|
|
|
|
flash('Schülerausweis-Modul ist deaktiviert.', 'error')
|
|
|
|
|
return redirect(url_for('home_admin'))
|
|
|
|
|
|
|
|
|
@@ -3623,7 +3620,7 @@ def student_card_barcode_download():
|
|
|
|
|
if not us.check_admin(session['username']):
|
|
|
|
|
flash('Zugriff verweigert.', 'error')
|
|
|
|
|
return redirect(url_for('login'))
|
|
|
|
|
if not cfg.STUDENT_CARDS_MODULE_ENABLED:
|
|
|
|
|
if not cfg.MODULES.is_enabled('student_cards'):
|
|
|
|
|
flash('Schülerausweis-Modul ist deaktiviert.', 'error')
|
|
|
|
|
return redirect(url_for('home_admin'))
|
|
|
|
|
|
|
|
|
@@ -3797,7 +3794,7 @@ def student_card_single_barcode_download(card_id):
|
|
|
|
|
if not us.check_admin(session['username']):
|
|
|
|
|
flash('Zugriff verweigert.', 'error')
|
|
|
|
|
return redirect(url_for('login'))
|
|
|
|
|
if not cfg.STUDENT_CARDS_MODULE_ENABLED:
|
|
|
|
|
if not cfg.MODULES.is_enabled('student_cards'):
|
|
|
|
|
flash('Schülerausweis-Modul ist deaktiviert.', 'error')
|
|
|
|
|
return redirect(url_for('home_admin'))
|
|
|
|
|
|
|
|
|
@@ -4666,7 +4663,7 @@ def upload_item():
|
|
|
|
|
|
|
|
|
|
item_isbn = ''
|
|
|
|
|
item_type = 'general'
|
|
|
|
|
if cfg.LIBRARY_MODULE_ENABLED:
|
|
|
|
|
if cfg.MODULES.is_enabled('library'):
|
|
|
|
|
item_isbn = normalize_and_validate_isbn(isbn_raw)
|
|
|
|
|
if isbn_raw and not item_isbn:
|
|
|
|
|
error_msg = 'Ungültige ISBN. Bitte ISBN-10 oder ISBN-13 verwenden.'
|
|
|
|
@@ -4678,7 +4675,7 @@ def upload_item():
|
|
|
|
|
item_type = 'book'
|
|
|
|
|
|
|
|
|
|
if upload_mode == 'library':
|
|
|
|
|
if not cfg.LIBRARY_MODULE_ENABLED:
|
|
|
|
|
if not cfg.MODULES.is_enabled('library'):
|
|
|
|
|
error_msg = 'Bibliotheks-Modul ist deaktiviert.'
|
|
|
|
|
if is_mobile:
|
|
|
|
|
return jsonify({'success': False, 'message': error_msg}), 400
|
|
|
|
@@ -4704,12 +4701,26 @@ def upload_item():
|
|
|
|
|
|
|
|
|
|
# Check if base code is unique for single-item uploads
|
|
|
|
|
if code_4 and item_count == 1 and not it.is_code_unique(code_4[0]):
|
|
|
|
|
error_msg = 'Der Code wird bereits verwendet. Bitte wählen Sie einen anderen Code.'
|
|
|
|
|
if is_mobile:
|
|
|
|
|
return jsonify({'success': False, 'message': error_msg}), 400
|
|
|
|
|
existing_item = it._get_items_collection().find_one({"code_4": code_4[0]})
|
|
|
|
|
if existing_item:
|
|
|
|
|
error_msg = 'Der Code wird bereits verwendet. Umleitung zum Eintrag.'
|
|
|
|
|
if is_mobile:
|
|
|
|
|
return jsonify({
|
|
|
|
|
'success': False,
|
|
|
|
|
'message': error_msg,
|
|
|
|
|
'existing_item_id': str(existing_item['_id']),
|
|
|
|
|
'redirect_to_item': True
|
|
|
|
|
}), 400
|
|
|
|
|
|
|
|
|
|
flash(error_msg, 'info')
|
|
|
|
|
return redirect(url_for(success_redirect_endpoint, open_item=str(existing_item['_id'])))
|
|
|
|
|
else:
|
|
|
|
|
flash(error_msg, 'error')
|
|
|
|
|
return redirect(url_for(success_redirect_endpoint))
|
|
|
|
|
error_msg = 'Der Code wird bereits verwendet. Bitte wählen Sie einen anderen Code.'
|
|
|
|
|
if is_mobile:
|
|
|
|
|
return jsonify({'success': False, 'message': error_msg}), 400
|
|
|
|
|
else:
|
|
|
|
|
flash(error_msg, 'error')
|
|
|
|
|
return redirect(url_for(success_redirect_endpoint))
|
|
|
|
|
|
|
|
|
|
# Validate optional per-item codes
|
|
|
|
|
if individual_codes:
|
|
|
|
@@ -5853,7 +5864,7 @@ def edit_item(id):
|
|
|
|
|
|
|
|
|
|
item_isbn = ''
|
|
|
|
|
item_type = 'general'
|
|
|
|
|
if cfg.LIBRARY_MODULE_ENABLED:
|
|
|
|
|
if cfg.MODULES.is_enabled('library'):
|
|
|
|
|
item_isbn = normalize_and_validate_isbn(isbn_raw)
|
|
|
|
|
if isbn_raw and not item_isbn:
|
|
|
|
|
flash('Ungültige ISBN. Bitte ISBN-10 oder ISBN-13 verwenden.', 'error')
|
|
|
|
@@ -6136,7 +6147,7 @@ def ausleihen(id):
|
|
|
|
|
|
|
|
|
|
username = session['username']
|
|
|
|
|
requested_return_to = (request.form.get('return_to') or '').strip().lower()
|
|
|
|
|
if requested_return_to == 'library' and cfg.LIBRARY_MODULE_ENABLED:
|
|
|
|
|
if requested_return_to == 'library' and cfg.MODULES.is_enabled('library'):
|
|
|
|
|
redirect_target = 'library_view'
|
|
|
|
|
else:
|
|
|
|
|
redirect_target = 'home_admin' if us.check_admin(username) else 'home'
|
|
|
|
@@ -6154,7 +6165,7 @@ def ausleihen(id):
|
|
|
|
|
|
|
|
|
|
# Library media can only be borrowed with a valid student card.
|
|
|
|
|
if is_library_item:
|
|
|
|
|
if not cfg.STUDENT_CARDS_MODULE_ENABLED:
|
|
|
|
|
if not cfg.MODULES.is_enabled('student_cards'):
|
|
|
|
|
flash('Bibliotheksmedien können nur mit aktivem Schülerausweis-Modul ausgeliehen werden.', 'error')
|
|
|
|
|
return redirect(url_for(redirect_target))
|
|
|
|
|
if not student_card_id:
|
|
|
|
@@ -6183,7 +6194,7 @@ def ausleihen(id):
|
|
|
|
|
if client:
|
|
|
|
|
client.close()
|
|
|
|
|
|
|
|
|
|
if cfg.STUDENT_CARDS_MODULE_ENABLED:
|
|
|
|
|
if cfg.MODULES.is_enabled('student_cards'):
|
|
|
|
|
duration_raw = (request.form.get('borrow_duration_days') or '').strip()
|
|
|
|
|
if duration_raw:
|
|
|
|
|
try:
|
|
|
|
@@ -7103,8 +7114,8 @@ def register():
|
|
|
|
|
return redirect(url_for('home'))
|
|
|
|
|
return render_template(
|
|
|
|
|
'register.html',
|
|
|
|
|
library_module_enabled=cfg.LIBRARY_MODULE_ENABLED,
|
|
|
|
|
student_cards_module_enabled=cfg.STUDENT_CARDS_MODULE_ENABLED,
|
|
|
|
|
library_module_enabled=cfg.MODULES.is_enabled('library'),
|
|
|
|
|
student_cards_module_enabled=cfg.MODULES.is_enabled('student_cards'),
|
|
|
|
|
student_default_borrow_days=cfg.STUDENT_DEFAULT_BORROW_DAYS,
|
|
|
|
|
student_max_borrow_days=cfg.STUDENT_MAX_BORROW_DAYS
|
|
|
|
|
)
|
|
|
|
@@ -7170,8 +7181,8 @@ def user_del():
|
|
|
|
|
return render_template(
|
|
|
|
|
'user_del.html',
|
|
|
|
|
users=users_list,
|
|
|
|
|
library_module_enabled=cfg.LIBRARY_MODULE_ENABLED,
|
|
|
|
|
student_cards_module_enabled=cfg.STUDENT_CARDS_MODULE_ENABLED
|
|
|
|
|
library_module_enabled=cfg.MODULES.is_enabled('library'),
|
|
|
|
|
student_cards_module_enabled=cfg.MODULES.is_enabled('student_cards')
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -7311,8 +7322,8 @@ def admin_borrowings():
|
|
|
|
|
return render_template(
|
|
|
|
|
'admin_borrowings.html',
|
|
|
|
|
entries=entries,
|
|
|
|
|
library_module_enabled=cfg.LIBRARY_MODULE_ENABLED,
|
|
|
|
|
student_cards_module_enabled=cfg.STUDENT_CARDS_MODULE_ENABLED
|
|
|
|
|
library_module_enabled=cfg.MODULES.is_enabled('library'),
|
|
|
|
|
student_cards_module_enabled=cfg.MODULES.is_enabled('student_cards')
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
"""-----------------------------------------------------------Audit Routes-------------------------------------------------------"""
|
|
|
|
@@ -7373,8 +7384,8 @@ def admin_audit_dashboard():
|
|
|
|
|
'admin_audit.html',
|
|
|
|
|
verify_result=verify_result,
|
|
|
|
|
audit_rows=audit_rows,
|
|
|
|
|
library_module_enabled=cfg.LIBRARY_MODULE_ENABLED,
|
|
|
|
|
student_cards_module_enabled=cfg.STUDENT_CARDS_MODULE_ENABLED,
|
|
|
|
|
library_module_enabled=cfg.MODULES.is_enabled('library'),
|
|
|
|
|
student_cards_module_enabled=cfg.MODULES.is_enabled('student_cards'),
|
|
|
|
|
)
|
|
|
|
|
except Exception as exc:
|
|
|
|
|
app.logger.error(f"Error loading audit dashboard: {exc}")
|
|
|
|
@@ -8120,7 +8131,7 @@ def library_item_invoices(item_id):
|
|
|
|
|
if 'username' not in session or not us.check_admin(session['username']):
|
|
|
|
|
flash('Ihnen ist es nicht gestattet auf dieser Internetanwendung, die eben besuchte Adrrese zu nutzen, versuchen sie es erneut nach dem sie sich mit einem berechtigten Nutzer angemeldet haben!', 'error')
|
|
|
|
|
return redirect(url_for('login'))
|
|
|
|
|
if not cfg.LIBRARY_MODULE_ENABLED:
|
|
|
|
|
if not cfg.MODULES.is_enabled('library'):
|
|
|
|
|
flash('Bibliotheks-Modul ist deaktiviert.', 'error')
|
|
|
|
|
return redirect(url_for('home_admin'))
|
|
|
|
|
|
|
|
|
@@ -8188,8 +8199,8 @@ def library_item_invoices(item_id):
|
|
|
|
|
'isbn': item_doc.get('ISBN', ''),
|
|
|
|
|
},
|
|
|
|
|
invoices=entries,
|
|
|
|
|
library_module_enabled=cfg.LIBRARY_MODULE_ENABLED,
|
|
|
|
|
student_cards_module_enabled=cfg.STUDENT_CARDS_MODULE_ENABLED,
|
|
|
|
|
library_module_enabled=cfg.MODULES.is_enabled('library'),
|
|
|
|
|
student_cards_module_enabled=cfg.MODULES.is_enabled('student_cards'),
|
|
|
|
|
)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
app.logger.error(f"Error loading invoice history for item {item_id}: {e}")
|
|
|
|
@@ -8515,8 +8526,8 @@ def logs():
|
|
|
|
|
return render_template(
|
|
|
|
|
'logs.html',
|
|
|
|
|
items=formatted_items,
|
|
|
|
|
library_module_enabled=cfg.LIBRARY_MODULE_ENABLED,
|
|
|
|
|
student_cards_module_enabled=cfg.STUDENT_CARDS_MODULE_ENABLED
|
|
|
|
|
library_module_enabled=cfg.MODULES.is_enabled('library'),
|
|
|
|
|
student_cards_module_enabled=cfg.MODULES.is_enabled('student_cards')
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -8581,8 +8592,8 @@ def manage_filters():
|
|
|
|
|
'manage_filters.html',
|
|
|
|
|
filter1_values=filter1_values,
|
|
|
|
|
filter2_values=filter2_values,
|
|
|
|
|
library_module_enabled=cfg.LIBRARY_MODULE_ENABLED,
|
|
|
|
|
student_cards_module_enabled=cfg.STUDENT_CARDS_MODULE_ENABLED
|
|
|
|
|
library_module_enabled=cfg.MODULES.is_enabled('library'),
|
|
|
|
|
student_cards_module_enabled=cfg.MODULES.is_enabled('student_cards')
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@app.route('/add_filter_value/<int:filter_num>', methods=['POST'])
|
|
|
|
@@ -8713,7 +8724,7 @@ def fetch_book_info(isbn):
|
|
|
|
|
if 'username' not in session or not us.check_admin(session['username']):
|
|
|
|
|
return jsonify({"error": "Not authorized"}), 403
|
|
|
|
|
|
|
|
|
|
if not cfg.LIBRARY_MODULE_ENABLED:
|
|
|
|
|
if not cfg.MODULES.is_enabled('library'):
|
|
|
|
|
return jsonify({"error": "Bibliotheks-Modul ist deaktiviert."}), 403
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
@@ -8808,7 +8819,7 @@ def download_book_cover():
|
|
|
|
|
return jsonify({"error": "Not authorized"}), 403
|
|
|
|
|
if not us.check_admin(session['username']):
|
|
|
|
|
return jsonify({"error": "Admin privileges required"}), 403
|
|
|
|
|
if not cfg.LIBRARY_MODULE_ENABLED:
|
|
|
|
|
if not cfg.MODULES.is_enabled('library'):
|
|
|
|
|
return jsonify({"error": "Bibliotheks-Modul ist deaktiviert."}), 403
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
@@ -9175,8 +9186,8 @@ def notifications_view():
|
|
|
|
|
user_notifications=user_notifications,
|
|
|
|
|
admin_notifications=admin_notifications,
|
|
|
|
|
is_admin_user=is_admin_user,
|
|
|
|
|
library_module_enabled=cfg.LIBRARY_MODULE_ENABLED,
|
|
|
|
|
student_cards_module_enabled=cfg.STUDENT_CARDS_MODULE_ENABLED,
|
|
|
|
|
library_module_enabled=cfg.MODULES.is_enabled('library'),
|
|
|
|
|
student_cards_module_enabled=cfg.MODULES.is_enabled('student_cards'),
|
|
|
|
|
)
|
|
|
|
|
except Exception as exc:
|
|
|
|
|
app.logger.error(f"Error loading notifications: {exc}")
|
|
|
|
@@ -9407,8 +9418,8 @@ def admin_damaged_items():
|
|
|
|
|
return render_template(
|
|
|
|
|
'admin_damaged_items.html',
|
|
|
|
|
damaged_items=damaged_rows,
|
|
|
|
|
library_module_enabled=cfg.LIBRARY_MODULE_ENABLED,
|
|
|
|
|
student_cards_module_enabled=cfg.STUDENT_CARDS_MODULE_ENABLED,
|
|
|
|
|
library_module_enabled=cfg.MODULES.is_enabled('library'),
|
|
|
|
|
student_cards_module_enabled=cfg.MODULES.is_enabled('student_cards'),
|
|
|
|
|
)
|
|
|
|
|
except Exception as exc:
|
|
|
|
|
app.logger.error(f"Error loading damaged-items admin view: {exc}")
|
|
|
|
@@ -9511,8 +9522,8 @@ def manage_locations():
|
|
|
|
|
return render_template(
|
|
|
|
|
'manage_locations.html',
|
|
|
|
|
location_values=location_values,
|
|
|
|
|
library_module_enabled=cfg.LIBRARY_MODULE_ENABLED,
|
|
|
|
|
student_cards_module_enabled=cfg.STUDENT_CARDS_MODULE_ENABLED
|
|
|
|
|
library_module_enabled=cfg.MODULES.is_enabled('library'),
|
|
|
|
|
student_cards_module_enabled=cfg.MODULES.is_enabled('student_cards')
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -9620,8 +9631,8 @@ def admin_school_settings():
|
|
|
|
|
school_info=current_school,
|
|
|
|
|
tenant_id=tenant_id,
|
|
|
|
|
tenant_db=tenant_db,
|
|
|
|
|
library_module_enabled=cfg.LIBRARY_MODULE_ENABLED,
|
|
|
|
|
student_cards_module_enabled=cfg.STUDENT_CARDS_MODULE_ENABLED,
|
|
|
|
|
library_module_enabled=cfg.MODULES.is_enabled('library'),
|
|
|
|
|
student_cards_module_enabled=cfg.MODULES.is_enabled('student_cards'),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@app.route('/check_code_unique/<code>')
|
|
|
|
|