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 9a92f92 commit e5e11d0
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions app/Module/ModuleMapProviderTrait.php
Expand Up @@ -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('<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 e5e11d0

Please sign in to comment.