From 080f2b37572788023142cc531739b89c80a6b1ae Mon Sep 17 00:00:00 2001 From: Amir Meshkin Date: Tue, 6 Feb 2024 10:06:46 -0500 Subject: [PATCH 1/4] FOIA-0000: Hotfix for the nasa_pafo webform. --- config/default/webform.webform.nasa_pafo_form.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/default/webform.webform.nasa_pafo_form.yml b/config/default/webform.webform.nasa_pafo_form.yml index f778467b4..af1938a5b 100644 --- a/config/default/webform.webform.nasa_pafo_form.yml +++ b/config/default/webform.webform.nasa_pafo_form.yml @@ -92,7 +92,7 @@ elements: |- required: ':input[name="email"]': empty: true - '#default_value': 'United States'j + '#default_value': 'United States' request_category: '#type': select '#title': 'What type of requester are you?' From 7811a63db89cee96e81c3850a3f4bd79fd1a32fe Mon Sep 17 00:00:00 2001 From: Amir Meshkin Date: Fri, 2 Feb 2024 16:21:23 -0500 Subject: [PATCH 2/4] FOIA-455: Return an error message if request is not from the website. --- .../src/Plugin/rest/resource/WebformSubmissionResource.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docroot/modules/custom/foia_api/src/Plugin/rest/resource/WebformSubmissionResource.php b/docroot/modules/custom/foia_api/src/Plugin/rest/resource/WebformSubmissionResource.php index ca25fa854..fb596a418 100644 --- a/docroot/modules/custom/foia_api/src/Plugin/rest/resource/WebformSubmissionResource.php +++ b/docroot/modules/custom/foia_api/src/Plugin/rest/resource/WebformSubmissionResource.php @@ -128,6 +128,13 @@ public function post($data) { $this->logSubmission($statusCode, $message); return new ModifiedResourceResponse(['errors' => $message], $statusCode); } + $websiteRequest = isset($_SERVER["HTTP_X_API_USER_ID"]) && $_SERVER["HTTP_X_API_USER_ID"] === \Drupal::config('foia.secrets')->get('api_user_id'); + if (!$websiteRequest) { + $statusCode = 400; + $message = t("To submit FOIA requests using FOIA.gov, you must use the request forms on the site."); + $this->logSubmission($statusCode, "api_submission: $message"); + return new ModifiedResourceResponse(['errors' => $message], $statusCode); + } $webformId = $data['id'] ?? ''; if (!$webformId) { From 556a3828ee287ee3b540646eb3f61a1bbe389082 Mon Sep 17 00:00:00 2001 From: Amir Meshkin Date: Mon, 5 Feb 2024 12:41:47 -0500 Subject: [PATCH 3/4] FOIA-455: Adding X-Api-User-Id which may be needed. --- docroot/sites/default/services.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docroot/sites/default/services.yml b/docroot/sites/default/services.yml index 5b91fead1..3b677868e 100644 --- a/docroot/sites/default/services.yml +++ b/docroot/sites/default/services.yml @@ -163,7 +163,7 @@ parameters: # Specify allowed headers, like 'x-allowed-header'. # X-Api-Key is needed for api.data.gov work-around # https://github.com/NREL/api-umbrella/issues/391 - allowedHeaders: ['Accept', 'Content-Type', 'X-Api-Key'] + allowedHeaders: ['Accept', 'Content-Type', 'X-Api-Key', 'X-Api-User-Id'] # Specify allowed request methods, specify ['*'] to allow all possible ones. allowedMethods: ['GET', 'POST'] # Configure requests allowed from specific origins. From 7d1a1c0e567fbee313df81f427928ee70e6a8476 Mon Sep 17 00:00:00 2001 From: Brock Fanning Date: Thu, 1 Feb 2024 17:40:59 +0000 Subject: [PATCH 4/4] FOIA-459: Safety code during the XML export. --- docroot/modules/custom/foia_export_xml/src/ExportXml.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docroot/modules/custom/foia_export_xml/src/ExportXml.php b/docroot/modules/custom/foia_export_xml/src/ExportXml.php index c2edef5de..e77d308e9 100644 --- a/docroot/modules/custom/foia_export_xml/src/ExportXml.php +++ b/docroot/modules/custom/foia_export_xml/src/ExportXml.php @@ -816,6 +816,11 @@ protected function exemption3StatuteSection() { // Add component data for each statute. foreach ($components as $component_info) { $agency_component = $component_info->field_agency_component->referencedEntities()[0]; + if (empty($agency_component)) { + // This protects against exceptions caused by the existence of empty + // paragraph items. + continue; + } $item = $this->addElementNs('foia:ReliedUponStatuteOrganizationAssociation', $statuteSection); $this->addElementNs('foia:ComponentDataReference', $item) ->setAttribute('s:ref', $local_id);