Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting expire on user / group shares via API #15459

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
8 changes: 2 additions & 6 deletions apps/files_sharing/api/local.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,13 +452,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 @@ -578,7 +574,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 @@ -1168,10 +1168,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)
* @return boolean
* @throws \Exception when the expire date is not set, in the past or further in the future then the enforced date
*/
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 @@ -1187,16 +1188,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 @@ -336,11 +336,12 @@ 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
* @since 5.0.0 - parameter $shareTime was added in 8.0.0
*/
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