From 6179f5ba0895df17cb4e25ac5d8f4f50ffca995e 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 | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/Module/ModuleMapProviderTrait.php b/app/Module/ModuleMapProviderTrait.php index 08a2af34a8..ed28cd471c 100644 --- a/app/Module/ModuleMapProviderTrait.php +++ b/app/Module/ModuleMapProviderTrait.php @@ -50,14 +50,19 @@ 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()) { + // Function count === 3 - module doesn't have methods to provide a config page + // Function count === 5 - module does have a config page + $function_count = count(array_diff(get_class_methods(__CLASS__), get_class_methods(get_parent_class()))); + + $error = $function_count === 5 && $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; } }