Skip to content

Commit

Permalink
Improve detection of valid api key
Browse files Browse the repository at this point in the history
  • Loading branch information
ddrury committed Feb 20, 2023
1 parent 8d36252 commit 6179f5b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/Module/ModuleMapProviderTrait.php
Expand Up @@ -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('<a href="%s">The %s service requires an API key.', e($this->getConfigLink()), $this->title());

throw new HttpServerErrorException($message);
}

return $api_key !== '';
return !$error;
}
}

0 comments on commit 6179f5b

Please sign in to comment.