diff --git a/app.py b/app.py index 6f81baf..3feec89 100644 --- a/app.py +++ b/app.py @@ -3518,9 +3518,10 @@ def add_suggestion(): @app.route("/admin/lists-access", methods=["GET", "POST"]) +@app.route("/admin/lists-access/", methods=["GET", "POST"]) @login_required @admin_required -def admin_lists_access(): +def admin_lists_access(list_id=None): try: page = int(request.args.get("page", 1)) except ValueError: @@ -3535,6 +3536,19 @@ def admin_lists_access(): ShoppingList.created_at.desc() ) + if list_id is not None: + target_list = db.session.get(ShoppingList, list_id) + if not target_list: + flash("Lista nie istnieje.", "danger") + return redirect(url_for("admin_lists_access")) + lists = [target_list] + list_ids = [list_id] + pagination = None + else: + pagination = q.paginate(page=page, per_page=per_page, error_out=False) + lists = pagination.items + list_ids = [l.id for l in lists] + if request.method == "POST": action = request.form.get("action") target_list_id = request.form.get("target_list_id", type=int) @@ -3575,9 +3589,9 @@ def admin_lists_access(): if action == "save_changes": ids = request.form.getlist("visible_ids", type=int) if ids: - lists = ShoppingList.query.filter(ShoppingList.id.in_(ids)).all() + lists_edit = ShoppingList.query.filter(ShoppingList.id.in_(ids)).all() posted = request.form - for l in lists: + for l in lists_edit: l.is_public = posted.get(f"is_public_{l.id}") is not None l.is_temporary = posted.get(f"is_temporary_{l.id}") is not None l.is_archived = posted.get(f"is_archived_{l.id}") is not None @@ -3585,10 +3599,6 @@ def admin_lists_access(): flash("Zapisano zmiany statusów.", "success") return redirect(request.url) - pagination = q.paginate(page=page, per_page=per_page, error_out=False) - lists = pagination.items - - list_ids = [l.id for l in lists] perms = ( db.session.query( ListPermission.list_id, @@ -3613,8 +3623,9 @@ def admin_lists_access(): permitted_by_list=permitted_by_list, page=page, per_page=per_page, - total_pages=pagination.pages or 1, + total_pages=pagination.pages if pagination else 1, query_string=query_string, + list_id=list_id, ) diff --git a/templates/admin/admin_lists_access.html b/templates/admin/admin_lists_access.html index 6d2ff9e..c48c59f 100644 --- a/templates/admin/admin_lists_access.html +++ b/templates/admin/admin_lists_access.html @@ -139,6 +139,7 @@ +{% if not list_id %}
@@ -170,4 +171,6 @@
+{% endif %} + {% endblock %} \ No newline at end of file diff --git a/templates/admin/edit_list.html b/templates/admin/edit_list.html index e61b935..cd24d39 100644 --- a/templates/admin/edit_list.html +++ b/templates/admin/edit_list.html @@ -122,6 +122,11 @@
🔐 Użytkownicy z dostępem
+ + ⚙️ Edytuj uprawnienia (admin) + + {% if permitted_users %}