Skip to content

Commit

Permalink
Set files_sharing:hide_disabled_user_shares to 'yes' to hide shares f…
Browse files Browse the repository at this point in the history
…rom disabled users

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
  • Loading branch information
come-nc committed Aug 3, 2023
1 parent 9e096ef commit 0d7d0d7
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1352,7 +1352,7 @@ public function getSharesBy($userId, $shareType, $path = null, $reshares = false
$added = 0;
foreach ($shares as $share) {
try {
$this->checkExpireDate($share);
$this->checkShare($share);
} catch (ShareNotFound $e) {
//Ignore since this basically means the share is deleted
continue;
Expand Down Expand Up @@ -1411,7 +1411,7 @@ public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $o
// remove all shares which are already expired
foreach ($shares as $key => $share) {
try {
$this->checkExpireDate($share);
$this->checkShare($share);
} catch (ShareNotFound $e) {
unset($shares[$key]);
}
Expand Down Expand Up @@ -1457,7 +1457,7 @@ public function getShareById($id, $recipient = null) {

$share = $provider->getShareById($id, $recipient);

$this->checkExpireDate($share);
$this->checkShare($share);

return $share;
}
Expand Down Expand Up @@ -1541,7 +1541,7 @@ public function getShareByToken($token) {
throw new ShareNotFound($this->l->t('The requested share does not exist anymore'));
}

$this->checkExpireDate($share);
$this->checkShare($share);

/*
* Reduce the permissions for link or email shares if public upload is not enabled
Expand All @@ -1554,11 +1554,25 @@ public function getShareByToken($token) {
return $share;
}

protected function checkExpireDate($share) {
/**
* Check expire date and disabled owner
*
* @throws ShareNotFound
*/
protected function checkShare(IShare $share): void {
if ($share->isExpired()) {
$this->deleteShare($share);
throw new ShareNotFound($this->l->t('The requested share does not exist anymore'));
}
if ($this->config->getAppValue('files_sharing', 'hide_disabled_user_shares', 'no') === 'yes') {
$uids = array_unique([$share->getShareOwner(),$share->getSharedBy()]);
foreach ($uids as $uid) {
$user = $this->userManager->get($uid);
if (($user !== null) && !$user->isEnabled()) {
throw new ShareNotFound($this->l->t('The requested share comes from a disabled user'));
}
}
}
}

/**
Expand Down

0 comments on commit 0d7d0d7

Please sign in to comment.