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
path: root/lib
diff options
context:
space:
mode:
authorAnna Larch <anna@nextcloud.com>2021-09-16 21:53:49 +0300
committerAnna Larch <anna@nextcloud.com>2021-09-17 13:33:26 +0300
commitc023e097b41e536a13771f557b449ebd27c1a1fd (patch)
treea22391d1c206ba371d19dbaa0eac3c661cca91ff /lib
parent409980e4bff96a486c060c6bb87ed0eb2b31fffb (diff)
Add tags for provisioned users
Signed-off-by: Anna Larch <anna@nextcloud.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Command/AddMissingTags.php98
-rw-r--r--lib/Service/Provisioning/Manager.php10
2 files changed, 107 insertions, 1 deletions
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