Completed
Push — stable13 ( 331f70...5b9429 )
by Roeland
20:34 queued 10:03
created
apps/user_ldap/lib/User/Manager.php 2 patches
Indentation   +199 added lines, -199 removed lines patch added patch discarded remove patch
@@ -45,231 +45,231 @@
 block discarded – undo
45 45
  * cache
46 46
  */
47 47
 class Manager {
48
-	/** @var IUserTools */
49
-	protected $access;
48
+    /** @var IUserTools */
49
+    protected $access;
50 50
 
51
-	/** @var IConfig */
52
-	protected $ocConfig;
51
+    /** @var IConfig */
52
+    protected $ocConfig;
53 53
 
54
-	/** @var IDBConnection */
55
-	protected $db;
54
+    /** @var IDBConnection */
55
+    protected $db;
56 56
 
57
-	/** @var IUserManager */
58
-	protected $userManager;
57
+    /** @var IUserManager */
58
+    protected $userManager;
59 59
 
60
-	/** @var INotificationManager */
61
-	protected $notificationManager;
60
+    /** @var INotificationManager */
61
+    protected $notificationManager;
62 62
 
63
-	/** @var FilesystemHelper */
64
-	protected $ocFilesystem;
63
+    /** @var FilesystemHelper */
64
+    protected $ocFilesystem;
65 65
 
66
-	/** @var LogWrapper */
67
-	protected $ocLog;
66
+    /** @var LogWrapper */
67
+    protected $ocLog;
68 68
 
69
-	/** @var Image */
70
-	protected $image;
69
+    /** @var Image */
70
+    protected $image;
71 71
 
72
-	/** @param \OCP\IAvatarManager */
73
-	protected $avatarManager;
72
+    /** @param \OCP\IAvatarManager */
73
+    protected $avatarManager;
74 74
 
75
-	/**
76
-	 * @var CappedMemoryCache $usersByDN
77
-	 */
78
-	protected $usersByDN;
79
-	/**
80
-	 * @var CappedMemoryCache $usersByUid
81
-	 */
82
-	protected $usersByUid;
75
+    /**
76
+     * @var CappedMemoryCache $usersByDN
77
+     */
78
+    protected $usersByDN;
79
+    /**
80
+     * @var CappedMemoryCache $usersByUid
81
+     */
82
+    protected $usersByUid;
83 83
 
84
-	/**
85
-	 * @param IConfig $ocConfig
86
-	 * @param \OCA\User_LDAP\FilesystemHelper $ocFilesystem object that
87
-	 * gives access to necessary functions from the OC filesystem
88
-	 * @param  \OCA\User_LDAP\LogWrapper $ocLog
89
-	 * @param IAvatarManager $avatarManager
90
-	 * @param Image $image an empty image instance
91
-	 * @param IDBConnection $db
92
-	 * @throws \Exception when the methods mentioned above do not exist
93
-	 */
94
-	public function __construct(IConfig $ocConfig,
95
-								FilesystemHelper $ocFilesystem, LogWrapper $ocLog,
96
-								IAvatarManager $avatarManager, Image $image,
97
-								IDBConnection $db, IUserManager $userManager,
98
-								INotificationManager $notificationManager) {
84
+    /**
85
+     * @param IConfig $ocConfig
86
+     * @param \OCA\User_LDAP\FilesystemHelper $ocFilesystem object that
87
+     * gives access to necessary functions from the OC filesystem
88
+     * @param  \OCA\User_LDAP\LogWrapper $ocLog
89
+     * @param IAvatarManager $avatarManager
90
+     * @param Image $image an empty image instance
91
+     * @param IDBConnection $db
92
+     * @throws \Exception when the methods mentioned above do not exist
93
+     */
94
+    public function __construct(IConfig $ocConfig,
95
+                                FilesystemHelper $ocFilesystem, LogWrapper $ocLog,
96
+                                IAvatarManager $avatarManager, Image $image,
97
+                                IDBConnection $db, IUserManager $userManager,
98
+                                INotificationManager $notificationManager) {
99 99
 
100
-		$this->ocConfig            = $ocConfig;
101
-		$this->ocFilesystem        = $ocFilesystem;
102
-		$this->ocLog               = $ocLog;
103
-		$this->avatarManager       = $avatarManager;
104
-		$this->image               = $image;
105
-		$this->db                  = $db;
106
-		$this->userManager         = $userManager;
107
-		$this->notificationManager = $notificationManager;
108
-		$this->usersByDN           = new CappedMemoryCache();
109
-		$this->usersByUid          = new CappedMemoryCache();
110
-	}
100
+        $this->ocConfig            = $ocConfig;
101
+        $this->ocFilesystem        = $ocFilesystem;
102
+        $this->ocLog               = $ocLog;
103
+        $this->avatarManager       = $avatarManager;
104
+        $this->image               = $image;
105
+        $this->db                  = $db;
106
+        $this->userManager         = $userManager;
107
+        $this->notificationManager = $notificationManager;
108
+        $this->usersByDN           = new CappedMemoryCache();
109
+        $this->usersByUid          = new CappedMemoryCache();
110
+    }
111 111
 
112
-	/**
113
-	 * @brief binds manager to an instance of IUserTools (implemented by
114
-	 * Access). It needs to be assigned first before the manager can be used.
115
-	 * @param IUserTools
116
-	 */
117
-	public function setLdapAccess(IUserTools $access) {
118
-		$this->access = $access;
119
-	}
112
+    /**
113
+     * @brief binds manager to an instance of IUserTools (implemented by
114
+     * Access). It needs to be assigned first before the manager can be used.
115
+     * @param IUserTools
116
+     */
117
+    public function setLdapAccess(IUserTools $access) {
118
+        $this->access = $access;
119
+    }
120 120
 
121
-	/**
122
-	 * @brief creates an instance of User and caches (just runtime) it in the
123
-	 * property array
124
-	 * @param string $dn the DN of the user
125
-	 * @param string $uid the internal (owncloud) username
126
-	 * @return \OCA\User_LDAP\User\User
127
-	 */
128
-	private function createAndCache($dn, $uid) {
129
-		$this->checkAccess();
130
-		$user = new User($uid, $dn, $this->access, $this->ocConfig,
131
-			$this->ocFilesystem, clone $this->image, $this->ocLog,
132
-			$this->avatarManager, $this->userManager, 
133
-			$this->notificationManager);
134
-		$this->usersByDN[$dn]   = $user;
135
-		$this->usersByUid[$uid] = $user;
136
-		return $user;
137
-	}
121
+    /**
122
+     * @brief creates an instance of User and caches (just runtime) it in the
123
+     * property array
124
+     * @param string $dn the DN of the user
125
+     * @param string $uid the internal (owncloud) username
126
+     * @return \OCA\User_LDAP\User\User
127
+     */
128
+    private function createAndCache($dn, $uid) {
129
+        $this->checkAccess();
130
+        $user = new User($uid, $dn, $this->access, $this->ocConfig,
131
+            $this->ocFilesystem, clone $this->image, $this->ocLog,
132
+            $this->avatarManager, $this->userManager, 
133
+            $this->notificationManager);
134
+        $this->usersByDN[$dn]   = $user;
135
+        $this->usersByUid[$uid] = $user;
136
+        return $user;
137
+    }
138 138
 
139
-	/**
140
-	 * removes a user entry from the cache
141
-	 * @param $uid
142
-	 */
143
-	public function invalidate($uid) {
144
-		if(!isset($this->usersByUid[$uid])) {
145
-			return;
146
-		}
147
-		$dn = $this->usersByUid[$uid]->getDN();
148
-		unset($this->usersByUid[$uid]);
149
-		unset($this->usersByDN[$dn]);
150
-	}
139
+    /**
140
+     * removes a user entry from the cache
141
+     * @param $uid
142
+     */
143
+    public function invalidate($uid) {
144
+        if(!isset($this->usersByUid[$uid])) {
145
+            return;
146
+        }
147
+        $dn = $this->usersByUid[$uid]->getDN();
148
+        unset($this->usersByUid[$uid]);
149
+        unset($this->usersByDN[$dn]);
150
+    }
151 151
 
152
-	/**
153
-	 * @brief checks whether the Access instance has been set
154
-	 * @throws \Exception if Access has not been set
155
-	 * @return null
156
-	 */
157
-	private function checkAccess() {
158
-		if(is_null($this->access)) {
159
-			throw new \Exception('LDAP Access instance must be set first');
160
-		}
161
-	}
152
+    /**
153
+     * @brief checks whether the Access instance has been set
154
+     * @throws \Exception if Access has not been set
155
+     * @return null
156
+     */
157
+    private function checkAccess() {
158
+        if(is_null($this->access)) {
159
+            throw new \Exception('LDAP Access instance must be set first');
160
+        }
161
+    }
162 162
 
163
-	/**
164
-	 * returns a list of attributes that will be processed further, e.g. quota,
165
-	 * email, displayname, or others.
166
-	 *
167
-	 * @param bool $minimal - optional, set to true to skip attributes with big
168
-	 * payload
169
-	 * @return string[]
170
-	 */
171
-	public function getAttributes($minimal = false) {
172
-		$baseAttributes = array_merge(Access::UUID_ATTRIBUTES, ['dn', 'uid', 'samaccountname', 'memberof']);
173
-		$attributes = [
174
-			$this->access->getConnection()->ldapExpertUUIDUserAttr,
175
-			$this->access->getConnection()->ldapQuotaAttribute,
176
-			$this->access->getConnection()->ldapEmailAttribute,
177
-			$this->access->getConnection()->ldapUserDisplayName,
178
-			$this->access->getConnection()->ldapUserDisplayName2,
179
-		];
163
+    /**
164
+     * returns a list of attributes that will be processed further, e.g. quota,
165
+     * email, displayname, or others.
166
+     *
167
+     * @param bool $minimal - optional, set to true to skip attributes with big
168
+     * payload
169
+     * @return string[]
170
+     */
171
+    public function getAttributes($minimal = false) {
172
+        $baseAttributes = array_merge(Access::UUID_ATTRIBUTES, ['dn', 'uid', 'samaccountname', 'memberof']);
173
+        $attributes = [
174
+            $this->access->getConnection()->ldapExpertUUIDUserAttr,
175
+            $this->access->getConnection()->ldapQuotaAttribute,
176
+            $this->access->getConnection()->ldapEmailAttribute,
177
+            $this->access->getConnection()->ldapUserDisplayName,
178
+            $this->access->getConnection()->ldapUserDisplayName2,
179
+        ];
180 180
 
181
-		$homeRule = $this->access->getConnection()->homeFolderNamingRule;
182
-		if(strpos($homeRule, 'attr:') === 0) {
183
-			$attributes[] = substr($homeRule, strlen('attr:'));
184
-		}
181
+        $homeRule = $this->access->getConnection()->homeFolderNamingRule;
182
+        if(strpos($homeRule, 'attr:') === 0) {
183
+            $attributes[] = substr($homeRule, strlen('attr:'));
184
+        }
185 185
 
186
-		if(!$minimal) {
187
-			// attributes that are not really important but may come with big
188
-			// payload.
189
-			$attributes = array_merge(
190
-				$attributes,
191
-				$this->access->getConnection()->resolveRule('avatar')
192
-			);
193
-		}
186
+        if(!$minimal) {
187
+            // attributes that are not really important but may come with big
188
+            // payload.
189
+            $attributes = array_merge(
190
+                $attributes,
191
+                $this->access->getConnection()->resolveRule('avatar')
192
+            );
193
+        }
194 194
 
195
-		$attributes = array_reduce($attributes,
196
-			function($list, $attribute) {
197
-				$attribute = strtolower(trim((string)$attribute));
198
-				if(!empty($attribute) && !in_array($attribute, $list)) {
199
-					$list[] = $attribute;
200
-				}
195
+        $attributes = array_reduce($attributes,
196
+            function($list, $attribute) {
197
+                $attribute = strtolower(trim((string)$attribute));
198
+                if(!empty($attribute) && !in_array($attribute, $list)) {
199
+                    $list[] = $attribute;
200
+                }
201 201
 
202
-				return $list;
203
-			},
204
-			$baseAttributes // hard-coded, lower-case, non-empty attributes
205
-		);
202
+                return $list;
203
+            },
204
+            $baseAttributes // hard-coded, lower-case, non-empty attributes
205
+        );
206 206
 
207
-		return $attributes;
208
-	}
207
+        return $attributes;
208
+    }
209 209
 
210
-	/**
211
-	 * Checks whether the specified user is marked as deleted
212
-	 * @param string $id the Nextcloud user name
213
-	 * @return bool
214
-	 */
215
-	public function isDeletedUser($id) {
216
-		$isDeleted = $this->ocConfig->getUserValue(
217
-			$id, 'user_ldap', 'isDeleted', 0);
218
-		return intval($isDeleted) === 1;
219
-	}
210
+    /**
211
+     * Checks whether the specified user is marked as deleted
212
+     * @param string $id the Nextcloud user name
213
+     * @return bool
214
+     */
215
+    public function isDeletedUser($id) {
216
+        $isDeleted = $this->ocConfig->getUserValue(
217
+            $id, 'user_ldap', 'isDeleted', 0);
218
+        return intval($isDeleted) === 1;
219
+    }
220 220
 
221
-	/**
222
-	 * creates and returns an instance of OfflineUser for the specified user
223
-	 * @param string $id
224
-	 * @return \OCA\User_LDAP\User\OfflineUser
225
-	 */
226
-	public function getDeletedUser($id) {
227
-		return new OfflineUser(
228
-			$id,
229
-			$this->ocConfig,
230
-			$this->db,
231
-			$this->access->getUserMapper());
232
-	}
221
+    /**
222
+     * creates and returns an instance of OfflineUser for the specified user
223
+     * @param string $id
224
+     * @return \OCA\User_LDAP\User\OfflineUser
225
+     */
226
+    public function getDeletedUser($id) {
227
+        return new OfflineUser(
228
+            $id,
229
+            $this->ocConfig,
230
+            $this->db,
231
+            $this->access->getUserMapper());
232
+    }
233 233
 
234
-	/**
235
-	 * @brief returns a User object by it's Nextcloud username
236
-	 * @param string $id the DN or username of the user
237
-	 * @return \OCA\User_LDAP\User\User|\OCA\User_LDAP\User\OfflineUser|null
238
-	 */
239
-	protected function createInstancyByUserName($id) {
240
-		//most likely a uid. Check whether it is a deleted user
241
-		if($this->isDeletedUser($id)) {
242
-			return $this->getDeletedUser($id);
243
-		}
244
-		$dn = $this->access->username2dn($id);
245
-		if($dn !== false) {
246
-			return $this->createAndCache($dn, $id);
247
-		}
248
-		return null;
249
-	}
234
+    /**
235
+     * @brief returns a User object by it's Nextcloud username
236
+     * @param string $id the DN or username of the user
237
+     * @return \OCA\User_LDAP\User\User|\OCA\User_LDAP\User\OfflineUser|null
238
+     */
239
+    protected function createInstancyByUserName($id) {
240
+        //most likely a uid. Check whether it is a deleted user
241
+        if($this->isDeletedUser($id)) {
242
+            return $this->getDeletedUser($id);
243
+        }
244
+        $dn = $this->access->username2dn($id);
245
+        if($dn !== false) {
246
+            return $this->createAndCache($dn, $id);
247
+        }
248
+        return null;
249
+    }
250 250
 
251
-	/**
252
-	 * @brief returns a User object by it's DN or Nextcloud username
253
-	 * @param string $id the DN or username of the user
254
-	 * @return \OCA\User_LDAP\User\User|\OCA\User_LDAP\User\OfflineUser|null
255
-	 * @throws \Exception when connection could not be established
256
-	 */
257
-	public function get($id) {
258
-		$this->checkAccess();
259
-		if(isset($this->usersByDN[$id])) {
260
-			return $this->usersByDN[$id];
261
-		} else if(isset($this->usersByUid[$id])) {
262
-			return $this->usersByUid[$id];
263
-		}
251
+    /**
252
+     * @brief returns a User object by it's DN or Nextcloud username
253
+     * @param string $id the DN or username of the user
254
+     * @return \OCA\User_LDAP\User\User|\OCA\User_LDAP\User\OfflineUser|null
255
+     * @throws \Exception when connection could not be established
256
+     */
257
+    public function get($id) {
258
+        $this->checkAccess();
259
+        if(isset($this->usersByDN[$id])) {
260
+            return $this->usersByDN[$id];
261
+        } else if(isset($this->usersByUid[$id])) {
262
+            return $this->usersByUid[$id];
263
+        }
264 264
 
265
-		if($this->access->stringResemblesDN($id) ) {
266
-			$uid = $this->access->dn2username($id);
267
-			if($uid !== false) {
268
-				return $this->createAndCache($id, $uid);
269
-			}
270
-		}
265
+        if($this->access->stringResemblesDN($id) ) {
266
+            $uid = $this->access->dn2username($id);
267
+            if($uid !== false) {
268
+                return $this->createAndCache($id, $uid);
269
+            }
270
+        }
271 271
 
272
-		return $this->createInstancyByUserName($id);
273
-	}
272
+        return $this->createInstancyByUserName($id);
273
+    }
274 274
 
275 275
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 	 * @param $uid
142 142
 	 */
143 143
 	public function invalidate($uid) {
144
-		if(!isset($this->usersByUid[$uid])) {
144
+		if (!isset($this->usersByUid[$uid])) {
145 145
 			return;
146 146
 		}
147 147
 		$dn = $this->usersByUid[$uid]->getDN();
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 	 * @return null
156 156
 	 */
157 157
 	private function checkAccess() {
158
-		if(is_null($this->access)) {
158
+		if (is_null($this->access)) {
159 159
 			throw new \Exception('LDAP Access instance must be set first');
160 160
 		}
161 161
 	}
@@ -179,11 +179,11 @@  discard block
 block discarded – undo
179 179
 		];
180 180
 
181 181
 		$homeRule = $this->access->getConnection()->homeFolderNamingRule;
182
-		if(strpos($homeRule, 'attr:') === 0) {
182
+		if (strpos($homeRule, 'attr:') === 0) {
183 183
 			$attributes[] = substr($homeRule, strlen('attr:'));
184 184
 		}
185 185
 
186
-		if(!$minimal) {
186
+		if (!$minimal) {
187 187
 			// attributes that are not really important but may come with big
188 188
 			// payload.
189 189
 			$attributes = array_merge(
@@ -194,8 +194,8 @@  discard block
 block discarded – undo
194 194
 
195 195
 		$attributes = array_reduce($attributes,
196 196
 			function($list, $attribute) {
197
-				$attribute = strtolower(trim((string)$attribute));
198
-				if(!empty($attribute) && !in_array($attribute, $list)) {
197
+				$attribute = strtolower(trim((string) $attribute));
198
+				if (!empty($attribute) && !in_array($attribute, $list)) {
199 199
 					$list[] = $attribute;
200 200
 				}
201 201
 
@@ -238,11 +238,11 @@  discard block
 block discarded – undo
238 238
 	 */
239 239
 	protected function createInstancyByUserName($id) {
240 240
 		//most likely a uid. Check whether it is a deleted user
241
-		if($this->isDeletedUser($id)) {
241
+		if ($this->isDeletedUser($id)) {
242 242
 			return $this->getDeletedUser($id);
243 243
 		}
244 244
 		$dn = $this->access->username2dn($id);
245
-		if($dn !== false) {
245
+		if ($dn !== false) {
246 246
 			return $this->createAndCache($dn, $id);
247 247
 		}
248 248
 		return null;
@@ -256,15 +256,15 @@  discard block
 block discarded – undo
256 256
 	 */
257 257
 	public function get($id) {
258 258
 		$this->checkAccess();
259
-		if(isset($this->usersByDN[$id])) {
259
+		if (isset($this->usersByDN[$id])) {
260 260
 			return $this->usersByDN[$id];
261
-		} else if(isset($this->usersByUid[$id])) {
261
+		} else if (isset($this->usersByUid[$id])) {
262 262
 			return $this->usersByUid[$id];
263 263
 		}
264 264
 
265
-		if($this->access->stringResemblesDN($id) ) {
265
+		if ($this->access->stringResemblesDN($id)) {
266 266
 			$uid = $this->access->dn2username($id);
267
-			if($uid !== false) {
267
+			if ($uid !== false) {
268 268
 				return $this->createAndCache($id, $uid);
269 269
 			}
270 270
 		}
Please login to merge, or discard this patch.