Skip to content

Commit 0436737

Browse files
authored
Merge pull request #902 from UN-OCHA/berliner/HPC-9390
HPC-9390: Fix issue with endpoint query arguments not being properly initialized, leading to invalid API requests in some situations
2 parents 10ff0f2 + 6fa561c commit 0436737

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

html/modules/custom/ghi_plans/src/Helpers/PlanEntityHelper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static function getPlanEntityObjects($plan_data) {
9090
*/
9191
public static function getPlanEntity($entity_id, $version_argument = 'current') {
9292
/** @var \Drupal\hpc_api\Query\EndpointQuery $query */
93-
$query = \Drupal::service('hpc_api.endpoint_query');
93+
$query = clone \Drupal::service('hpc_api.endpoint_query');
9494
$query->setArguments([
9595
'endpoint' => 'planEntity/' . $entity_id,
9696
'api_version' => 'v2',

html/modules/custom/ghi_plans/src/Plugin/EndpointQuery/PlanProjectFundingQuery.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@
1414
* id = "plan_project_funding_query",
1515
* label = @Translation("Plan funding summary query"),
1616
* endpoint = {
17-
* "public" = "fts/project/plan?planid={plan_id}&groupBy=project",
18-
* "version" = "v1"
17+
* "public" = "fts/project/plan",
18+
* "version" = "v1",
19+
* "query" = {
20+
* "planid" = "{plan_id}",
21+
* "groupBy" = "project"
22+
* }
1923
* }
2024
* )
2125
*/

html/modules/custom/hpc_api/src/Query/EndpointQueryBase.php

+10-8
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,19 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
7272
$endpoint_query_args = $plugin_definition['endpoint']['query'] ?? [];
7373

7474
$this->isAutenticatedEndpoint = $endpoint_authenticated && $this->user->isAuthenticated() && $this->getHidAccessToken();
75+
$endpoint_url = $this->isAutenticatedEndpoint ? $endpoint_authenticated : $endpoint_public;
76+
$auth_method = EndpointQuery::AUTH_METHOD_BASIC;
7577
if ($endpoint_api_key) {
76-
$this->endpointQuery->setAuthMethod(EndpointQuery::AUTH_METHOD_API_KEY);
77-
$this->endpointQuery->setEndpoint($endpoint_api_key);
78-
}
79-
else {
80-
$this->endpointQuery->setAuthMethod(EndpointQuery::AUTH_METHOD_BASIC);
81-
$this->endpointQuery->setEndpoint($this->isAutenticatedEndpoint ? $endpoint_authenticated : $endpoint_public);
78+
$auth_method = EndpointQuery::AUTH_METHOD_API_KEY;
79+
$endpoint_url = $endpoint_api_key;
8280
}
8381

84-
$this->endpointQuery->setEndpointVersion($endpoint_version);
85-
$this->endpointQuery->setEndpointArguments($endpoint_query_args);
82+
$this->endpointQuery->setArguments([
83+
'api_version' => $endpoint_version,
84+
'endpoint' => $endpoint_url,
85+
'query_args' => $endpoint_query_args,
86+
'auth_method' => $auth_method,
87+
]);
8688
}
8789

8890
/**

0 commit comments

Comments
 (0)