diff options
author | Corentin Damman <c.damman@intopix.com> | 2022-09-16 17:43:01 +0200 |
---|---|---|
committer | skjnldsv <skjnldsv@protonmail.com> | 2024-03-15 16:52:59 +0100 |
commit | 0fa9f3049f20ee4d573a6c615ebf9e7ecf7abdd1 (patch) | |
tree | 29110a4f03ce26db4419817aec2b2e996b22bd27 /lib/private/Share20 | |
parent | a0913739c68d9c4263fc0a9fa7e58f4276458f45 (diff) | |
download | nextcloud-server-0fa9f3049f20ee4d573a6c615ebf9e7ecf7abdd1.tar.gz nextcloud-server-0fa9f3049f20ee4d573a6c615ebf9e7ecf7abdd1.zip |
feat(files_sharing): allow to specify allowed groups to share instead of excluded groups
Relates to #3387
Signed-off-by: Corentin Damman <c.damman@intopix.com>
Diffstat (limited to 'lib/private/Share20')
-rw-r--r-- | lib/private/Share20/ShareDisableChecker.php | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/lib/private/Share20/ShareDisableChecker.php b/lib/private/Share20/ShareDisableChecker.php index 9d0c2b8c2b4..1e72ce84a59 100644 --- a/lib/private/Share20/ShareDisableChecker.php +++ b/lib/private/Share20/ShareDisableChecker.php @@ -35,7 +35,9 @@ class ShareDisableChecker { return $this->sharingDisabledForUsersCache[$userId]; } - if ($this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { + $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)) { @@ -48,14 +50,28 @@ class ShareDisableChecker { return false; } $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; + if ($excludeGroups !== 'allow') { + 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; + } + } + } else { + if (!empty($usersGroups)) { + $remainingGroups = array_intersect($usersGroups, $excludedGroups); + // if the user is in any group which is allowed for sharing then + // sharing is also allowed for the user + if (!empty($remainingGroups)) { + $this->sharingDisabledForUsersCache[$userId] = false; + return false; + } } + $this->sharingDisabledForUsersCache[$userId] = true; + return true; } } |