LuminaWebsite/includes/calendar_audience.php
Maaxxs b96bbd1780 Consilium: own Discord server - its roles decide who sees the Consilium; rights for Consilium raids and entries
Asked for: the alliances move to their own Discord server with the roles Force Commander, Legion Lead, Legion
Officer and Legionär. Decided: everyone with a role there sees the Consilium (our members too), no role per legion
(assignment stays on the website), new accounts are approved by our admins, rights per role as planned, a
permission for Consilium calendar entries that is assigned later. Server ID 1553882046793777283.

- Two Discord servers: settings.consilium_guild_id (seeded, Verwaltung -> Discord-Bot with a check whether the bot
  is there); a group's role lies on one of them (roles.discord_guild_id, NULL = legion, schema 71). Login and the
  periodic sync read both memberships (discord_fetch_memberships/discord_apply_memberships) and sync groups per
  server; name, avatar, joined date and classes come from the legion server, for allies from the Consilium server.
- Leaving: whoever leaves a server loses its groups; an account is deactivated only when it is on neither
  (discord_member_left_guild; bot_api.php takes in_guilds from the bot, the sync checks all servers, older bot
  versions cannot deactivate Consilium members). Logout text no longer names a server.
- Group form lists the roles of both servers, the group list marks Consilium roles; Consilium-Raids channel is
  chosen from the Consilium server's channels.
- Rights per area: consilium.raids / consilium.raids.manage for Consilium raids (create, manage, restore, delete),
  raids.create / raids.manage only for legion raids (raid_area_can_create, raid_area_can_manage_all,
  raid_can_manage asks the raid's area). consilium.calendar: only with it Consilium calendar entries (allies without
  it cannot add entries; legion members with it get "Für wen?" with legion/Consilium).
- Consilium member list: everyone with a role on the Consilium server - our legion as its own section, allied legions,
  without legion - with the Consilium ranks as tags; legion list and profiles leave the Consilium groups out for
  those who do not see the Consilium. Allies pick their class in the profile.
- Consilium admin page: setup checklist for the new structure with the groups of the Consilium server and their
  rights (setup only for roles.manage). Privacy page, README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 02:55:59 +02:00

77 lines
3.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
declare(strict_types=1);
/**
* Fuer wen ein Kalender-Termin der Mitglieder gedacht ist (calendar_entries.audience). Termine nur
* fuer die Leitung tragen Konten mit calendar.leadership ein (die Sedes Luminis):
* all - wie bisher: alle sehen ihn und koennen "Bin dabei" klicken
* consilium - fuer das Consilium Elyseum: sehen und teilnehmen nur mit consilium.view - die verbuendeten Legionen
* und aus der Legion z.B. die Leitung, normale Mitglieder nicht
* leadership - alle sehen ihn, teilnehmen kann nur die Leitung (z.B. eine Besprechung)
* internal - nur die Leitung sieht ihn ueberhaupt
* Mitglieder verbuendeter Legionen (consilium_only()) sehen nur Consilium-Termine und tragen nur solche ein; der
* oeffentliche Kalender zeigt sie nicht.
*/
const CALENDAR_AUDIENCES = [
'all' => 'Alle Mitglieder',
'consilium' => 'Consilium Elyseum – auch die verbündeten Legionen sehen ihn und nehmen teil',
'leadership' => 'Nur Leitung nimmt teil (für alle sichtbar)',
'internal' => 'Intern – nur für die Leitung sichtbar',
];
function calendar_can_lead(): bool
{
return user_has_permission('calendar.leadership');
}
/**
* Darf der Betrachter den Termin sehen? (Freigabe/Moderation prueft der Aufrufer wie bisher.) $consiliumOnly: ob er nur
* zum Consilium gehoert, $seeConsilium: ob er das Consilium sieht (consilium.view) - null = das angemeldete Konto.
*/
function calendar_can_view(array $row, bool $canLead, int $myId, ?bool $consiliumOnly = null, ?bool $seeConsilium = null): bool
{
$audience = $row['audience'] ?? 'all';
if ((int) $row['user_id'] === $myId) {
return true;
}
if ($consiliumOnly ?? consilium_only()) {
return $audience === 'consilium';
}
if ($audience === 'consilium') {
return $seeConsilium ?? consilium_can_view();
}
return $audience !== 'internal' || $canLead;
}
/** Darf der Betrachter sich mit "Bin dabei" eintragen? (Sehen darf er ihn, siehe calendar_can_view().) */
function calendar_can_join(array $row, bool $canLead): bool
{
return in_array($row['audience'] ?? 'all', ['all', 'consilium'], true) || $canLead;
}
/** Darf das angemeldete Konto Consilium-Termine eintragen (consilium.calendar, und es sieht das Consilium)? */
function calendar_can_add_consilium(): bool
{
return consilium_can_view() && user_has_permission('consilium.calendar');
}
/**
* Zielgruppe aus dem Formular: die der Leitung nur mit calendar.leadership, Consilium-Termine nur mit
* consilium.calendar - sonst bleibt es beim bisherigen Wert. Verbuendete aus dem Consilium tragen immer
* Consilium-Termine ein.
*/
function calendar_audience_input(?string $current, bool $canLead): string
{
if (consilium_only()) {
return 'consilium';
}
$value = (string) ($_POST['audience'] ?? '');
if ($value === 'consilium') {
if (calendar_can_add_consilium()) {
return $value;
}
} elseif (isset(CALENDAR_AUDIENCES[$value]) && ($canLead || ($value === 'all' && calendar_can_add_consilium()))) {
return $value;
}
return $current !== null && isset(CALENDAR_AUDIENCES[$current]) ? $current : 'all';
}