aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2014-04-23 12:50:24 +0200
committerBjoern Schiessle <schiessle@owncloud.com>2014-04-24 13:34:31 +0200
commit6650be99136bbeecc39a28cbe9c22de0c5cf08ac (patch)
tree169e3a0eb7ce95878ddc89387cfd948a53586040 /lib
parent8127e984bdd56d53279d720d2cf0b5504633c375 (diff)
downloadnextcloud-server-6650be99136bbeecc39a28cbe9c22de0c5cf08ac.tar.gz
nextcloud-server-6650be99136bbeecc39a28cbe9c22de0c5cf08ac.zip
add setting to set default expire date
Diffstat (limited to 'lib')
-rw-r--r--lib/private/share/helper.php49
-rw-r--r--lib/private/share/share.php15
2 files changed, 62 insertions, 2 deletions
diff --git a/lib/private/share/helper.php b/lib/private/share/helper.php
index fde55667281..515ec85909a 100644
--- a/lib/private/share/helper.php
+++ b/lib/private/share/helper.php
@@ -199,4 +199,53 @@ class Helper extends \OC\Share\Constants {
$query->execute();
}
}
+
+ /**
+ * @brief get default expire settings defined by the admin
+ * @return array contains 'defaultExpireDateSet', 'enforceExpireDate', 'expireAfterDays'
+ */
+ public static function getDefaultExpireSetting() {
+
+ $defaultExpireSettings = array('defaultExpireDateSet' => false);
+
+ // get default expire settings
+ $defaultExpireDate = \OC_Appconfig::getValue('core', 'shareapi_default_expire_date', 'no');
+ if ($defaultExpireDate === 'yes') {
+ $enforceExpireDate = \OC_Appconfig::getValue('core', 'shareapi_enforce_expire_date', 'no');
+ $defaultExpireSettings['defaultExpireDateSet'] = true;
+ $defaultExpireSettings['expireAfterDays'] = (int)\OC_Appconfig::getValue('core', 'shareapi_expire_after_n_days', '7');
+ $defaultExpireSettings['enforceExpireDate'] = $enforceExpireDate === 'yes' ? true : false;
+ }
+
+ return $defaultExpireSettings;
+ }
+
+ /**
+ * @brief calculate expire date
+ * @param array $defaultExpireSettings contains 'defaultExpireDateSet', 'enforceExpireDate', 'expireAfterDays'
+ * @param int $creationTime timestamp when the share was created
+ * @param int $userExpireDate expire timestamp set by the user
+ * @return mixed integer timestamp or False
+ */
+ public static function calculateExpireDate($defaultExpireSettings, $creationTime, $userExpireDate = null) {
+
+ $expires = false;
+
+ if (isset($defaultExpireSettings['defaultExpireDateSet']) && $defaultExpireSettings['defaultExpireDateSet']) {
+ $expires = $creationTime + $defaultExpireSettings['expireAfterDays'] * 86400;
+ }
+
+
+ if (isset($userExpireDate)) {
+ // if the admin decided to enforce the default expire date then we only take
+ // the user defined expire date of it is before the default expire date
+ if ($expires && isset($defaultExpireSettings['enforceExpireDate']) && $defaultExpireSettings['enforceExpireDate']) {
+ $expires = ($userExpireDate < $expires) ? $userExpireDate : $expires;
+ } else {
+ $expires = $userExpireDate;
+ }
+ }
+
+ return $expires;
+ }
}
diff --git a/lib/private/share/share.php b/lib/private/share/share.php
index fe756b5ae7f..a18c54af8a3 100644
--- a/lib/private/share/share.php
+++ b/lib/private/share/share.php
@@ -844,9 +844,20 @@ class Share extends \OC\Share\Constants {
* @return bool True if item was expired, false otherwise.
*/
protected static function expireItem(array $item) {
+
+ // get default expire settings
+ $defaultSettings = Helper::getDefaultExpireSetting();
+ // calculate expire date
if (!empty($item['expiration'])) {
- $now = new \DateTime();
- $expires = new \DateTime($item['expiration']);
+ $userDefinedExpire = new \DateTime($item['expiration']);
+ $userDefinedExpireTimestamp = $userDefinedExpire->getTimestamp();
+ } else {
+ $userDefinedExpireTimestamp = null;
+ }
+ $expires = Helper::calculateExpireDate($defaultSettings, $item['stime'], $userDefinedExpireTimestamp);
+
+ if (is_int($expires)) {
+ $now = time();
if ($now > $expires) {
self::unshareItem($item);
return true;