PluginProbe
The Innovative Form Builder – IvyForms / 1.5.1
The Innovative Form Builder – IvyForms v1.5.1
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
← All changes | backend/src/Controllers/Entry/GetEntryCountController.php +34 -4 1.0 → 1.5.1 View file →
@@ -12,8 +12,9 @@
12 12 use IvyForms\Common\Exceptions\NotFoundException;
13 13 use IvyForms\Common\Sanitizer\Sanitizer;
14 14 use IvyForms\Controllers\Controller;
15 15 use IvyForms\Services\Entry\EntryService;
16 +use IvyForms\Services\Permissions\RoutePermissionService;
16 17 use IvyForms\Services\Translations\BackendStrings;
17 18 use WP_REST_Request;
18 19 use WP_REST_Response;
19 20
@@ -25,11 +26,16 @@
25 26 class GetEntryCountController extends Controller
26 27 {
27 28 private EntryService $entryService;
28 29
29 - public function __construct(EntryService $entryService)
30 - {
31 - $this->entryService = $entryService;
30 + private RoutePermissionService $routePermissionService;
31 +
32 + public function __construct(
33 + EntryService $entryService,
34 + RoutePermissionService $routePermissionService
35 + ) {
36 + $this->entryService = $entryService;
37 + $this->routePermissionService = $routePermissionService;
32 38 }
33 39
34 40 /**
35 41 * Fetches the count of entries for a given form ID or multiple form IDs.
@@ -52,9 +58,33 @@
52 58 BackendStrings::getExceptionStrings()['form_id_required']
53 59 );
54 60 }
55 61
56 - $formIds = Sanitizer::sanitizeIds($data->get_param('id')) ;
62 + $idParam = $data->get_param('id');
63 + if ($idParam === null || $idParam === '') {
64 + throw new InvalidArgumentException(
65 + BackendStrings::getExceptionStrings()['form_id_required']
66 + );
67 + }
68 +
69 + $formIds = array_values(array_filter(
70 + Sanitizer::sanitizeIds(is_array($idParam) ? $idParam : [$idParam]),
71 + static function (int $formId): bool {
72 + return $formId > 0;
73 + }
74 + ));
75 + if ($formIds === []) {
76 + throw new InvalidArgumentException(
77 + BackendStrings::getExceptionStrings()['form_id_required']
78 + );
79 + }
80 +
81 + foreach ($formIds as $formId) {
82 + if (!$this->routePermissionService->canViewEntries($formId)) {
83 + throw new ForbiddenException('forbidden');
84 + }
85 + }
86 +
57 87 $counts = $this->entryService->getEntryManager()->getEntryCountByFormIds($formIds);
58 88 return new WP_REST_Response([
59 89 'message' => BackendStrings::getCommonStrings()['ok'],
60 90 'data' => ['counts' => $counts],