Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
23 changes: 16 additions & 7 deletions lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/models/DownloadLimitAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ 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),
value: this._store.limit,
title: t('files_downloadlimit', 'Downloads: {count}', this._store),
value: this._store.limit ? this._store.limit - this._store.count : this._store.limit,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this change makes sense, the label says download limit so it should show the limit, not something else.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense because the remaining downloads is the current download limit. To show the initial download limit one week later to the customer does not deliver any new information to the user because he may remember the initial download limit or can calculate it with the download counter. It is more helpful to tell the user the current download limit to enable him to decide if he wants to increase it or not.

}
}

Expand Down