mirror of
https://github.com/JanGross/quicknotes.git
synced 2025-12-01 07:37:18 +01:00
Fix unable to forget shared note... Part of issue #72
This commit is contained in:
@@ -55,15 +55,11 @@ class ShareController extends Controller {
|
||||
* @param int $noteId
|
||||
*/
|
||||
public function destroy(int $noteId): JSONResponse {
|
||||
try {
|
||||
$noteShare = $this->noteShareMapper->findByNoteAndUser($noteId, $this->userId);
|
||||
} catch (DoesNotExistException $e) {
|
||||
if ($this->noteShareMapper->forgetShareByNoteIdAndSharedUser($noteId, $this->userId)) {
|
||||
return new JSONResponse([], Http::STATUS_OK);
|
||||
} else {
|
||||
return new JSONResponse([], Http::STATUS_NOT_FOUND);
|
||||
}
|
||||
|
||||
$this->noteShareMapper->delete($noteShare);
|
||||
|
||||
return new JSONResponse([]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ class NoteShareMapper extends QBMapper {
|
||||
parent::__construct($db, 'quicknotes_shares', NoteShare::class);
|
||||
}
|
||||
|
||||
public function findForUser(string $userId): array {
|
||||
public function findSharesForUserId(string $userId): array {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select('*')
|
||||
->from($this->getTableName())
|
||||
@@ -24,7 +24,7 @@ class NoteShareMapper extends QBMapper {
|
||||
return $this->findEntities($qb);
|
||||
}
|
||||
|
||||
public function findForGroup(string $groupId): array {
|
||||
public function findSharesForGroupId(string $groupId): array {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select('*')
|
||||
->from($this->getTableName())
|
||||
@@ -34,7 +34,7 @@ class NoteShareMapper extends QBMapper {
|
||||
return $this->findEntities($qb);
|
||||
}
|
||||
|
||||
public function findByNoteAndUser(int $noteId, string $userId): NoteShare {
|
||||
public function findSharesByNoteIsAndSharedUser(int $noteId, string $userId): NoteShare {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select('*')
|
||||
->from($this->getTableName())
|
||||
@@ -45,7 +45,7 @@ class NoteShareMapper extends QBMapper {
|
||||
return $this->findEntity($qb);
|
||||
}
|
||||
|
||||
public function findByNoteAndGroup(int $noteId, string $groupId): NoteShare {
|
||||
public function findSharesByNoteIdAndGroupId(int $noteId, string $groupId): NoteShare {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select('*')
|
||||
->from($this->getTableName())
|
||||
@@ -56,7 +56,7 @@ class NoteShareMapper extends QBMapper {
|
||||
return $this->findEntity($qb);
|
||||
}
|
||||
|
||||
public function getSharesForNote(int $noteId): array {
|
||||
public function findSharesForNoteId(int $noteId): array {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select('*')
|
||||
->from($this->getTableName())
|
||||
@@ -66,19 +66,29 @@ class NoteShareMapper extends QBMapper {
|
||||
return $this->findEntities($qb);
|
||||
}
|
||||
|
||||
public function deleteByNoteId(int $noteId): void {
|
||||
public function forgetSharesByNoteId(int $noteId): void {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->delete($this->getTableName())
|
||||
->where($qb->expr()->eq('note_id', $qb->createNamedParameter($noteId)))
|
||||
->execute();
|
||||
}
|
||||
|
||||
public function forgetShareByNoteIdAndSharedUser(int $noteId, string $userId) {
|
||||
try {
|
||||
$noteShare = $this->findSharesByNoteIsAndSharedUser($noteId, $userId);
|
||||
} catch (DoesNotExistException $e) {
|
||||
return false;
|
||||
}
|
||||
$this->delete($noteShare);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function existsByNoteAndUser(int $noteId, string $userId) {
|
||||
public function existsByNoteAndSharedUser(int $noteId, string $userId) {
|
||||
try {
|
||||
$this->findByNoteAndUser($noteId, $userId);
|
||||
$this->findSharesByNoteIsAndSharedUser($noteId, $userId);
|
||||
} catch (DoesNotExistException $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ class NoteService {
|
||||
// Set shares with others.
|
||||
foreach($notes as $note) {
|
||||
$sharedWith = [];
|
||||
$sharedEntries = $this->noteShareMapper->getSharesForNote($note->getId());
|
||||
$sharedEntries = $this->noteShareMapper->findSharesForNoteId($note->getId());
|
||||
foreach ($sharedEntries as $sharedEntry) {
|
||||
$sharedUid = $sharedEntry->getSharedUser();
|
||||
$user = $this->userManager->get($sharedUid);
|
||||
@@ -107,7 +107,7 @@ class NoteService {
|
||||
|
||||
// Get shares from others.
|
||||
$shares = [];
|
||||
$sharedEntries = $this->noteShareMapper->findForUser($userId);
|
||||
$sharedEntries = $this->noteShareMapper->findSharesForUserId($userId);
|
||||
foreach($sharedEntries as $sharedEntry) {
|
||||
$sharedNote = $this->notemapper->findShared($sharedEntry->getNoteId());
|
||||
|
||||
@@ -323,7 +323,7 @@ class NoteService {
|
||||
}
|
||||
|
||||
// Delete old shares
|
||||
$dbShares = $this->noteShareMapper->getSharesForNote($id);
|
||||
$dbShares = $this->noteShareMapper->findSharesForNoteId($id);
|
||||
foreach ($dbShares as $dbShare) {
|
||||
$delete = true;
|
||||
foreach ($sharedWith as $share) {
|
||||
@@ -339,7 +339,7 @@ class NoteService {
|
||||
|
||||
// Add new shares
|
||||
foreach ($sharedWith as $share) {
|
||||
if (!$this->noteShareMapper->existsByNoteAndUser($id, $share['id'])) {
|
||||
if (!$this->noteShareMapper->existsByNoteAndSharedUser($id, $share['id'])) {
|
||||
$hShare = new NoteShare();
|
||||
$hShare->setNoteId($id);
|
||||
$hShare->setSharedUser($share['id']);
|
||||
@@ -412,7 +412,7 @@ class NoteService {
|
||||
|
||||
// Fill shared with with others
|
||||
$sharedWith = [];
|
||||
$sharedEntries = $this->noteShareMapper->getSharesForNote($note->getId());
|
||||
$sharedEntries = $this->noteShareMapper->findSharesForNoteId($note->getId());
|
||||
foreach ($sharedEntries as $sharedEntry) {
|
||||
$sharedUid = $sharedEntry->getSharedUser();
|
||||
$user = $this->userManager->get($sharedUid);
|
||||
@@ -454,7 +454,7 @@ class NoteService {
|
||||
}
|
||||
$oldcolorid = $note->getColorId();
|
||||
|
||||
$this->noteShareMapper->deleteByNoteId($note->getId());
|
||||
$this->noteShareMapper->forgetSharesByNoteId($note->getId());
|
||||
|
||||
// Delete note.
|
||||
$this->notemapper->delete($note);
|
||||
|
||||
Reference in New Issue
Block a user