Skip to content

Commit

Permalink
fixup! feat: add internal addresses
Browse files Browse the repository at this point in the history
Signed-off-by: Hamza Mahjoubi <[email protected]>
  • Loading branch information
hamza221 committed Aug 12, 2024
1 parent 5cf2846 commit 8a4c5bf
Show file tree
Hide file tree
Showing 6 changed files with 253 additions and 14 deletions.
6 changes: 5 additions & 1 deletion lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ public function index(): TemplateResponse {
$this->internalAddressService->getInternalAddresses($this->currentUserId)
);

$this->initialStateService->provideInitialState(
'internal-addresses',
$this->preferences->getPreference($this->currentUserId, 'internal-addresses', 'false')
);

$this->initialStateService->provideInitialState(
'sort-order',
$this->preferences->getPreference($this->currentUserId, 'sort-order', 'newest')
Expand Down Expand Up @@ -208,7 +213,6 @@ public function index(): TemplateResponse {
'start-mailbox-id' => $this->preferences->getPreference($this->currentUserId, 'start-mailbox-id'),
'tag-classified-messages' => $this->classificationSettingsService->isClassificationEnabled($this->currentUserId) ? 'true' : 'false',
'follow-up-reminders' => $this->preferences->getPreference($this->currentUserId, 'follow-up-reminders', 'true'),
'internal-addresses' => $this->preferences->getPreference($this->currentUserId, 'internal-addresses', 'false'),
]);
$this->initialStateService->provideInitialState(
'prefill_displayName',
Expand Down
19 changes: 13 additions & 6 deletions src/components/InternalAddress.vue
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
<!--
- SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
- SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->

<template>
<div>
<div v-for="domain in sortedDomains"
class="address"
:key="domain.address">
{{ domain.address }}
{{ senderType(domain.type) }}
<p class="address__type">({{ t('mail', 'domain') }})</p>
<ButtonVue type="tertiary"
class="button"
:aria-label="t('mail','Remove')"
:aria-label="t('mail', 'Remove')"
@click="removeInternalAddress(domain)">
{{ t('mail','Remove') }}
</ButtonVue>
</div>
<div v-for="email in sortedEmails"
class="address"
:key="email.address">
{{ email.address }}
{{ t('mail', 'domain') }}
<p class="address__type">({{ t('mail', 'email') }})</p>
<ButtonVue type="tertiary"
class="button"
:aria-label="t('mail','Remove')"
Expand Down Expand Up @@ -154,7 +156,12 @@ export default {
</script>

<style lang="scss" scoped>
.button-vue:deep() {
display: inline-block !important;
.address {
display: flex;
align-items: center;
&__type{
color: var(--color-text-maxcontrast);
}
}

</style>
10 changes: 5 additions & 5 deletions src/components/ThreadEnvelope.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<div class="envelope__header__left__sender-subject-tags">
<div class="sender">
{{ envelope.from && envelope.from[0] ? envelope.from[0].label : '' }}
<p :class="isInternal?'sender__email':'sender__email external'">
<p :class="isInternal?'sender__email':'sender__email sender__external'">
{{ envelope.from && envelope.from[0] ? envelope.from[0].email : '' }}
</p>
</div>
Expand Down Expand Up @@ -867,6 +867,10 @@ export default {
&__email{
color: var(--color-text-maxcontrast);
}

&__external{
color: var(--color-error);
}
}

.right {
Expand Down Expand Up @@ -902,10 +906,6 @@ export default {
}
}

.external {
color: var(--color-error);
}

.envelope {
display: flex;
flex-direction: column;
Expand Down
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ store.commit('savePreference', {
})
store.commit('savePreference', {
key: 'internal-addresses',
value: getPreferenceFromPage('internal-addresses'),
value: loadState('mail','internal-addresses', false),
})

const accountSettings = loadState('mail', 'account-settings')
Expand Down
1 change: 0 additions & 1 deletion templates/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@
<input type="hidden" id="search-priority-body" value="<?php p($_['search-priority-body']); ?>">
<input type="hidden" id="layout-mode" value="<?php p($_['layout-mode']); ?>">
<input type="hidden" id="follow-up-reminders" value="<?php p($_['follow-up-reminders']); ?>">
<input type="hidden" id="internal-addresses" value="<?php p($_['internal-addresses']); ?>">

229 changes: 229 additions & 0 deletions tests/Integration/Db/InternalAddressMapperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Mail\Tests\Integration\Db;

use ChristophWurst\Nextcloud\Testing\DatabaseTransaction;
use ChristophWurst\Nextcloud\Testing\TestCase;
use ChristophWurst\Nextcloud\Testing\TestUser;
use OCA\Mail\Db\InternalAddressMapper;
use OCP\IDBConnection;
use OCP\IUser;
use OCP\Server;

class InternalAddressMapperTest extends TestCase {
use DatabaseTransaction, TestUser;

/** @var IDBConnection */
private $db;

/** @var IUser */
private $user;

/** @var InternalAddressMapper */
private $mapper;

protected function setUp(): void {
parent::setUp();

/** @var IDBConnection $db */
$this->db = Server::get(IDBConnection::class);
$this->user = $this->createTestUser();

$this->mapper = new InternalAddressMapper(
$this->db
);
}

public function testDoesntExist(): void {
$exists = $this->mapper->exists($this->user->getUID(), "[email protected]");

$this->assertFalse($exists);
}

public function testIndividualExists(): void {
$uid = $this->user->getUID();
$qb = $this->db->getQueryBuilder();
$qb->insert('mail_internal_address')
->values([
'user_id' => $qb->createNamedParameter($uid),
'address' => $qb->createNamedParameter('[email protected]'),
'type' => $qb->createNamedParameter('individual')

])
->executeStatement();

$exists = $this->mapper->exists($uid, "[email protected]");

$this->assertTrue($exists);
}

public function testDomainExists(): void {
$uid = $this->user->getUID();
$qb = $this->db->getQueryBuilder();
$qb->insert('mail_internal_address')
->values([
'user_id' => $qb->createNamedParameter($uid),
'address' => $qb->createNamedParameter('next.cloud'),
'type' => $qb->createNamedParameter('domain'),

])
->executeStatement();

$exists = $this->mapper->exists($uid, "[email protected]");

$this->assertTrue($exists);
}

public function testCreateIndividual(): void {
$uid = $this->user->getUID();
$this->mapper->create(
$uid,
"[email protected]",
'individual'
);

$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from('mail_internal_address')
->where(
$qb->expr()->eq('user_id', $qb->createNamedParameter($uid)),
$qb->expr()->eq('address', $qb->createNamedParameter("[email protected]"))
);
$result = $qb->executeQuery();
$rows = $result->fetchAll();
$result->closeCursor();
$this->assertCount(1, $rows);
}

public function testRemoveIndividual(): void {
$uid = $this->user->getUID();
$qb = $this->db->getQueryBuilder();
$qb->insert('mail_internal_address')
->values([
'user_id' => $qb->createNamedParameter($uid),
'address' => $qb->createNamedParameter('[email protected]'),
'type' => $qb->createNamedParameter('individual'),
])
->executeStatement();

$this->mapper->remove(
$uid,
"[email protected]",
'individual'
);

$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from('mail_internal_address')
->where(
$qb->expr()->eq('user_id', $qb->createNamedParameter($uid)),
$qb->expr()->eq('address', $qb->createNamedParameter("[email protected]"))
);
$result = $qb->executeQuery();
$rows = $result->fetchAll();
$result->closeCursor();
$this->assertEmpty($rows);
}

public function testCreateDomain(): void {
$uid = $this->user->getUID();
$this->mapper->create(
$uid,
"next.cloud",
'domain'
);

$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from('mail_internal_address')
->where(
$qb->expr()->eq('user_id', $qb->createNamedParameter($uid)),
$qb->expr()->eq('address', $qb->createNamedParameter("next.cloud")),
$qb->expr()->eq('type', $qb->createNamedParameter('domain'))
);
$result = $qb->executeQuery();
$rows = $result->fetchAll();
$result->closeCursor();
$this->assertCount(1, $rows);
}

public function testRemoveDomain(): void {
$uid = $this->user->getUID();
$qb = $this->db->getQueryBuilder();
$qb->insert('mail_internal_address')
->values([
'user_id' => $qb->createNamedParameter($uid),
'address' => $qb->createNamedParameter('next.cloud'),
'type' => $qb->createNamedParameter('domain'),
])
->executeStatement();

$this->mapper->remove(
$uid,
"next.cloud",
'domain'
);

$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from('mail_internal_address')
->where(
$qb->expr()->eq('user_id', $qb->createNamedParameter($uid)),
$qb->expr()->eq('address', $qb->createNamedParameter("next.cloud")),
$qb->expr()->eq('type', $qb->createNamedParameter("domain"))
);
$result = $qb->executeQuery();
$rows = $result->fetchAll();
$result->closeCursor();
$this->assertEmpty($rows);
}

/* public function testFindAll(): void {
$uid = $this->user->getUID();
$qb = $this->db->getQueryBuilder();
$qb->i('mail_internal_address')
->values([
'user_id' => $qb->createNamedParameter($uid),
'address' => $qb->createNamedParameter('[email protected]'),
'type' => $qb->createNamedParameter('individual'),
],
)->insert('mail_internal_address')
->values([
'user_id' => $qb->createNamedParameter($uid),
'address' => $qb->createNamedParameter('[email protected]'),
'type' => $qb->createNamedParameter('individual'),
])
->executeStatement();
$result = $qb->executeQuery();
$result->closeCursor();
$rows = $this->mapper->findAll($uid);
$this->assertCount(2, $rows);
$resultArray = [];
foreach ($rows as $row) {
$resultArray[] = $row->jsonSerialize();
}
$expected = [
[
'id' => 1,
'user_id' => $uid,
'address' => '[email protected]',
'type' => 'individual',
],
[
'id' => 2,
'user_id' => $uid,
'address' => '[email protected]',
'type' => 'individual',
],
];
$this->assertEquals($expected, $resultArray);
}*/
}

0 comments on commit 8a4c5bf

Please sign in to comment.