Completed
Push — master ( cf83eb...8e5120 )
by Blizzz
37s
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   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -37,165 +37,165 @@
 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 (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 = ['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
-								$singleResult = [[
140
-									'label' => $contact['FN'] . " ($emailAddress)",
141
-									'value' => [
142
-										'shareType' => Share::SHARE_TYPE_USER,
143
-										'shareWith' => $cloud->getUser(),
144
-									]],
145
-								];
146
-								$searchResult->addResultSet($userType, $singleResult, []);
147
-							}
148
-						}
149
-						continue;
150
-					}
151
-
152
-					if ($exactEmailMatch || strtolower($contact['FN']) === $lowerSearch) {
153
-						if ($exactEmailMatch) {
154
-							$searchResult->markExactIdMatch($emailType);
155
-						}
156
-						$result['exact'][] = [
157
-							'label' => $contact['FN'] . " ($emailAddress)",
158
-							'value' => [
159
-								'shareType' => Share::SHARE_TYPE_EMAIL,
160
-								'shareWith' => $emailAddress,
161
-							],
162
-						];
163
-					} else {
164
-						$result['wide'][] = [
165
-							'label' => $contact['FN'] . " ($emailAddress)",
166
-							'value' => [
167
-								'shareType' => Share::SHARE_TYPE_EMAIL,
168
-								'shareWith' => $emailAddress,
169
-							],
170
-						];
171
-					}
172
-				}
173
-			}
174
-		}
175
-
176
-		if (!$this->shareeEnumeration) {
177
-			$result['wide'] = [];
178
-		} else {
179
-			$result['wide'] = array_slice($result['wide'], $offset, $limit);
180
-		}
181
-
182
-		if (!$searchResult->hasExactIdMatch($emailType) && filter_var($search, FILTER_VALIDATE_EMAIL)) {
183
-			$result['exact'][] = [
184
-				'label' => $search,
185
-				'value' => [
186
-					'shareType' => Share::SHARE_TYPE_EMAIL,
187
-					'shareWith' => $search,
188
-				],
189
-			];
190
-		}
191
-
192
-		$searchResult->addResultSet($emailType, $result['wide'], $result['exact']);
193
-
194
-		return true;
195
-	}
196
-
197
-	public function isCurrentUser(ICloudId $cloud): bool {
198
-		$currentUser = $this->userSession->getUser();
199
-		return $currentUser instanceof IUser ? $currentUser->getUID() === $cloud->getUser() : false;
200
-	}
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
+                                $singleResult = [[
140
+                                    'label' => $contact['FN'] . " ($emailAddress)",
141
+                                    'value' => [
142
+                                        'shareType' => Share::SHARE_TYPE_USER,
143
+                                        'shareWith' => $cloud->getUser(),
144
+                                    ]],
145
+                                ];
146
+                                $searchResult->addResultSet($userType, $singleResult, []);
147
+                            }
148
+                        }
149
+                        continue;
150
+                    }
151
+
152
+                    if ($exactEmailMatch || strtolower($contact['FN']) === $lowerSearch) {
153
+                        if ($exactEmailMatch) {
154
+                            $searchResult->markExactIdMatch($emailType);
155
+                        }
156
+                        $result['exact'][] = [
157
+                            'label' => $contact['FN'] . " ($emailAddress)",
158
+                            'value' => [
159
+                                'shareType' => Share::SHARE_TYPE_EMAIL,
160
+                                'shareWith' => $emailAddress,
161
+                            ],
162
+                        ];
163
+                    } else {
164
+                        $result['wide'][] = [
165
+                            'label' => $contact['FN'] . " ($emailAddress)",
166
+                            'value' => [
167
+                                'shareType' => Share::SHARE_TYPE_EMAIL,
168
+                                'shareWith' => $emailAddress,
169
+                            ],
170
+                        ];
171
+                    }
172
+                }
173
+            }
174
+        }
175
+
176
+        if (!$this->shareeEnumeration) {
177
+            $result['wide'] = [];
178
+        } else {
179
+            $result['wide'] = array_slice($result['wide'], $offset, $limit);
180
+        }
181
+
182
+        if (!$searchResult->hasExactIdMatch($emailType) && filter_var($search, FILTER_VALIDATE_EMAIL)) {
183
+            $result['exact'][] = [
184
+                'label' => $search,
185
+                'value' => [
186
+                    'shareType' => Share::SHARE_TYPE_EMAIL,
187
+                    'shareWith' => $search,
188
+                ],
189
+            ];
190
+        }
191
+
192
+        $searchResult->addResultSet($emailType, $result['wide'], $result['exact']);
193
+
194
+        return true;
195
+    }
196
+
197
+    public function isCurrentUser(ICloudId $cloud): bool {
198
+        $currentUser = $this->userSession->getUser();
199
+        return $currentUser instanceof IUser ? $currentUser->getUID() === $cloud->getUser() : false;
200
+    }
201 201
 }
Please login to merge, or discard this patch.