Completed
Pull Request — master (#8206)
by Joas
17:05
created
lib/private/Collaboration/Collaborators/RemotePlugin.php 1 patch
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -33,107 +33,107 @@
 block discarded – undo
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
-		} else {
106
-			$result['wide'] = array_slice($result['wide'], $offset, $limit);
107
-		}
103
+        if (!$this->shareeEnumeration) {
104
+            $result['wide'] = [];
105
+        } else {
106
+            $result['wide'] = array_slice($result['wide'], $offset, $limit);
107
+        }
108 108
 
109
-		if (!$searchResult->hasExactIdMatch($resultType) && $this->cloudIdManager->isValidCloudId($search) && $offset === 0) {
110
-			$result['exact'][] = [
111
-				'label' => $search,
112
-				'value' => [
113
-					'shareType' => Share::SHARE_TYPE_REMOTE,
114
-					'shareWith' => $search,
115
-				],
116
-			];
117
-		}
109
+        if (!$searchResult->hasExactIdMatch($resultType) && $this->cloudIdManager->isValidCloudId($search) && $offset === 0) {
110
+            $result['exact'][] = [
111
+                'label' => $search,
112
+                'value' => [
113
+                    'shareType' => Share::SHARE_TYPE_REMOTE,
114
+                    'shareWith' => $search,
115
+                ],
116
+            ];
117
+        }
118 118
 
119
-		$searchResult->addResultSet($resultType, $result['wide'], $result['exact']);
119
+        $searchResult->addResultSet($resultType, $result['wide'], $result['exact']);
120 120
 
121
-		return true;
122
-	}
121
+        return true;
122
+    }
123 123
 
124
-	/**
125
-	 * split user and remote from federated cloud id
126
-	 *
127
-	 * @param string $address federated share address
128
-	 * @return array [user, remoteURL]
129
-	 * @throws \InvalidArgumentException
130
-	 */
131
-	public function splitUserRemote($address) {
132
-		try {
133
-			$cloudId = $this->cloudIdManager->resolveCloudId($address);
134
-			return [$cloudId->getUser(), $cloudId->getRemote()];
135
-		} catch (\InvalidArgumentException $e) {
136
-			throw new \InvalidArgumentException('Invalid Federated Cloud ID', 0, $e);
137
-		}
138
-	}
124
+    /**
125
+     * split user and remote from federated cloud id
126
+     *
127
+     * @param string $address federated share address
128
+     * @return array [user, remoteURL]
129
+     * @throws \InvalidArgumentException
130
+     */
131
+    public function splitUserRemote($address) {
132
+        try {
133
+            $cloudId = $this->cloudIdManager->resolveCloudId($address);
134
+            return [$cloudId->getUser(), $cloudId->getRemote()];
135
+        } catch (\InvalidArgumentException $e) {
136
+            throw new \InvalidArgumentException('Invalid Federated Cloud ID', 0, $e);
137
+        }
138
+    }
139 139
 }
