From 9a0d6453bc84de194dd67ab750af514d6360de67 Mon Sep 17 00:00:00 2001 From: David Drury Date: Mon, 20 Feb 2023 14:27:35 +0000 Subject: [PATCH] Improve detection of valid api key --- app/Module/ModuleMapProviderTrait.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/Module/ModuleMapProviderTrait.php b/app/Module/ModuleMapProviderTrait.php index 08a2af34a8d..e99ab31e9e1 100644 --- a/app/Module/ModuleMapProviderTrait.php +++ b/app/Module/ModuleMapProviderTrait.php @@ -50,14 +50,18 @@ public function leafletJsTileLayers(): array */ public function hasApiKey(): bool { - $api_key = $this->getPreference('api_key', 'not-needed'); + $api_key = $this->getPreference('api_key'); - if ($api_key !== 'not-needed' && $api_key === '' && Auth::isAdmin()) { + // Do the functions to manage the config page exist in the provider module? + $function_diff = array_diff(get_class_methods(get_class($this)), get_class_methods(get_parent_class($this) ?? '')); + + $error = in_array("getAdminAction", $function_diff) && $api_key === ''; + if ($error && Auth::isAdmin()) { $message = I18N::translate('The %s service requires an API key.', e($this->getConfigLink()), $this->title()); throw new HttpServerErrorException($message); } - return $api_key !== ''; + return !$error; } }