Skip to content

Commit

Permalink
fixup! feat: mail snippets
Browse files Browse the repository at this point in the history
Signed-off-by: Hamza Mahjoubi <[email protected]>
  • Loading branch information
hamza221 committed Nov 8, 2024
1 parent 991c761 commit fadacf6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
1 change: 1 addition & 0 deletions lib/Db/SnippetMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,5 @@ public function findSharedWithMe(string $userId, array $groups): array {
);
return $this->findEntities($qb);
}

}
14 changes: 11 additions & 3 deletions lib/Db/SnippetShareMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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))
);
}


}
1 change: 1 addition & 0 deletions lib/Service/SnippetService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
20 changes: 9 additions & 11 deletions src/components/snippets/ListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
:get-option-label="option => option.displayName"
@option:selecting="shareSnippet"
@search="asyncFind" />
<p v-for="shareaa in shares" :key="shareaa.displayName">
{{ shareaa.displayName }}
<NcActionButton icon="icon-delete" @click="removeShare(shareaa)">
<p v-for="user in shares" :key="user.shareWith">
{{ user.shareWith }}
<NcActionButton icon="icon-delete" @click="removeShare(user)">
{{ t('mail','Remove share') }}
</NcActionButton>
</p>
Expand Down Expand Up @@ -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: {
Expand All @@ -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 }))
})
},

Expand Down

0 comments on commit fadacf6

Please sign in to comment.