Please login to merge, or discard this patch.
lib/private/Collaboration/Collaborators/MailPlugin.php 1 patch
Indentation   +165 added lines, -165 removed lines patch added patch discarded remove patch
@@ -37,171 +37,171 @@
 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 = ['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 ($search === '' && isset($contact['isLocalSystemBook'])) {
86
-				// All local users are already listed via the getUsers()
87
-				// So no need to include them again, when the search term is empty
88
-				continue;
89
-			}
90
-
91
-			if (isset($contact['EMAIL'])) {
92
-				$emailAddresses = $contact['EMAIL'];
93
-				if (!is_array($emailAddresses)) {
94
-					$emailAddresses = [$emailAddresses];
95
-				}
96
-				foreach ($emailAddresses as $emailAddress) {
97
-					$exactEmailMatch = strtolower($emailAddress) === $lowerSearch;
98
-
99
-					if (isset($contact['isLocalSystemBook'])) {
100
-						if ($this->shareWithGroupOnly) {
101
-							/*
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 = ['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 ($search === '' && isset($contact['isLocalSystemBook'])) {
86
+                // All local users are already listed via the getUsers()
87
+                // So no need to include them again, when the search term is empty
88
+                continue;
89
+            }
90
+
91
+            if (isset($contact['EMAIL'])) {
92
+                $emailAddresses = $contact['EMAIL'];
93
+                if (!is_array($emailAddresses)) {
94
+                    $emailAddresses = [$emailAddresses];
95
+                }
96
+                foreach ($emailAddresses as $emailAddress) {
97
+                    $exactEmailMatch = strtolower($emailAddress) === $lowerSearch;
98
+
99
+                    if (isset($contact['isLocalSystemBook'])) {
100
+                        if ($this->shareWithGroupOnly) {
101
+                            /*
102 102
 							 * Check if the user may share with the user associated with the e-mail of the just found contact
103 103
 							 */
104
-							$userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
105
-							$found = false;
106
-							foreach ($userGroups as $userGroup) {
107
-								if ($this->groupManager->isInGroup($contact['UID'], $userGroup)) {
108
-									$found = true;
109
-									break;
110
-								}
111
-							}
112
-							if (!$found) {
113
-								continue;
114
-							}
115
-						}
116
-						if ($exactEmailMatch) {
117
-							try {
118
-								$cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
119
-							} catch (\InvalidArgumentException $e) {
120
-								continue;
121
-							}
122
-
123
-							if (!$this->isCurrentUser($cloud) && !$searchResult->hasResult($userType, $cloud->getUser())) {
124
-								$singleResult = [[
125
-									'label' => $contact['FN'] . " ($emailAddress)",
126
-									'value' => [
127
-										'shareType' => Share::SHARE_TYPE_USER,
128
-										'shareWith' => $cloud->getUser(),
129
-									],
130
-								]];
131
-								$searchResult->addResultSet($userType, [], $singleResult);
132
-								$searchResult->markExactIdMatch($emailType);
133
-							}
134
-							return false;
135
-						}
136
-
137
-						if ($this->shareeEnumeration) {
138
-							try {
139
-								$cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
140
-							} catch (\InvalidArgumentException $e) {
141
-								continue;
142
-							}
143
-
144
-							if (!$this->isCurrentUser($cloud) && !$searchResult->hasResult($userType, $cloud->getUser())) {
145
-								$singleResult = [[
146
-									'label' => $contact['FN'] . " ($emailAddress)",
147
-									'value' => [
148
-										'shareType' => Share::SHARE_TYPE_USER,
149
-										'shareWith' => $cloud->getUser(),
150
-									]],
151
-								];
152
-								$searchResult->addResultSet($userType, $singleResult, []);
153
-							}
154
-						}
155
-						continue;
156
-					}
157
-
158
-					if ($exactEmailMatch || strtolower($contact['FN']) === $lowerSearch) {
159
-						if ($exactEmailMatch) {
160
-							$searchResult->markExactIdMatch($emailType);
161
-						}
162
-						$result['exact'][] = [
163
-							'label' => $contact['FN'] . " ($emailAddress)",
164
-							'value' => [
165
-								'shareType' => Share::SHARE_TYPE_EMAIL,
166
-								'shareWith' => $emailAddress,
167
-							],
168
-						];
169
-					} else {
170
-						$result['wide'][] = [
171
-							'label' => $contact['FN'] . " ($emailAddress)",
172
-							'value' => [
173
-								'shareType' => Share::SHARE_TYPE_EMAIL,
174
-								'shareWith' => $emailAddress,
175
-							],
176
-						];
177
-					}
178
-				}
179
-			}
180
-		}
181
-
182
-		if (!$this->shareeEnumeration) {
183
-			$result['wide'] = [];
184
-		} else {
185
-			$result['wide'] = array_slice($result['wide'], $offset, $limit);
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
-		$searchResult->addResultSet($emailType, $result['wide'], $result['exact']);
199
-
200
-		return true;
201
-	}
202
-
203
-	public function isCurrentUser(ICloudId $cloud): bool {
204
-		$currentUser = $this->userSession->getUser();
205
-		return $currentUser instanceof IUser ? $currentUser->getUID() === $cloud->getUser() : false;
206
-	}
104
+                            $userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
105
+                            $found = false;
106
+                            foreach ($userGroups as $userGroup) {
107
+                                if ($this->groupManager->isInGroup($contact['UID'], $userGroup)) {
108
+                                    $found = true;
109
+                                    break;
110
+                                }
111
+                            }
112
+                            if (!$found) {
113
+                                continue;
114
+                            }
115
+                        }
116
+                        if ($exactEmailMatch) {
117
+                            try {
118
+                                $cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
119
+                            } catch (\InvalidArgumentException $e) {
120
+                                continue;
121
+                            }
122
+
123
+                            if (!$this->isCurrentUser($cloud) && !$searchResult->hasResult($userType, $cloud->getUser())) {
124
+                                $singleResult = [[
125
+                                    'label' => $contact['FN'] . " ($emailAddress)",
126
+                                    'value' => [
127
+                                        'shareType' => Share::SHARE_TYPE_USER,
128
+                                        'shareWith' => $cloud->getUser(),
129
+                                    ],
130
+                                ]];
131
+                                $searchResult->addResultSet($userType, [], $singleResult);
132
+                                $searchResult->markExactIdMatch($emailType);
133
+                            }
134
+                            return false;
135
+                        }
136
+
137
+                        if ($this->shareeEnumeration) {
138
+                            try {
139
+                                $cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
140
+                            } catch (\InvalidArgumentException $e) {
141
+                                continue;
142
+                            }
143
+
144
+                            if (!$this->isCurrentUser($cloud) && !$searchResult->hasResult($userType, $cloud->getUser())) {
145
+                                $singleResult = [[
146
+                                    'label' => $contact['FN'] . " ($emailAddress)",
147
+                                    'value' => [
148
+                                        'shareType' => Share::SHARE_TYPE_USER,
149
+                                        'shareWith' => $cloud->getUser(),
150
+                                    ]],
151
+                                ];
152
+                                $searchResult->addResultSet($userType, $singleResult, []);
153
+                            }
154
+                        }
155
+                        continue;
156
+                    }
157
+
158
+                    if ($exactEmailMatch || strtolower($contact['FN']) === $lowerSearch) {
159
+                        if ($exactEmailMatch) {
160
+                            $searchResult->markExactIdMatch($emailType);
161
+                        }
162
+                        $result['exact'][] = [
163
+                            'label' => $contact['FN'] . " ($emailAddress)",
164
+                            'value' => [
165
+                                'shareType' => Share::SHARE_TYPE_EMAIL,
166
+                                'shareWith' => $emailAddress,
167
+                            ],
168
+                        ];
169
+                    } else {
170
+                        $result['wide'][] = [
171
+                            'label' => $contact['FN'] . " ($emailAddress)",
172
+                            'value' => [
173
+                                'shareType' => Share::SHARE_TYPE_EMAIL,
174
+                                'shareWith' => $emailAddress,
175
+                            ],
176
+                        ];
177
+                    }
178
+                }
179
+            }
180
+        }
181
+
182
+        if (!$this->shareeEnumeration) {
183
+            $result['wide'] = [];
184
+        } else {
185
+            $result['wide'] = array_slice($result['wide'], $offset, $limit);
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
+        $searchResult->addResultSet($emailType, $result['wide'], $result['exact']);
199
+
200
+        return true;
201
+    }
202
+
203
+    public function isCurrentUser(ICloudId $cloud): bool {
204
+        $currentUser = $this->userSession->getUser();
205
+        return $currentUser instanceof IUser ? $currentUser->getUID() === $cloud->getUser() : false;
206
+    }
207 207
 }
Please login to merge, or discard this patch.