RemoteGroupPlugin.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace OC\Collaboration\Collaborators;
  24. use OCP\Collaboration\Collaborators\ISearchPlugin;
  25. use OCP\Collaboration\Collaborators\ISearchResult;
  26. use OCP\Collaboration\Collaborators\SearchResultType;
  27. use OCP\Contacts\IManager;
  28. use OCP\Federation\ICloudFederationProviderManager;
  29. use OCP\Federation\ICloudIdManager;
  30. use OCP\IConfig;
  31. use OCP\Share;
  32. class RemoteGroupPlugin implements ISearchPlugin {
  33. protected $shareeEnumeration;
  34. /** @var ICloudIdManager */
  35. private $cloudIdManager;
  36. /** @var IConfig */
  37. private $config;
  38. /** @var bool */
  39. private $enabled = false;
  40. public function __construct(ICloudFederationProviderManager $cloudFederationProviderManager, ICloudIdManager $cloudIdManager) {
  41. try {
  42. $fileSharingProvider = $cloudFederationProviderManager->getCloudFederationProvider('file');
  43. $supportedShareTypes = $fileSharingProvider->getSupportedShareTypes();
  44. if (in_array('group', $supportedShareTypes)) {
  45. $this->enabled = true;
  46. }
  47. } catch (\Exception $e) {
  48. // do nothing, just don't enable federated group shares
  49. }
  50. $this->cloudIdManager = $cloudIdManager;
  51. }
  52. public function search($search, $limit, $offset, ISearchResult $searchResult) {
  53. $result = ['wide' => [], 'exact' => []];
  54. $resultType = new SearchResultType('remote_groups');
  55. if ($this->enabled && $this->cloudIdManager->isValidCloudId($search) && $offset === 0) {
  56. $result['exact'][] = [
  57. 'label' => $search,
  58. 'value' => [
  59. 'shareType' => Share::SHARE_TYPE_REMOTE_GROUP,
  60. 'shareWith' => $search,
  61. ],
  62. ];
  63. }
  64. $searchResult->addResultSet($resultType, $result['wide'], $result['exact']);
  65. return true;
  66. }
  67. }