Skip to content
Open
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
10 changes: 10 additions & 0 deletions lib/Service/Provisioning/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace OCA\Mail\Service\Provisioning;

use Horde_Mail_Rfc822_Address;
use OCA\Mail\AppInfo\Application;
use OCA\Mail\Db\Alias;
use OCA\Mail\Db\AliasMapper;
use OCA\Mail\Db\MailAccount;
Expand All @@ -19,6 +20,7 @@
use OCA\Mail\Db\TagMapper;
use OCA\Mail\Exception\ValidationException;
use OCA\Mail\Service\AccountService;
use OCP\App\IAppManager;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\ICacheFactory;
Expand All @@ -30,6 +32,8 @@

class Manager {
public const MAIL_PROVISIONINGS = 'mail_provisionings';
/** @var IAppManager */
private $appManager;
/** @var IUserManager */
private $userManager;

Expand Down Expand Up @@ -58,6 +62,7 @@ class Manager {
private $cacheFactory;

public function __construct(
IAppManager $appManager,
IUserManager $userManager,
ProvisioningMapper $provisioningMapper,
MailAccountMapper $mailAccountMapper,
Expand All @@ -69,6 +74,7 @@ public function __construct(
ICacheFactory $cacheFactory,
private AccountService $accountService,
) {
$this->appManager = $appManager;
$this->userManager = $userManager;
$this->provisioningMapper = $provisioningMapper;
$this->mailAccountMapper = $mailAccountMapper;
Expand Down Expand Up @@ -186,6 +192,10 @@ public function ldapAliasesIntegration(Provisioning $provisioning, IUser $user):
* @param Provisioning[] $provisionings
*/
public function provisionSingleUser(array $provisionings, IUser $user): bool {
if (!$this->appManager->isEnabledForUser(Application::APP_ID, $user)) {
return false;
}

$provisioning = $this->findMatchingConfig($provisionings, $user);

if ($provisioning === null) {
Expand Down
36 changes: 36 additions & 0 deletions tests/Unit/Service/Provisioning/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ public function testProvisionSkipWithoutConfigurations(): void {
$this->assertEquals(0, $count);
}

public function testDisabledAppDoesNotProvision() {
/** @var IUser|MockObject $user */
$user = $this->createConfiguredMock(IUser::class, [
'getEmailAddress' => '[email protected]',
'getUID' => 'bruce'
]);
$configs = [new Provisioning()];
$this->mock->getParameter('appManager')
->expects($this->once())
->method('isEnabledForUser')
->willReturn(false);

$result = $this->manager->provisionSingleUser($configs, $user);
$this->assertFalse($result);
}

public function testUpdateProvisionSingleUser() {
/** @var IUser|MockObject $user */
$user = $this->createConfiguredMock(IUser::class, [
Expand All @@ -74,6 +90,10 @@ public function testUpdateProvisionSingleUser() {
$configs = [$config];
$mailAccount = new MailAccount();
$mailAccount->setId(1000);
$this->mock->getParameter('appManager')
->expects($this->once())
->method('isEnabledForUser')
->willReturn(true);
$this->mock->getParameter('mailAccountMapper')
->expects($this->once())
->method('findProvisionedAccount')
Expand All @@ -100,6 +120,10 @@ public function testProvisionSingleUser() {
$config->setProvisioningDomain('batman.com');
$config->setEmailTemplate('%USER%@batman.com');
$configs = [$config];
$this->mock->getParameter('appManager')
->expects($this->once())
->method('isEnabledForUser')
->willReturn(true);
$this->mock->getParameter('mailAccountMapper')
->expects($this->once())
->method('findProvisionedAccount')
Expand Down Expand Up @@ -133,6 +157,10 @@ public function testUpdateProvisionSingleUserWithWildcard() {
$configs = [$config];
$mailAccount = new MailAccount();
$mailAccount->setId(1000);
$this->mock->getParameter('appManager')
->expects($this->once())
->method('isEnabledForUser')
->willReturn(true);
$this->mock->getParameter('mailAccountMapper')
->expects($this->once())
->method('findProvisionedAccount')
Expand All @@ -159,6 +187,10 @@ public function testProvisionSingleUserWithWildcard() {
$config->setProvisioningDomain('*');
$config->setEmailTemplate('%USER%@batman.com');
$configs = [$config];
$this->mock->getParameter('appManager')
->expects($this->once())
->method('isEnabledForUser')
->willReturn(true);
$this->mock->getParameter('mailAccountMapper')
->expects($this->once())
->method('findProvisionedAccount')
Expand Down Expand Up @@ -186,6 +218,10 @@ public function testProvisionSingleUserNoDomainMatch() {
$config->setProvisioningDomain('arkham-asylum.com');
$config->setEmailTemplate('%USER%@batman.com');
$configs = [$config];
$this->mock->getParameter('appManager')
->expects($this->once())
->method('isEnabledForUser')
->willReturn(true);
$this->mock->getParameter('mailAccountMapper')
->expects($this->never())
->method('findProvisionedAccount');
Expand Down
Loading