From 1bf86a3703cf4f7f62453302fe19ba8a6837426a Mon Sep 17 00:00:00 2001 From: Yogesh Shejwadkar Date: Thu, 17 Mar 2022 09:44:42 +0530 Subject: [PATCH 1/5] fixed the issue to accept 0 and null and changed the default text value to remaining downloads Signed-off-by: Yogesh Shejwadkar --- lib/Controller/ApiController.php | 23 ++++++++++++++++------- src/models/DownloadLimitAction.js | 2 +- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index 0b9588be..1a32a746 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -73,12 +73,13 @@ public function __construct(IRequest $request, * * Set the download limit for a given link share */ - public function setDownloadLimit(string $token, int $limit): Response { + public function setDownloadLimit(string $token, $limit): Response { $this->validateToken($token); + $limit = trim($limit); - // Count needs to be at least 1 - if ($limit < 1) { - throw new OCSBadRequestException('Limit needs to be greater or equal than 1'); + // Count needs to be at least 0 or null + if (!is_numeric($limit) && $limit !== '') { + throw new OCSBadRequestException('Limit must be greater than or equal to 0 or null'); } // Getting existing limit and init if unset @@ -93,10 +94,18 @@ public function setDownloadLimit(string $token, int $limit): Response { // Update DB $shareLimit->setLimit($limit); - if ($insert) { - $this->mapper->insert($shareLimit); + if($limit == 0 || $limit == ''){ + $this->mapper->delete($shareLimit); } else { - $this->mapper->update($shareLimit); + if($limit < 0) { + throw new OCSBadRequestException('Limit must be greater than or equal to 0 or null'); + } else { + if ($insert) { + $this->mapper->insert($shareLimit); + } else { + $this->mapper->update($shareLimit); + } + } } return new DataResponse(); diff --git a/src/models/DownloadLimitAction.js b/src/models/DownloadLimitAction.js index 7a472c75..0ef4b59b 100644 --- a/src/models/DownloadLimitAction.js +++ b/src/models/DownloadLimitAction.js @@ -49,7 +49,7 @@ export default class DownloadLimitAction { is: this._store.enabled ? ActionInput : null, text: t('files_downloadlimit', 'Download limit'), title: t('files_downloadlimit', 'Download count: {count}', this._store), - value: this._store.limit, + value: this._store.limit ? this._store.limit - this._store.count : this._store.limit, } } From 806e7bbadba7332161100c98d9aa34e429517cf0 Mon Sep 17 00:00:00 2001 From: Yogesh Shejwadkar Date: Tue, 22 Mar 2022 11:14:44 +0530 Subject: [PATCH 2/5] Changed the hover label from Download count to Downloads Signed-off-by: Yogesh Shejwadkar --- src/models/DownloadLimitAction.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/models/DownloadLimitAction.js b/src/models/DownloadLimitAction.js index 0ef4b59b..65465b5d 100644 --- a/src/models/DownloadLimitAction.js +++ b/src/models/DownloadLimitAction.js @@ -48,7 +48,7 @@ export default class DownloadLimitAction { icon: 'icon-download', is: this._store.enabled ? ActionInput : null, text: t('files_downloadlimit', 'Download limit'), - title: t('files_downloadlimit', 'Download count: {count}', this._store), + title: t('files_downloadlimit', 'Downloads: {count}', this._store), value: this._store.limit ? this._store.limit - this._store.count : this._store.limit, } } From 0b3d05c18c023362f07c0f3621eed52a15e77a57 Mon Sep 17 00:00:00 2001 From: Yogesh Shejwadkar Date: Fri, 25 Mar 2022 14:24:37 +0530 Subject: [PATCH 3/5] changed the type to int for limit as per the review comment Signed-off-by: Yogesh Shejwadkar --- lib/Controller/ApiController.php | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index 1a32a746..07bdcf58 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -73,13 +73,12 @@ public function __construct(IRequest $request, * * Set the download limit for a given link share */ - public function setDownloadLimit(string $token, $limit): Response { + public function setDownloadLimit(string $token, int $limit): Response { $this->validateToken($token); - $limit = trim($limit); // Count needs to be at least 0 or null - if (!is_numeric($limit) && $limit !== '') { - throw new OCSBadRequestException('Limit must be greater than or equal to 0 or null'); + if ($limit < 0) { + throw new OCSBadRequestException('Limit must be greater than or equal to 0'); } // Getting existing limit and init if unset @@ -94,17 +93,13 @@ public function setDownloadLimit(string $token, $limit): Response { // Update DB $shareLimit->setLimit($limit); - if($limit == 0 || $limit == ''){ + if($limit === 0){ $this->mapper->delete($shareLimit); } else { - if($limit < 0) { - throw new OCSBadRequestException('Limit must be greater than or equal to 0 or null'); + if ($insert) { + $this->mapper->insert($shareLimit); } else { - if ($insert) { - $this->mapper->insert($shareLimit); - } else { - $this->mapper->update($shareLimit); - } + $this->mapper->update($shareLimit); } } From e14e219c96f49b3fdd27b5b93d6eee75add419cd Mon Sep 17 00:00:00 2001 From: Yogesh Shejwadkar Date: Tue, 29 Mar 2022 12:03:43 +0530 Subject: [PATCH 4/5] done the changes as per the review comments Signed-off-by: Yogesh Shejwadkar --- lib/Controller/ApiController.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index 07bdcf58..8cee6a6f 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -95,12 +95,10 @@ public function setDownloadLimit(string $token, int $limit): Response { $shareLimit->setLimit($limit); if($limit === 0){ $this->mapper->delete($shareLimit); + } elseif ($insert) { + $this->mapper->insert($shareLimit); } else { - if ($insert) { - $this->mapper->insert($shareLimit); - } else { - $this->mapper->update($shareLimit); - } + $this->mapper->update($shareLimit); } return new DataResponse(); From cfbe4c0bb4baea9a8a107d484484287ac3df0c15 Mon Sep 17 00:00:00 2001 From: Yogesh Shejwadkar Date: Wed, 6 Apr 2022 18:41:29 +0530 Subject: [PATCH 5/5] changed the implementation to allow to set the download limit to the file having allow resharing permissions Signed-off-by: Yogesh Shejwadkar --- lib/Controller/ApiController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index 8cee6a6f..d9d91967 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -151,13 +151,13 @@ protected function validateToken(string $token = '') { try { $share = $this->shareManager->getShareByToken($token); } catch (ShareNotFound $e) { - throw new OCSNotFoundException('Unknown share'); + throw new OCSNotFoundException('Unknown share. token missing'); } // Make sure the user is owner of the share - if ($user == null || $share->getShareOwner() !== $user->getUID()) { - throw new OCSNotFoundException('Unknown share'); - } + // if ($user == null || $share->getShareOwner() !== $user->getUID()) { + // throw new OCSNotFoundException('Unknown share. user is not owner'); + // } // Download count limit only works on links if ($share->getShareType() !== IShare::TYPE_LINK