Completed
Push — master ( 734cdd...7ae42f )
by Blizzz
17:54
created
lib/private/Collaboration/Collaborators/MailPlugin.php 1 patch
Indentation   +174 added lines, -174 removed lines patch added patch discarded remove patch
@@ -37,180 +37,180 @@
 block discarded – undo
37 37
 use OCP\Share;
38 38
 
39 39
 class MailPlugin implements ISearchPlugin {
40
-	protected $shareeEnumeration;
41
-	protected $shareWithGroupOnly;
42
-
43
-	/** @var IManager */
44
-	private $contactsManager;
45
-	/** @var ICloudIdManager */
46
-	private $cloudIdManager;
47
-	/** @var IConfig */
48
-	private $config;
49
-
50
-	/** @var IGroupManager */
51
-	private $groupManager;
52
-
53
-	/** @var IUserSession */
54
-	private $userSession;
55
-
56
-	public function __construct(IManager $contactsManager, ICloudIdManager $cloudIdManager, IConfig $config, IGroupManager $groupManager, IUserSession $userSession) {
57
-		$this->contactsManager = $contactsManager;
58
-		$this->cloudIdManager = $cloudIdManager;
59
-		$this->config = $config;
60
-		$this->groupManager = $groupManager;
61
-		$this->userSession = $userSession;
62
-
63
-		$this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
64
-		$this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
65
-	}
66
-
67
-	/**
68
-	 * @param $search
69
-	 * @param $limit
70
-	 * @param $offset
71
-	 * @param ISearchResult $searchResult
72
-	 * @return bool
73
-	 * @since 13.0.0
74
-	 */
75
-	public function search($search, $limit, $offset, ISearchResult $searchResult) {
76
-		$result = $userResults = ['wide' => [], 'exact' => []];
77
-		$userType = new SearchResultType('users');
78
-		$emailType = new SearchResultType('emails');
79
-
80
-		// Search in contacts
81
-		//@todo Pagination missing
82
-		$addressBookContacts = $this->contactsManager->search($search, ['EMAIL', 'FN']);
83
-		$lowerSearch = strtolower($search);
84
-		foreach ($addressBookContacts as $contact) {
85
-			if (isset($contact['EMAIL'])) {
86
-				$emailAddresses = $contact['EMAIL'];
87
-				if (!is_array($emailAddresses)) {
88
-					$emailAddresses = [$emailAddresses];
89
-				}
90
-				foreach ($emailAddresses as $emailAddress) {
91
-					$displayName = $emailAddress;
92
-					if (isset($contact['FN'])) 	{
93
-						$displayName = $contact['FN'] . ' (' . $emailAddress . ')';
94
-					}
95
-					$exactEmailMatch = strtolower($emailAddress) === $lowerSearch;
96
-
97
-					if (isset($contact['isLocalSystemBook'])) {
98
-						if ($this->shareWithGroupOnly) {
99
-							/*
40
+    protected $shareeEnumeration;
41
+    protected $shareWithGroupOnly;
42
+
43
+    /** @var IManager */
44
+    private $contactsManager;
45
+    /** @var ICloudIdManager */
46
+    private $cloudIdManager;
47
+    /** @var IConfig */
48
+    private $config;
49
+
50
+    /** @var IGroupManager */
51
+    private $groupManager;
52
+
53
+    /** @var IUserSession */
54
+    private $userSession;
55
+
56
+    public function __construct(IManager $contactsManager, ICloudIdManager $cloudIdManager, IConfig $config, IGroupManager $groupManager, IUserSession $userSession) {
57
+        $this->contactsManager = $contactsManager;
58
+        $this->cloudIdManager = $cloudIdManager;
59
+        $this->config = $config;
60
+        $this->groupManager = $groupManager;
61
+        $this->userSession = $userSession;
62
+
63
+        $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
64
+        $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
65
+    }
66
+
67
+    /**
68
+     * @param $search
69
+     * @param $limit
70
+     * @param $offset
71
+     * @param ISearchResult $searchResult
72
+     * @return bool
73
+     * @since 13.0.0
74
+     */
75
+    public function search($search, $limit, $offset, ISearchResult $searchResult) {
76
+        $result = $userResults = ['wide' => [], 'exact' => []];
77
+        $userType = new SearchResultType('users');
78
+        $emailType = new SearchResultType('emails');
79
+
80
+        // Search in contacts
81
+        //@todo Pagination missing
82
+        $addressBookContacts = $this->contactsManager->search($search, ['EMAIL', 'FN']);
83
+        $lowerSearch = strtolower($search);
84
+        foreach ($addressBookContacts as $contact) {
85
+            if (isset($contact['EMAIL'])) {
86
+                $emailAddresses = $contact['EMAIL'];
87
+                if (!is_array($emailAddresses)) {
88
+                    $emailAddresses = [$emailAddresses];
89
+                }
90
+                foreach ($emailAddresses as $emailAddress) {
91
+                    $displayName = $emailAddress;
92
+                    if (isset($contact['FN'])) 	{
93
+                        $displayName = $contact['FN'] . ' (' . $emailAddress . ')';
94
+                    }
95
+                    $exactEmailMatch = strtolower($emailAddress) === $lowerSearch;
96
+
97
+                    if (isset($contact['isLocalSystemBook'])) {
98
+                        if ($this->shareWithGroupOnly) {
99
+                            /*
100 100
 							 * Check if the user may share with the user associated with the e-mail of the just found contact
101 101
 							 */
102
-							$userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
103
-							$found = false;
104
-							foreach ($userGroups as $userGroup) {
105
-								if ($this->groupManager->isInGroup($contact['UID'], $userGroup)) {
106
-									$found = true;
107
-									break;
108
-								}
109
-							}
110
-							if (!$found) {
111
-								continue;
112
-							}
113
-						}
114
-						if ($exactEmailMatch) {
115
-							try {
116
-								$cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
117
-							} catch (\InvalidArgumentException $e) {
118
-								continue;
119
-							}
120
-
121
-							if (!$this->isCurrentUser($cloud) && !$searchResult->hasResult($userType, $cloud->getUser())) {
122
-								$singleResult = [[
123
-									'label' => $displayName,
124
-									'value' => [
125
-										'shareType' => Share::SHARE_TYPE_USER,
126
-										'shareWith' => $cloud->getUser(),
127
-									],
128
-								]];
129
-								$searchResult->addResultSet($userType, [], $singleResult);
130
-								$searchResult->markExactIdMatch($emailType);
131
-							}
132
-							return false;
133
-						}
134
-
135
-						if ($this->shareeEnumeration) {
136
-							try {
137
-								$cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
138
-							} catch (\InvalidArgumentException $e) {
139
-								continue;
140
-							}
141
-
142
-							if (!$this->isCurrentUser($cloud) && !$searchResult->hasResult($userType, $cloud->getUser())) {
143
-								$userResults['wide'][] = [
144
-									'label' => $displayName,
145
-									'value' => [
146
-										'shareType' => Share::SHARE_TYPE_USER,
147
-										'shareWith' => $cloud->getUser(),
148
-									],
149
-								];
150
-							}
151
-						}
152
-						continue;
153
-					}
154
-
155
-					if ($exactEmailMatch
156
-						|| isset($contact['FN']) && strtolower($contact['FN']) === $lowerSearch)
157
-					{
158
-						if ($exactEmailMatch) {
159
-							$searchResult->markExactIdMatch($emailType);
160
-						}
161
-						$result['exact'][] = [
162
-							'label' => $displayName,
163
-							'value' => [
164
-								'shareType' => Share::SHARE_TYPE_EMAIL,
165
-								'shareWith' => $emailAddress,
166
-							],
167
-						];
168
-					} else {
169
-						$result['wide'][] = [
170
-							'label' => $displayName,
171
-							'value' => [
172
-								'shareType' => Share::SHARE_TYPE_EMAIL,
173
-								'shareWith' => $emailAddress,
174
-							],
175
-						];
176
-					}
177
-				}
178
-			}
179
-		}
180
-
181
-		$reachedEnd = true;
182
-		if (!$this->shareeEnumeration) {
183
-			$result['wide'] = [];
184
-			$userResults['wide'] = [];
185
-		} else {
186
-			$reachedEnd = (count($result['wide']) < $offset + $limit) &&
187
-				(count($userResults['wide']) < $offset + $limit);
188
-
189
-			$result['wide'] = array_slice($result['wide'], $offset, $limit);
190
-			$userResults['wide'] = array_slice($userResults['wide'], $offset, $limit);
191
-		}
192
-
193
-
194
-		if (!$searchResult->hasExactIdMatch($emailType) && filter_var($search, FILTER_VALIDATE_EMAIL)) {
195
-			$result['exact'][] = [
196
-				'label' => $search,
197
-				'value' => [
198
-					'shareType' => Share::SHARE_TYPE_EMAIL,
199
-					'shareWith' => $search,
200
-				],
201
-			];
202
-		}
203
-
204
-		if (!empty($userResults['wide'])) {
205
-			$searchResult->addResultSet($userType, $userResults['wide'], []);
206
-		}
207
-		$searchResult->addResultSet($emailType, $result['wide'], $result['exact']);
208
-
209
-		return !$reachedEnd;
210
-	}
211
-
212
-	public function isCurrentUser(ICloudId $cloud): bool {
213
-		$currentUser = $this->userSession->getUser();
214
-		return $currentUser instanceof IUser ? $currentUser->getUID() === $cloud->getUser() : false;
215
-	}
102
+                            $userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
103
+                            $found = false;
104
+                            foreach ($userGroups as $userGroup) {
105
+                                if ($this->groupManager->isInGroup($contact['UID'], $userGroup)) {
106
+                                    $found = true;
107
+                                    break;
108
+                                }
109
+                            }
110
+                            if (!$found) {
111
+                                continue;
112
+                            }
113
+                        }
114
+                        if ($exactEmailMatch) {
115
+                            try {
116
+                                $cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
117
+                            } catch (\InvalidArgumentException $e) {
118
+                                continue;
119
+                            }
120
+
121
+                            if (!$this->isCurrentUser($cloud) && !$searchResult->hasResult($userType, $cloud->getUser())) {
122
+                                $singleResult = [[
123
+                                    'label' => $displayName,
124
+                                    'value' => [
125
+                                        'shareType' => Share::SHARE_TYPE_USER,
126
+                                        'shareWith' => $cloud->getUser(),
127
+                                    ],
128
+                                ]];
129
+                                $searchResult->addResultSet($userType, [], $singleResult);
130
+                                $searchResult->markExactIdMatch($emailType);
131
+                            }
132
+                            return false;
133
+                        }
134
+
135
+                        if ($this->shareeEnumeration) {
136
+                            try {
137
+                                $cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
138
+                            } catch (\InvalidArgumentException $e) {
139
+                                continue;
140
+                            }
141
+
142
+                            if (!$this->isCurrentUser($cloud) && !$searchResult->hasResult($userType, $cloud->getUser())) {
143
+                                $userResults['wide'][] = [
144
+                                    'label' => $displayName,
145
+                                    'value' => [
146
+                                        'shareType' => Share::SHARE_TYPE_USER,
147
+                                        'shareWith' => $cloud->getUser(),
148
+                                    ],
149
+                                ];
150
+                            }
151
+                        }
152
+                        continue;
153
+                    }
154
+
155
+                    if ($exactEmailMatch
156
+                        || isset($contact['FN']) && strtolower($contact['FN']) === $lowerSearch)
157
+                    {
158
+                        if ($exactEmailMatch) {
159
+                            $searchResult->markExactIdMatch($emailType);
160
+                        }
161
+                        $result['exact'][] = [
162
+                            'label' => $displayName,
163
+                            'value' => [
164
+                                'shareType' => Share::SHARE_TYPE_EMAIL,
165
+                                'shareWith' => $emailAddress,
166
+                            ],
167
+                        ];
168
+                    } else {
169
+                        $result['wide'][] = [
170
+                            'label' => $displayName,
171
+                            'value' => [
172
+                                'shareType' => Share::SHARE_TYPE_EMAIL,
173
+                                'shareWith' => $emailAddress,
174
+                            ],
175
+                        ];
176
+                    }
177
+                }
178
+            }
179
+        }
180
+
181
+        $reachedEnd = true;
182
+        if (!$this->shareeEnumeration) {
183
+            $result['wide'] = [];
184
+            $userResults['wide'] = [];
185
+        } else {
186
+            $reachedEnd = (count($result['wide']) < $offset + $limit) &&
187
+                (count($userResults['wide']) < $offset + $limit);
188
+
189
+            $result['wide'] = array_slice($result['wide'], $offset, $limit);
190
+            $userResults['wide'] = array_slice($userResults['wide'], $offset, $limit);
191
+        }
192
+
193
+
194
+        if (!$searchResult->hasExactIdMatch($emailType) && filter_var($search, FILTER_VALIDATE_EMAIL)) {
195
+            $result['exact'][] = [
196
+                'label' => $search,
197
+                'value' => [
198
+                    'shareType' => Share::SHARE_TYPE_EMAIL,
199
+                    'shareWith' => $search,
200
+                ],
201
+            ];
202
+        }
203
+
204
+        if (!empty($userResults['wide'])) {
205
+            $searchResult->addResultSet($userType, $userResults['wide'], []);
206
+        }
207
+        $searchResult->addResultSet($emailType, $result['wide'], $result['exact']);
208
+
209
+        return !$reachedEnd;
210
+    }
211
+
212
+    public function isCurrentUser(ICloudId $cloud): bool {
213
+        $currentUser = $this->userSession->getUser();
214
+        return $currentUser instanceof IUser ? $currentUser->getUID() === $cloud->getUser() : false;
215
+    }
216 216
 }
Please login to merge, or discard this patch.