Completed
Pull Request — master (#5585)
by Lukas
15:54
created
apps/dav/appinfo/app.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -30,27 +30,27 @@
 block discarded – undo
30 30
 $app->registerHooks();
31 31
 
32 32
 \OC::$server->registerService('CardDAVSyncService', function() use ($app) {
33
-	return $app->getSyncService();
33
+    return $app->getSyncService();
34 34
 });
35 35
 
36 36
 $eventDispatcher = \OC::$server->getEventDispatcher();
37 37
 
38 38
 $eventDispatcher->addListener('OCP\Federation\TrustedServerEvent::remove',
39
-	function(GenericEvent $event) use ($app) {
40
-		/** @var CardDavBackend $cardDavBackend */
41
-		$cardDavBackend = $app->getContainer()->query(CardDavBackend::class);
42
-		$addressBookUri = $event->getSubject();
43
-		$addressBook = $cardDavBackend->getAddressBooksByUri('principals/system/system', $addressBookUri);
44
-		if (!is_null($addressBook)) {
45
-			$cardDavBackend->deleteAddressBook($addressBook['id']);
46
-		}
47
-	}
39
+    function(GenericEvent $event) use ($app) {
40
+        /** @var CardDavBackend $cardDavBackend */
41
+        $cardDavBackend = $app->getContainer()->query(CardDavBackend::class);
42
+        $addressBookUri = $event->getSubject();
43
+        $addressBook = $cardDavBackend->getAddressBooksByUri('principals/system/system', $addressBookUri);
44
+        if (!is_null($addressBook)) {
45
+            $cardDavBackend->deleteAddressBook($addressBook['id']);
46
+        }
47
+    }
48 48
 );
49 49
 
50 50
 $cm = \OC::$server->getContactsManager();
51 51
 $cm->register(function() use ($cm, $app) {
52
-	$user = \OC::$server->getUserSession()->getUser();
53
-	if (!is_null($user)) {
54
-		$app->setupContactsProvider($cm, $user->getUID());
55
-	}
52
+    $user = \OC::$server->getUserSession()->getUser();
53
+    if (!is_null($user)) {
54
+        $app->setupContactsProvider($cm, $user->getUID());
55
+    }
56 56
 });
Please login to merge, or discard this patch.
lib/private/Contacts/ContactsMenu/ContactsStore.php 1 patch
Indentation   +215 added lines, -215 removed lines patch added patch discarded remove patch
@@ -36,220 +36,220 @@
 block discarded – undo
36 36
 
37 37
 class ContactsStore {
38 38
 
39
-	/** @var IManager */
40
-	private $contactsManager;
41
-
42
-	/** @var IConfig */
43
-	private $config;
44
-
45
-	/** @var IUserManager */
46
-	private $userManager;
47
-
48
-	/** @var IGroupManager */
49
-	private $groupManager;
50
-
51
-	/**
52
-	 * @param IManager $contactsManager
53
-	 * @param IConfig $config
54
-	 * @param IUserManager $userManager
55
-	 * @param IGroupManager $groupManager
56
-	 */
57
-	public function __construct(IManager $contactsManager,
58
-								IConfig $config,
59
-								IUserManager $userManager,
60
-								IGroupManager $groupManager) {
61
-		$this->contactsManager = $contactsManager;
62
-		$this->config = $config;
63
-		$this->userManager = $userManager;
64
-		$this->groupManager = $groupManager;
65
-	}
66
-
67
-	/**
68
-	 * @param IUser $user
69
-	 * @param string|null $filter
70
-	 * @return IEntry[]
71
-	 */
72
-	public function getContacts(IUser $user, $filter) {
73
-		$allContacts = $this->contactsManager->search($filter ?: '', [
74
-			'FN',
75
-			'EMAIL'
76
-		]);
77
-
78
-		$entries = array_map(function(array $contact) {
79
-			return $this->contactArrayToEntry($contact);
80
-		}, $allContacts);
81
-		return $this->filterContacts(
82
-			$user,
83
-			$entries,
84
-			$filter
85
-		);
86
-	}
87
-
88
-	/**
89
-	 * Filters the contacts. Applies 3 filters:
90
-	 *  1. filter the current user
91
-	 *  2. if the `shareapi_allow_share_dialog_user_enumeration` config option is
92
-	 * enabled it will filter all local users
93
-	 *  3. if the `shareapi_exclude_groups` config option is enabled and the
94
-	 * current user is in an excluded group it will filter all local users.
95
-	 *  4. if the `shareapi_only_share_with_group_members` config option is
96
-	 * enabled it will filter all users which doens't have a common group
97
-	 * with the current user.
98
-	 *
99
-	 * @param IUser $self
100
-	 * @param Entry[] $entries
101
-	 * @param string $filter
102
-	 * @return Entry[] the filtered contacts
103
-	 */
104
-	private function filterContacts(IUser $self,
105
-									array $entries,
106
-									$filter) {
107
-		$disallowEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') !== 'yes';
108
-		$excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes';
109
-
110
-		// whether to filter out local users
111
-		$skipLocal = false;
112
-		// whether to filter out all users which doesn't have the same group as the current user
113
-		$ownGroupsOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
114
-
115
-		$selfGroups = $this->groupManager->getUserGroupIds($self);
116
-
117
-		if ($excludedGroups) {
118
-			$excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '');
119
-			$decodedExcludeGroups = json_decode($excludedGroups, true);
120
-			$excludeGroupsList = ($decodedExcludeGroups !== null) ? $decodedExcludeGroups :  [];
121
-
122
-			if (count(array_intersect($excludeGroupsList, $selfGroups)) !== 0) {
123
-				// a group of the current user is excluded -> filter all local users
124
-				$skipLocal = true;
125
-			}
126
-		}
127
-
128
-		$selfUID = $self->getUID();
129
-
130
-		return array_values(array_filter($entries, function(IEntry $entry) use ($self, $skipLocal, $ownGroupsOnly, $selfGroups, $selfUID, $disallowEnumeration, $filter) {
131
-			if ($skipLocal && $entry->getProperty('isLocalSystemBook') === true) {
132
-				return false;
133
-			}
134
-
135
-			// Prevent enumerating local users
136
-			if($disallowEnumeration && $entry->getProperty('isLocalSystemBook')) {
137
-				$filterUser = true;
138
-
139
-				$mailAddresses = $entry->getEMailAddresses();
140
-				foreach($mailAddresses as $mailAddress) {
141
-					if($mailAddress === $filter) {
142
-						$filterUser = false;
143
-						break;
144
-					}
145
-				}
146
-
147
-				if($entry->getProperty('UID') && $entry->getProperty('UID') === $filter) {
148
-					$filterUser = false;
149
-				}
150
-
151
-				if($filterUser) {
152
-					return false;
153
-				}
154
-			}
155
-
156
-			if ($ownGroupsOnly && $entry->getProperty('isLocalSystemBook') === true) {
157
-				$contactGroups = $this->groupManager->getUserGroupIds($this->userManager->get($entry->getProperty('UID')));
158
-				if (count(array_intersect($contactGroups, $selfGroups)) === 0) {
159
-					// no groups in common, so shouldn't see the contact
160
-					return false;
161
-				}
162
-			}
163
-
164
-			return $entry->getProperty('UID') !== $selfUID;
165
-		}));
166
-	}
167
-
168
-	/**
169
-	 * @param IUser $user
170
-	 * @param integer $shareType
171
-	 * @param string $shareWith
172
-	 * @return IEntry|null
173
-	 */
174
-	public function findOne(IUser $user, $shareType, $shareWith) {
175
-		switch($shareType) {
176
-			case 0:
177
-			case 6:
178
-				$filter = ['UID'];
179
-				break;
180
-			case 4:
181
-				$filter = ['EMAIL'];
182
-				break;
183
-			default:
184
-				return null;
185
-		}
186
-
187
-		$userId = $user->getUID();
188
-		$allContacts = $this->contactsManager->search($shareWith, $filter);
189
-		$contacts = array_filter($allContacts, function($contact) use ($userId) {
190
-			return $contact['UID'] !== $userId;
191
-		});
192
-		$match = null;
193
-
194
-		foreach ($contacts as $contact) {
195
-			if ($shareType === 4 && isset($contact['EMAIL'])) {
196
-				if (in_array($shareWith, $contact['EMAIL'])) {
197
-					$match = $contact;
198
-					break;
199
-				}
200
-			}
201
-			if ($shareType === 0 || $shareType === 6) {
202
-				if ($contact['UID'] === $shareWith && $contact['isLocalSystemBook'] === true) {
203
-					$match = $contact;
204
-					break;
205
-				}
206
-			}
207
-		}
208
-
209
-		if ($match) {
210
-			$match = $this->filterContacts($user, [$this->contactArrayToEntry($match)], $shareWith);
211
-			if (count($match) === 1) {
212
-				$match = $match[0];
213
-			} else {
214
-				$match = null;
215
-			}
216
-
217
-		}
218
-
219
-		return $match;
220
-	}
221
-
222
-	/**
223
-	 * @param array $contact
224
-	 * @return Entry
225
-	 */
226
-	private function contactArrayToEntry(array $contact) {
227
-		$entry = new Entry();
228
-
229
-		if (isset($contact['id'])) {
230
-			$entry->setId($contact['id']);
231
-		}
232
-
233
-		if (isset($contact['FN'])) {
234
-			$entry->setFullName($contact['FN']);
235
-		}
236
-
237
-		$avatarPrefix = "VALUE=uri:";
238
-		if (isset($contact['PHOTO']) && strpos($contact['PHOTO'], $avatarPrefix) === 0) {
239
-			$entry->setAvatar(substr($contact['PHOTO'], strlen($avatarPrefix)));
240
-		}
241
-
242
-		if (isset($contact['EMAIL'])) {
243
-			foreach ($contact['EMAIL'] as $email) {
244
-				$entry->addEMailAddress($email);
245
-			}
246
-		}
247
-
248
-		// Attach all other properties to the entry too because some
249
-		// providers might make use of it.
250
-		$entry->setProperties($contact);
251
-
252
-		return $entry;
253
-	}
39
+    /** @var IManager */
40
+    private $contactsManager;
41
+
42
+    /** @var IConfig */
43
+    private $config;
44
+
45
+    /** @var IUserManager */
46
+    private $userManager;
47
+
48
+    /** @var IGroupManager */
49
+    private $groupManager;
50
+
51
+    /**
52
+     * @param IManager $contactsManager
53
+     * @param IConfig $config
54
+     * @param IUserManager $userManager
55
+     * @param IGroupManager $groupManager
56
+     */
57
+    public function __construct(IManager $contactsManager,
58
+                                IConfig $config,
59
+                                IUserManager $userManager,
60
+                                IGroupManager $groupManager) {
61
+        $this->contactsManager = $contactsManager;
62
+        $this->config = $config;
63
+        $this->userManager = $userManager;
64
+        $this->groupManager = $groupManager;
65
+    }
66
+
67
+    /**
68
+     * @param IUser $user
69
+     * @param string|null $filter
70
+     * @return IEntry[]
71
+     */
72
+    public function getContacts(IUser $user, $filter) {
73
+        $allContacts = $this->contactsManager->search($filter ?: '', [
74
+            'FN',
75
+            'EMAIL'
76
+        ]);
77
+
78
+        $entries = array_map(function(array $contact) {
79
+            return $this->contactArrayToEntry($contact);
80
+        }, $allContacts);
81
+        return $this->filterContacts(
82
+            $user,
83
+            $entries,
84
+            $filter
85
+        );
86
+    }
87
+
88
+    /**
89
+     * Filters the contacts. Applies 3 filters:
90
+     *  1. filter the current user
91
+     *  2. if the `shareapi_allow_share_dialog_user_enumeration` config option is
92
+     * enabled it will filter all local users
93
+     *  3. if the `shareapi_exclude_groups` config option is enabled and the
94
+     * current user is in an excluded group it will filter all local users.
95
+     *  4. if the `shareapi_only_share_with_group_members` config option is
96
+     * enabled it will filter all users which doens't have a common group
97
+     * with the current user.
98
+     *
99
+     * @param IUser $self
100
+     * @param Entry[] $entries
101
+     * @param string $filter
102
+     * @return Entry[] the filtered contacts
103
+     */
104
+    private function filterContacts(IUser $self,
105
+                                    array $entries,
106
+                                    $filter) {
107
+        $disallowEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') !== 'yes';
108
+        $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes';
109
+
110
+        // whether to filter out local users
111
+        $skipLocal = false;
112
+        // whether to filter out all users which doesn't have the same group as the current user
113
+        $ownGroupsOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
114
+
115
+        $selfGroups = $this->groupManager->getUserGroupIds($self);
116
+
117
+        if ($excludedGroups) {
118
+            $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '');
119
+            $decodedExcludeGroups = json_decode($excludedGroups, true);
120
+            $excludeGroupsList = ($decodedExcludeGroups !== null) ? $decodedExcludeGroups :  [];
121
+
122
+            if (count(array_intersect($excludeGroupsList, $selfGroups)) !== 0) {
123
+                // a group of the current user is excluded -> filter all local users
124
+                $skipLocal = true;
125
+            }
126
+        }
127
+
128
+        $selfUID = $self->getUID();
129
+
130
+        return array_values(array_filter($entries, function(IEntry $entry) use ($self, $skipLocal, $ownGroupsOnly, $selfGroups, $selfUID, $disallowEnumeration, $filter) {
131
+            if ($skipLocal && $entry->getProperty('isLocalSystemBook') === true) {
132
+                return false;
133
+            }
134
+
135
+            // Prevent enumerating local users
136
+            if($disallowEnumeration && $entry->getProperty('isLocalSystemBook')) {
137
+                $filterUser = true;
138
+
139
+                $mailAddresses = $entry->getEMailAddresses();
140
+                foreach($mailAddresses as $mailAddress) {
141
+                    if($mailAddress === $filter) {
142
+                        $filterUser = false;
143
+                        break;
144
+                    }
145
+                }
146
+
147
+                if($entry->getProperty('UID') && $entry->getProperty('UID') === $filter) {
148
+                    $filterUser = false;
149
+                }
150
+
151
+                if($filterUser) {
152
+                    return false;
153
+                }
154
+            }
155
+
156
+            if ($ownGroupsOnly && $entry->getProperty('isLocalSystemBook') === true) {
157
+                $contactGroups = $this->groupManager->getUserGroupIds($this->userManager->get($entry->getProperty('UID')));
158
+                if (count(array_intersect($contactGroups, $selfGroups)) === 0) {
159
+                    // no groups in common, so shouldn't see the contact
160
+                    return false;
161
+                }
162
+            }
163
+
164
+            return $entry->getProperty('UID') !== $selfUID;
165
+        }));
166
+    }
167
+
168
+    /**
169
+     * @param IUser $user
170
+     * @param integer $shareType
171
+     * @param string $shareWith
172
+     * @return IEntry|null
173
+     */
174
+    public function findOne(IUser $user, $shareType, $shareWith) {
175
+        switch($shareType) {
176
+            case 0:
177
+            case 6:
178
+                $filter = ['UID'];
179
+                break;
180
+            case 4:
181
+                $filter = ['EMAIL'];
182
+                break;
183
+            default:
184
+                return null;
185
+        }
186
+
187
+        $userId = $user->getUID();
188
+        $allContacts = $this->contactsManager->search($shareWith, $filter);
189
+        $contacts = array_filter($allContacts, function($contact) use ($userId) {
190
+            return $contact['UID'] !== $userId;
191
+        });
192
+        $match = null;
193
+
194
+        foreach ($contacts as $contact) {
195
+            if ($shareType === 4 && isset($contact['EMAIL'])) {
196
+                if (in_array($shareWith, $contact['EMAIL'])) {
197
+                    $match = $contact;
198
+                    break;
199
+                }
200
+            }
201
+            if ($shareType === 0 || $shareType === 6) {
202
+                if ($contact['UID'] === $shareWith && $contact['isLocalSystemBook'] === true) {
203
+                    $match = $contact;
204
+                    break;
205
+                }
206
+            }
207
+        }
208
+
209
+        if ($match) {
210
+            $match = $this->filterContacts($user, [$this->contactArrayToEntry($match)], $shareWith);
211
+            if (count($match) === 1) {
212
+                $match = $match[0];
213
+            } else {
214
+                $match = null;
215
+            }
216
+
217
+        }
218
+
219
+        return $match;
220
+    }
221
+
222
+    /**
223
+     * @param array $contact
224
+     * @return Entry
225
+     */
226
+    private function contactArrayToEntry(array $contact) {
227
+        $entry = new Entry();
228
+
229
+        if (isset($contact['id'])) {
230
+            $entry->setId($contact['id']);
231
+        }
232
+
233
+        if (isset($contact['FN'])) {
234
+            $entry->setFullName($contact['FN']);
235
+        }
236
+
237
+        $avatarPrefix = "VALUE=uri:";
238
+        if (isset($contact['PHOTO']) && strpos($contact['PHOTO'], $avatarPrefix) === 0) {
239
+            $entry->setAvatar(substr($contact['PHOTO'], strlen($avatarPrefix)));
240
+        }
241
+
242
+        if (isset($contact['EMAIL'])) {
243
+            foreach ($contact['EMAIL'] as $email) {
244
+                $entry->addEMailAddress($email);
245
+            }
246
+        }
247
+
248
+        // Attach all other properties to the entry too because some
249
+        // providers might make use of it.
250
+        $entry->setProperties($contact);
251
+
252
+        return $entry;
253
+    }
254 254
 
255 255
 }
Please login to merge, or discard this patch.