Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--appinfo/info.xml1
-rw-r--r--lib/Command/AddMissingTags.php98
-rw-r--r--lib/Service/Provisioning/Manager.php10
-rw-r--r--tests/Unit/Service/Provisioning/ManagerTest.php23
-rw-r--r--tests/psalm-baseline.xml17
5 files changed, 133 insertions, 16 deletions
diff --git a/appinfo/info.xml b/appinfo/info.xml
index c3479bef9..6859f66c7 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -50,6 +50,7 @@
</post-migration>
</repair-steps>
<commands>
+ <command>OCA\Mail\Command\AddMissingTags</command>
<command>OCA\Mail\Command\CleanUp</command>
<command>OCA\Mail\Command\CreateAccount</command>
<command>OCA\Mail\Command\CreateTagMigrationJobEntry</command>
diff --git a/lib/Command/AddMissingTags.php b/lib/Command/AddMissingTags.php
new file mode 100644
index 000000000..41e4ec680
--- /dev/null
+++ b/lib/Command/AddMissingTags.php
@@ -0,0 +1,98 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @author Anna Larch <anna.larch@nextcloud.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace OCA\Mail\Command;
+
+use OCA\Mail\Db\MailAccountMapper;
+use OCA\Mail\Db\TagMapper;
+use Psr\Log\LoggerInterface;
+use OCP\AppFramework\Db\DoesNotExistException;
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Helper\ProgressBar;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class AddMissingTags extends Command {
+ public const ARGUMENT_ACCOUNT_ID = 'account-id';
+
+ /** @var LoggerInterface */
+ private $logger;
+
+ /** @var TagMapper */
+ private $tagMapper;
+
+ /** @var MailAccountMapper */
+ private $mapper;
+
+ public function __construct(MailAccountMapper $mapper,
+ TagMapper $tagMapper,
+ LoggerInterface $logger) {
+ parent::__construct();
+
+ $this->mapper = $mapper;
+ $this->tagMapper = $tagMapper;
+ $this->logger = $logger;
+ }
+
+ /**
+ * @return void
+ */
+ protected function configure() {
+ $this->setName('mail:repair:tags');
+ $this->setDescription('Create default tags for account. If no account ID given, all tag entries will be repaired');
+ $this->addArgument(self::ARGUMENT_ACCOUNT_ID, InputArgument::OPTIONAL);
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output): int {
+ $accountId = (int)$input->getArgument(self::ARGUMENT_ACCOUNT_ID);
+
+ if ($accountId === 0) {
+ $accounts = $this->mapper->getAllAccounts();
+ $output->writeln(sprintf('%d accounts to check found', count($accounts)));
+ if (empty($accounts)) {
+ $output->writeLn('<error>No accounts exist</error>');
+ return 1;
+ }
+ } else {
+ try {
+ $account = $this->mapper->findById($accountId);
+ $accounts = [$account];
+ $output->writeLn("<info>Found account with email: " . $account->getEmail() . "</info>");
+ } catch (DoesNotExistException $e) {
+ $output->writeLn('<info>This account does not exist</info>');
+ }
+ }
+
+ $progress = new ProgressBar($output);
+ foreach ($accounts as $account) {
+ $this->tagMapper->createDefaultTags($account);
+ $progress->advance();
+ }
+
+ $progress->finish();
+ $output->writeln('');
+ $output->writeln('Patched default tags for ' . count($accounts));
+ return 0;
+ }
+}
diff --git a/lib/Service/Provisioning/Manager.php b/lib/Service/Provisioning/Manager.php
index 99ea491f7..b545e0f15 100644
--- a/lib/Service/Provisioning/Manager.php
+++ b/lib/Service/Provisioning/Manager.php
@@ -30,6 +30,7 @@ use OCA\Mail\Db\MailAccount;
use OCA\Mail\Db\MailAccountMapper;
use OCA\Mail\Db\Provisioning;
use OCA\Mail\Db\ProvisioningMapper;
+use OCA\Mail\Db\TagMapper;
use OCA\Mail\Exception\ValidationException;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
@@ -63,13 +64,17 @@ class Manager {
/** @var LoggerInterface */
private $logger;
+ /** @var TagMapper */
+ private $tagMapper;
+
public function __construct(IUserManager $userManager,
ProvisioningMapper $provisioningMapper,
MailAccountMapper $mailAccountMapper,
ICrypto $crypto,
ILDAPProviderFactory $ldapProviderFactory,
AliasMapper $aliasMapper,
- LoggerInterface $logger) {
+ LoggerInterface $logger,
+ TagMapper $tagMapper) {
$this->userManager = $userManager;
$this->provisioningMapper = $provisioningMapper;
$this->mailAccountMapper = $mailAccountMapper;
@@ -77,6 +82,7 @@ class Manager {
$this->ldapProviderFactory = $ldapProviderFactory;
$this->aliasMapper = $aliasMapper;
$this->logger = $logger;
+ $this->tagMapper = $tagMapper;
}
public function getConfigById(int $provisioningId): ?Provisioning {
@@ -199,6 +205,8 @@ class Manager {
$mailAccount = $this->mailAccountMapper->insert(
$this->updateAccount($user, $mailAccount, $provisioning)
);
+
+ $this->tagMapper->createDefaultTags($mailAccount);
}
// @TODO: Remove method_exists once Mail requires Nextcloud 22 or above
diff --git a/tests/Unit/Service/Provisioning/ManagerTest.php b/tests/Unit/Service/Provisioning/ManagerTest.php
index 2b2dd9449..3b36f9839 100644
--- a/tests/Unit/Service/Provisioning/ManagerTest.php
+++ b/tests/Unit/Service/Provisioning/ManagerTest.php
@@ -67,7 +67,7 @@ class ManagerTest extends TestCase {
$config->setProvisioningDomain('batman.com');
$config->setEmailTemplate('%USER%@batman.com');
$configs = [$config];
- $account = $this->createMock(MailAccount::class);
+ $account = new MailAccount();
$this->mock->getParameter('mailAccountMapper')
->expects($this->once())
->method('findProvisionedAccount')
@@ -86,6 +86,7 @@ class ManagerTest extends TestCase {
$user = $this->createConfiguredMock(IUser::class, [
'getEmailAddress' => 'bruce.wayne@batman.com'
]);
+ $account = new MailAccount();
$config = new Provisioning();
$config->setId(1);
$config->setProvisioningDomain('batman.com');
@@ -97,7 +98,12 @@ class ManagerTest extends TestCase {
->willThrowException($this->createMock(DoesNotExistException::class));
$this->mock->getParameter('mailAccountMapper')
->expects($this->once())
- ->method('insert');
+ ->method('insert')
+ ->willReturn($account);
+ $this->mock->getParameter('tagMapper')
+ ->expects($this->once())
+ ->method('createDefaultTags')
+ ->with($account);
$result = $this->manager->provisionSingleUser($configs, $user);
$this->assertTrue($result);
@@ -108,6 +114,7 @@ class ManagerTest extends TestCase {
$user = $this->createConfiguredMock(IUser::class, [
'getEmailAddress' => 'bruce.wayne@batman.com'
]);
+ $account = new MailAccount();
$config = new Provisioning();
$config->setId(1);
$config->setProvisioningDomain('*');
@@ -132,6 +139,7 @@ class ManagerTest extends TestCase {
$user = $this->createConfiguredMock(IUser::class, [
'getEmailAddress' => 'bruce.wayne@batman.com'
]);
+ $account = new MailAccount();
$config = new Provisioning();
$config->setId(1);
$config->setProvisioningDomain('*');
@@ -143,7 +151,12 @@ class ManagerTest extends TestCase {
->willThrowException($this->createMock(DoesNotExistException::class));
$this->mock->getParameter('mailAccountMapper')
->expects($this->once())
- ->method('insert');
+ ->method('insert')
+ ->willReturn($account);
+ $this->mock->getParameter('tagMapper')
+ ->expects($this->once())
+ ->method('createDefaultTags')
+ ->with($account);
$result = $this->manager->provisionSingleUser($configs, $user);
$this->assertTrue($result);
@@ -154,6 +167,7 @@ class ManagerTest extends TestCase {
$user = $this->createConfiguredMock(IUser::class, [
'getEmailAddress' => 'bruce.wayne@batman.com'
]);
+ $account = new MailAccount();
$config = new Provisioning();
$config->setId(1);
$config->setProvisioningDomain('arkham-asylum.com');
@@ -168,6 +182,9 @@ class ManagerTest extends TestCase {
$this->mock->getParameter('mailAccountMapper')
->expects($this->never())
->method('insert');
+ $this->mock->getParameter('tagMapper')
+ ->expects($this->never())
+ ->method('createDefaultTags');
$result = $this->manager->provisionSingleUser($configs, $user);
$this->assertFalse($result);
diff --git a/tests/psalm-baseline.xml b/tests/psalm-baseline.xml
index 19d2f3e35..da9f432f9 100644
--- a/tests/psalm-baseline.xml
+++ b/tests/psalm-baseline.xml
@@ -35,6 +35,11 @@
<code>get</code>
</TooManyArguments>
</file>
+ <file src="lib/Command/AddMissingTags.php">
+ <UndefinedClass occurrences="1">
+ <code>Command</code>
+ </UndefinedClass>
+ </file>
<file src="lib/Command/CleanUp.php">
<UndefinedClass occurrences="1">
<code>Command</code>
@@ -278,11 +283,6 @@
<code>UserDeletedListener</code>
</MissingDependency>
</file>
- <file src="lib/Service/AntiSpamService.php">
- <MissingDependency occurrences="1">
- <code>MessageFlaggedEvent</code>
- </MissingDependency>
- </file>
<file src="lib/Service/Classification/ImportanceClassifier.php">
<InvalidScalarArgument occurrences="1">
<code>$predictedValidationLabel</code>
@@ -293,13 +293,6 @@
<code>$this-&gt;contactsManager-&gt;getUserAddressBooks()</code>
</UndefinedDocblockClass>
</file>
- <file src="lib/Service/HtmlPurify/TransformURLScheme.php">
- <NullArgument occurrences="3">
- <code>null</code>
- <code>null</code>
- <code>null</code>
- </NullArgument>
- </file>
<file src="lib/Service/MailManager.php">
<MissingDependency occurrences="8">
<code>BeforeMessageDeletedEvent</code>