-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
ShareesAPIController should respect groups disallowed from sharing #25744
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
Changes from all commits
ce0aa8e
56cc408
be8bd42
d8396ef
e40590c
ded214e
5550611
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -50,8 +50,10 @@ | |||||||||||||
| use OCP\Collaboration\Collaborators\SearchResultType; | ||||||||||||||
| use OCP\Constants; | ||||||||||||||
| use OCP\IConfig; | ||||||||||||||
| use OCP\IGroupManager; | ||||||||||||||
| use OCP\IRequest; | ||||||||||||||
| use OCP\IURLGenerator; | ||||||||||||||
| use OCP\IUserManager; | ||||||||||||||
| use OCP\Share\IManager; | ||||||||||||||
| use OCP\Share\IShare; | ||||||||||||||
| use function array_slice; | ||||||||||||||
|
|
@@ -108,6 +110,12 @@ class ShareesAPIController extends OCSController { | |||||||||||||
| /** @var ISearch */ | ||||||||||||||
| private $collaboratorSearch; | ||||||||||||||
|
|
||||||||||||||
| /** @var IGroupManager */ | ||||||||||||||
| private $groupManager; | ||||||||||||||
|
|
||||||||||||||
| /** @var IUserManager */ | ||||||||||||||
| private $userManager; | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * @param string $UserId | ||||||||||||||
| * @param string $appName | ||||||||||||||
|
|
@@ -124,14 +132,20 @@ public function __construct( | |||||||||||||
| IConfig $config, | ||||||||||||||
| IURLGenerator $urlGenerator, | ||||||||||||||
| IManager $shareManager, | ||||||||||||||
| ISearch $collaboratorSearch | ||||||||||||||
| ISearch $collaboratorSearch, | ||||||||||||||
| IGroupManager $groupManager, | ||||||||||||||
| IUserManager $userManager | ||||||||||||||
|
|
||||||||||||||
| ) { | ||||||||||||||
| parent::__construct($appName, $request); | ||||||||||||||
| $this->userId = $UserId; | ||||||||||||||
| $this->config = $config; | ||||||||||||||
| $this->urlGenerator = $urlGenerator; | ||||||||||||||
| $this->shareManager = $shareManager; | ||||||||||||||
| $this->collaboratorSearch = $collaboratorSearch; | ||||||||||||||
| $this->groupManager = $groupManager; | ||||||||||||||
| $this->userManager = $userManager; | ||||||||||||||
|
|
||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
|
|
@@ -152,6 +166,16 @@ public function __construct( | |||||||||||||
| */ | ||||||||||||||
| public function search(string $search = '', string $itemType = null, int $page = 1, int $perPage = 200, $shareType = null, bool $lookup = false): DataResponse { | ||||||||||||||
|
|
||||||||||||||
| // if some groups are excluded, check the user is allowed to share | ||||||||||||||
| if ($this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { | ||||||||||||||
| $excludedGroups = (array)json_decode($this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''), true); | ||||||||||||||
Check noticeCode scanning / Psalm DeprecatedMethod
The method OCP\IConfig::getAppValue has been marked as deprecated
|
||||||||||||||
| $usersGroups = $this->groupManager->getUserGroupIds($this->userManager->get($this->userId)); | ||||||||||||||
Check noticeCode scanning / Psalm PossiblyNullArgument
Argument 1 of OCP\IGroupManager::getUserGroupIds cannot be null, possibly null value provided
|
||||||||||||||
| if (array_intersect($usersGroups, $excludedGroups) === $usersGroups) { | ||||||||||||||
| return new DataResponse($this->result); | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+173
to
+175
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Am I right that case #3 should return early? This might be more correct:
Suggested change
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's been a while since I've looked at Nextcloud, so please excuse any terminology mixups. If I remember correctly my theory was that a user should be blocked from viewing potential Sharees only if all the groups they are a member of are blocked from sharing. (#20950 (comment)) I was looking at it from a scenario where some imaginary Admin user is also a member of a group which is blocked from sharing: should membership of a single excludedGroup prevent a user from getting a list of sharees? At the time Share Manager took the approach that a user should be blocked from sharing only if they were only a member of excluded groups so I followed that precedent (appears to still be the decision made in https://github.com/nextcloud/server/blob/master/lib/private/Share20/ShareDisableChecker.php#L52) Either way, that's probably a higher level design decision that I'll leave to someone else.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes sharing is only disabled if the user is only in groups disabled for sharing.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it can be simplified to just: |
||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| // only search for string larger than a given threshold | ||||||||||||||
| $threshold = $this->config->getSystemValueInt('sharing.minSearchStringLength', 0); | ||||||||||||||
| if (strlen($search) < $threshold) { | ||||||||||||||
|
|
||||||||||||||
Check notice
Code scanning / Psalm
DeprecatedMethod