fe_comment: recipients are the FE users of the feedback group
- The selectable recipients are no longer a hand-maintained setting but
every active frontend user of the feedback group (feUserGroup) with a
valid e-mail address; the id is the fe_users uid, so a stored selection
survives users joining or leaving. The `recipients` setting is marked
unused
- Each recipient in the state payload carries label, email and selected
(the stored choice), for a checkbox list with "select all" above the
submit button
- submit accepts the checked ids directly ({"recipients": [uids]}),
validates them against the group, stores and uses them, and reports
the addresses used as sentTo; no selection falls back to mailTo
- migrations/check_fecomment_user.php: all summaries and items of one
user incl. deleted ones, for diagnosis
This commit is contained in:
1 parent
eb0d0d9ebc
commit
74502e60a3
5 files changed
+114
-14
No files matched your search
@@ -79,7 +79,7 @@ final class FeedbackApiMiddleware implements MiddlewareInterface
|
||||
$route === 'upload' => $this->upload($request, $user),
|
||||
(bool)preg_match('#^attachment/(\d+)/delete$#', $route, $m) => $this->deleteAttachment($user, (int)$m[1]),
|
||||
$route === 'summary' => $this->updateSummary($request, $user),
|
||||
$route === 'submit' => $this->submit($user),
|
||||
$route === 'submit' => $this->submit($request, $user),
|
||||
default => new JsonResponse(['error' => 'unknown route'], 404),
|
||||
};
|
||||
} catch (\Throwable $e) {
|
||||
@@ -237,7 +237,7 @@ final class FeedbackApiMiddleware implements MiddlewareInterface
|
||||
}
|
||||
|
||||
/** @param array{uid:int,username:string,name:string,email:string} $user */
|
||||
private function submit(array $user): ResponseInterface
|
||||
private function submit(ServerRequestInterface $request, array $user): ResponseInterface
|
||||
{
|
||||
$summary = $this->openSummary($user['uid'], false);
|
||||
if ($summary === null) {
|
||||
@@ -249,6 +249,19 @@ final class FeedbackApiMiddleware implements MiddlewareInterface
|
||||
}
|
||||
|
||||
$recipientMap = $this->recipientMap();
|
||||
|
||||
// The checkbox selection may travel with the submit itself
|
||||
// ({"recipients": [ids]}) - validated against the configured list,
|
||||
// stored on the summary, then used. Without it the stored selection
|
||||
// applies; an empty selection falls back to mailTo.
|
||||
$body = $this->jsonBody($request);
|
||||
if (array_key_exists('recipients', $body) && is_array($body['recipients'])) {
|
||||
$chosenIds = array_values(array_intersect(array_map('intval', $body['recipients']), array_keys($recipientMap)));
|
||||
$summary['recipients'] = implode(',', $chosenIds);
|
||||
GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable(self::T_SUMMARY)
|
||||
->update(self::T_SUMMARY, ['recipients' => $summary['recipients'], 'tstamp' => time()], ['uid' => (int)$summary['uid']]);
|
||||
}
|
||||
|
||||
$chosen = GeneralUtility::intExplode(',', (string)$summary['recipients'], true);
|
||||
$to = [];
|
||||
foreach ($chosen as $id) {
|
||||
@@ -307,7 +320,8 @@ final class FeedbackApiMiddleware implements MiddlewareInterface
|
||||
|
||||
GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable(self::T_SUMMARY)
|
||||
->update(self::T_SUMMARY, ['status' => 'sent', 'sent_at' => time(), 'tstamp' => time()], ['uid' => (int)$summary['uid']]);
|
||||
return new JsonResponse(['ok' => true, 'sent' => count($payload['items'])]);
|
||||
// sentTo: the addresses actually used, for the confirmation message
|
||||
return new JsonResponse(['ok' => true, 'sent' => count($payload['items']), 'sentTo' => array_values($to)]);
|
||||
}
|
||||
|
||||
// ---- helpers ------------------------------------------------------------
|
||||
@@ -379,10 +393,10 @@ final class FeedbackApiMiddleware implements MiddlewareInterface
|
||||
->update(self::T_FEEDBACK, ['attachments' => $count, 'tstamp' => time()], ['uid' => $feedbackUid]);
|
||||
}
|
||||
|
||||
/** @return array<int,array{label:string,email:string}> id => recipient */
|
||||
/** @return array<int,array{label:string,email:string}> fe_users uid => recipient (FE users of the feedback group) */
|
||||
private function recipientMap(): array
|
||||
{
|
||||
return $this->settings->recipients();
|
||||
return $this->stateService()->recipientMap();
|
||||
}
|
||||
|
||||
/** @return array<string,mixed> */
|
||||
|
||||
Reference in new issue
Block a user