"Refactor user blueprint and database configuration"

This commit is contained in:
Till Tomczak 2025-05-29 10:02:45 +02:00
parent f9733fccb6
commit 08c922d8f5
6 changed files with 30 additions and 9 deletions

View File

@ -1,6 +1,7 @@
from flask import Blueprint, render_template, request, jsonify, redirect, url_for, abort from flask import Blueprint, render_template, request, jsonify, redirect, url_for, abort
from flask_login import current_user, login_required from flask_login import current_user, login_required
from sqlalchemy.exc import SQLAlchemyError from sqlalchemy.exc import SQLAlchemyError
from functools import wraps
from models import User, UserPermission, get_cached_session from models import User, UserPermission, get_cached_session
from utils.logging_config import get_logger from utils.logging_config import get_logger
@ -10,6 +11,7 @@ logger = get_logger("users")
def users_admin_required(f): def users_admin_required(f):
"""Decorator zur Prüfung der Admin-Berechtigung für Users Blueprint.""" """Decorator zur Prüfung der Admin-Berechtigung für Users Blueprint."""
@wraps(f)
@login_required @login_required
def users_decorated_function(*args, **kwargs): def users_decorated_function(*args, **kwargs):
if not current_user.is_admin: if not current_user.is_admin:

Binary file not shown.

Binary file not shown.

View File

@ -49,14 +49,21 @@ def test_new_tables():
# Test der UserPermission-Tabelle (mit Admin-User falls vorhanden) # Test der UserPermission-Tabelle (mit Admin-User falls vorhanden)
admin_user = session.query(User).filter_by(role="admin").first() admin_user = session.query(User).filter_by(role="admin").first()
if admin_user: if admin_user:
permission = UserPermission( # Prüfen, ob bereits Permissions für diesen User existieren
user_id=admin_user.id, existing_permission = session.query(UserPermission).filter_by(user_id=admin_user.id).first()
can_start_jobs=True,
needs_approval=False, if not existing_permission:
can_approve_jobs=True permission = UserPermission(
) user_id=admin_user.id,
session.add(permission) can_start_jobs=True,
session.flush() needs_approval=False,
can_approve_jobs=True
)
session.add(permission)
session.flush()
logger.info(f"UserPermission für Admin-User {admin_user.id} erstellt")
else:
logger.info(f"UserPermission für Admin-User {admin_user.id} existiert bereits")
# Test der Notification-Tabelle # Test der Notification-Tabelle
notification = Notification( notification = Notification(

File diff suppressed because one or more lines are too long

View File

@ -335,6 +335,18 @@
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true"> <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"/> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"/>
</svg> </svg>
<span>Gastanfrage</span>
</a>
{% if current_user.is_authenticated and current_user.is_admin %}
<a href="{{ url_for('admin_page') }}"
class="mobile-nav-item {{ 'active' if request.endpoint == 'admin_page' else '' }}">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"/>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/>
</svg>
<span>Administration</span>
</a>
{% endif %} {% endif %}
</nav> </nav>
</div> </div>