Caroouusseelll gemacht und bookmarks
This commit is contained in:
@@ -48,6 +48,7 @@ def init_db():
|
||||
title TEXT NOT NULL,
|
||||
url TEXT NOT NULL,
|
||||
icon_class TEXT NOT NULL DEFAULT 'fas fa-bookmark',
|
||||
bg_color TEXT NOT NULL DEFAULT 'fas fa-bookmark',
|
||||
FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
);
|
||||
""")
|
||||
@@ -381,16 +382,32 @@ def manage_bookmarks(user_id):
|
||||
bookmarks = db.execute("SELECT * FROM bookmarks WHERE user_id=?", (user_id,)).fetchall()
|
||||
return render_template('admin.html', single_user=user, bookmarks=bookmarks)
|
||||
|
||||
@app.route('/admin/delete_bookmark/<int:bookmark_id>/<int:user_id>', methods=['POST'])
|
||||
def delete_bookmark(bookmark_id, user_id):
|
||||
if not is_admin():
|
||||
flash("Zugriff verweigert!", "red")
|
||||
return redirect(url_for('dashboard'))
|
||||
@app.route('/bookmarks/delete/<int:bookmark_id>', methods=['POST'])
|
||||
def delete_bookmark(bookmark_id):
|
||||
"""Löscht ein Lesezeichen, wenn der Benutzer es besitzt oder Admin ist."""
|
||||
if 'user_id' not in session:
|
||||
flash("Bitte melde dich an!", "red")
|
||||
return redirect(url_for('login'))
|
||||
|
||||
user_id = session['user_id']
|
||||
db = get_db()
|
||||
|
||||
# Prüfen, ob der Benutzer das Lesezeichen besitzt
|
||||
bookmark = db.execute("SELECT user_id FROM bookmarks WHERE id=?", (bookmark_id,)).fetchone()
|
||||
if not bookmark:
|
||||
flash("Lesezeichen nicht gefunden!", "red")
|
||||
return redirect(url_for('dashboard'))
|
||||
|
||||
# Benutzer darf nur eigene Lesezeichen löschen, Admin kann alle löschen
|
||||
if bookmark['user_id'] != user_id and not is_admin():
|
||||
flash("Keine Berechtigung zum Löschen!", "red")
|
||||
return redirect(url_for('dashboard'))
|
||||
|
||||
db.execute("DELETE FROM bookmarks WHERE id=?", (bookmark_id,))
|
||||
db.commit()
|
||||
|
||||
flash("Lesezeichen gelöscht!", "green")
|
||||
return redirect(url_for('manage_bookmarks', user_id=user_id))
|
||||
return redirect(url_for('dashboard'))
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# ZEITERFASSUNG
|
||||
@@ -490,7 +507,7 @@ def dashboard():
|
||||
|
||||
# DB-Bookmarks für den eingeloggten User
|
||||
user_bookmarks = db.execute("""
|
||||
SELECT id, title, url, icon_class
|
||||
SELECT id, title, url, icon_class, bg_color
|
||||
FROM bookmarks
|
||||
WHERE user_id=?
|
||||
ORDER BY id DESC
|
||||
@@ -708,6 +725,37 @@ def add_notification_multi():
|
||||
flash("Benachrichtigungen erstellt!", "green")
|
||||
return redirect(url_for('admin_panel'))
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# BENUTZER-LESEZEICHEN (nur für sich selbst)
|
||||
# ------------------------------------------------------------
|
||||
|
||||
@app.route('/bookmarks/add', methods=['POST'])
|
||||
def add_bookmark():
|
||||
if 'user_id' not in session:
|
||||
flash("Bitte melde dich an!", "red")
|
||||
return redirect(url_for('login'))
|
||||
|
||||
user_id = session['user_id']
|
||||
title = request.form.get('title')
|
||||
url_ = request.form.get('url')
|
||||
icon_class = request.form.get('icon_class', 'fas fa-bookmark')
|
||||
bg_color = request.form.get('bg_color', 'bg-blue-500') # Standardfarbe
|
||||
|
||||
if not title or not url_:
|
||||
flash("Bitte Titel und URL angeben!", "red")
|
||||
return redirect(url_for('dashboard'))
|
||||
|
||||
db = get_db()
|
||||
db.execute(
|
||||
"INSERT INTO bookmarks (user_id, title, url, icon_class, bg_color) VALUES (?, ?, ?, ?, ?)",
|
||||
(user_id, title, url_, icon_class, bg_color)
|
||||
)
|
||||
db.commit()
|
||||
|
||||
flash("Lesezeichen erfolgreich hinzugefügt!", "green")
|
||||
return redirect(url_for('dashboard'))
|
||||
|
||||
|
||||
|
||||
@app.route('/admin/bookmarks/multi', methods=['POST'])
|
||||
def add_bookmarks_multi():
|
||||
|
||||
Reference in New Issue
Block a user