Share repeated controller and service code
- AppController: joinUrl(), adminUrlFor(), setPollInterval() and protect() instead of copies in Admin-, Home-, Participate- and EmbedController. - PollMailer::sendSafely() replaces two try/catch blocks around mail sending. - Slide::optionIds() replaces five identical array_map() calls. - PollStateService: one pollPayload() for presenter and embed; the vote action passes the already loaded slide instead of loading it again. - ResultsService::forSlide() takes the answer/comment limit and the rating flag, so ReportService no longer queries answers, comments and the scale distribution twice and the export loads the slides only once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ad537b9b34
commit
3e44ded107
14 files changed
+189
-137
No files matched your search
@@ -3,10 +3,12 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Model\Entity\Poll;
|
||||
use App\Service\ThrottleService;
|
||||
use Cake\Controller\Controller;
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Http\Response;
|
||||
use Cake\Routing\Router;
|
||||
|
||||
/**
|
||||
* Base controller of PlenarIO. Security headers (CSP, framing, nosniff) are set for every
|
||||
@@ -24,6 +26,53 @@ class AppController extends Controller
|
||||
$this->loadComponent('Flash');
|
||||
}
|
||||
|
||||
/**
|
||||
* Pages whose URL contains a secret (admin token, embed key): never send it as referrer,
|
||||
* never index them, never cache them.
|
||||
*
|
||||
* @param \Cake\Http\Response $response Response
|
||||
* @return \Cake\Http\Response
|
||||
*/
|
||||
protected function protect(Response $response): Response
|
||||
{
|
||||
return $response
|
||||
->withHeader('Referrer-Policy', 'no-referrer')
|
||||
->withHeader('X-Robots-Tag', 'noindex, nofollow')
|
||||
->withHeader('Cache-Control', 'no-store, private');
|
||||
}
|
||||
|
||||
/**
|
||||
* Absolute participant URL of a poll (QR code, mails, presenter).
|
||||
*
|
||||
* @param \App\Model\Entity\Poll $poll Poll
|
||||
* @return string
|
||||
*/
|
||||
protected function joinUrl(Poll $poll): string
|
||||
{
|
||||
return Router::url(['_name' => 'participate', 'code' => $poll->join_code], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Absolute admin URL for a plain token (only for mails and the confirmation page).
|
||||
*
|
||||
* @param string $token Plain admin token
|
||||
* @return string
|
||||
*/
|
||||
protected function adminUrlFor(string $token): string
|
||||
{
|
||||
return Router::url(['_name' => 'admin', 'token' => $token], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Passes the polling interval of live pages to the view (`pollIntervalMs`).
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setPollInterval(): void
|
||||
{
|
||||
$this->set('pollIntervalMs', (int)Configure::read('Plenario.pollIntervalMs', 2000));
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a hit of the client IP in a throttle bucket (see ThrottleService).
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user