Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,19 @@ public function isMailConfigEnabled(): bool {
return $this->config->getAppValue('mail', 'ionos-mailconfig-enabled', 'no') === 'yes';
}

/**
* Check if mailbox creation is possible for this instance.
*
* This flag is provided by the operator via the IONOS_MAILBOX_POSSIBLE environment
* variable (set by PSS through the helm chart). It is only true when a customer
* domain is connected to the instance.
*
* @return bool True if mailbox creation is possible, false otherwise
*/
public function isMailboxPossible(): bool {
return $this->config->getSystemValue('ncw.mailboxPossible', '') === 'true';
}

/**
* Check if IONOS integration is fully enabled and configured
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ public function isMailConfigAvailable(?string $userId = null): bool {
return false;
}

// Check if mailbox creation is possible for this instance.
// This flag is set by the operator (via IONOS_MAILBOX_POSSIBLE env var) and reflects
// whether a customer domain is connected. Without a customer domain, mailbox creation
// must not be offered.
if (!$this->ionosConfigService->isMailboxPossible()) {
$this->logger->debug('IONOS mail config not available - mailbox creation not possible for this instance');
return false;
}

// Get user ID - either from parameter or from session
if ($userId === null) {
$user = $this->userSession->getUser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,33 @@ public function testGetMailDomainWithSimpleDomain(): void {
$this->assertEquals('example.com', $result);
}

public function testIsMailboxPossibleWhenTrue(): void {
$this->config->method('getSystemValue')
->with('ncw.mailboxPossible', '')
->willReturn('true');

$result = $this->service->isMailboxPossible();
$this->assertTrue($result);
}

public function testIsMailboxPossibleWhenFalse(): void {
$this->config->method('getSystemValue')
->with('ncw.mailboxPossible', '')
->willReturn('false');

$result = $this->service->isMailboxPossible();
$this->assertFalse($result);
}

public function testIsMailboxPossibleWhenEmpty(): void {
$this->config->method('getSystemValue')
->with('ncw.mailboxPossible', '')
->willReturn('');

$result = $this->service->isMailboxPossible();
$this->assertFalse($result);
}

public function testIsMailConfigEnabledWhenEnabled(): void {
$this->config->method('getAppValue')
->with('mail', 'ionos-mailconfig-enabled', 'no')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,27 @@ protected function setUp(): void {
);
}

public function testIsMailConfigAvailableReturnsFalseWhenMailboxNotPossible(): void {
$this->ionosConfigService->expects($this->once())
->method('isIonosIntegrationEnabled')
->willReturn(true);

$this->ionosConfigService->expects($this->once())
->method('isMailboxPossible')
->willReturn(false);

$this->logger->expects($this->once())
->method('debug')
->with('IONOS mail config not available - mailbox creation not possible for this instance');

$this->userSession->expects($this->never())
->method('getUser');

$result = $this->service->isMailConfigAvailable();

$this->assertFalse($result);
}

public function testIsMailConfigAvailableReturnsFalseWhenFeatureDisabled(): void {
$this->ionosConfigService->expects($this->once())
->method('isIonosIntegrationEnabled')
Expand All @@ -63,6 +84,10 @@ public function testIsMailConfigAvailableReturnsFalseWhenNoUserSession(): void {
->method('isIonosIntegrationEnabled')
->willReturn(true);

$this->ionosConfigService->expects($this->once())
->method('isMailboxPossible')
->willReturn(true);

$this->userSession->expects($this->once())
->method('getUser')
->willReturn(null);
Expand All @@ -84,6 +109,10 @@ public function testIsMailConfigAvailableReturnsTrueWhenUserHasNoRemoteAccount()
->method('isIonosIntegrationEnabled')
->willReturn(true);

$this->ionosConfigService->expects($this->once())
->method('isMailboxPossible')
->willReturn(true);

$this->userSession->expects($this->once())
->method('getUser')
->willReturn($user);
Expand All @@ -108,6 +137,10 @@ public function testIsMailConfigAvailableReturnsFalseWhenUserHasRemoteAndLocalAc
->method('isIonosIntegrationEnabled')
->willReturn(true);

$this->ionosConfigService->expects($this->once())
->method('isMailboxPossible')
->willReturn(true);

$this->userSession->expects($this->once())
->method('getUser')
->willReturn($user);
Expand Down Expand Up @@ -147,6 +180,10 @@ public function testIsMailConfigAvailableReturnsTrueWhenUserHasRemoteAccountButN
->method('isIonosIntegrationEnabled')
->willReturn(true);

$this->ionosConfigService->expects($this->once())
->method('isMailboxPossible')
->willReturn(true);

$this->userSession->expects($this->once())
->method('getUser')
->willReturn($user);
Expand Down Expand Up @@ -184,6 +221,10 @@ public function testIsMailConfigAvailableReturnsFalseWhenEmailCannotBeRetrieved(
->method('isIonosIntegrationEnabled')
->willReturn(true);

$this->ionosConfigService->expects($this->once())
->method('isMailboxPossible')
->willReturn(true);

$this->userSession->expects($this->once())
->method('getUser')
->willReturn($user);
Expand Down Expand Up @@ -214,6 +255,10 @@ public function testIsMailConfigAvailableWithExplicitUserIdReturnsTrueWhenUserHa
->method('isIonosIntegrationEnabled')
->willReturn(true);

$this->ionosConfigService->expects($this->once())
->method('isMailboxPossible')
->willReturn(true);

// When userId is provided, userSession should NOT be called
$this->userSession->expects($this->never())
->method('getUser');
Expand All @@ -235,6 +280,10 @@ public function testIsMailConfigAvailableWithExplicitUserIdReturnsTrueWhenUserHa
->method('isIonosIntegrationEnabled')
->willReturn(true);

$this->ionosConfigService->expects($this->once())
->method('isMailboxPossible')
->willReturn(true);

// When userId is provided, userSession should NOT be called
$this->userSession->expects($this->never())
->method('getUser');
Expand Down Expand Up @@ -269,6 +318,10 @@ public function testIsMailConfigAvailableReturnsFalseOnException(): void {
->method('isIonosIntegrationEnabled')
->willReturn(true);

$this->ionosConfigService->expects($this->once())
->method('isMailboxPossible')
->willReturn(true);

$exception = new \Exception('Test exception');

$this->userSession->expects($this->once())
Expand Down
Loading