-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cleanup di for share permissions wrapper
Signed-off-by: Robin Appelman <[email protected]>
- Loading branch information
1 parent
a031bc4
commit 79dab07
Showing
5 changed files
with
116 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace OC\Share20; | ||
|
||
use OCP\Cache\CappedMemoryCache; | ||
use OCP\IConfig; | ||
use OCP\IGroupManager; | ||
use OCP\IUserManager; | ||
|
||
/** | ||
* split of from the share manager to allow using it with minimal DI | ||
*/ | ||
class ShareDisableChecker { | ||
private CappedMemoryCache $sharingDisabledForUsersCache; | ||
|
||
public function __construct( | ||
private IConfig $config, | ||
private IUserManager $userManager, | ||
private IGroupManager $groupManager, | ||
) { | ||
$this->sharingDisabledForUsersCache = new CappedMemoryCache(); | ||
} | ||
|
||
|
||
/** | ||
* Copied from \OC_Util::isSharingDisabledForUser | ||
* | ||
* TODO: Deprecate function from OC_Util | ||
* | ||
* @param string $userId | ||
* @return bool | ||
*/ | ||
public function sharingDisabledForUser($userId) { | ||
if ($userId === null) { | ||
return false; | ||
} | ||
|
||
if (isset($this->sharingDisabledForUsersCache[$userId])) { | ||
return $this->sharingDisabledForUsersCache[$userId]; | ||
} | ||
|
||
if ($this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { | ||
$groupsList = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); | ||
$excludedGroups = json_decode($groupsList); | ||
if (is_null($excludedGroups)) { | ||
$excludedGroups = explode(',', $groupsList); | ||
$newValue = json_encode($excludedGroups); | ||
$this->config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue); | ||
} | ||
$user = $this->userManager->get($userId); | ||
$usersGroups = $this->groupManager->getUserGroupIds($user); | ||
if (!empty($usersGroups)) { | ||
$remainingGroups = array_diff($usersGroups, $excludedGroups); | ||
// if the user is only in groups which are disabled for sharing then | ||
// sharing is also disabled for the user | ||
if (empty($remainingGroups)) { | ||
$this->sharingDisabledForUsersCache[$userId] = true; | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
$this->sharingDisabledForUsersCache[$userId] = false; | ||
return false; | ||
} | ||
} |