From fadacf692b85ff19b079ebd40f7f6895ad1d1098 Mon Sep 17 00:00:00 2001 From: Hamza Mahjoubi Date: Fri, 8 Nov 2024 12:59:18 +0100 Subject: [PATCH] fixup! feat: mail snippets Signed-off-by: Hamza Mahjoubi --- lib/Db/SnippetMapper.php | 1 + lib/Db/SnippetShareMapper.php | 14 +++++++++++--- lib/Service/SnippetService.php | 1 + src/components/snippets/ListItem.vue | 20 +++++++++----------- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/lib/Db/SnippetMapper.php b/lib/Db/SnippetMapper.php index 5265d1ad94..a7648d6312 100644 --- a/lib/Db/SnippetMapper.php +++ b/lib/Db/SnippetMapper.php @@ -79,4 +79,5 @@ public function findSharedWithMe(string $userId, array $groups): array { ); return $this->findEntities($qb); } + } diff --git a/lib/Db/SnippetShareMapper.php b/lib/Db/SnippetShareMapper.php index a9c6b109af..76e6ccc6a2 100644 --- a/lib/Db/SnippetShareMapper.php +++ b/lib/Db/SnippetShareMapper.php @@ -32,12 +32,12 @@ public function __construct(IDBConnection $db) { * * @throws DoesNotExistException */ - public function find(int $id, string $owner): SnippetShare { + public function find(int $snippetId, string $shareWith): SnippetShare { $qb = $this->db->getQueryBuilder(); $qb->select('*') ->from($this->getTableName()) - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) - ->andWhere($qb->expr()->eq('owner', $qb->createNamedParameter($owner))); + ->where($qb->expr()->eq('snippet_id', $qb->createNamedParameter($snippetId))) + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($shareWith))); return $this->findEntity($qb); } @@ -93,5 +93,13 @@ public function findSnippetShares(int $snippetId): array { return $this->findEntities($qb); } + public function deleteBySnippetId(int $snippetId): void { + $qb = $this->db->getQueryBuilder(); + $qb->delete($this->getTableName()) + ->where( + $qb->expr()->eq('snippet_id', $qb->createNamedParameter($snippetId, IQueryBuilder::PARAM_INT)) + ); + } + } diff --git a/lib/Service/SnippetService.php b/lib/Service/SnippetService.php index 2f2127cab2..bac6d11f20 100644 --- a/lib/Service/SnippetService.php +++ b/lib/Service/SnippetService.php @@ -110,6 +110,7 @@ public function update(int $snippetId, string $userId, string $title, string $co public function delete(int $snippetId, string $userId): void { $snippet = $this->snippetMapper->find($snippetId, $userId); $this->snippetMapper->delete($snippet); + $this->snippetShareMapper->deleteBySnippetId($snippetId); } diff --git a/src/components/snippets/ListItem.vue b/src/components/snippets/ListItem.vue index d07f8f0916..848ef0d0ab 100644 --- a/src/components/snippets/ListItem.vue +++ b/src/components/snippets/ListItem.vue @@ -39,9 +39,9 @@ :get-option-label="option => option.displayName" @option:selecting="shareSnippet" @search="asyncFind" /> -

- {{ shareaa.displayName }} - +

+ {{ user.shareWith }} + {{ t('mail','Remove share') }}

@@ -118,9 +118,7 @@ export default { }, async mounted() { if (!this.shared) { - this.shares = await getShares(this.snippet.id).then((response) => { - return response.map(share => share.shareWith) - }) + this.shares = await getShares(this.snippet.id) } }, methods: { @@ -133,19 +131,19 @@ export default { }, async shareSnippet(sharee) { await shareSnippet(this.snippet.id, sharee.shareWith, sharee.shareType === ShareType.User ? 'user' : 'group').then(() => { - this.shares.push([{ name: sharee.shareWith, type: sharee.isNoUser ? 'group' : 'user' }]) - showSuccess(t('mail', 'Snippet shared with {sharee}', { sharee: sharee.displayName })) + this.shares.push({ shareWith: sharee.shareWith, type: sharee.isNoUser ? 'group' : 'user' }) + showSuccess(t('mail', 'Snippet shared with {sharee}', { sharee: sharee.shareWith })) this.share = null }).catch(() => { - showError(t('mail', 'Failed to share snippet with {sharee}', { sharee: sharee.displayName })) + showError(t('mail', 'Failed to share snippet with {sharee}', { sharee: sharee.shareWith })) }) }, async removeShare(sharee) { await unshareSnippet(this.snippet.id, sharee.shareWith).then(() => { - this.shares = this.shares.filter(share => share.name !== sharee.name) + this.shares = this.shares.filter(share => share.shareWith !== sharee.shareWith) showSuccess(t('mail', 'Share deleted for {sharee}', { sharee })) }).catch(() => { - showError(t('mail', 'Failed to delete share for {sharee}', { sharee })) + showError(t('mail', 'Failed to delete share with {name}', { name: sharee.shareWith })) }) },