Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 47 additions & 24 deletions lib/Controller/BookmarkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,19 @@ private function toExternalFolderId(int $internal): int {
*/
public function getSingleBookmark($id): JSONResponse {
if (!Authorizer::hasPermission(Authorizer::PERM_READ, $this->authorizer->getPermissionsForBookmark((int)$id, $this->request))) {
return new JSONResponse(['status' => 'error', 'data' => ['Not found']], Http::STATUS_NOT_FOUND);
$res = new JSONResponse(['status' => 'error', 'data' => ['Not found']], Http::STATUS_NOT_FOUND);
$res->throttle();
return $res;
}
try {
/**
* @var Bookmark $bm
*/
$bm = $this->bookmarkMapper->find((int)$id);
} catch (DoesNotExistException $e) {
return new JSONResponse(['status' => 'error', 'data' => ['Not found']], Http::STATUS_NOT_FOUND);
$res = new JSONResponse(['status' => 'error', 'data' => ['Not found']], Http::STATUS_NOT_FOUND);
$res->throttle();
return $res;
} catch (MultipleObjectsReturnedException $e) {
return new JSONResponse(['status' => 'error', 'data' => ['Not found']], Http::STATUS_NOT_FOUND);
}
Expand Down Expand Up @@ -370,7 +374,9 @@ public function getBookmarks(

if ($folder !== null) {
if (!Authorizer::hasPermission(Authorizer::PERM_READ, $this->authorizer->getPermissionsForFolder($folder, $this->request))) {
return new DataResponse(['status' => 'error', 'data' => ['Not found']], Http::STATUS_BAD_REQUEST);
$res = new DataResponse(['status' => 'error', 'data' => ['Not found']], Http::STATUS_BAD_REQUEST);
$res->throttle();
return $res;
}
try {
/** @var Folder $folderEntity */
Expand All @@ -380,7 +386,9 @@ public function getBookmarks(
// to theirs
$userId = $folderEntity->getUserId();
} catch (DoesNotExistException|MultipleObjectsReturnedException $e) {
return new DataResponse(['status' => 'error', 'data' => ['Not found']], Http::STATUS_BAD_REQUEST);
$res = new DataResponse(['status' => 'error', 'data' => ['Not found']], Http::STATUS_BAD_REQUEST);
$res->throttle();
return $res;
}
$params->setFolder($this->toInternalFolderId($folder));
$params->setRecursive($recursive);
Expand Down Expand Up @@ -431,7 +439,9 @@ public function newBookmark($url = '', $title = null, $description = null, $tags
$permissions &= $this->authorizer->getPermissionsForFolder($folder, $this->request);
}
if (!Authorizer::hasPermission(Authorizer::PERM_WRITE, $permissions) || $this->authorizer->getUserId() === null) {
return new JSONResponse(['status' => 'error', 'data' => ['Could not add bookmark']], Http::STATUS_BAD_REQUEST);
$res = new JSONResponse(['status' => 'error', 'data' => ['Could not add bookmark']], Http::STATUS_BAD_REQUEST);
$res->throttle();
return $res;
}

try {
Expand Down Expand Up @@ -474,7 +484,9 @@ public function newBookmark($url = '', $title = null, $description = null, $tags
*/
public function editBookmark($id = null, $url = null, $title = null, $description = null, $tags = null, $folders = null, $target = null): JSONResponse {
if (!Authorizer::hasPermission(Authorizer::PERM_EDIT, $this->authorizer->getPermissionsForBookmark($id, $this->request))) {
return new JSONResponse(['status' => 'error', 'data' => ['Could not edit bookmark']], Http::STATUS_NOT_FOUND);
$res = new JSONResponse(['status' => 'error', 'data' => ['Could not edit bookmark']], Http::STATUS_NOT_FOUND);
$res->throttle();
return $res;
}

try {
Expand Down Expand Up @@ -522,13 +534,17 @@ public function editBookmark($id = null, $url = null, $title = null, $descriptio
*/
public function deleteBookmark($id): JSONResponse {
if (!Authorizer::hasPermission(Authorizer::PERM_EDIT, $this->authorizer->getPermissionsForBookmark($id, $this->request))) {
return new JSONResponse(['status' => 'success']);
$res = new JSONResponse(['status' => 'success']);
$res->throttle();
return $res;
}

try {
$this->bookmarkMapper->find($id);
} catch (DoesNotExistException|MultipleObjectsReturnedException) {
return new JSONResponse(['status' => 'success']);
$res = new JSONResponse(['status' => 'success']);
$res->throttle();
return $res;
}

try {
Expand All @@ -550,6 +566,7 @@ public function deleteBookmark($id): JSONResponse {
*
* @NoAdminRequired
* @NoCSRFRequired
* @BruteForceProtection
*
* @PublicPage
*/
Expand All @@ -561,13 +578,17 @@ public function clickBookmark($url = ''): JSONResponse {
try {
$bookmark = $this->bookmarks->findByUrl($this->authorizer->getUserId(), $url);
} catch (DoesNotExistException $e) {
return new JSONResponse(['status' => 'error', 'data' => ['Not found']], Http::STATUS_BAD_REQUEST);
$res = new JSONResponse(['status' => 'error', 'data' => ['Not found']], Http::STATUS_BAD_REQUEST);
$res->throttle();
return $res;
} catch (UrlParseError $e) {
return new JSONResponse(['status' => 'error', 'data' => ['Failed to parse URL']], Http::STATUS_BAD_REQUEST);
}

if ($bookmark->getUserId() !== $this->authorizer->getUserId()) {
return new JSONResponse(['status' => 'error', 'data' => ['Not found']], Http::STATUS_BAD_REQUEST);
$res = new JSONResponse(['status' => 'error', 'data' => ['Not found']], Http::STATUS_BAD_REQUEST);
$res->throttle();
return $res;
}

try {
Expand All @@ -591,7 +612,7 @@ public function clickBookmark($url = ''): JSONResponse {
* @NoCSRFRequired
*
* @PublicPage
* @BruteForceProtection(action=bookmarks#getBookmarkImage)
* @BruteForceProtection
* @return DataDisplayResponse|NotFoundResponse|RedirectResponse
*/
public function getBookmarkImage($id) {
Expand All @@ -617,7 +638,7 @@ public function getBookmarkImage($id) {
*
* @NoAdminRequired
* @NoCSRFRequired
* @BruteForceProtection(action=bookmarks#getBookmarkFavicon)
* @BruteForceProtection
* @PublicPage
* @return DataDisplayResponse|NotFoundResponse|DataResponse
*/
Expand Down Expand Up @@ -670,7 +691,7 @@ public function doImageResponse(?IImage $image) {
*
* @NoAdminRequired
* @NoCSRFRequired
* @BruteForceProtection(action=bookmarks#importBookmark)
* @BruteForceProtection
* @PublicPage
*/
public function importBookmark($folder = null): JSONResponse {
Expand Down Expand Up @@ -712,7 +733,9 @@ public function importBookmark($folder = null): JSONResponse {
$res->throttle();
return $res;
} catch (DoesNotExistException $e) {
return new JSONResponse(['status' => 'error', 'data' => ['Folder not found']], Http::STATUS_BAD_REQUEST);
$res = new JSONResponse(['status' => 'error', 'data' => ['Folder not found']], Http::STATUS_BAD_REQUEST);
$res->throttle();
return $res;
} catch (MultipleObjectsReturnedException $e) {
return new JSONResponse(['status' => 'error', 'data' => ['Multiple objects found']], Http::STATUS_INTERNAL_SERVER_ERROR);
} catch (HtmlParseError $e) {
Expand All @@ -739,7 +762,7 @@ public function importBookmark($folder = null): JSONResponse {
* @return ExportResponse|JSONResponse
* @NoAdminRequired
* @NoCSRFRequired
* @BruteForceProtection(action=bookmarks#exportBookmark)
* @BruteForceProtection
* @PublicPage
*/
public function exportBookmark() {
Expand Down Expand Up @@ -769,7 +792,7 @@ public function exportBookmark() {
* @return JSONResponse
* @NoAdminRequired
* @NoCSRFRequired
* @BruteForceProtection(action=bookmarks#countBookmarks)
* @BruteForceProtection
* @PublicPage
* @throws UnauthenticatedError
*/
Expand All @@ -794,7 +817,7 @@ public function countBookmarks(int $folder): JSONResponse {
* @return JSONResponse
* @NoAdminRequired
* @NoCSRFRequired
* @BruteForceProtection(action=bookmarks#countUnavailable)
* @BruteForceProtection
* @PublicPage
* @throws UnauthenticatedError
*/
Expand All @@ -817,7 +840,7 @@ public function countUnavailable(): JSONResponse {
* @return JSONResponse
* @NoAdminRequired
* @NoCSRFRequired
* @BruteForceProtection(action=bookmarks#countArchived)
* @BruteForceProtection
* @PublicPage
* @throws UnauthenticatedError
*/
Expand All @@ -836,7 +859,7 @@ public function countArchived(): JSONResponse {
* @return JSONResponse
* @NoAdminRequired
* @NoCSRFRequired
* @BruteForceProtection(action=bookmarks#countDuplicated)
* @BruteForceProtection
* @PublicPage
* @throws UnauthenticatedError
*/
Expand All @@ -855,7 +878,7 @@ public function countDuplicated(): JSONResponse {
* @return JSONResponse
* @NoAdminRequired
* @NoCSRFRequired
* @BruteForceProtection(action=bookmarks#acquireLock)
* @BruteForceProtection
* @PublicPage
* @throws UnauthenticatedError
*/
Expand Down Expand Up @@ -883,7 +906,7 @@ public function acquireLock(): JSONResponse {
* @return JSONResponse
* @NoAdminRequired
* @NoCSRFRequired
* @BruteForceProtection(action=bookmarks#releaseLock)
* @BruteForceProtection
* @PublicPage
* @throws UnauthenticatedError
*/
Expand Down Expand Up @@ -911,7 +934,7 @@ public function releaseLock(): JSONResponse {
* @return Http\DataResponse
* @NoAdminRequired
* @NoCSRFRequired
* @BruteForceProtection(action=bookmarks#getDeletedBookmarks)
* @BruteForceProtection
* @PublicPage
*/
public function getDeletedBookmarks(): DataResponse {
Expand All @@ -933,7 +956,7 @@ public function getDeletedBookmarks(): DataResponse {
/**
* @NoAdminRequired
* @NoCSRFRequired
* @BruteForceProtection(action=bookmarks#countAllClicks)
* @BruteForceProtection
* @return DataResponse
*/
public function countAllClicks(): DataResponse {
Expand All @@ -954,7 +977,7 @@ public function countAllClicks(): DataResponse {
/**
* @NoAdminRequired
* @NoCSRFRequired
* @BruteForceProtection(action=bookmarks#countWithClicks)
* @BruteForceProtection
* @return DataResponse
*/
public function countWithClicks(): DataResponse {
Expand Down
Loading
Loading