Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2019-11-28 10:37:19 +0300
committerGitHub <noreply@github.com>2019-11-28 10:37:19 +0300
commit62dc32019146bdc186e110bde23dd210633acbe7 (patch)
treea4947d148758d953fa5d3777333e8190ab84fb3b /lib/private
parent669302e570024c83140ff5c4f4b1489c5a1c66ed (diff)
parent078f4efb20f269394e5f60fe327ba36c0279d77e (diff)
Merge pull request #17725 from nextcloud/enh/share_exp_internal
Allow internal shares to have a default expiration date
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Share20/DefaultShareProvider.php10
-rw-r--r--lib/private/Share20/Manager.php129
-rw-r--r--lib/private/Template/JSConfigHelper.php12
3 files changed, 145 insertions, 6 deletions
diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php
index c25a7b03d5c..152e5d55394 100644
--- a/lib/private/Share20/DefaultShareProvider.php
+++ b/lib/private/Share20/DefaultShareProvider.php
@@ -144,9 +144,19 @@ class DefaultShareProvider implements IShareProvider {
//Set the UID of the user we share with
$qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith()));
$qb->setValue('accepted', $qb->createNamedParameter(IShare::STATUS_PENDING));
+
+ //If an expiration date is set store it
+ if ($share->getExpirationDate() !== null) {
+ $qb->setValue('expiration', $qb->createNamedParameter($share->getExpirationDate(), 'datetime'));
+ }
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
//Set the GID of the group we share with
$qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith()));
+
+ //If an expiration date is set store it
+ if ($share->getExpirationDate() !== null) {
+ $qb->setValue('expiration', $qb->createNamedParameter($share->getExpirationDate(), 'datetime'));
+ }
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
//set label for public link
$qb->setValue('label', $qb->createNamedParameter($share->getLabel()));
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php
index 210dc7772c0..db9c704871d 100644
--- a/lib/private/Share20/Manager.php
+++ b/lib/private/Share20/Manager.php
@@ -360,6 +360,77 @@ class Manager implements IManager {
* @throws \InvalidArgumentException
* @throws \Exception
*/
+ protected function validateExpirationDateInternal(\OCP\Share\IShare $share) {
+ $expirationDate = $share->getExpirationDate();
+
+ if ($expirationDate !== null) {
+ //Make sure the expiration date is a date
+ $expirationDate->setTime(0, 0, 0);
+
+ $date = new \DateTime();
+ $date->setTime(0, 0, 0);
+ if ($date >= $expirationDate) {
+ $message = $this->l->t('Expiration date is in the past');
+ throw new GenericShareException($message, $message, 404);
+ }
+ }
+
+ // If expiredate is empty set a default one if there is a default
+ $fullId = null;
+ try {
+ $fullId = $share->getFullId();
+ } catch (\UnexpectedValueException $e) {
+ // This is a new share
+ }
+
+ if ($fullId === null && $expirationDate === null && $this->shareApiInternalDefaultExpireDate()) {
+ $expirationDate = new \DateTime();
+ $expirationDate->setTime(0,0,0);
+ $expirationDate->add(new \DateInterval('P'.$this->shareApiInternalDefaultExpireDays().'D'));
+ }
+
+ // If we enforce the expiration date check that is does not exceed
+ if ($this->shareApiInternalDefaultExpireDateEnforced()) {
+ 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'));
+ if ($date < $expirationDate) {
+ $message = $this->l->t('Can’t set expiration date more than %s days in the future', [$this->shareApiInternalDefaultExpireDays()]);
+ throw new GenericShareException($message, $message, 404);
+ }
+ }
+
+ $accepted = true;
+ $message = '';
+ \OCP\Util::emitHook('\OC\Share', 'verifyExpirationDate', [
+ 'expirationDate' => &$expirationDate,
+ 'accepted' => &$accepted,
+ 'message' => &$message,
+ 'passwordSet' => $share->getPassword() !== null,
+ ]);
+
+ if (!$accepted) {
+ throw new \Exception($message);
+ }
+
+ $share->setExpirationDate($expirationDate);
+
+ return $share;
+ }
+
+ /**
+ * Validate if the expiration date fits the system settings
+ *
+ * @param \OCP\Share\IShare $share The share to validate the expiration date of
+ * @return \OCP\Share\IShare The modified share object
+ * @throws GenericShareException
+ * @throws \InvalidArgumentException
+ * @throws \Exception
+ */
protected function validateExpirationDate(\OCP\Share\IShare $share) {
$expirationDate = $share->getExpirationDate();
@@ -636,8 +707,16 @@ class Manager implements IManager {
//Verify share type
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
$this->userCreateChecks($share);
+
+ //Verify the expiration date
+ $share = $this->validateExpirationDateInternal($share);
+
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
$this->groupCreateChecks($share);
+
+ //Verify the expiration date
+ $share = $this->validateExpirationDateInternal($share);
+
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
$this->linkCreateChecks($share);
$this->setLinkParent($share);
@@ -653,7 +732,7 @@ class Manager implements IManager {
);
//Verify the expiration date
- $this->validateExpirationDate($share);
+ $share = $this->validateExpirationDate($share);
//Verify the password
$this->verifyPassword($share->getPassword());
@@ -850,8 +929,20 @@ class Manager implements IManager {
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
$this->userCreateChecks($share);
+
+ if ($share->getExpirationDate() != $originalShare->getExpirationDate()) {
+ //Verify the expiration date
+ $this->validateExpirationDate($share);
+ $expirationDateUpdated = true;
+ }
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
$this->groupCreateChecks($share);
+
+ if ($share->getExpirationDate() != $originalShare->getExpirationDate()) {
+ //Verify the expiration date
+ $this->validateExpirationDate($share);
+ $expirationDateUpdated = true;
+ }
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
$this->linkCreateChecks($share);
@@ -1575,7 +1666,7 @@ class Manager implements IManager {
}
/**
- * Is default expire date enabled
+ * Is default link expire date enabled
*
* @return bool
*/
@@ -1584,7 +1675,7 @@ class Manager implements IManager {
}
/**
- * Is default expire date enforced
+ * Is default link expire date enforced
*`
* @return bool
*/
@@ -1593,9 +1684,9 @@ class Manager implements IManager {
$this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes';
}
+
/**
- * Number of default expire days
- *shareApiLinkAllowPublicUpload
+ * Number of default link expire days
* @return int
*/
public function shareApiLinkDefaultExpireDays() {
@@ -1603,6 +1694,34 @@ class Manager implements IManager {
}
/**
+ * Is default internal expire date enabled
+ *
+ * @return bool
+ */
+ public function shareApiInternalDefaultExpireDate(): bool {
+ return $this->config->getAppValue('core', 'shareapi_default_internal_expire_date', 'no') === 'yes';
+ }
+
+ /**
+ * Is default expire date enforced
+ *`
+ * @return bool
+ */
+ public function shareApiInternalDefaultExpireDateEnforced(): bool {
+ return $this->shareApiInternalDefaultExpireDate() &&
+ $this->config->getAppValue('core', 'shareapi_enforce_internal_expire_date', 'no') === 'yes';
+ }
+
+
+ /**
+ * Number of default expire days
+ * @return int
+ */
+ public function shareApiInternalDefaultExpireDays(): int {
+ return (int)$this->config->getAppValue('core', 'shareapi_internal_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 df5eda9121b..065bf2545e0 100644
--- a/lib/private/Template/JSConfigHelper.php
+++ b/lib/private/Template/JSConfigHelper.php
@@ -149,6 +149,13 @@ class JSConfigHelper {
}
$outgoingServer2serverShareEnabled = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes';
+ $defaultInternalExpireDateEnabled = $this->config->getAppValue('core', 'shareapi_default_internal_expire_date', 'no') === 'yes';
+ $defaultInternalExpireDate = $defaultInternalExpireDateEnforced = null;
+ if ($defaultInternalExpireDateEnabled) {
+ $defaultInternalExpireDate = (int) $this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7');
+ $defaultInternalExpireDateEnforced = $this->config->getAppValue('core', 'shareapi_internal_enforce_expire_date', 'no') === 'yes';
+ }
+
$countOfDataLocation = 0;
$dataLocation = str_replace(\OC::$SERVERROOT .'/', '', $this->config->getSystemValue('datadirectory', ''), $countOfDataLocation);
if($countOfDataLocation !== 1 || !$this->groupManager->isAdmin($uid)) {
@@ -255,7 +262,10 @@ class JSConfigHelper {
'resharingAllowed' => \OC\Share\Share::isResharingAllowed(),
'remoteShareAllowed' => $outgoingServer2serverShareEnabled,
'federatedCloudShareDoc' => $this->urlGenerator->linkToDocs('user-sharing-federated'),
- 'allowGroupSharing' => \OC::$server->getShareManager()->allowGroupSharing()
+ 'allowGroupSharing' => \OC::$server->getShareManager()->allowGroupSharing(),
+ 'defaultInternalExpireDateEnabled' => $defaultInternalExpireDateEnabled,
+ 'defaultInternalExpireDate' => $defaultInternalExpireDate,
+ 'defaultInternalExpireDateEnforced' => $defaultInternalExpireDateEnforced,
]
]),
"_theme" => json_encode([