fix(admin): resolve colon-formatted project strings like plants:plants and storymachine:geschichtenmaschine

This commit is contained in:
Philipp Urbschat 2026-09-13 00:03:03 +02:00
parent 50b4a70045
commit 7ebfb9cb63
Signed by: Phili
SSH key fingerprint: SHA256:ZSQWnldzrYiABzOV6vTICPe0h19pTpus7sCbm2S0po0
2 changed files with 48 additions and 17 deletions

View file

@ -31,7 +31,7 @@ class Invitation {
$this->db->bind(':id', $id); $this->db->bind(':id', $id);
$inv = $this->db->single(); $inv = $this->db->single();
if ($inv) { if ($inv) {
$inv['assigned_projects'] = json_decode($inv['assigned_projects'] ?? '[]', true) ?? []; $inv['assigned_projects'] = User::parseProjects($inv['assigned_projects'] ?? []);
} }
return $inv ?: null; return $inv ?: null;
} }
@ -60,7 +60,7 @@ class Invitation {
} }
} }
$invitation['assigned_projects'] = json_decode($invitation['assigned_projects'] ?? '[]', true) ?? []; $invitation['assigned_projects'] = User::parseProjects($invitation['assigned_projects'] ?? []);
return $invitation; return $invitation;
} }
@ -77,7 +77,7 @@ class Invitation {
$invitations = $this->db->resultSet(); $invitations = $this->db->resultSet();
foreach ($invitations as &$inv) { foreach ($invitations as &$inv) {
$inv['assigned_projects'] = json_decode($inv['assigned_projects'] ?? '[]', true) ?? []; $inv['assigned_projects'] = User::parseProjects($inv['assigned_projects'] ?? []);
$isExpired = false; $isExpired = false;
if (!empty($inv['expires_at'])) { if (!empty($inv['expires_at'])) {
$isExpired = (new DateTime()) > (new DateTime($inv['expires_at'])); $isExpired = (new DateTime()) > (new DateTime($inv['expires_at']));

View file

@ -40,16 +40,24 @@ class User {
} }
$slugMap['web audio synth'] = 'test'; $slugMap['web audio synth'] = 'test';
$slugMap['webaudiosynth'] = 'test'; $slugMap['webaudiosynth'] = 'test';
$slugMap['synth'] = 'test';
$slugMap['geschichtenmaschine'] = 'storymachine';
$slugMap['geschichten-maschine'] = 'storymachine';
$slugMap['pflanzen'] = 'plants';
$slugMap['pflanzentracker'] = 'plants';
$ignore = ['on', 'off', 'true', 'false', '1', '0', 'null', 'undefined'];
$clean = []; $clean = [];
foreach ($projects as $key => $val) { foreach ($projects as $key => $val) {
$candidates = []; $candidates = [];
if (is_string($key) && !is_numeric($key)) { if (is_string($key) && !is_numeric($key)) {
if ($val === true || $val === 1 || $val === '1' || $val === 'on' || $val === 'true' || is_array($val)) { $candidates[] = $key;
$candidates[] = $key; if (is_string($val) && !in_array(strtolower(trim($val)), $ignore, true)) {
$candidates[] = $val;
} }
} else { } else {
if (is_string($val)) { if (is_string($val) && !in_array(strtolower(trim($val)), $ignore, true)) {
$candidates[] = $val; $candidates[] = $val;
} elseif (is_array($val)) { } elseif (is_array($val)) {
if (!empty($val['slug'])) $candidates[] = $val['slug']; if (!empty($val['slug'])) $candidates[] = $val['slug'];
@ -58,23 +66,46 @@ class User {
elseif (!empty($val['project'])) $candidates[] = $val['project']; elseif (!empty($val['project'])) $candidates[] = $val['project'];
else { else {
foreach ($val as $sub) { foreach ($val as $sub) {
if (is_string($sub)) $candidates[] = $sub; if (is_string($sub) && !in_array(strtolower(trim($sub)), $ignore, true)) {
$candidates[] = $sub;
}
} }
} }
} }
} }
foreach ($candidates as $cand) { foreach ($candidates as $cand) {
$sanitized = trim($cand, " \t\n\r\0\x0B[]\"'/"); $candSan = trim($cand, " \t\n\r\0\x0B[]\"'/");
if (empty($sanitized)) continue; if (empty($candSan)) continue;
$lower = strtolower($sanitized);
$normalized = str_replace([' ', '-', '_'], '', $lower); // Check if candidate contains colon or equals, e.g. "plants:plants" or "storymachine:geschichtenmaschine"
if (isset($slugMap[$lower])) { $subParts = preg_split('/[:=]/', $candSan);
$clean[] = $slugMap[$lower]; $matched = false;
} elseif (isset($slugMap[$normalized])) { foreach ($subParts as $part) {
$clean[] = $slugMap[$normalized]; $pSan = trim($part, " \t\n\r\0\x0B[]\"'/");
} else { if (empty($pSan)) continue;
$clean[] = $sanitized; $pLower = strtolower($pSan);
$pNorm = str_replace([' ', '-', '_'], '', $pLower);
if (isset($slugMap[$pLower])) {
$clean[] = $slugMap[$pLower];
$matched = true;
break;
} elseif (isset($slugMap[$pNorm])) {
$clean[] = $slugMap[$pNorm];
$matched = true;
break;
}
}
if (!$matched) {
$lower = strtolower($candSan);
$normalized = str_replace([' ', '-', '_'], '', $lower);
if (isset($slugMap[$lower])) {
$clean[] = $slugMap[$lower];
} elseif (isset($slugMap[$normalized])) {
$clean[] = $slugMap[$normalized];
} elseif (isset($allModules[$lower])) {
$clean[] = $lower;
}
} }
} }
} }