aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorVincent Petry <vincent@nextcloud.com>2021-03-25 17:32:49 +0100
committerVincent Petry <vincent@nextcloud.com>2021-04-15 10:06:09 +0200
commitaf61486aea90cfc1a82301ce624dffb59ed01e07 (patch)
tree9b608272439503e0015ece40ae4b77013eabc81f /lib
parent2650da70caa73c8bf3119edebb37e91d67f3a214 (diff)
downloadnextcloud-server-af61486aea90cfc1a82301ce624dffb59ed01e07.tar.gz
nextcloud-server-af61486aea90cfc1a82301ce624dffb59ed01e07.zip
Separate settings for remote share expiration
Added separate settings for default and enforced expiration date for remote shares. Signed-off-by: Vincent Petry <vincent@nextcloud.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Share20/Manager.php55
-rw-r--r--lib/private/Template/JSConfigHelper.php10
2 files changed, 57 insertions, 8 deletions
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php
index f7e7f371b51..7211a4eb1e8 100644
--- a/lib/private/Share20/Manager.php
+++ b/lib/private/Share20/Manager.php
@@ -385,6 +385,8 @@ class Manager implements IManager {
* @throws \Exception
*/
protected function validateExpirationDateInternal(IShare $share) {
+ $isRemote = $share->getShareType() === IShare::TYPE_REMOTE || $share->getShareType() === IShare::TYPE_REMOTE_GROUP;
+
$expirationDate = $share->getExpirationDate();
if ($expirationDate !== null) {
@@ -407,28 +409,39 @@ class Manager implements IManager {
// This is a new share
}
- if ($fullId === null && $expirationDate === null && $this->shareApiInternalDefaultExpireDate()) {
+ if ($isRemote) {
+ $defaultExpireDate = $this->shareApiRemoteDefaultExpireDate();
+ $defaultExpireDays = $this->shareApiRemoteDefaultExpireDays();
+ $configProp = 'remote_defaultExpDays';
+ $isEnforced = $this->shareApiRemoteDefaultExpireDateEnforced();
+ } else {
+ $defaultExpireDate = $this->shareApiInternalDefaultExpireDate();
+ $defaultExpireDays = $this->shareApiInternalDefaultExpireDays();
+ $configProp = 'internal_defaultExpDays';
+ $isEnforced = $this->shareApiInternalDefaultExpireDateEnforced();
+ }
+ if ($fullId === null && $expirationDate === null && $defaultExpireDate) {
$expirationDate = new \DateTime();
$expirationDate->setTime(0,0,0);
- $days = (int)$this->config->getAppValue('core', 'internal_defaultExpDays', (string)$this->shareApiInternalDefaultExpireDays());
- if ($days > $this->shareApiInternalDefaultExpireDays()) {
- $days = $this->shareApiInternalDefaultExpireDays();
+ $days = (int)$this->config->getAppValue('core', $configProp, (string)$defaultExpireDays);
+ if ($days > $defaultExpireDays) {
+ $days = $defaultExpireDays;
}
$expirationDate->add(new \DateInterval('P'.$days.'D'));
}
// If we enforce the expiration date check that is does not exceed
- if ($this->shareApiInternalDefaultExpireDateEnforced()) {
+ if ($isEnforced) {
if ($expirationDate === null) {
throw new \InvalidArgumentException('Expiration date is enforced');
}
$date = new \DateTime();
$date->setTime(0, 0, 0);
- $date->add(new \DateInterval('P' . $this->shareApiInternalDefaultExpireDays() . 'D'));
+ $date->add(new \DateInterval('P' . $defaultExpireDays . 'D'));
if ($date < $expirationDate) {
- $message = $this->l->t('Can’t set expiration date more than %s days in the future', [$this->shareApiInternalDefaultExpireDays()]);
+ $message = $this->l->t('Can’t set expiration date more than %s days in the future', [$defaultExpireDays]);
throw new GenericShareException($message, $message, 404);
}
}
@@ -1793,8 +1806,17 @@ class Manager implements IManager {
}
/**
+ * Is default remote expire date enabled
+ *
+ * @return bool
+ */
+ public function shareApiRemoteDefaultExpireDate(): bool {
+ return $this->config->getAppValue('core', 'shareapi_default_remote_expire_date', 'no') === 'yes';
+ }
+
+ /**
* Is default expire date enforced
- *`
+ *
* @return bool
*/
public function shareApiInternalDefaultExpireDateEnforced(): bool {
@@ -1802,6 +1824,15 @@ class Manager implements IManager {
$this->config->getAppValue('core', 'shareapi_enforce_internal_expire_date', 'no') === 'yes';
}
+ /**
+ * Is default expire date enforced for remote shares
+ *
+ * @return bool
+ */
+ public function shareApiRemoteDefaultExpireDateEnforced(): bool {
+ return $this->shareApiRemoteDefaultExpireDate() &&
+ $this->config->getAppValue('core', 'shareapi_enforce_remote_expire_date', 'no') === 'yes';
+ }
/**
* Number of default expire days
@@ -1812,6 +1843,14 @@ class Manager implements IManager {
}
/**
+ * Number of default expire days for remote shares
+ * @return int
+ */
+ public function shareApiRemoteDefaultExpireDays(): int {
+ return (int)$this->config->getAppValue('core', 'shareapi_remote_expire_after_n_days', '7');
+ }
+
+ /**
* Allow public upload on link shares
*
* @return bool
diff --git a/lib/private/Template/JSConfigHelper.php b/lib/private/Template/JSConfigHelper.php
index cd466575601..c8f5fc63b70 100644
--- a/lib/private/Template/JSConfigHelper.php
+++ b/lib/private/Template/JSConfigHelper.php
@@ -165,6 +165,13 @@ class JSConfigHelper {
$defaultInternalExpireDateEnforced = $this->config->getAppValue('core', 'shareapi_enforce_internal_expire_date', 'no') === 'yes';
}
+ $defaultRemoteExpireDateEnabled = $this->config->getAppValue('core', 'shareapi_default_remote_expire_date', 'no') === 'yes';
+ $defaultRemoteExpireDate = $defaultRemoteExpireDateEnforced = null;
+ if ($defaultRemoteExpireDateEnabled) {
+ $defaultRemoteExpireDate = (int)$this->config->getAppValue('core', 'shareapi_remote_expire_after_n_days', '7');
+ $defaultRemoteExpireDateEnforced = $this->config->getAppValue('core', 'shareapi_enforce_remote_expire_date', 'no') === 'yes';
+ }
+
$countOfDataLocation = 0;
$dataLocation = str_replace(\OC::$SERVERROOT . '/', '', $this->config->getSystemValue('datadirectory', ''), $countOfDataLocation);
if ($countOfDataLocation !== 1 || $uid === null || !$this->groupManager->isAdmin($uid)) {
@@ -278,6 +285,9 @@ class JSConfigHelper {
'defaultInternalExpireDateEnabled' => $defaultInternalExpireDateEnabled,
'defaultInternalExpireDate' => $defaultInternalExpireDate,
'defaultInternalExpireDateEnforced' => $defaultInternalExpireDateEnforced,
+ 'defaultRemoteExpireDateEnabled' => $defaultRemoteExpireDateEnabled,
+ 'defaultRemoteExpireDate' => $defaultRemoteExpireDate,
+ 'defaultRemoteExpireDateEnforced' => $defaultRemoteExpireDateEnforced,
]
]),
"_theme" => json_encode([