chore: Änderungen commited

This commit is contained in:
2025-05-10 23:20:10 +02:00
parent 02d1801fc9
commit d0f32a8355
2 changed files with 297 additions and 11 deletions

69
app.py
View File

@@ -861,11 +861,17 @@ def api_get_user_mindmaps():
@app.route('/api/mindmaps/<int:mindmap_id>', methods=['GET'])
@login_required
@handle_api_exception
def api_get_user_mindmap_detail(mindmap_id):
mindmap = UserMindmap.query.filter_by(id=mindmap_id, user_id=current_user.id).first_or_404()
# Bestehende Logik von get_user_mindmap kann hier wiederverwendet oder angepasst werden
# Für eine einfache Detailansicht:
return jsonify({
# Berechtigungsprüfung (mindestens READ-Zugriff)
has_permission, error_msg = check_mindmap_permission(mindmap_id, "READ")
if not has_permission:
return ErrorHandler.api_error(error_msg, 403)
mindmap = UserMindmap.query.get_or_404(mindmap_id)
# Logik für eine detaillierte Ansicht
result = {
'id': mindmap.id,
'name': mindmap.name,
'description': mindmap.description,
@@ -873,18 +879,44 @@ def api_get_user_mindmap_detail(mindmap_id):
'user_id': mindmap.user_id,
'created_at': mindmap.created_at.isoformat(),
'last_modified': mindmap.last_modified.isoformat(),
# Hier könnten auch Knoten und Notizen hinzugefügt werden, ähnlich wie in get_user_mindmap
})
'is_owner': mindmap.user_id == current_user.id
}
# Berechtigungsinformationen hinzufügen, falls nicht der Eigentümer
if mindmap.user_id != current_user.id:
share = MindmapShare.query.filter_by(
mindmap_id=mindmap_id,
shared_with_id=current_user.id
).first()
if share:
result['permission'] = share.permission_type.name
result['owner'] = {
'id': mindmap.user_id,
'username': User.query.get(mindmap.user_id).username
}
return jsonify(result)
@app.route('/api/mindmaps/<int:mindmap_id>', methods=['PUT'])
@login_required
@handle_api_exception
def api_update_user_mindmap(mindmap_id):
mindmap = UserMindmap.query.filter_by(id=mindmap_id, user_id=current_user.id).first_or_404()
# Berechtigungsprüfung (mindestens EDIT-Zugriff)
has_permission, error_msg = check_mindmap_permission(mindmap_id, "EDIT")
if not has_permission:
return ErrorHandler.api_error(error_msg, 403)
mindmap = UserMindmap.query.get_or_404(mindmap_id)
data = request.get_json()
# Grundlegende Informationen aktualisieren
mindmap.name = data.get('name', mindmap.name)
mindmap.description = data.get('description', mindmap.description)
mindmap.is_private = data.get('is_private', mindmap.is_private)
# is_private kann nur vom Eigentümer geändert werden
if mindmap.user_id == current_user.id and 'is_private' in data:
mindmap.is_private = data.get('is_private')
db.session.commit()
return jsonify({
@@ -892,16 +924,31 @@ def api_update_user_mindmap(mindmap_id):
'name': mindmap.name,
'description': mindmap.description,
'is_private': mindmap.is_private,
'last_modified': mindmap.last_modified.isoformat()
'last_modified': mindmap.last_modified.isoformat(),
'success': True
})
@app.route('/api/mindmaps/<int:mindmap_id>', methods=['DELETE'])
@login_required
@handle_api_exception
def api_delete_user_mindmap(mindmap_id):
mindmap = UserMindmap.query.filter_by(id=mindmap_id, user_id=current_user.id).first_or_404()
# Nur der Eigentümer kann eine Mindmap löschen
mindmap = UserMindmap.query.get_or_404(mindmap_id)
if mindmap.user_id != current_user.id:
return ErrorHandler.api_error("Nur der Eigentümer kann eine Mindmap löschen.", 403)
# Alle Freigaben löschen
MindmapShare.query.filter_by(mindmap_id=mindmap_id).delete()
# Mindmap löschen
db.session.delete(mindmap)
db.session.commit()
return jsonify({'message': 'Mindmap erfolgreich gelöscht'}), 200
return jsonify({
'success': True,
'message': 'Mindmap erfolgreich gelöscht'
}), 200
# API-Endpunkte für Mindmap-Daten (öffentlich und benutzerspezifisch)
@app.route('/api/mindmap/public')