Passed
Push — master ( 2d262a...b5cf04 )
by Roeland
12:12 queued 12s
created
lib/private/Collaboration/Collaborators/UserPlugin.php 2 patches
Indentation   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -42,155 +42,155 @@
 block discarded – undo
42 42
 use OCP\Share\IShare;
43 43
 
44 44
 class UserPlugin implements ISearchPlugin {
45
-	/* @var bool */
46
-	protected $shareWithGroupOnly;
47
-	protected $shareeEnumeration;
48
-	protected $shareeEnumerationInGroupOnly;
49
-
50
-	/** @var IConfig */
51
-	private $config;
52
-	/** @var IGroupManager */
53
-	private $groupManager;
54
-	/** @var IUserSession */
55
-	private $userSession;
56
-	/** @var IUserManager */
57
-	private $userManager;
58
-
59
-	public function __construct(IConfig $config, IUserManager $userManager, IGroupManager $groupManager, IUserSession $userSession) {
60
-		$this->config = $config;
61
-
62
-		$this->groupManager = $groupManager;
63
-		$this->userSession = $userSession;
64
-		$this->userManager = $userManager;
65
-
66
-		$this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
67
-		$this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
68
-		$this->shareeEnumerationInGroupOnly = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes';
69
-	}
70
-
71
-	public function search($search, $limit, $offset, ISearchResult $searchResult) {
72
-		$result = ['wide' => [], 'exact' => []];
73
-		$users = [];
74
-		$hasMoreResults = false;
75
-
76
-		$userGroups = [];
77
-		if ($this->shareWithGroupOnly) {
78
-			// Search in all the groups this user is part of
79
-			$userGroups = $this->groupManager->getUserGroups($this->userSession->getUser());
80
-			foreach ($userGroups as $userGroup) {
81
-				$usersInGroup = $userGroup->searchDisplayName($search, $limit, $offset);
82
-				foreach ($usersInGroup as $user) {
83
-					$users[$user->getUID()] = $user;
84
-				}
85
-			}
86
-		} else {
87
-			// Search in all users
88
-			$usersTmp = $this->userManager->searchDisplayName($search, $limit, $offset);
89
-			$currentUserGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
90
-			foreach ($usersTmp as $user) {
91
-				if ($user->isEnabled()) { // Don't keep deactivated users
92
-					$users[$user->getUID()] = $user;
93
-				}
94
-			}
95
-		}
96
-
97
-		$this->takeOutCurrentUser($users);
98
-
99
-		if (!$this->shareeEnumeration || count($users) < $limit) {
100
-			$hasMoreResults = true;
101
-		}
102
-
103
-		$foundUserById = false;
104
-		$lowerSearch = strtolower($search);
105
-		foreach ($users as $uid => $user) {
106
-			$userDisplayName = $user->getDisplayName();
107
-			$userEmail = $user->getEMailAddress();
108
-			$uid = (string) $uid;
109
-			if (
110
-				strtolower($uid) === $lowerSearch ||
111
-				strtolower($userDisplayName) === $lowerSearch ||
112
-				strtolower($userEmail) === $lowerSearch
113
-			) {
114
-				if (strtolower($uid) === $lowerSearch) {
115
-					$foundUserById = true;
116
-				}
117
-				$result['exact'][] = [
118
-					'label' => $userDisplayName,
119
-					'value' => [
120
-						'shareType' => Share::SHARE_TYPE_USER,
121
-						'shareWith' => $uid,
122
-					],
123
-				];
124
-			} else {
125
-				$addToWideResults = false;
126
-				if ($this->shareeEnumeration && !$this->shareeEnumerationInGroupOnly) {
127
-					$addToWideResults = true;
128
-				}
129
-
130
-				if ($this->shareeEnumerationInGroupOnly) {
131
-					$commonGroups = array_intersect($currentUserGroups, $this->groupManager->getUserGroupIds($user));
132
-					if (!empty($commonGroups)) {
133
-						$addToWideResults = true;
134
-					}
135
-				}
136
-
137
-				if ($addToWideResults) {
138
-					$result['wide'][] = [
139
-						'label' => $userDisplayName,
140
-						'value' => [
141
-							'shareType' => IShare::TYPE_USER,
142
-							'shareWith' => $uid,
143
-						],
144
-					];
145
-				}
146
-			}
147
-		}
148
-
149
-		if ($offset === 0 && !$foundUserById) {
150
-			// On page one we try if the search result has a direct hit on the
151
-			// user id and if so, we add that to the exact match list
152
-			$user = $this->userManager->get($search);
153
-			if ($user instanceof IUser) {
154
-				$addUser = true;
155
-
156
-				if ($this->shareWithGroupOnly) {
157
-					// Only add, if we have a common group
158
-					$userGroupIds = array_map(function (IGroup $group) {
159
-						return $group->getGID();
160
-					}, $userGroups);
161
-					$commonGroups = array_intersect($userGroupIds, $this->groupManager->getUserGroupIds($user));
162
-					$addUser = !empty($commonGroups);
163
-				}
164
-
165
-				if ($addUser) {
166
-					$result['exact'][] = [
167
-						'label' => $user->getDisplayName(),
168
-						'value' => [
169
-							'shareType' => Share::SHARE_TYPE_USER,
170
-							'shareWith' => $user->getUID(),
171
-						],
172
-					];
173
-				}
174
-			}
175
-		}
176
-
177
-
178
-
179
-		$type = new SearchResultType('users');
180
-		$searchResult->addResultSet($type, $result['wide'], $result['exact']);
181
-		if (count($result['exact'])) {
182
-			$searchResult->markExactIdMatch($type);
183
-		}
184
-
185
-		return $hasMoreResults;
186
-	}
187
-
188
-	public function takeOutCurrentUser(array &$users) {
189
-		$currentUser = $this->userSession->getUser();
190
-		if (!is_null($currentUser)) {
191
-			if (isset($users[$currentUser->getUID()])) {
192
-				unset($users[$currentUser->getUID()]);
193
-			}
194
-		}
195
-	}
45
+    /* @var bool */
46
+    protected $shareWithGroupOnly;
47
+    protected $shareeEnumeration;
48
+    protected $shareeEnumerationInGroupOnly;
49
+
50
+    /** @var IConfig */
51
+    private $config;
52
+    /** @var IGroupManager */
53
+    private $groupManager;
54
+    /** @var IUserSession */
55
+    private $userSession;
56
+    /** @var IUserManager */
57
+    private $userManager;
58
+
59
+    public function __construct(IConfig $config, IUserManager $userManager, IGroupManager $groupManager, IUserSession $userSession) {
60
+        $this->config = $config;
61
+
62
+        $this->groupManager = $groupManager;
63
+        $this->userSession = $userSession;
64
+        $this->userManager = $userManager;
65
+
66
+        $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
67
+        $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
68
+        $this->shareeEnumerationInGroupOnly = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes';
69
+    }
70
+
71
+    public function search($search, $limit, $offset, ISearchResult $searchResult) {
72
+        $result = ['wide' => [], 'exact' => []];
73
+        $users = [];
74
+        $hasMoreResults = false;
75
+
76
+        $userGroups = [];
77
+        if ($this->shareWithGroupOnly) {
78
+            // Search in all the groups this user is part of
79
+            $userGroups = $this->groupManager->getUserGroups($this->userSession->getUser());
80
+            foreach ($userGroups as $userGroup) {
81
+                $usersInGroup = $userGroup->searchDisplayName($search, $limit, $offset);
82
+                foreach ($usersInGroup as $user) {
83
+                    $users[$user->getUID()] = $user;
84
+                }
85
+            }
86
+        } else {
87
+            // Search in all users
88
+            $usersTmp = $this->userManager->searchDisplayName($search, $limit, $offset);
89
+            $currentUserGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
90
+            foreach ($usersTmp as $user) {
91
+                if ($user->isEnabled()) { // Don't keep deactivated users
92
+                    $users[$user->getUID()] = $user;
93
+                }
94
+            }
95
+        }
96
+
97
+        $this->takeOutCurrentUser($users);
98
+
99
+        if (!$this->shareeEnumeration || count($users) < $limit) {
100
+            $hasMoreResults = true;
101
+        }
102
+
103
+        $foundUserById = false;
104
+        $lowerSearch = strtolower($search);
105
+        foreach ($users as $uid => $user) {
106
+            $userDisplayName = $user->getDisplayName();
107
+            $userEmail = $user->getEMailAddress();
108
+            $uid = (string) $uid;
109
+            if (
110
+                strtolower($uid) === $lowerSearch ||
111
+                strtolower($userDisplayName) === $lowerSearch ||
112
+                strtolower($userEmail) === $lowerSearch
113
+            ) {
114
+                if (strtolower($uid) === $lowerSearch) {
115
+                    $foundUserById = true;
116
+                }
117
+                $result['exact'][] = [
118
+                    'label' => $userDisplayName,
119
+                    'value' => [
120
+                        'shareType' => Share::SHARE_TYPE_USER,
121
+                        'shareWith' => $uid,
122
+                    ],
123
+                ];
124
+            } else {
125
+                $addToWideResults = false;
126
+                if ($this->shareeEnumeration && !$this->shareeEnumerationInGroupOnly) {
127
+                    $addToWideResults = true;
128
+                }
129
+
130
+                if ($this->shareeEnumerationInGroupOnly) {
131
+                    $commonGroups = array_intersect($currentUserGroups, $this->groupManager->getUserGroupIds($user));
132
+                    if (!empty($commonGroups)) {
133
+                        $addToWideResults = true;
134
+                    }
135
+                }
136
+
137
+                if ($addToWideResults) {
138
+                    $result['wide'][] = [
139
+                        'label' => $userDisplayName,
140
+                        'value' => [
141
+                            'shareType' => IShare::TYPE_USER,
142
+                            'shareWith' => $uid,
143
+                        ],
144
+                    ];
145
+                }
146
+            }
147
+        }
148
+
149
+        if ($offset === 0 && !$foundUserById) {
150
+            // On page one we try if the search result has a direct hit on the
151
+            // user id and if so, we add that to the exact match list
152
+            $user = $this->userManager->get($search);
153
+            if ($user instanceof IUser) {
154
+                $addUser = true;
155
+
156
+                if ($this->shareWithGroupOnly) {
157
+                    // Only add, if we have a common group
158
+                    $userGroupIds = array_map(function (IGroup $group) {
159
+                        return $group->getGID();
160
+                    }, $userGroups);
161
+                    $commonGroups = array_intersect($userGroupIds, $this->groupManager->getUserGroupIds($user));
162
+                    $addUser = !empty($commonGroups);
163
+                }
164
+
165
+                if ($addUser) {
166
+                    $result['exact'][] = [
167
+                        'label' => $user->getDisplayName(),
168
+                        'value' => [
169
+                            'shareType' => Share::SHARE_TYPE_USER,
170
+                            'shareWith' => $user->getUID(),
171
+                        ],
172
+                    ];
173
+                }
174
+            }
175
+        }
176
+
177
+
178
+
179
+        $type = new SearchResultType('users');
180
+        $searchResult->addResultSet($type, $result['wide'], $result['exact']);
181
+        if (count($result['exact'])) {
182
+            $searchResult->markExactIdMatch($type);
183
+        }
184
+
185
+        return $hasMoreResults;
186
+    }
187
+
188
+    public function takeOutCurrentUser(array &$users) {
189
+        $currentUser = $this->userSession->getUser();
190
+        if (!is_null($currentUser)) {
191
+            if (isset($users[$currentUser->getUID()])) {
192
+                unset($users[$currentUser->getUID()]);
193
+            }
194
+        }
195
+    }
196 196
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -155,7 +155,7 @@
 block discarded – undo
155 155
 
156 156
 				if ($this->shareWithGroupOnly) {
157 157
 					// Only add, if we have a common group
158
-					$userGroupIds = array_map(function (IGroup $group) {
158
+					$userGroupIds = array_map(function(IGroup $group) {
159 159
 						return $group->getGID();
160 160
 					}, $userGroups);
161 161
 					$commonGroups = array_intersect($userGroupIds, $this->groupManager->getUserGroupIds($user));
Please login to merge, or discard this patch.