12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace OC\Share20;
- use OCP\Cache\CappedMemoryCache;
- use OCP\IConfig;
- use OCP\IGroupManager;
- use OCP\IUserManager;
- class ShareDisableChecker {
- private CappedMemoryCache $sharingDisabledForUsersCache;
- public function __construct(
- private IConfig $config,
- private IUserManager $userManager,
- private IGroupManager $groupManager,
- ) {
- $this->sharingDisabledForUsersCache = new CappedMemoryCache();
- }
-
- public function sharingDisabledForUser(?string $userId) {
- if ($userId === null) {
- return false;
- }
- if (isset($this->sharingDisabledForUsersCache[$userId])) {
- return $this->sharingDisabledForUsersCache[$userId];
- }
- $excludeGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no');
- if ($excludeGroups && $excludeGroups !== 'no') {
- $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);
- if (!$user) {
- return false;
- }
- $usersGroups = $this->groupManager->getUserGroupIds($user);
- if ($excludeGroups !== 'allow') {
- if (!empty($usersGroups)) {
- $remainingGroups = array_diff($usersGroups, $excludedGroups);
-
-
- if (empty($remainingGroups)) {
- $this->sharingDisabledForUsersCache[$userId] = true;
- return true;
- }
- }
- } else {
- if (!empty($usersGroups)) {
- $remainingGroups = array_intersect($usersGroups, $excludedGroups);
-
-
- if (!empty($remainingGroups)) {
- $this->sharingDisabledForUsersCache[$userId] = false;
- return false;
- }
- }
- $this->sharingDisabledForUsersCache[$userId] = true;
- return true;
- }
- }
- $this->sharingDisabledForUsersCache[$userId] = false;
- return false;
- }
- }
|