From 41fdf7aa2cc1c2cd6af00be51f42a26313280c51 Mon Sep 17 00:00:00 2001 From: Terranom674 Date: Sun, 16 Aug 2026 23:27:42 +0200 Subject: [PATCH] Fix private album owner access on permissions form --- main.inc.php | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/main.inc.php b/main.inc.php index 7112371..5b0a1a8 100644 --- a/main.inc.php +++ b/main.inc.php @@ -1,7 +1,7 @@ private transition so Piwigo itself + * persists the permission together with the other selected users. + */ +function bratonien_tools_prepare_private_album_permissions() +{ + global $user; + + if ( + !defined('IN_ADMIN') + || $_SERVER['REQUEST_METHOD'] !== 'POST' + || empty($user['id']) + || (string)($_POST['status'] ?? '') !== 'private' + ) + { + return; + } + + $page = (string)($_GET['page'] ?? ''); + if (!preg_match('/^album-(\d+)-permissions$/', $page, $matches)) + { + return; + } + + $category_id = (int)$matches[1]; + if ($category_id < 1) + { + return; + } + + $result = pwg_query('SELECT status FROM '.CATEGORIES_TABLE.' WHERE id = '.$category_id.' LIMIT 1'); + if (!pwg_db_num_rows($result)) + { + return; + } + + $category = pwg_db_fetch_assoc($result); + if ($category['status'] !== 'public') + { + return; + } + + $users = isset($_POST['users']) && is_array($_POST['users']) ? $_POST['users'] : array(); + $current_user_id = (int)$user['id']; + $normalized_user_ids = array_map('intval', $users); + + if (!in_array($current_user_id, $normalized_user_ids, true)) + { + $users[] = $current_user_id; + } + + $_POST['users'] = $users; +} + function bratonien_tools_admin_menu($menu) { $menu[] = array(