Skip to content

Commit

Permalink
feat: remove toggle for move junk
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Kesselberg <[email protected]>
  • Loading branch information
kesselb committed Aug 15, 2023
1 parent 49b34a6 commit 62eb649
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 127 deletions.
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Positive:
Learn more about the Nextcloud Ethical AI Rating [in our blog](https://nextcloud.com/blog/nextcloud-ethical-ai-rating/).
]]></description>
<version>3.4.0-beta.2</version>
<version>3.4.0-beta.3</version>
<licence>agpl</licence>
<author>Greta Doçi</author>
<author homepage="https://github.com/nextcloud/groupware">Nextcloud Groupware Team</author>
Expand Down
6 changes: 1 addition & 5 deletions lib/Controller/AccountsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,7 @@ public function patchAccount(int $id,
int $snoozeMailboxId = null,
bool $signatureAboveQuote = null,
int $trashRetentionDays = null,
int $junkMailboxId = null,
bool $moveJunk = null): JSONResponse {
int $junkMailboxId = null): JSONResponse {
$account = $this->accountService->find($this->currentUserId, $id);

$dbAccount = $account->getMailAccount();
Expand Down Expand Up @@ -291,9 +290,6 @@ public function patchAccount(int $id,
$this->mailManager->getMailbox($this->currentUserId, $junkMailboxId);
$dbAccount->setJunkMailboxId($junkMailboxId);
}
if ($moveJunk !== null) {
$dbAccount->setMoveJunk($moveJunk);
}
return new JSONResponse(
$this->accountService->save($dbAccount)
);
Expand Down
5 changes: 0 additions & 5 deletions lib/Db/MailAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@
* @method void setTrashRetentionDays(int|null $trashRetentionDays)
* @method int|null getJunkMailboxId()
* @method void setJunkMailboxId(?int $id)
* @method bool isMoveJunk()
* @method void setMoveJunk(bool $moveJunk)
*/
class MailAccount extends Entity {
public const SIGNATURE_MODE_PLAIN = 0;
Expand Down Expand Up @@ -191,7 +189,6 @@ class MailAccount extends Entity {
protected $trashRetentionDays;

protected ?int $junkMailboxId = null;
protected bool $moveJunk = false;

/**
* @param array $params
Expand Down Expand Up @@ -268,7 +265,6 @@ public function __construct(array $params = []) {
$this->addType('quotaPercentage', 'integer');
$this->addType('trashRetentionDays', 'integer');
$this->addType('junkMailboxId', 'integer');
$this->addType('moveJunk', 'boolean');
}

/**
Expand Down Expand Up @@ -302,7 +298,6 @@ public function toJson() {
'quotaPercentage' => $this->getQuotaPercentage(),
'trashRetentionDays' => $this->getTrashRetentionDays(),
'junkMailboxId' => $this->getJunkMailboxId(),
'moveJunk' => ($this->isMoveJunk() === true),
];

if (!is_null($this->getOutboundHost())) {
Expand Down
11 changes: 6 additions & 5 deletions lib/Listener/MoveJunkListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,20 @@ public function handle(Event $event): void {
$account = $event->getAccount();
$mailAccount = $account->getMailAccount();

if (!$mailAccount->isMoveJunk()) {
$junkMailboxId = $mailAccount->getJunkMailboxId();
if ($junkMailboxId === null) {
return;
}

$mailbox = $event->getMailbox();

if ($event->isSet() && $mailAccount->getJunkMailboxId() !== $mailbox->getId()) {
if ($event->isSet() && $junkMailboxId !== $mailbox->getId()) {
try {
$junkMailbox = $this->mailManager->getMailbox($account->getUserId(), $mailAccount->getJunkMailboxId());
$junkMailbox = $this->mailManager->getMailbox($account->getUserId(), $junkMailboxId);
} catch (ClientException) {
$this->logger->debug('move to junk enabled, but junk mailbox does not exist. account_id: {account_id}, junk_mailbox_id: {junk_mailbox_id}', [
$this->logger->debug('junk mailbox set, but junk mailbox does not exist. account_id: {account_id}, junk_mailbox_id: {junk_mailbox_id}', [
'account_id' => $account->getId(),
'junk_mailbox_id' => $mailAccount->getJunkMailboxId(),
'junk_mailbox_id' => $junkMailboxId,
]);
return;
}
Expand Down
53 changes: 53 additions & 0 deletions lib/Migration/Version3400Date20230814160451.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2023 Daniel Kesselberg <[email protected]>
*
* @author Daniel Kesselberg <[email protected]>
*
* @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\IOutput;
use OCP\Migration\SimpleMigrationStep;

class Version3400Date20230814160451 extends SimpleMigrationStep {

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

$accountsTable = $schema->getTable('mail_accounts');
if ($accountsTable->hasColumn('move_junk')) {
$accountsTable->dropColumn('move_junk');
}

return $schema;
}
}
4 changes: 2 additions & 2 deletions src/components/AccountDefaultsSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ export default {
await this.$store.dispatch('patchAccount', {
account: this.account,
data: {
junkMailboxId,
},
junkMailboxId

Check warning on line 201 in src/components/AccountDefaultsSettings.vue

View workflow job for this annotation

GitHub Actions / eslint

Missing trailing comma
}

Check warning on line 202 in src/components/AccountDefaultsSettings.vue

View workflow job for this annotation

GitHub Actions / eslint

Missing trailing comma
})
} catch (error) {
logger.error('could not set junk mailbox', {
Expand Down
5 changes: 0 additions & 5 deletions src/components/AccountSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@
</p>
<TrashRetentionSettings :account="account" />
</AppSettingsSection>
<AppSettingsSection id="junk-settings" :title="t('mail', 'Junk settings')">
<JunkSettings :account="account" />
</AppSettingsSection>
<AppSettingsSection
v-if="account"
id="out-of-office-replies"
Expand Down Expand Up @@ -131,7 +128,6 @@ import SieveFilterForm from './SieveFilterForm'
import OutOfOfficeForm from './OutOfOfficeForm'
import CertificateSettings from './CertificateSettings'
import TrashRetentionSettings from './TrashRetentionSettings'
import JunkSettings from './JunkSettings'
export default {
name: 'AccountSettings',
Expand All @@ -149,7 +145,6 @@ export default {
OutOfOfficeForm,
CertificateSettings,
TrashRetentionSettings,
JunkSettings,
},
props: {
account: {
Expand Down
75 changes: 0 additions & 75 deletions src/components/JunkSettings.vue

This file was deleted.

10 changes: 7 additions & 3 deletions src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1393,17 +1393,21 @@ export default {
*/
async moveEnvelopeToJunk({ getters }, envelope) {
const account = getters.getAccount(envelope.accountId)
if (account.moveJunk === false) {
if (account.junkMailboxId === null) {
return false
}

if (!envelope.flags.$junk) {
// move message to junk
return account.junkMailboxId && envelope.mailboxId !== account.junkMailboxId
return envelope.mailboxId !== account.junkMailboxId
}

const inbox = getters.getInbox(account.id)
if (inbox === undefined) {
return false
}

// move message to inbox
return inbox && envelope.mailboxId !== inbox.databaseId
return envelope.mailboxId !== inbox.databaseId
},
}
21 changes: 1 addition & 20 deletions src/tests/unit/store/actions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,25 +516,8 @@ describe('Vuex store actions', () => {
})
})

it('should move message to junk', async() => {
context.getters.getAccount.mockReturnValueOnce({
moveJunk: true,
junkMailboxId: 10
})

const removeEnvelope = await actions.moveEnvelopeToJunk(context, {
flags: {
$junk: false
},
mailboxId: 1
})

expect(removeEnvelope).toBeTruthy()
})

it('should move message to junk, no mailbox configured', async() => {
context.getters.getAccount.mockReturnValueOnce({
moveJunk: true,
junkMailboxId: null
})

Expand All @@ -550,7 +533,6 @@ describe('Vuex store actions', () => {

it('should move message to inbox', async() => {
context.getters.getAccount.mockReturnValueOnce({
moveJunk: true,
junkMailboxId: 10
})
context.getters.getInbox.mockReturnValueOnce({
Expand All @@ -569,7 +551,6 @@ describe('Vuex store actions', () => {

it('should move message to inbox, inbox not found', async() => {
context.getters.getAccount.mockReturnValueOnce({
moveJunk: true,
junkMailboxId: 10
})
context.getters.getInbox.mockReturnValueOnce(undefined)
Expand All @@ -586,7 +567,7 @@ describe('Vuex store actions', () => {

it('should not move messages', async() => {
context.getters.getAccount.mockReturnValueOnce({
moveJunk: false
junkMailboxId: null
})

const removeEnvelope = await actions.moveEnvelopeToJunk(context, {
Expand Down
6 changes: 0 additions & 6 deletions tests/Unit/Listener/MoveJunkListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public function testIgnoreOtherFlags(): void {

public function testMoveJunkDisabled(): void {
$mailAccount = new MailAccount();
$mailAccount->setMoveJunk(false);
$account = new Account($mailAccount);

$event = $this->createMock(MessageFlaggedEvent::class);
Expand All @@ -84,7 +83,6 @@ public function testMoveJunkDisabled(): void {
public function testMoveJunkMailboxNotFound(): void {
$mailAccount = new MailAccount();
$mailAccount->setJunkMailboxId(200);
$mailAccount->setMoveJunk(true);
$mailAccount->setUserId('bob');
$account = new Account($mailAccount);

Expand All @@ -110,7 +108,6 @@ public function testMoveJunkMailboxNotFound(): void {
public function testMoveJunkAlreadyInJunk(): void {
$mailAccount = new MailAccount();
$mailAccount->setJunkMailboxId(200);
$mailAccount->setMoveJunk(true);
$mailAccount->setUserId('bob');
$account = new Account($mailAccount);

Expand All @@ -134,7 +131,6 @@ public function testMoveJunkAlreadyInJunk(): void {
public function testMoveJunkFailed(): void {
$mailAccount = new MailAccount();
$mailAccount->setJunkMailboxId(200);
$mailAccount->setMoveJunk(true);
$mailAccount->setUserId('bob');
$account = new Account($mailAccount);

Expand Down Expand Up @@ -168,7 +164,6 @@ public function testMoveJunkFailed(): void {
public function testMoveJunkAlreadyInInbox(): void {
$mailAccount = new MailAccount();
$mailAccount->setJunkMailboxId(200);
$mailAccount->setMoveJunk(true);
$mailAccount->setUserId('bob');
$account = new Account($mailAccount);

Expand All @@ -193,7 +188,6 @@ public function testMoveJunkAlreadyInInbox(): void {
public function testMoveJunkToInboxFailed(): void {
$mailAccount = new MailAccount();
$mailAccount->setJunkMailboxId(200);
$mailAccount->setMoveJunk(true);
$mailAccount->setUserId('bob');
$account = new Account($mailAccount);

Expand Down

0 comments on commit 62eb649

Please sign in to comment.