Skip to content

Commit

Permalink
[TASK] Make it possible to disable flash messages in MauticAuthorizeS…
Browse files Browse the repository at this point in the history
…ervice
  • Loading branch information
yabid21 committed Sep 15, 2021
1 parent d20181f commit cc8fd6f
Showing 1 changed file with 35 additions and 13 deletions.
48 changes: 35 additions & 13 deletions Classes/Service/MauticAuthorizeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class MauticAuthorizeService
*/
protected $minimumMauticVersion = '2.14.2';

/** @var bool */
protected $createFlashMessages = true;

public function __construct(
array $extensionConfiguration = [],
AuthInterface $authorization = null,
Expand All @@ -58,7 +61,9 @@ public function validateCredentials(): bool
|| $this->extensionConfiguration['secretKey'] === ''
|| $this->extensionConfiguration['authorizeMode'] === ''
) {
$this->showCredentialsInformation();
if ($this->createFlashMessages) {
$this->showCredentialsInformation();
}

return false;
}
Expand Down Expand Up @@ -91,13 +96,17 @@ public function checkConnection()
$version = $api->getMauticVersion();

if ($version === null) {
$this->addErrorMessage();
if ($this->createFlashMessages) {
$this->addErrorMessage();
}

return false;
}

if (version_compare($version, $this->minimumMauticVersion, '<')) {
$this->showIncorrectVersionInformation($version);
if ($this->createFlashMessages) {
$this->showIncorrectVersionInformation($version);
}

return false;
}
Expand All @@ -117,12 +126,16 @@ public function checkConnection()
}

if (0 === strpos($this->extensionConfiguration['baseUrl'], 'http:')) {
$this->showInsecureConnectionInformation();
if ($this->createFlashMessages) {
$this->showInsecureConnectionInformation();
}

return false;
}

$this->showSuccessMessage();
if ($this->createFlashMessages) {
$this->showSuccessMessage();
}

return true;
}
Expand All @@ -140,13 +153,15 @@ protected function showCredentialsInformation()
$missingInformation[] = 'secretKey';
}

$this->addErrorMessage(
$this->translate('authorization.missingInformation.title'),
sprintf(
$this->translate('authorization.missingInformation.message'),
implode(', ', $missingInformation)
)
);
if ($this->createFlashMessages) {
$this->addErrorMessage(
$this->translate('authorization.missingInformation.title'),
sprintf(
$this->translate('authorization.missingInformation.message'),
implode(', ', $missingInformation)
)
);
}
}

public function authorize()
Expand All @@ -170,7 +185,9 @@ public function authorize()
HttpUtility::redirect($_SERVER['REQUEST_URI']);
}
} catch (\Exception $exception) {
$this->addErrorMessage((string)$exception->getCode(), (string)$exception->getMessage());
if ($this->createFlashMessages) {
$this->addErrorMessage((string)$exception->getCode(), (string)$exception->getMessage());
}

return false;
}
Expand Down Expand Up @@ -288,4 +305,9 @@ public function accessTokenToBeRefreshed(): bool

return false;
}

public function deactivateFlashMessages(): void
{
$this->createFlashMessages = false;
}
}

0 comments on commit cc8fd6f

Please sign in to comment.