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

[full-ci] Expiration date limits for reshare of a received share #40263

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 63 additions & 0 deletions apps/files_sharing/lib/Controller/Share20OcsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,30 @@ public function createShare() {
$share = $this->setShareAttributes($share, []);
}

/**
* Check if shared data is a re-share,
* set or deny expiration date if the parent share has applying restrictions.
*/
if ($path->getStorage()->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) {
$parentStorage = $path->getStorage();
/** @var \OCA\Files_Sharing\SharedStorage $parentStorage */
'@phan-var \OCA\Files_Sharing\SharedStorage $parentStorage';
$parentShare = $parentStorage->getShare();
// $share does not have exp date set, care later
$fullShare = $this->getShareById($parentShare->getId());
$paramExpireDate = $this->request->getParam('expireDate', '');

if ($fullShare->getExpirationDate() !== null && $paramExpireDate === '') {
$share->setExpirationDate($fullShare->getExpirationDate());
}

if ($fullShare->getExpirationDate() !== null && $paramExpireDate !== '') {
if ($this->parseDate($paramExpireDate) > $fullShare->getExpirationDate()) {
return new Result(null, 403, 'Expiration date exceeds the parent share\'s expiration date');
}
}
}

try {
$share = $this->shareManager->createShare($share);
/**
Expand Down Expand Up @@ -961,6 +985,45 @@ public function updateShare($id) {
$share = $this->setShareAttributes($share, $newAttributes);
}

/**
* Check if shared data is a re-share,
* set or deny expiration date if the parent share has applying restrictions.
*/
$uf = $this->getCurrentUserFolder();
$target = $share->getTarget();
// Target can be a string that includes the share_folder,
// for example, "/Shares/folder" or "/Shares/document.txt"
// Take the share_folder off the start of target.
$shareFolder = \OC::$server->getConfig()->getSystemValue('share_folder', '/');
if ($shareFolder !== "/") {
$shareFolderNormalized = "/" . \ltrim($shareFolder, "/");
$targetNormalized = "/" . \ltrim($target, "/");
if (\strpos($targetNormalized, $shareFolderNormalized) === 0) {
$target = \substr($targetNormalized, \strlen($shareFolderNormalized));
}
}
$path = $uf->get($target);

if ($path->getStorage()->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) {
$parentStorage = $path->getStorage();
/** @var \OCA\Files_Sharing\SharedStorage $parentStorage */
'@phan-var \OCA\Files_Sharing\SharedStorage $parentStorage';
$parentShare = $parentStorage->getShare();
// $share does not have exp date set, care later
$fullShare = $this->getShareById($parentShare->getId());
$paramExpireDate = $this->request->getParam('expireDate', '');

if ($fullShare->getExpirationDate() !== null && $paramExpireDate === '') {
$share->setExpirationDate($fullShare->getExpirationDate());
}

if ($fullShare->getExpirationDate() !== null && $paramExpireDate !== '') {
if ($this->parseDate($paramExpireDate) > $fullShare->getExpirationDate()) {
return new Result(null, 403, 'Expiration date exceeds the parent share\'s expiration date');
}
}
}

try {
$share = $this->shareManager->updateShare($share);
} catch (GenericShareException $e) {
Expand Down