Skip to content

Commit

Permalink
allow setting expire on user / group shares
Browse files Browse the repository at this point in the history
  • Loading branch information
butonic committed Apr 8, 2015
1 parent 6c327f8 commit 2b041b1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
8 changes: 2 additions & 6 deletions apps/files_sharing/api/local.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,13 +439,9 @@ private static function updatePublicUpload($share, $params) {
* @return \OC_OCS_Result
*/
private static function updateExpireDate($share, $params) {
// only public links can have a expire date
if ((int)$share['share_type'] !== \OCP\Share::SHARE_TYPE_LINK ) {
return new \OC_OCS_Result(null, 400, "expire date only exists for public link shares");
}

try {
$expireDateSet = \OCP\Share::setExpirationDate($share['item_type'], $share['item_source'], $params['_put']['expireDate'], (int)$share['stime']);
$expireDateSet = \OCP\Share::setExpirationDate($share['item_type'], $share['item_source'], $params['_put']['expireDate'], (int)$share['stime'], (int)$share['id']);
$result = ($expireDateSet) ? new \OC_OCS_Result() : new \OC_OCS_Result(null, 404, "couldn't set expire date");
} catch (\Exception $e) {
$result = new \OC_OCS_Result(null, 404, $e->getMessage());
Expand Down Expand Up @@ -590,7 +586,7 @@ private static function getItemType($path) {
* @return array with: item_source, share_type, share_with, item_type, permissions
*/
private static function getShareFromId($shareID) {
$sql = 'SELECT `file_source`, `item_source`, `share_type`, `share_with`, `item_type`, `permissions`, `stime` FROM `*PREFIX*share` WHERE `id` = ?';
$sql = 'SELECT `id`, `file_source`, `item_source`, `share_type`, `share_with`, `item_type`, `permissions`, `stime` FROM `*PREFIX*share` WHERE `id` = ?';
$args = array($shareID);
$query = \OCP\DB::prepare($sql);
$result = $query->execute($args);
Expand Down
23 changes: 16 additions & 7 deletions lib/private/share/share.php
Original file line number Diff line number Diff line change
Expand Up @@ -1112,10 +1112,11 @@ private static function validateExpireDate($expireDate, $shareTime, $itemType, $
* @param string $itemSource
* @param string $date expiration date
* @param int $shareTime timestamp from when the file was shared
* @param int $id share id (optional, set it to set expiration for user or group shares)
* @throws \Exception
* @return boolean
*/
public static function setExpirationDate($itemType, $itemSource, $date, $shareTime = null) {
public static function setExpirationDate($itemType, $itemSource, $date, $shareTime = null, $id = null) {
$user = \OC_User::getUser();
$l = \OC::$server->getL10N('lib');

Expand All @@ -1131,16 +1132,24 @@ public static function setExpirationDate($itemType, $itemSource, $date, $shareTi
} else {
$date = self::validateExpireDate($date, $shareTime, $itemType, $itemSource);
}
$query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `expiration` = ? WHERE `item_type` = ? AND `item_source` = ? AND `uid_owner` = ? AND `share_type` = ?');
$query->bindValue(1, $date, 'datetime');
$query->bindValue(2, $itemType);
$query->bindValue(3, $itemSource);
$query->bindValue(4, $user);
$query->bindValue(5, \OCP\Share::SHARE_TYPE_LINK);
if (!is_null($id)) {
$query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `expiration` = ? WHERE `id` = ? AND `uid_owner` = ?');
$query->bindValue(1, $date, 'datetime');
$query->bindValue(2, $id);
$query->bindValue(3, $user);
} else {
$query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `expiration` = ? WHERE `item_type` = ? AND `item_source` = ? AND `uid_owner` = ? AND `share_type` = ?');
$query->bindValue(1, $date, 'datetime');
$query->bindValue(2, $itemType);
$query->bindValue(3, $itemSource);
$query->bindValue(4, $user);
$query->bindValue(5, \OCP\Share::SHARE_TYPE_LINK);
}

$query->execute();

\OC_Hook::emit('OCP\Share', 'post_set_expiration_date', array(
'id' => $id,
'itemType' => $itemType,
'itemSource' => $itemSource,
'date' => $date,
Expand Down
5 changes: 3 additions & 2 deletions lib/public/share.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,11 @@ public static function setPermissions($itemType, $itemSource, $shareType, $share
* @param string $itemSource
* @param string $date expiration date
* @param int $shareTime timestamp from when the file was shared
* @param int $id share id (optional, set it to set expiration for user or group shares)
* @return boolean
*/
public static function setExpirationDate($itemType, $itemSource, $date, $shareTime = null) {
return \OC\Share\Share::setExpirationDate($itemType, $itemSource, $date, $shareTime);
public static function setExpirationDate($itemType, $itemSource, $date, $shareTime = null, $id = null) {
return \OC\Share\Share::setExpirationDate($itemType, $itemSource, $date, $shareTime, $id);
}

/**
Expand Down

0 comments on commit 2b041b1

Please sign in to comment.