Completed
Push — master ( 5924f9...054a45 )
by Blizzz
29:30 queued 11:49
created
lib/private/Collaboration/Collaborators/MailPlugin.php 1 patch
Indentation   +168 added lines, -168 removed lines patch added patch discarded remove patch
@@ -37,174 +37,174 @@
 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
-					$exactEmailMatch = strtolower($emailAddress) === $lowerSearch;
92
-
93
-					if (isset($contact['isLocalSystemBook'])) {
94
-						if ($this->shareWithGroupOnly) {
95
-							/*
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
+                    $exactEmailMatch = strtolower($emailAddress) === $lowerSearch;
92
+
93
+                    if (isset($contact['isLocalSystemBook'])) {
94
+                        if ($this->shareWithGroupOnly) {
95
+                            /*
96 96
 							 * Check if the user may share with the user associated with the e-mail of the just found contact
97 97
 							 */
98
-							$userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
99
-							$found = false;
100
-							foreach ($userGroups as $userGroup) {
101
-								if ($this->groupManager->isInGroup($contact['UID'], $userGroup)) {
102
-									$found = true;
103
-									break;
104
-								}
105
-							}
106
-							if (!$found) {
107
-								continue;
108
-							}
109
-						}
110
-						if ($exactEmailMatch) {
111
-							try {
112
-								$cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
113
-							} catch (\InvalidArgumentException $e) {
114
-								continue;
115
-							}
116
-
117
-							if (!$this->isCurrentUser($cloud) && !$searchResult->hasResult($userType, $cloud->getUser())) {
118
-								$singleResult = [[
119
-									'label' => $contact['FN'] . " ($emailAddress)",
120
-									'value' => [
121
-										'shareType' => Share::SHARE_TYPE_USER,
122
-										'shareWith' => $cloud->getUser(),
123
-									],
124
-								]];
125
-								$searchResult->addResultSet($userType, [], $singleResult);
126
-								$searchResult->markExactIdMatch($emailType);
127
-							}
128
-							return false;
129
-						}
130
-
131
-						if ($this->shareeEnumeration) {
132
-							try {
133
-								$cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
134
-							} catch (\InvalidArgumentException $e) {
135
-								continue;
136
-							}
137
-
138
-							if (!$this->isCurrentUser($cloud) && !$searchResult->hasResult($userType, $cloud->getUser())) {
139
-								$userResults['wide'][] = [
140
-									'label' => $contact['FN'] . " ($emailAddress)",
141
-									'value' => [
142
-										'shareType' => Share::SHARE_TYPE_USER,
143
-										'shareWith' => $cloud->getUser(),
144
-									],
145
-								];
146
-							}
147
-						}
148
-						continue;
149
-					}
150
-
151
-					if ($exactEmailMatch || strtolower($contact['FN']) === $lowerSearch) {
152
-						if ($exactEmailMatch) {
153
-							$searchResult->markExactIdMatch($emailType);
154
-						}
155
-						$result['exact'][] = [
156
-							'label' => $contact['FN'] . " ($emailAddress)",
157
-							'value' => [
158
-								'shareType' => Share::SHARE_TYPE_EMAIL,
159
-								'shareWith' => $emailAddress,
160
-							],
161
-						];
162
-					} else {
163
-						$result['wide'][] = [
164
-							'label' => $contact['FN'] . " ($emailAddress)",
165
-							'value' => [
166
-								'shareType' => Share::SHARE_TYPE_EMAIL,
167
-								'shareWith' => $emailAddress,
168
-							],
169
-						];
170
-					}
171
-				}
172
-			}
173
-		}
174
-
175
-		$reachedEnd = true;
176
-		if (!$this->shareeEnumeration) {
177
-			$result['wide'] = [];
178
-			$userResults['wide'] = [];
179
-		} else {
180
-			$reachedEnd = (count($result['wide']) < $offset + $limit) &&
181
-				(count($userResults['wide']) < $offset + $limit);
182
-
183
-			$result['wide'] = array_slice($result['wide'], $offset, $limit);
184
-			$userResults['wide'] = array_slice($userResults['wide'], $offset, $limit);
185
-		}
186
-
187
-
188
-		if (!$searchResult->hasExactIdMatch($emailType) && filter_var($search, FILTER_VALIDATE_EMAIL)) {
189
-			$result['exact'][] = [
190
-				'label' => $search,
191
-				'value' => [
192
-					'shareType' => Share::SHARE_TYPE_EMAIL,
193
-					'shareWith' => $search,
194
-				],
195
-			];
196
-		}
197
-
198
-		if (!empty($userResults['wide'])) {
199
-			$searchResult->addResultSet($userType, $userResults['wide'], []);
200
-		}
201
-		$searchResult->addResultSet($emailType, $result['wide'], $result['exact']);
202
-
203
-		return !$reachedEnd;
204
-	}
205
-
206
-	public function isCurrentUser(ICloudId $cloud): bool {
207
-		$currentUser = $this->userSession->getUser();
208
-		return $currentUser instanceof IUser ? $currentUser->getUID() === $cloud->getUser() : false;
209
-	}
98
+                            $userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
99
+                            $found = false;
100
+                            foreach ($userGroups as $userGroup) {
101
+                                if ($this->groupManager->isInGroup($contact['UID'], $userGroup)) {
102
+                                    $found = true;
103
+                                    break;
104
+                                }
105
+                            }
106
+                            if (!$found) {
107
+                                continue;
108
+                            }
109
+                        }
110
+                        if ($exactEmailMatch) {
111
+                            try {
112
+                                $cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
113
+                            } catch (\InvalidArgumentException $e) {
114
+                                continue;
115
+                            }
116
+
117
+                            if (!$this->isCurrentUser($cloud) && !$searchResult->hasResult($userType, $cloud->getUser())) {
118
+                                $singleResult = [[
119
+                                    'label' => $contact['FN'] . " ($emailAddress)",
120
+                                    'value' => [
121
+                                        'shareType' => Share::SHARE_TYPE_USER,
122
+                                        'shareWith' => $cloud->getUser(),
123
+                                    ],
124
+                                ]];
125
+                                $searchResult->addResultSet($userType, [], $singleResult);
126
+                                $searchResult->markExactIdMatch($emailType);
127
+                            }
128
+                            return false;
129
+                        }
130
+
131
+                        if ($this->shareeEnumeration) {
132
+                            try {
133
+                                $cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
134
+                            } catch (\InvalidArgumentException $e) {
135
+                                continue;
136
+                            }
137
+
138
+                            if (!$this->isCurrentUser($cloud) && !$searchResult->hasResult($userType, $cloud->getUser())) {
139
+                                $userResults['wide'][] = [
140
+                                    'label' => $contact['FN'] . " ($emailAddress)",
141
+                                    'value' => [
142
+                                        'shareType' => Share::SHARE_TYPE_USER,
143
+                                        'shareWith' => $cloud->getUser(),
144
+                                    ],
145
+                                ];
146
+                            }
147
+                        }
148
+                        continue;
149
+                    }
150
+
151
+                    if ($exactEmailMatch || strtolower($contact['FN']) === $lowerSearch) {
152
+                        if ($exactEmailMatch) {
153
+                            $searchResult->markExactIdMatch($emailType);
154
+                        }
155
+                        $result['exact'][] = [
156
+                            'label' => $contact['FN'] . " ($emailAddress)",
157
+                            'value' => [
158
+                                'shareType' => Share::SHARE_TYPE_EMAIL,
159
+                                'shareWith' => $emailAddress,
160
+                            ],
161
+                        ];
162
+                    } else {
163
+                        $result['wide'][] = [
164
+                            'label' => $contact['FN'] . " ($emailAddress)",
165
+                            'value' => [
166
+                                'shareType' => Share::SHARE_TYPE_EMAIL,
167
+                                'shareWith' => $emailAddress,
168
+                            ],
169
+                        ];
170
+                    }
171
+                }
172
+            }
173
+        }
174
+
175
+        $reachedEnd = true;
176
+        if (!$this->shareeEnumeration) {
177
+            $result['wide'] = [];
178
+            $userResults['wide'] = [];
179
+        } else {
180
+            $reachedEnd = (count($result['wide']) < $offset + $limit) &&
181
+                (count($userResults['wide']) < $offset + $limit);
182
+
183
+            $result['wide'] = array_slice($result['wide'], $offset, $limit);
184
+            $userResults['wide'] = array_slice($userResults['wide'], $offset, $limit);
185
+        }
186
+
187
+
188
+        if (!$searchResult->hasExactIdMatch($emailType) && filter_var($search, FILTER_VALIDATE_EMAIL)) {
189
+            $result['exact'][] = [
190
+                'label' => $search,
191
+                'value' => [
192
+                    'shareType' => Share::SHARE_TYPE_EMAIL,
193
+                    'shareWith' => $search,
194
+                ],
195
+            ];
196
+        }
197
+
198
+        if (!empty($userResults['wide'])) {
199
+            $searchResult->addResultSet($userType, $userResults['wide'], []);
200
+        }
201
+        $searchResult->addResultSet($emailType, $result['wide'], $result['exact']);
202
+
203
+        return !$reachedEnd;
204
+    }
205
+
206
+    public function isCurrentUser(ICloudId $cloud): bool {
207
+        $currentUser = $this->userSession->getUser();
208
+        return $currentUser instanceof IUser ? $currentUser->getUID() === $cloud->getUser() : false;
209
+    }
210 210
 }
Please login to merge, or discard this patch.