diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2019-04-08 16:53:53 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2019-04-09 12:02:53 +0300 |
commit | c1fbb530e48048f0b3594f6b0537c2d651d5ca99 (patch) | |
tree | 8596c8523b8d3f48130a8fc169a5c5095d7e9503 /lib | |
parent | b1acb3019d71b94e20ffe56ac00644245b4282cf (diff) |
Add support for signatures
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Controller/AccountsController.php | 14 | ||||
-rw-r--r-- | lib/Db/MailAccount.php | 30 | ||||
-rw-r--r-- | lib/Migration/Version0130Date20190408134101.php | 55 | ||||
-rw-r--r-- | lib/Service/AccountService.php | 11 |
4 files changed, 97 insertions, 13 deletions
diff --git a/lib/Controller/AccountsController.php b/lib/Controller/AccountsController.php index 15af56962..ec6010694 100644 --- a/lib/Controller/AccountsController.php +++ b/lib/Controller/AccountsController.php @@ -196,6 +196,20 @@ class AccountsController extends Controller { * @NoAdminRequired * @TrapError * + * @param int $accountId + * @param string|null $signature + * + * @return JSONResponse + */ + public function updateSignature(int $accountId, string $signature = null) { + $this->accountService->updateSignature($accountId, $this->currentUserId, $signature); + return new JSONResponse(); + } + + /** + * @NoAdminRequired + * @TrapError + * * @param int $id * @return JSONResponse */ diff --git a/lib/Db/MailAccount.php b/lib/Db/MailAccount.php index 29334760f..15bc52365 100644 --- a/lib/Db/MailAccount.php +++ b/lib/Db/MailAccount.php @@ -57,22 +57,25 @@ use OCP\AppFramework\Db\Entity; * @method void setOutboundUser(string $outboundUser) * @method string getOutboundPassword() * @method void setOutboundPassword(string $outboundPassword) + * @method string|null getSignature() + * @method void setSignature(string|null $signature) */ class MailAccount extends Entity { - public $userId; - public $name; - public $email; - public $inboundHost; - public $inboundPort; - public $inboundSslMode; - public $inboundUser; - public $inboundPassword; - public $outboundHost; - public $outboundPort; - public $outboundSslMode; - public $outboundUser; - public $outboundPassword; + protected $userId; + protected $name; + protected $email; + protected $inboundHost; + protected $inboundPort; + protected $inboundSslMode; + protected $inboundUser; + protected $inboundPassword; + protected $outboundHost; + protected $outboundPort; + protected $outboundSslMode; + protected $outboundUser; + protected $outboundPassword; + protected $signature; /** * @param array $params @@ -134,6 +137,7 @@ class MailAccount extends Entity { 'imapPort' => $this->getInboundPort(), 'imapUser' => $this->getInboundUser(), 'imapSslMode' => $this->getInboundSslMode(), + 'signature' => $this->getSignature(), ]; if (!is_null($this->getOutboundHost())) { diff --git a/lib/Migration/Version0130Date20190408134101.php b/lib/Migration/Version0130Date20190408134101.php new file mode 100644 index 000000000..71b087979 --- /dev/null +++ b/lib/Migration/Version0130Date20190408134101.php @@ -0,0 +1,55 @@ +<?php + +declare(strict_types=1); + +/** + * @author Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @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\Migration; + +use Closure; +use OCP\DB\ISchemaWrapper; +use OCP\Migration\SimpleMigrationStep; +use OCP\Migration\IOutput; + +class Version0130Date20190408134101 extends SimpleMigrationStep { + + /** + * @param IOutput $output + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` + * @param array $options + * + * @return ISchemaWrapper + */ + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + $accountsTable = $schema->getTable('mail_accounts'); + $accountsTable->addColumn('signature', 'text', [ + 'notnull' => false, + 'length' => 1024, + 'default' => '', + ]); + + return $schema; + } + +} diff --git a/lib/Service/AccountService.php b/lib/Service/AccountService.php index c3cfec3b2..74740d31b 100644 --- a/lib/Service/AccountService.php +++ b/lib/Service/AccountService.php @@ -28,6 +28,7 @@ use Exception; use OCA\Mail\Account; use OCA\Mail\Db\MailAccount; use OCA\Mail\Db\MailAccountMapper; +use OCA\Mail\Exception\ServiceException; use OCA\Mail\Service\DefaultAccount\Manager; use OCP\IL10N; @@ -129,4 +130,14 @@ class AccountService { return $this->mapper->save($newAccount); } + public function updateSignature(int $id, string $uid, string $signature = null) { + $account = $this->find($uid, $id); + if ($account === null) { + throw new ServiceException("Account does not exist or user is not permitted to change it"); + } + $mailAccount = $account->getMailAccount(); + $mailAccount->setSignature($signature); + $this->mapper->save($mailAccount); + } + } |