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