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