This commit is contained in:
@@ -179,10 +179,14 @@ final class AccountPages
|
||||
$calendarSync = $pdo ? new CalendarSync($app) : null;
|
||||
$section = (string)($_GET['section'] ?? 'profile');
|
||||
$canManageSystemSettings = $communityAccess ? $communityAccess->canManageApplications($userId) : false;
|
||||
$canManageProfileLevels = $communityAccess ? $communityAccess->canManageRoles($userId) : false;
|
||||
$allowedSections = ['profile', 'children', 'events', 'places', 'community', 'settings'];
|
||||
if ($canManageSystemSettings) {
|
||||
$allowedSections[] = 'system';
|
||||
}
|
||||
if ($canManageProfileLevels) {
|
||||
$allowedSections[] = 'profile-levels';
|
||||
}
|
||||
|
||||
if ($systemSettings) {
|
||||
$systemSettings->ensureSchema();
|
||||
@@ -641,6 +645,68 @@ final class AccountPages
|
||||
}
|
||||
$communityAccess->submitApplication($userId, (string)($_POST['motivation'] ?? ''));
|
||||
$info = 'Deine Bewerbung wurde eingereicht.';
|
||||
} elseif ($action === 'community_level_save') {
|
||||
if (!$canManageProfileLevels || !$community) {
|
||||
throw new \RuntimeException('Keine Berechtigung für Profil-Levels.');
|
||||
}
|
||||
|
||||
$levelId = trim((string)($_POST['level_id'] ?? ''));
|
||||
$label = trim((string)($_POST['label'] ?? ''));
|
||||
$minValueRaw = trim((string)($_POST['min_points'] ?? '0'));
|
||||
$icon = trim((string)($_POST['icon'] ?? ''));
|
||||
if ($label === '') {
|
||||
throw new \RuntimeException('Bitte gib einen Namen für das Community-Level an.');
|
||||
}
|
||||
if ($minValueRaw === '' || !is_numeric($minValueRaw)) {
|
||||
throw new \RuntimeException('Bitte gib eine gültige Mindestpunktzahl an.');
|
||||
}
|
||||
|
||||
$rights = [];
|
||||
foreach (array_keys(Community::membershipRightDefinitions()) as $rightKey) {
|
||||
$rights[$rightKey] = ((string)($_POST['rights'][$rightKey] ?? '0')) === '1';
|
||||
}
|
||||
|
||||
$levels = $community->listMembershipLevels();
|
||||
$updated = false;
|
||||
foreach ($levels as &$level) {
|
||||
if ((string)($level['id'] ?? '') !== $levelId) {
|
||||
continue;
|
||||
}
|
||||
$level['label'] = $label;
|
||||
$level['min'] = (float)$minValueRaw;
|
||||
$level['icon'] = $icon;
|
||||
$level['rights'] = $rights;
|
||||
$updated = true;
|
||||
break;
|
||||
}
|
||||
unset($level);
|
||||
|
||||
if (!$updated) {
|
||||
$levels[] = [
|
||||
'id' => $levelId !== '' ? $levelId : self::slugifyValue($label . '-' . $minValueRaw . '-' . bin2hex(random_bytes(3))),
|
||||
'label' => $label,
|
||||
'min' => (float)$minValueRaw,
|
||||
'icon' => $icon,
|
||||
'rights' => $rights,
|
||||
];
|
||||
}
|
||||
|
||||
$community->saveMembershipLevels($levels, $userId);
|
||||
$info = $updated ? 'Community-Level gespeichert.' : 'Community-Level angelegt.';
|
||||
} elseif ($action === 'community_level_delete') {
|
||||
if (!$canManageProfileLevels || !$community) {
|
||||
throw new \RuntimeException('Keine Berechtigung für Profil-Levels.');
|
||||
}
|
||||
$levelId = trim((string)($_POST['level_id'] ?? ''));
|
||||
$levels = array_values(array_filter(
|
||||
$community->listMembershipLevels(),
|
||||
static fn(array $level): bool => (string)($level['id'] ?? '') !== $levelId
|
||||
));
|
||||
if ($levels === []) {
|
||||
throw new \RuntimeException('Mindestens ein Community-Level muss erhalten bleiben.');
|
||||
}
|
||||
$community->saveMembershipLevels($levels, $userId);
|
||||
$info = 'Community-Level gelöscht.';
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
$error = $e->getMessage();
|
||||
@@ -843,7 +909,10 @@ final class AccountPages
|
||||
|
||||
$communityPoints = $community ? $community->computePoints($userId) : 0.0;
|
||||
$communityLevel = $community ? $community->membershipLevel($communityPoints) : ['label' => '', 'icon' => ''];
|
||||
$communityLevelDefinitions = $community ? $community->listMembershipLevels() : [];
|
||||
$communityLevelRightDefinitions = Community::membershipRightDefinitions();
|
||||
$communityRoles = $communityAccess ? $communityAccess->getUserRoles($userId) : [];
|
||||
$systemRoleAssignments = $communityAccess && $canManageProfileLevels ? $communityAccess->listRoleAssignments() : [];
|
||||
$communityApplication = $communityAccess ? $communityAccess->getLatestApplication($userId) : null;
|
||||
$communityCanApply = $communityAccess ? $communityAccess->canApplyForForumAdmin($userId, $communityPoints) : false;
|
||||
$communityRestrictions = $communityAccess ? $communityAccess->getRestrictionState($userId) : [
|
||||
@@ -851,6 +920,35 @@ final class AccountPages
|
||||
'reply_blocked' => false,
|
||||
'reason' => null,
|
||||
];
|
||||
$systemLevelDefinitions = [
|
||||
[
|
||||
'key' => 'forum_admin',
|
||||
'label' => 'Forum-Admin',
|
||||
'rights' => [
|
||||
'Themen und Antworten moderieren',
|
||||
'Community-Sperren setzen und aufheben',
|
||||
'Meldungen bearbeiten',
|
||||
],
|
||||
],
|
||||
[
|
||||
'key' => 'site_admin',
|
||||
'label' => 'Site-Admin',
|
||||
'rights' => [
|
||||
'Beinhaltet alle Rechte von Forum-Admin',
|
||||
'Community-Admin-Bewerbungen bearbeiten',
|
||||
'System-Einstellungen verwalten',
|
||||
],
|
||||
],
|
||||
[
|
||||
'key' => 'owner',
|
||||
'label' => 'SiteOwner',
|
||||
'rights' => [
|
||||
'Beinhaltet alle Rechte von Site-Admin',
|
||||
'System-Rollen vergeben und entziehen',
|
||||
'Profil-Levels verwalten',
|
||||
],
|
||||
],
|
||||
];
|
||||
$systemSettingsValues = $systemSettings ? $systemSettings->getAll() : [];
|
||||
$listingCatalogStatus = $listingCatalog ? $listingCatalog->status() : ['complete' => false, 'missing' => [], 'tables' => []];
|
||||
if (!in_array($section, $allowedSections, true)) {
|
||||
@@ -889,11 +987,16 @@ final class AccountPages
|
||||
'eventLocationOptions',
|
||||
'communityPoints',
|
||||
'communityLevel',
|
||||
'communityLevelDefinitions',
|
||||
'communityLevelRightDefinitions',
|
||||
'communityRoles',
|
||||
'systemRoleAssignments',
|
||||
'communityApplication',
|
||||
'communityCanApply',
|
||||
'communityRestrictions',
|
||||
'systemLevelDefinitions',
|
||||
'canManageSystemSettings',
|
||||
'canManageProfileLevels',
|
||||
'systemSettingsValues',
|
||||
'listingCatalogStatus',
|
||||
'avatarBuilder',
|
||||
|
||||
Reference in New Issue
Block a user