@@ -29,58 +29,58 @@ |
||
29 | 29 | |
30 | 30 | class SearchResult implements ISearchResult { |
31 | 31 | |
32 | - protected $result = [ |
|
33 | - 'exact' => [], |
|
34 | - ]; |
|
32 | + protected $result = [ |
|
33 | + 'exact' => [], |
|
34 | + ]; |
|
35 | 35 | |
36 | - protected $exactIdMatches = []; |
|
36 | + protected $exactIdMatches = []; |
|
37 | 37 | |
38 | - public function addResultSet(SearchResultType $type, array $matches, array $exactMatches = null) { |
|
39 | - $type = $type->getLabel(); |
|
40 | - if(!isset($this->result[$type])) { |
|
41 | - $this->result[$type] = []; |
|
42 | - $this->result['exact'][$type] = []; |
|
43 | - } |
|
38 | + public function addResultSet(SearchResultType $type, array $matches, array $exactMatches = null) { |
|
39 | + $type = $type->getLabel(); |
|
40 | + if(!isset($this->result[$type])) { |
|
41 | + $this->result[$type] = []; |
|
42 | + $this->result['exact'][$type] = []; |
|
43 | + } |
|
44 | 44 | |
45 | - $this->result[$type] = array_merge($this->result[$type], $matches); |
|
46 | - if(is_array($exactMatches)) { |
|
47 | - $this->result['exact'][$type] = array_merge($this->result['exact'][$type], $exactMatches); |
|
48 | - } |
|
49 | - } |
|
45 | + $this->result[$type] = array_merge($this->result[$type], $matches); |
|
46 | + if(is_array($exactMatches)) { |
|
47 | + $this->result['exact'][$type] = array_merge($this->result['exact'][$type], $exactMatches); |
|
48 | + } |
|
49 | + } |
|
50 | 50 | |
51 | - public function markExactIdMatch(SearchResultType $type) { |
|
52 | - $this->exactIdMatches[$type->getLabel()] = 1; |
|
53 | - } |
|
51 | + public function markExactIdMatch(SearchResultType $type) { |
|
52 | + $this->exactIdMatches[$type->getLabel()] = 1; |
|
53 | + } |
|
54 | 54 | |
55 | - public function hasExactIdMatch(SearchResultType$type) { |
|
56 | - return isset($this->exactIdMatches[$type->getLabel()]); |
|
57 | - } |
|
55 | + public function hasExactIdMatch(SearchResultType$type) { |
|
56 | + return isset($this->exactIdMatches[$type->getLabel()]); |
|
57 | + } |
|
58 | 58 | |
59 | - public function hasResult(SearchResultType $type, $collaboratorId) { |
|
60 | - $type = $type->getLabel(); |
|
61 | - if(!isset($this->result[$type])) { |
|
62 | - return false; |
|
63 | - } |
|
59 | + public function hasResult(SearchResultType $type, $collaboratorId) { |
|
60 | + $type = $type->getLabel(); |
|
61 | + if(!isset($this->result[$type])) { |
|
62 | + return false; |
|
63 | + } |
|
64 | 64 | |
65 | - $resultArrays = [$this->result['exact'][$type], $this->result[$type]]; |
|
66 | - foreach($resultArrays as $resultArray) { |
|
67 | - if ($resultArray['value']['shareWith'] === $collaboratorId) { |
|
68 | - return true; |
|
69 | - } |
|
70 | - } |
|
65 | + $resultArrays = [$this->result['exact'][$type], $this->result[$type]]; |
|
66 | + foreach($resultArrays as $resultArray) { |
|
67 | + if ($resultArray['value']['shareWith'] === $collaboratorId) { |
|
68 | + return true; |
|
69 | + } |
|
70 | + } |
|
71 | 71 | |
72 | - return false; |
|
73 | - } |
|
72 | + return false; |
|
73 | + } |
|
74 | 74 | |
75 | - public function asArray() { |
|
76 | - return $this->result; |
|
77 | - } |
|
75 | + public function asArray() { |
|
76 | + return $this->result; |
|
77 | + } |
|
78 | 78 | |
79 | - public function unsetResult(SearchResultType $type) { |
|
80 | - $type = $type->getLabel(); |
|
81 | - $this->result[$type] = []; |
|
82 | - if(isset($this->result['exact'][$type])) { |
|
83 | - $this->result['exact'][$type] = []; |
|
84 | - } |
|
85 | - } |
|
79 | + public function unsetResult(SearchResultType $type) { |
|
80 | + $type = $type->getLabel(); |
|
81 | + $this->result[$type] = []; |
|
82 | + if(isset($this->result['exact'][$type])) { |
|
83 | + $this->result['exact'][$type] = []; |
|
84 | + } |
|
85 | + } |
|
86 | 86 | } |
@@ -37,13 +37,13 @@ discard block |
||
37 | 37 | |
38 | 38 | public function addResultSet(SearchResultType $type, array $matches, array $exactMatches = null) { |
39 | 39 | $type = $type->getLabel(); |
40 | - if(!isset($this->result[$type])) { |
|
40 | + if (!isset($this->result[$type])) { |
|
41 | 41 | $this->result[$type] = []; |
42 | 42 | $this->result['exact'][$type] = []; |
43 | 43 | } |
44 | 44 | |
45 | 45 | $this->result[$type] = array_merge($this->result[$type], $matches); |
46 | - if(is_array($exactMatches)) { |
|
46 | + if (is_array($exactMatches)) { |
|
47 | 47 | $this->result['exact'][$type] = array_merge($this->result['exact'][$type], $exactMatches); |
48 | 48 | } |
49 | 49 | } |
@@ -58,12 +58,12 @@ discard block |
||
58 | 58 | |
59 | 59 | public function hasResult(SearchResultType $type, $collaboratorId) { |
60 | 60 | $type = $type->getLabel(); |
61 | - if(!isset($this->result[$type])) { |
|
61 | + if (!isset($this->result[$type])) { |
|
62 | 62 | return false; |
63 | 63 | } |
64 | 64 | |
65 | 65 | $resultArrays = [$this->result['exact'][$type], $this->result[$type]]; |
66 | - foreach($resultArrays as $resultArray) { |
|
66 | + foreach ($resultArrays as $resultArray) { |
|
67 | 67 | if ($resultArray['value']['shareWith'] === $collaboratorId) { |
68 | 68 | return true; |
69 | 69 | } |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | public function unsetResult(SearchResultType $type) { |
80 | 80 | $type = $type->getLabel(); |
81 | 81 | $this->result[$type] = []; |
82 | - if(isset($this->result['exact'][$type])) { |
|
82 | + if (isset($this->result['exact'][$type])) { |
|
83 | 83 | $this->result['exact'][$type] = []; |
84 | 84 | } |
85 | 85 | } |
@@ -35,115 +35,115 @@ |
||
35 | 35 | use OCP\Share; |
36 | 36 | |
37 | 37 | class UserPlugin implements ISearchPlugin { |
38 | - /* @var bool */ |
|
39 | - protected $shareWithGroupOnly; |
|
40 | - protected $shareeEnumeration; |
|
41 | - |
|
42 | - /** @var IConfig */ |
|
43 | - private $config; |
|
44 | - /** @var IGroupManager */ |
|
45 | - private $groupManager; |
|
46 | - /** @var IUserSession */ |
|
47 | - private $userSession; |
|
48 | - /** @var IUserManager */ |
|
49 | - private $userManager; |
|
50 | - |
|
51 | - public function __construct(IConfig $config, IUserManager $userManager, IGroupManager $groupManager, IUserSession $userSession) { |
|
52 | - $this->config = $config; |
|
53 | - |
|
54 | - $this->groupManager = $groupManager; |
|
55 | - $this->userSession = $userSession; |
|
56 | - $this->userManager = $userManager; |
|
57 | - |
|
58 | - $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
59 | - $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
60 | - } |
|
61 | - |
|
62 | - public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
63 | - $result = ['wide' => [], 'exact' => []]; |
|
64 | - $users = []; |
|
65 | - $hasMoreResults = false; |
|
66 | - |
|
67 | - $userGroups = []; |
|
68 | - if ($this->shareWithGroupOnly) { |
|
69 | - // Search in all the groups this user is part of |
|
70 | - $userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser()); |
|
71 | - foreach ($userGroups as $userGroup) { |
|
72 | - $usersTmp = $this->groupManager->displayNamesInGroup($userGroup, $search, $limit, $offset); |
|
73 | - foreach ($usersTmp as $uid => $userDisplayName) { |
|
74 | - $users[$uid] = $userDisplayName; |
|
75 | - } |
|
76 | - } |
|
77 | - } else { |
|
78 | - // Search in all users |
|
79 | - $usersTmp = $this->userManager->searchDisplayName($search, $limit, $offset); |
|
80 | - |
|
81 | - foreach ($usersTmp as $user) { |
|
82 | - $users[$user->getUID()] = $user->getDisplayName(); |
|
83 | - } |
|
84 | - } |
|
85 | - |
|
86 | - if (!$this->shareeEnumeration || sizeof($users) < $limit) { |
|
87 | - $hasMoreResults = true; |
|
88 | - } |
|
89 | - |
|
90 | - $foundUserById = false; |
|
91 | - $lowerSearch = strtolower($search); |
|
92 | - foreach ($users as $uid => $userDisplayName) { |
|
93 | - if (strtolower($uid) === $lowerSearch || strtolower($userDisplayName) === $lowerSearch) { |
|
94 | - if (strtolower($uid) === $lowerSearch) { |
|
95 | - $foundUserById = true; |
|
96 | - } |
|
97 | - $result['exact'][] = [ |
|
98 | - 'label' => $userDisplayName, |
|
99 | - 'value' => [ |
|
100 | - 'shareType' => Share::SHARE_TYPE_USER, |
|
101 | - 'shareWith' => $uid, |
|
102 | - ], |
|
103 | - ]; |
|
104 | - } else { |
|
105 | - $result['wide'][] = [ |
|
106 | - 'label' => $userDisplayName, |
|
107 | - 'value' => [ |
|
108 | - 'shareType' => Share::SHARE_TYPE_USER, |
|
109 | - 'shareWith' => $uid, |
|
110 | - ], |
|
111 | - ]; |
|
112 | - } |
|
113 | - } |
|
114 | - |
|
115 | - if ($offset === 0 && !$foundUserById) { |
|
116 | - // On page one we try if the search result has a direct hit on the |
|
117 | - // user id and if so, we add that to the exact match list |
|
118 | - $user = $this->userManager->get($search); |
|
119 | - if ($user instanceof IUser) { |
|
120 | - $addUser = true; |
|
121 | - |
|
122 | - if ($this->shareWithGroupOnly) { |
|
123 | - // Only add, if we have a common group |
|
124 | - $commonGroups = array_intersect($userGroups, $this->groupManager->getUserGroupIds($user)); |
|
125 | - $addUser = !empty($commonGroups); |
|
126 | - } |
|
127 | - |
|
128 | - if ($addUser) { |
|
129 | - array_push($result['exact'], [ |
|
130 | - 'label' => $user->getDisplayName(), |
|
131 | - 'value' => [ |
|
132 | - 'shareType' => Share::SHARE_TYPE_USER, |
|
133 | - 'shareWith' => $user->getUID(), |
|
134 | - ], |
|
135 | - ]); |
|
136 | - } |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - if (!$this->shareeEnumeration) { |
|
141 | - $result['wide'] = []; |
|
142 | - } |
|
143 | - |
|
144 | - $type = new SearchResultType('users'); |
|
145 | - $searchResult->addResultSet($type, $result['wide'], $result['exact']); |
|
146 | - |
|
147 | - return $hasMoreResults; |
|
148 | - } |
|
38 | + /* @var bool */ |
|
39 | + protected $shareWithGroupOnly; |
|
40 | + protected $shareeEnumeration; |
|
41 | + |
|
42 | + /** @var IConfig */ |
|
43 | + private $config; |
|
44 | + /** @var IGroupManager */ |
|
45 | + private $groupManager; |
|
46 | + /** @var IUserSession */ |
|
47 | + private $userSession; |
|
48 | + /** @var IUserManager */ |
|
49 | + private $userManager; |
|
50 | + |
|
51 | + public function __construct(IConfig $config, IUserManager $userManager, IGroupManager $groupManager, IUserSession $userSession) { |
|
52 | + $this->config = $config; |
|
53 | + |
|
54 | + $this->groupManager = $groupManager; |
|
55 | + $this->userSession = $userSession; |
|
56 | + $this->userManager = $userManager; |
|
57 | + |
|
58 | + $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
59 | + $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
60 | + } |
|
61 | + |
|
62 | + public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
63 | + $result = ['wide' => [], 'exact' => []]; |
|
64 | + $users = []; |
|
65 | + $hasMoreResults = false; |
|
66 | + |
|
67 | + $userGroups = []; |
|
68 | + if ($this->shareWithGroupOnly) { |
|
69 | + // Search in all the groups this user is part of |
|
70 | + $userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser()); |
|
71 | + foreach ($userGroups as $userGroup) { |
|
72 | + $usersTmp = $this->groupManager->displayNamesInGroup($userGroup, $search, $limit, $offset); |
|
73 | + foreach ($usersTmp as $uid => $userDisplayName) { |
|
74 | + $users[$uid] = $userDisplayName; |
|
75 | + } |
|
76 | + } |
|
77 | + } else { |
|
78 | + // Search in all users |
|
79 | + $usersTmp = $this->userManager->searchDisplayName($search, $limit, $offset); |
|
80 | + |
|
81 | + foreach ($usersTmp as $user) { |
|
82 | + $users[$user->getUID()] = $user->getDisplayName(); |
|
83 | + } |
|
84 | + } |
|
85 | + |
|
86 | + if (!$this->shareeEnumeration || sizeof($users) < $limit) { |
|
87 | + $hasMoreResults = true; |
|
88 | + } |
|
89 | + |
|
90 | + $foundUserById = false; |
|
91 | + $lowerSearch = strtolower($search); |
|
92 | + foreach ($users as $uid => $userDisplayName) { |
|
93 | + if (strtolower($uid) === $lowerSearch || strtolower($userDisplayName) === $lowerSearch) { |
|
94 | + if (strtolower($uid) === $lowerSearch) { |
|
95 | + $foundUserById = true; |
|
96 | + } |
|
97 | + $result['exact'][] = [ |
|
98 | + 'label' => $userDisplayName, |
|
99 | + 'value' => [ |
|
100 | + 'shareType' => Share::SHARE_TYPE_USER, |
|
101 | + 'shareWith' => $uid, |
|
102 | + ], |
|
103 | + ]; |
|
104 | + } else { |
|
105 | + $result['wide'][] = [ |
|
106 | + 'label' => $userDisplayName, |
|
107 | + 'value' => [ |
|
108 | + 'shareType' => Share::SHARE_TYPE_USER, |
|
109 | + 'shareWith' => $uid, |
|
110 | + ], |
|
111 | + ]; |
|
112 | + } |
|
113 | + } |
|
114 | + |
|
115 | + if ($offset === 0 && !$foundUserById) { |
|
116 | + // On page one we try if the search result has a direct hit on the |
|
117 | + // user id and if so, we add that to the exact match list |
|
118 | + $user = $this->userManager->get($search); |
|
119 | + if ($user instanceof IUser) { |
|
120 | + $addUser = true; |
|
121 | + |
|
122 | + if ($this->shareWithGroupOnly) { |
|
123 | + // Only add, if we have a common group |
|
124 | + $commonGroups = array_intersect($userGroups, $this->groupManager->getUserGroupIds($user)); |
|
125 | + $addUser = !empty($commonGroups); |
|
126 | + } |
|
127 | + |
|
128 | + if ($addUser) { |
|
129 | + array_push($result['exact'], [ |
|
130 | + 'label' => $user->getDisplayName(), |
|
131 | + 'value' => [ |
|
132 | + 'shareType' => Share::SHARE_TYPE_USER, |
|
133 | + 'shareWith' => $user->getUID(), |
|
134 | + ], |
|
135 | + ]); |
|
136 | + } |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + if (!$this->shareeEnumeration) { |
|
141 | + $result['wide'] = []; |
|
142 | + } |
|
143 | + |
|
144 | + $type = new SearchResultType('users'); |
|
145 | + $searchResult->addResultSet($type, $result['wide'], $result['exact']); |
|
146 | + |
|
147 | + return $hasMoreResults; |
|
148 | + } |
|
149 | 149 | } |
@@ -33,105 +33,105 @@ |
||
33 | 33 | use OCP\Share; |
34 | 34 | |
35 | 35 | class RemotePlugin implements ISearchPlugin { |
36 | - protected $shareeEnumeration; |
|
36 | + protected $shareeEnumeration; |
|
37 | 37 | |
38 | - /** @var IManager */ |
|
39 | - private $contactsManager; |
|
40 | - /** @var ICloudIdManager */ |
|
41 | - private $cloudIdManager; |
|
42 | - /** @var IConfig */ |
|
43 | - private $config; |
|
38 | + /** @var IManager */ |
|
39 | + private $contactsManager; |
|
40 | + /** @var ICloudIdManager */ |
|
41 | + private $cloudIdManager; |
|
42 | + /** @var IConfig */ |
|
43 | + private $config; |
|
44 | 44 | |
45 | - public function __construct(IManager $contactsManager, ICloudIdManager $cloudIdManager, IConfig $config) { |
|
46 | - $this->contactsManager = $contactsManager; |
|
47 | - $this->cloudIdManager = $cloudIdManager; |
|
48 | - $this->config = $config; |
|
45 | + public function __construct(IManager $contactsManager, ICloudIdManager $cloudIdManager, IConfig $config) { |
|
46 | + $this->contactsManager = $contactsManager; |
|
47 | + $this->cloudIdManager = $cloudIdManager; |
|
48 | + $this->config = $config; |
|
49 | 49 | |
50 | - $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
51 | - } |
|
50 | + $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
51 | + } |
|
52 | 52 | |
53 | - public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
54 | - $result = ['wide' => [], 'exact' => []]; |
|
55 | - $resultType = new SearchResultType('remotes'); |
|
53 | + public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
54 | + $result = ['wide' => [], 'exact' => []]; |
|
55 | + $resultType = new SearchResultType('remotes'); |
|
56 | 56 | |
57 | - // Search in contacts |
|
58 | - //@todo Pagination missing |
|
59 | - $addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN']); |
|
60 | - foreach ($addressBookContacts as $contact) { |
|
61 | - if (isset($contact['isLocalSystemBook'])) { |
|
62 | - continue; |
|
63 | - } |
|
64 | - if (isset($contact['CLOUD'])) { |
|
65 | - $cloudIds = $contact['CLOUD']; |
|
66 | - if (!is_array($cloudIds)) { |
|
67 | - $cloudIds = [$cloudIds]; |
|
68 | - } |
|
69 | - $lowerSearch = strtolower($search); |
|
70 | - foreach ($cloudIds as $cloudId) { |
|
71 | - try { |
|
72 | - list(, $serverUrl) = $this->splitUserRemote($cloudId); |
|
73 | - } catch (\InvalidArgumentException $e) { |
|
74 | - continue; |
|
75 | - } |
|
57 | + // Search in contacts |
|
58 | + //@todo Pagination missing |
|
59 | + $addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN']); |
|
60 | + foreach ($addressBookContacts as $contact) { |
|
61 | + if (isset($contact['isLocalSystemBook'])) { |
|
62 | + continue; |
|
63 | + } |
|
64 | + if (isset($contact['CLOUD'])) { |
|
65 | + $cloudIds = $contact['CLOUD']; |
|
66 | + if (!is_array($cloudIds)) { |
|
67 | + $cloudIds = [$cloudIds]; |
|
68 | + } |
|
69 | + $lowerSearch = strtolower($search); |
|
70 | + foreach ($cloudIds as $cloudId) { |
|
71 | + try { |
|
72 | + list(, $serverUrl) = $this->splitUserRemote($cloudId); |
|
73 | + } catch (\InvalidArgumentException $e) { |
|
74 | + continue; |
|
75 | + } |
|
76 | 76 | |
77 | - if (strtolower($contact['FN']) === $lowerSearch || strtolower($cloudId) === $lowerSearch) { |
|
78 | - if (strtolower($cloudId) === $lowerSearch) { |
|
79 | - $searchResult->markExactIdMatch($resultType); |
|
80 | - } |
|
81 | - $result['exact'][] = [ |
|
82 | - 'label' => $contact['FN'] . " ($cloudId)", |
|
83 | - 'value' => [ |
|
84 | - 'shareType' => Share::SHARE_TYPE_REMOTE, |
|
85 | - 'shareWith' => $cloudId, |
|
86 | - 'server' => $serverUrl, |
|
87 | - ], |
|
88 | - ]; |
|
89 | - } else { |
|
90 | - $result['wide'][] = [ |
|
91 | - 'label' => $contact['FN'] . " ($cloudId)", |
|
92 | - 'value' => [ |
|
93 | - 'shareType' => Share::SHARE_TYPE_REMOTE, |
|
94 | - 'shareWith' => $cloudId, |
|
95 | - 'server' => $serverUrl, |
|
96 | - ], |
|
97 | - ]; |
|
98 | - } |
|
99 | - } |
|
100 | - } |
|
101 | - } |
|
77 | + if (strtolower($contact['FN']) === $lowerSearch || strtolower($cloudId) === $lowerSearch) { |
|
78 | + if (strtolower($cloudId) === $lowerSearch) { |
|
79 | + $searchResult->markExactIdMatch($resultType); |
|
80 | + } |
|
81 | + $result['exact'][] = [ |
|
82 | + 'label' => $contact['FN'] . " ($cloudId)", |
|
83 | + 'value' => [ |
|
84 | + 'shareType' => Share::SHARE_TYPE_REMOTE, |
|
85 | + 'shareWith' => $cloudId, |
|
86 | + 'server' => $serverUrl, |
|
87 | + ], |
|
88 | + ]; |
|
89 | + } else { |
|
90 | + $result['wide'][] = [ |
|
91 | + 'label' => $contact['FN'] . " ($cloudId)", |
|
92 | + 'value' => [ |
|
93 | + 'shareType' => Share::SHARE_TYPE_REMOTE, |
|
94 | + 'shareWith' => $cloudId, |
|
95 | + 'server' => $serverUrl, |
|
96 | + ], |
|
97 | + ]; |
|
98 | + } |
|
99 | + } |
|
100 | + } |
|
101 | + } |
|
102 | 102 | |
103 | - if (!$this->shareeEnumeration) { |
|
104 | - $result['wide'] = []; |
|
105 | - } |
|
103 | + if (!$this->shareeEnumeration) { |
|
104 | + $result['wide'] = []; |
|
105 | + } |
|
106 | 106 | |
107 | - if (!$searchResult->hasExactIdMatch($resultType) && $this->cloudIdManager->isValidCloudId($search) && $offset === 0) { |
|
108 | - $result['exact'][] = [ |
|
109 | - 'label' => $search, |
|
110 | - 'value' => [ |
|
111 | - 'shareType' => Share::SHARE_TYPE_REMOTE, |
|
112 | - 'shareWith' => $search, |
|
113 | - ], |
|
114 | - ]; |
|
115 | - } |
|
107 | + if (!$searchResult->hasExactIdMatch($resultType) && $this->cloudIdManager->isValidCloudId($search) && $offset === 0) { |
|
108 | + $result['exact'][] = [ |
|
109 | + 'label' => $search, |
|
110 | + 'value' => [ |
|
111 | + 'shareType' => Share::SHARE_TYPE_REMOTE, |
|
112 | + 'shareWith' => $search, |
|
113 | + ], |
|
114 | + ]; |
|
115 | + } |
|
116 | 116 | |
117 | - $searchResult->addResultSet($resultType, $result['wide'], $result['exact']); |
|
117 | + $searchResult->addResultSet($resultType, $result['wide'], $result['exact']); |
|
118 | 118 | |
119 | - return true; |
|
120 | - } |
|
119 | + return true; |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * split user and remote from federated cloud id |
|
124 | - * |
|
125 | - * @param string $address federated share address |
|
126 | - * @return array [user, remoteURL] |
|
127 | - * @throws \InvalidArgumentException |
|
128 | - */ |
|
129 | - public function splitUserRemote($address) { |
|
130 | - try { |
|
131 | - $cloudId = $this->cloudIdManager->resolveCloudId($address); |
|
132 | - return [$cloudId->getUser(), $cloudId->getRemote()]; |
|
133 | - } catch (\InvalidArgumentException $e) { |
|
134 | - throw new \InvalidArgumentException('Invalid Federated Cloud ID', 0, $e); |
|
135 | - } |
|
136 | - } |
|
122 | + /** |
|
123 | + * split user and remote from federated cloud id |
|
124 | + * |
|
125 | + * @param string $address federated share address |
|
126 | + * @return array [user, remoteURL] |
|
127 | + * @throws \InvalidArgumentException |
|
128 | + */ |
|
129 | + public function splitUserRemote($address) { |
|
130 | + try { |
|
131 | + $cloudId = $this->cloudIdManager->resolveCloudId($address); |
|
132 | + return [$cloudId->getUser(), $cloudId->getRemote()]; |
|
133 | + } catch (\InvalidArgumentException $e) { |
|
134 | + throw new \InvalidArgumentException('Invalid Federated Cloud ID', 0, $e); |
|
135 | + } |
|
136 | + } |
|
137 | 137 | } |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | $searchResult->markExactIdMatch($resultType); |
80 | 80 | } |
81 | 81 | $result['exact'][] = [ |
82 | - 'label' => $contact['FN'] . " ($cloudId)", |
|
82 | + 'label' => $contact['FN']." ($cloudId)", |
|
83 | 83 | 'value' => [ |
84 | 84 | 'shareType' => Share::SHARE_TYPE_REMOTE, |
85 | 85 | 'shareWith' => $cloudId, |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | ]; |
89 | 89 | } else { |
90 | 90 | $result['wide'][] = [ |
91 | - 'label' => $contact['FN'] . " ($cloudId)", |
|
91 | + 'label' => $contact['FN']." ($cloudId)", |
|
92 | 92 | 'value' => [ |
93 | 93 | 'shareType' => Share::SHARE_TYPE_REMOTE, |
94 | 94 | 'shareWith' => $cloudId, |
@@ -36,206 +36,206 @@ |
||
36 | 36 | use OCP\Share\IManager; |
37 | 37 | |
38 | 38 | class ShareesAPIController extends OCSController { |
39 | - /** @var IConfig */ |
|
40 | - protected $config; |
|
41 | - |
|
42 | - /** @var IURLGenerator */ |
|
43 | - protected $urlGenerator; |
|
44 | - |
|
45 | - /** @var IManager */ |
|
46 | - protected $shareManager; |
|
47 | - |
|
48 | - /** @var bool */ |
|
49 | - protected $shareWithGroupOnly = false; |
|
50 | - |
|
51 | - /** @var bool */ |
|
52 | - protected $shareeEnumeration = true; |
|
53 | - |
|
54 | - /** @var int */ |
|
55 | - protected $offset = 0; |
|
56 | - |
|
57 | - /** @var int */ |
|
58 | - protected $limit = 10; |
|
59 | - |
|
60 | - /** @var array */ |
|
61 | - protected $result = [ |
|
62 | - 'exact' => [ |
|
63 | - 'users' => [], |
|
64 | - 'groups' => [], |
|
65 | - 'remotes' => [], |
|
66 | - 'emails' => [], |
|
67 | - 'circles' => [], |
|
68 | - ], |
|
69 | - 'users' => [], |
|
70 | - 'groups' => [], |
|
71 | - 'remotes' => [], |
|
72 | - 'emails' => [], |
|
73 | - 'lookup' => [], |
|
74 | - 'circles' => [], |
|
75 | - ]; |
|
76 | - |
|
77 | - protected $reachedEndFor = []; |
|
78 | - /** @var ISearch */ |
|
79 | - private $collaboratorSearch; |
|
80 | - |
|
81 | - /** |
|
82 | - * @param string $appName |
|
83 | - * @param IRequest $request |
|
84 | - * @param IConfig $config |
|
85 | - * @param IURLGenerator $urlGenerator |
|
86 | - * @param IManager $shareManager |
|
87 | - * @param ISearch $collaboratorSearch |
|
88 | - */ |
|
89 | - public function __construct( |
|
90 | - $appName, |
|
91 | - IRequest $request, |
|
92 | - IConfig $config, |
|
93 | - IURLGenerator $urlGenerator, |
|
94 | - IManager $shareManager, |
|
95 | - ISearch $collaboratorSearch |
|
96 | - ) { |
|
97 | - parent::__construct($appName, $request); |
|
98 | - |
|
99 | - $this->config = $config; |
|
100 | - $this->urlGenerator = $urlGenerator; |
|
101 | - $this->shareManager = $shareManager; |
|
102 | - $this->collaboratorSearch = $collaboratorSearch; |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * @NoAdminRequired |
|
107 | - * |
|
108 | - * @param string $search |
|
109 | - * @param string $itemType |
|
110 | - * @param int $page |
|
111 | - * @param int $perPage |
|
112 | - * @param int|int[] $shareType |
|
113 | - * @param bool $lookup |
|
114 | - * @return DataResponse |
|
115 | - * @throws OCSBadRequestException |
|
116 | - */ |
|
117 | - public function search($search = '', $itemType = null, $page = 1, $perPage = 200, $shareType = null, $lookup = true) { |
|
118 | - |
|
119 | - // only search for string larger than a given threshold |
|
120 | - $threshold = (int)$this->config->getSystemValue('sharing.minSearchStringLength', 0); |
|
121 | - if (strlen($search) < $threshold) { |
|
122 | - return new DataResponse($this->result); |
|
123 | - } |
|
124 | - |
|
125 | - // never return more than the max. number of results configured in the config.php |
|
126 | - $maxResults = (int)$this->config->getSystemValue('sharing.maxAutocompleteResults', 0); |
|
127 | - if ($maxResults > 0) { |
|
128 | - $perPage = min($perPage, $maxResults); |
|
129 | - } |
|
130 | - if ($perPage <= 0) { |
|
131 | - throw new OCSBadRequestException('Invalid perPage argument'); |
|
132 | - } |
|
133 | - if ($page <= 0) { |
|
134 | - throw new OCSBadRequestException('Invalid page'); |
|
135 | - } |
|
136 | - |
|
137 | - $shareTypes = [ |
|
138 | - Share::SHARE_TYPE_USER, |
|
139 | - ]; |
|
140 | - |
|
141 | - if ($itemType === null) { |
|
142 | - throw new OCSBadRequestException('Missing itemType'); |
|
143 | - } elseif ($itemType === 'file' || $itemType === 'folder') { |
|
144 | - if ($this->shareManager->allowGroupSharing()) { |
|
145 | - $shareTypes[] = Share::SHARE_TYPE_GROUP; |
|
146 | - } |
|
147 | - |
|
148 | - if ($this->isRemoteSharingAllowed($itemType)) { |
|
149 | - $shareTypes[] = Share::SHARE_TYPE_REMOTE; |
|
150 | - } |
|
151 | - |
|
152 | - if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) { |
|
153 | - $shareTypes[] = Share::SHARE_TYPE_EMAIL; |
|
154 | - } |
|
155 | - } else { |
|
156 | - $shareTypes[] = Share::SHARE_TYPE_GROUP; |
|
157 | - $shareTypes[] = Share::SHARE_TYPE_EMAIL; |
|
158 | - } |
|
159 | - |
|
160 | - // FIXME: DI |
|
161 | - if (\OC::$server->getAppManager()->isEnabledForUser('circles') && class_exists('\OCA\Circles\ShareByCircleProvider')) { |
|
162 | - $shareTypes[] = Share::SHARE_TYPE_CIRCLE; |
|
163 | - } |
|
164 | - |
|
165 | - if (isset($_GET['shareType']) && is_array($_GET['shareType'])) { |
|
166 | - $shareTypes = array_intersect($shareTypes, $_GET['shareType']); |
|
167 | - sort($shareTypes); |
|
168 | - } else if (is_numeric($shareType)) { |
|
169 | - $shareTypes = array_intersect($shareTypes, [(int) $shareType]); |
|
170 | - sort($shareTypes); |
|
171 | - } |
|
172 | - |
|
173 | - $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
174 | - $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
175 | - $this->limit = (int) $perPage; |
|
176 | - $this->offset = $perPage * ($page - 1); |
|
177 | - |
|
178 | - list($result, $hasMoreResults) = $this->collaboratorSearch->search($search, $shareTypes, $lookup, $this->limit, $this->offset); |
|
179 | - |
|
180 | - // extra treatment for 'exact' subarray, with a single merge expected keys might be lost |
|
181 | - if(isset($result['exact'])) { |
|
182 | - $result['exact'] = array_merge($this->result['exact'], $result['exact']); |
|
183 | - } |
|
184 | - $this->result = array_merge($this->result, $result); |
|
185 | - $response = new DataResponse($this->result); |
|
186 | - |
|
187 | - if ($hasMoreResults) { |
|
188 | - $response->addHeader('Link', $this->getPaginationLink($page, [ |
|
189 | - 'search' => $search, |
|
190 | - 'itemType' => $itemType, |
|
191 | - 'shareType' => $shareTypes, |
|
192 | - 'perPage' => $perPage, |
|
193 | - ])); |
|
194 | - } |
|
195 | - |
|
196 | - return $response; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Method to get out the static call for better testing |
|
201 | - * |
|
202 | - * @param string $itemType |
|
203 | - * @return bool |
|
204 | - */ |
|
205 | - protected function isRemoteSharingAllowed($itemType) { |
|
206 | - try { |
|
207 | - // FIXME: static foo makes unit testing unnecessarily difficult |
|
208 | - $backend = \OC\Share\Share::getBackend($itemType); |
|
209 | - return $backend->isShareTypeAllowed(Share::SHARE_TYPE_REMOTE); |
|
210 | - } catch (\Exception $e) { |
|
211 | - return false; |
|
212 | - } |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * Generates a bunch of pagination links for the current page |
|
218 | - * |
|
219 | - * @param int $page Current page |
|
220 | - * @param array $params Parameters for the URL |
|
221 | - * @return string |
|
222 | - */ |
|
223 | - protected function getPaginationLink($page, array $params) { |
|
224 | - if ($this->isV2()) { |
|
225 | - $url = $this->urlGenerator->getAbsoluteURL('/ocs/v2.php/apps/files_sharing/api/v1/sharees') . '?'; |
|
226 | - } else { |
|
227 | - $url = $this->urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/sharees') . '?'; |
|
228 | - } |
|
229 | - $params['page'] = $page + 1; |
|
230 | - $link = '<' . $url . http_build_query($params) . '>; rel="next"'; |
|
231 | - |
|
232 | - return $link; |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * @return bool |
|
237 | - */ |
|
238 | - protected function isV2() { |
|
239 | - return $this->request->getScriptName() === '/ocs/v2.php'; |
|
240 | - } |
|
39 | + /** @var IConfig */ |
|
40 | + protected $config; |
|
41 | + |
|
42 | + /** @var IURLGenerator */ |
|
43 | + protected $urlGenerator; |
|
44 | + |
|
45 | + /** @var IManager */ |
|
46 | + protected $shareManager; |
|
47 | + |
|
48 | + /** @var bool */ |
|
49 | + protected $shareWithGroupOnly = false; |
|
50 | + |
|
51 | + /** @var bool */ |
|
52 | + protected $shareeEnumeration = true; |
|
53 | + |
|
54 | + /** @var int */ |
|
55 | + protected $offset = 0; |
|
56 | + |
|
57 | + /** @var int */ |
|
58 | + protected $limit = 10; |
|
59 | + |
|
60 | + /** @var array */ |
|
61 | + protected $result = [ |
|
62 | + 'exact' => [ |
|
63 | + 'users' => [], |
|
64 | + 'groups' => [], |
|
65 | + 'remotes' => [], |
|
66 | + 'emails' => [], |
|
67 | + 'circles' => [], |
|
68 | + ], |
|
69 | + 'users' => [], |
|
70 | + 'groups' => [], |
|
71 | + 'remotes' => [], |
|
72 | + 'emails' => [], |
|
73 | + 'lookup' => [], |
|
74 | + 'circles' => [], |
|
75 | + ]; |
|
76 | + |
|
77 | + protected $reachedEndFor = []; |
|
78 | + /** @var ISearch */ |
|
79 | + private $collaboratorSearch; |
|
80 | + |
|
81 | + /** |
|
82 | + * @param string $appName |
|
83 | + * @param IRequest $request |
|
84 | + * @param IConfig $config |
|
85 | + * @param IURLGenerator $urlGenerator |
|
86 | + * @param IManager $shareManager |
|
87 | + * @param ISearch $collaboratorSearch |
|
88 | + */ |
|
89 | + public function __construct( |
|
90 | + $appName, |
|
91 | + IRequest $request, |
|
92 | + IConfig $config, |
|
93 | + IURLGenerator $urlGenerator, |
|
94 | + IManager $shareManager, |
|
95 | + ISearch $collaboratorSearch |
|
96 | + ) { |
|
97 | + parent::__construct($appName, $request); |
|
98 | + |
|
99 | + $this->config = $config; |
|
100 | + $this->urlGenerator = $urlGenerator; |
|
101 | + $this->shareManager = $shareManager; |
|
102 | + $this->collaboratorSearch = $collaboratorSearch; |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * @NoAdminRequired |
|
107 | + * |
|
108 | + * @param string $search |
|
109 | + * @param string $itemType |
|
110 | + * @param int $page |
|
111 | + * @param int $perPage |
|
112 | + * @param int|int[] $shareType |
|
113 | + * @param bool $lookup |
|
114 | + * @return DataResponse |
|
115 | + * @throws OCSBadRequestException |
|
116 | + */ |
|
117 | + public function search($search = '', $itemType = null, $page = 1, $perPage = 200, $shareType = null, $lookup = true) { |
|
118 | + |
|
119 | + // only search for string larger than a given threshold |
|
120 | + $threshold = (int)$this->config->getSystemValue('sharing.minSearchStringLength', 0); |
|
121 | + if (strlen($search) < $threshold) { |
|
122 | + return new DataResponse($this->result); |
|
123 | + } |
|
124 | + |
|
125 | + // never return more than the max. number of results configured in the config.php |
|
126 | + $maxResults = (int)$this->config->getSystemValue('sharing.maxAutocompleteResults', 0); |
|
127 | + if ($maxResults > 0) { |
|
128 | + $perPage = min($perPage, $maxResults); |
|
129 | + } |
|
130 | + if ($perPage <= 0) { |
|
131 | + throw new OCSBadRequestException('Invalid perPage argument'); |
|
132 | + } |
|
133 | + if ($page <= 0) { |
|
134 | + throw new OCSBadRequestException('Invalid page'); |
|
135 | + } |
|
136 | + |
|
137 | + $shareTypes = [ |
|
138 | + Share::SHARE_TYPE_USER, |
|
139 | + ]; |
|
140 | + |
|
141 | + if ($itemType === null) { |
|
142 | + throw new OCSBadRequestException('Missing itemType'); |
|
143 | + } elseif ($itemType === 'file' || $itemType === 'folder') { |
|
144 | + if ($this->shareManager->allowGroupSharing()) { |
|
145 | + $shareTypes[] = Share::SHARE_TYPE_GROUP; |
|
146 | + } |
|
147 | + |
|
148 | + if ($this->isRemoteSharingAllowed($itemType)) { |
|
149 | + $shareTypes[] = Share::SHARE_TYPE_REMOTE; |
|
150 | + } |
|
151 | + |
|
152 | + if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) { |
|
153 | + $shareTypes[] = Share::SHARE_TYPE_EMAIL; |
|
154 | + } |
|
155 | + } else { |
|
156 | + $shareTypes[] = Share::SHARE_TYPE_GROUP; |
|
157 | + $shareTypes[] = Share::SHARE_TYPE_EMAIL; |
|
158 | + } |
|
159 | + |
|
160 | + // FIXME: DI |
|
161 | + if (\OC::$server->getAppManager()->isEnabledForUser('circles') && class_exists('\OCA\Circles\ShareByCircleProvider')) { |
|
162 | + $shareTypes[] = Share::SHARE_TYPE_CIRCLE; |
|
163 | + } |
|
164 | + |
|
165 | + if (isset($_GET['shareType']) && is_array($_GET['shareType'])) { |
|
166 | + $shareTypes = array_intersect($shareTypes, $_GET['shareType']); |
|
167 | + sort($shareTypes); |
|
168 | + } else if (is_numeric($shareType)) { |
|
169 | + $shareTypes = array_intersect($shareTypes, [(int) $shareType]); |
|
170 | + sort($shareTypes); |
|
171 | + } |
|
172 | + |
|
173 | + $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
174 | + $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
175 | + $this->limit = (int) $perPage; |
|
176 | + $this->offset = $perPage * ($page - 1); |
|
177 | + |
|
178 | + list($result, $hasMoreResults) = $this->collaboratorSearch->search($search, $shareTypes, $lookup, $this->limit, $this->offset); |
|
179 | + |
|
180 | + // extra treatment for 'exact' subarray, with a single merge expected keys might be lost |
|
181 | + if(isset($result['exact'])) { |
|
182 | + $result['exact'] = array_merge($this->result['exact'], $result['exact']); |
|
183 | + } |
|
184 | + $this->result = array_merge($this->result, $result); |
|
185 | + $response = new DataResponse($this->result); |
|
186 | + |
|
187 | + if ($hasMoreResults) { |
|
188 | + $response->addHeader('Link', $this->getPaginationLink($page, [ |
|
189 | + 'search' => $search, |
|
190 | + 'itemType' => $itemType, |
|
191 | + 'shareType' => $shareTypes, |
|
192 | + 'perPage' => $perPage, |
|
193 | + ])); |
|
194 | + } |
|
195 | + |
|
196 | + return $response; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Method to get out the static call for better testing |
|
201 | + * |
|
202 | + * @param string $itemType |
|
203 | + * @return bool |
|
204 | + */ |
|
205 | + protected function isRemoteSharingAllowed($itemType) { |
|
206 | + try { |
|
207 | + // FIXME: static foo makes unit testing unnecessarily difficult |
|
208 | + $backend = \OC\Share\Share::getBackend($itemType); |
|
209 | + return $backend->isShareTypeAllowed(Share::SHARE_TYPE_REMOTE); |
|
210 | + } catch (\Exception $e) { |
|
211 | + return false; |
|
212 | + } |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * Generates a bunch of pagination links for the current page |
|
218 | + * |
|
219 | + * @param int $page Current page |
|
220 | + * @param array $params Parameters for the URL |
|
221 | + * @return string |
|
222 | + */ |
|
223 | + protected function getPaginationLink($page, array $params) { |
|
224 | + if ($this->isV2()) { |
|
225 | + $url = $this->urlGenerator->getAbsoluteURL('/ocs/v2.php/apps/files_sharing/api/v1/sharees') . '?'; |
|
226 | + } else { |
|
227 | + $url = $this->urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/sharees') . '?'; |
|
228 | + } |
|
229 | + $params['page'] = $page + 1; |
|
230 | + $link = '<' . $url . http_build_query($params) . '>; rel="next"'; |
|
231 | + |
|
232 | + return $link; |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * @return bool |
|
237 | + */ |
|
238 | + protected function isV2() { |
|
239 | + return $this->request->getScriptName() === '/ocs/v2.php'; |
|
240 | + } |
|
241 | 241 | } |
@@ -117,13 +117,13 @@ discard block |
||
117 | 117 | public function search($search = '', $itemType = null, $page = 1, $perPage = 200, $shareType = null, $lookup = true) { |
118 | 118 | |
119 | 119 | // only search for string larger than a given threshold |
120 | - $threshold = (int)$this->config->getSystemValue('sharing.minSearchStringLength', 0); |
|
120 | + $threshold = (int) $this->config->getSystemValue('sharing.minSearchStringLength', 0); |
|
121 | 121 | if (strlen($search) < $threshold) { |
122 | 122 | return new DataResponse($this->result); |
123 | 123 | } |
124 | 124 | |
125 | 125 | // never return more than the max. number of results configured in the config.php |
126 | - $maxResults = (int)$this->config->getSystemValue('sharing.maxAutocompleteResults', 0); |
|
126 | + $maxResults = (int) $this->config->getSystemValue('sharing.maxAutocompleteResults', 0); |
|
127 | 127 | if ($maxResults > 0) { |
128 | 128 | $perPage = min($perPage, $maxResults); |
129 | 129 | } |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | list($result, $hasMoreResults) = $this->collaboratorSearch->search($search, $shareTypes, $lookup, $this->limit, $this->offset); |
179 | 179 | |
180 | 180 | // extra treatment for 'exact' subarray, with a single merge expected keys might be lost |
181 | - if(isset($result['exact'])) { |
|
181 | + if (isset($result['exact'])) { |
|
182 | 182 | $result['exact'] = array_merge($this->result['exact'], $result['exact']); |
183 | 183 | } |
184 | 184 | $this->result = array_merge($this->result, $result); |
@@ -222,12 +222,12 @@ discard block |
||
222 | 222 | */ |
223 | 223 | protected function getPaginationLink($page, array $params) { |
224 | 224 | if ($this->isV2()) { |
225 | - $url = $this->urlGenerator->getAbsoluteURL('/ocs/v2.php/apps/files_sharing/api/v1/sharees') . '?'; |
|
225 | + $url = $this->urlGenerator->getAbsoluteURL('/ocs/v2.php/apps/files_sharing/api/v1/sharees').'?'; |
|
226 | 226 | } else { |
227 | - $url = $this->urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/sharees') . '?'; |
|
227 | + $url = $this->urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/sharees').'?'; |
|
228 | 228 | } |
229 | 229 | $params['page'] = $page + 1; |
230 | - $link = '<' . $url . http_build_query($params) . '>; rel="next"'; |
|
230 | + $link = '<'.$url.http_build_query($params).'>; rel="next"'; |
|
231 | 231 | |
232 | 232 | return $link; |
233 | 233 | } |
@@ -31,59 +31,59 @@ |
||
31 | 31 | use OCP\Share; |
32 | 32 | |
33 | 33 | class Search implements ISearch { |
34 | - /** @var IContainer */ |
|
35 | - private $c; |
|
34 | + /** @var IContainer */ |
|
35 | + private $c; |
|
36 | 36 | |
37 | - protected $pluginList = []; |
|
37 | + protected $pluginList = []; |
|
38 | 38 | |
39 | - public function __construct(IContainer $c) { |
|
40 | - $this->c = $c; |
|
41 | - } |
|
39 | + public function __construct(IContainer $c) { |
|
40 | + $this->c = $c; |
|
41 | + } |
|
42 | 42 | |
43 | - public function search($search, array $shareTypes, $lookup, $limit, $offset) { |
|
44 | - $hasMoreResults = false; |
|
43 | + public function search($search, array $shareTypes, $lookup, $limit, $offset) { |
|
44 | + $hasMoreResults = false; |
|
45 | 45 | |
46 | - /** @var ISearchResult $searchResult */ |
|
47 | - $searchResult = $this->c->resolve(SearchResult::class); |
|
46 | + /** @var ISearchResult $searchResult */ |
|
47 | + $searchResult = $this->c->resolve(SearchResult::class); |
|
48 | 48 | |
49 | - foreach ($shareTypes as $type) { |
|
50 | - if(!isset($this->pluginList[$type])) { |
|
51 | - continue; |
|
52 | - } |
|
53 | - foreach ($this->pluginList[$type] as $plugin) { |
|
54 | - /** @var ISearchPlugin $searchPlugin */ |
|
55 | - $searchPlugin = $this->c->resolve($plugin); |
|
56 | - $hasMoreResults |= $searchPlugin->search($search, $limit, $offset, $searchResult); |
|
57 | - } |
|
58 | - } |
|
49 | + foreach ($shareTypes as $type) { |
|
50 | + if(!isset($this->pluginList[$type])) { |
|
51 | + continue; |
|
52 | + } |
|
53 | + foreach ($this->pluginList[$type] as $plugin) { |
|
54 | + /** @var ISearchPlugin $searchPlugin */ |
|
55 | + $searchPlugin = $this->c->resolve($plugin); |
|
56 | + $hasMoreResults |= $searchPlugin->search($search, $limit, $offset, $searchResult); |
|
57 | + } |
|
58 | + } |
|
59 | 59 | |
60 | - // Get from lookup server, not a separate share type |
|
61 | - if ($lookup) { |
|
62 | - $searchPlugin = $this->c->resolve(LookupPlugin::class); |
|
63 | - $hasMoreResults |= $searchPlugin->search($search, $limit, $offset, $searchResult); |
|
64 | - } |
|
60 | + // Get from lookup server, not a separate share type |
|
61 | + if ($lookup) { |
|
62 | + $searchPlugin = $this->c->resolve(LookupPlugin::class); |
|
63 | + $hasMoreResults |= $searchPlugin->search($search, $limit, $offset, $searchResult); |
|
64 | + } |
|
65 | 65 | |
66 | - // sanitizing, could go into the plugins as well |
|
66 | + // sanitizing, could go into the plugins as well |
|
67 | 67 | |
68 | - // if we have a exact match, either for the federated cloud id or for the |
|
69 | - // email address we only return the exact match. It is highly unlikely |
|
70 | - // that the exact same email address and federated cloud id exists |
|
71 | - $emailType = new SearchResultType('emails'); |
|
72 | - $remoteType = new SearchResultType('remotes'); |
|
73 | - if($searchResult->hasExactIdMatch($emailType) && !$searchResult->hasExactIdMatch($remoteType)) { |
|
74 | - $searchResult->unsetResult($remoteType); |
|
75 | - } elseif (!$searchResult->hasExactIdMatch($emailType) && $searchResult->hasExactIdMatch($remoteType)) { |
|
76 | - $searchResult->unsetResult($emailType); |
|
77 | - } |
|
68 | + // if we have a exact match, either for the federated cloud id or for the |
|
69 | + // email address we only return the exact match. It is highly unlikely |
|
70 | + // that the exact same email address and federated cloud id exists |
|
71 | + $emailType = new SearchResultType('emails'); |
|
72 | + $remoteType = new SearchResultType('remotes'); |
|
73 | + if($searchResult->hasExactIdMatch($emailType) && !$searchResult->hasExactIdMatch($remoteType)) { |
|
74 | + $searchResult->unsetResult($remoteType); |
|
75 | + } elseif (!$searchResult->hasExactIdMatch($emailType) && $searchResult->hasExactIdMatch($remoteType)) { |
|
76 | + $searchResult->unsetResult($emailType); |
|
77 | + } |
|
78 | 78 | |
79 | - return [$searchResult->asArray(), (bool)$hasMoreResults]; |
|
80 | - } |
|
79 | + return [$searchResult->asArray(), (bool)$hasMoreResults]; |
|
80 | + } |
|
81 | 81 | |
82 | - public function registerPlugin(array $pluginInfo) { |
|
83 | - $shareType = constant(Share::class . '::' . $pluginInfo['shareType']); |
|
84 | - if($shareType === null) { |
|
85 | - throw new \InvalidArgumentException('Provided ShareType is invalid'); |
|
86 | - } |
|
87 | - $this->pluginList[$shareType][] = $pluginInfo['class']; |
|
88 | - } |
|
82 | + public function registerPlugin(array $pluginInfo) { |
|
83 | + $shareType = constant(Share::class . '::' . $pluginInfo['shareType']); |
|
84 | + if($shareType === null) { |
|
85 | + throw new \InvalidArgumentException('Provided ShareType is invalid'); |
|
86 | + } |
|
87 | + $this->pluginList[$shareType][] = $pluginInfo['class']; |
|
88 | + } |
|
89 | 89 | } |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | $searchResult = $this->c->resolve(SearchResult::class); |
48 | 48 | |
49 | 49 | foreach ($shareTypes as $type) { |
50 | - if(!isset($this->pluginList[$type])) { |
|
50 | + if (!isset($this->pluginList[$type])) { |
|
51 | 51 | continue; |
52 | 52 | } |
53 | 53 | foreach ($this->pluginList[$type] as $plugin) { |
@@ -70,18 +70,18 @@ discard block |
||
70 | 70 | // that the exact same email address and federated cloud id exists |
71 | 71 | $emailType = new SearchResultType('emails'); |
72 | 72 | $remoteType = new SearchResultType('remotes'); |
73 | - if($searchResult->hasExactIdMatch($emailType) && !$searchResult->hasExactIdMatch($remoteType)) { |
|
73 | + if ($searchResult->hasExactIdMatch($emailType) && !$searchResult->hasExactIdMatch($remoteType)) { |
|
74 | 74 | $searchResult->unsetResult($remoteType); |
75 | 75 | } elseif (!$searchResult->hasExactIdMatch($emailType) && $searchResult->hasExactIdMatch($remoteType)) { |
76 | 76 | $searchResult->unsetResult($emailType); |
77 | 77 | } |
78 | 78 | |
79 | - return [$searchResult->asArray(), (bool)$hasMoreResults]; |
|
79 | + return [$searchResult->asArray(), (bool) $hasMoreResults]; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | public function registerPlugin(array $pluginInfo) { |
83 | - $shareType = constant(Share::class . '::' . $pluginInfo['shareType']); |
|
84 | - if($shareType === null) { |
|
83 | + $shareType = constant(Share::class.'::'.$pluginInfo['shareType']); |
|
84 | + if ($shareType === null) { |
|
85 | 85 | throw new \InvalidArgumentException('Provided ShareType is invalid'); |
86 | 86 | } |
87 | 87 | $this->pluginList[$shareType][] = $pluginInfo['class']; |