Skip to content

Commit 6da33e1

Browse files
committed
introduce names for user backends - IUserBackend
* LDAP with multiple servers also proved backendName
1 parent 5c6e082 commit 6da33e1

File tree

11 files changed

+105
-11
lines changed

11 files changed

+105
-11
lines changed

apps/user_ldap/user_ldap.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
use OCA\user_ldap\lib\BackendUtility;
2929

30-
class USER_LDAP extends BackendUtility implements \OCP\UserInterface {
30+
class USER_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserInterface {
3131
/**
3232
* checks whether the user is allowed to change his avatar in ownCloud
3333
* @param string $uid the ownCloud user name
@@ -299,4 +299,13 @@ public function countUsers() {
299299
$this->access->connection->writeToCache($cacheKey, $entries);
300300
return $entries;
301301
}
302+
303+
/**
304+
* Backend name to be shown in user management
305+
* @return string the name of the backend to be shown
306+
*/
307+
public function getBackendName(){
308+
return 'LDAP';
309+
}
310+
302311
}

apps/user_ldap/user_proxy.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
use OCA\user_ldap\lib\ILDAPWrapper;
2727

28-
class User_Proxy extends lib\Proxy implements \OCP\UserInterface {
28+
class User_Proxy extends lib\Proxy implements \OCP\IUserBackend, \OCP\UserInterface {
2929
private $backends = array();
3030
private $refBackend = null;
3131

@@ -117,6 +117,14 @@ public function implementsActions($actions) {
117117
return $this->refBackend->implementsActions($actions);
118118
}
119119

120+
/**
121+
* Backend name to be shown in user management
122+
* @return string the name of the backend to be shown
123+
*/
124+
public function getBackendName() {
125+
return $this->refBackend->getBackendName();
126+
}
127+
120128
/**
121129
* Get a list of all users
122130
* @return string[] with all uids

apps/user_webdavauth/user_webdavauth.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
*/
2323

24-
class OC_USER_WEBDAVAUTH extends OC_User_Backend {
24+
class OC_USER_WEBDAVAUTH extends OC_User_Backend implements \OCP\IUserBackend {
2525
protected $webdavauth_url;
2626

2727
public function __construct() {
@@ -86,4 +86,12 @@ public function getUsers($search = '', $limit = 10, $offset = 0) {
8686

8787
return $returnArray;
8888
}
89+
90+
/**
91+
* Backend name to be shown in user management
92+
* @return string the name of the backend to be shown
93+
*/
94+
public function getBackendName(){
95+
return 'WebDAV';
96+
}
8997
}

lib/private/user/database.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
/**
3737
* Class for user management in a SQL Database (e.g. MySQL, SQLite)
3838
*/
39-
class OC_User_Database extends OC_User_Backend {
39+
class OC_User_Database extends OC_User_Backend implements \OCP\IUserBackend {
4040
private $cache = array();
4141

4242
/**
@@ -260,4 +260,12 @@ public function countUsers() {
260260
return $result->fetchOne();
261261
}
262262

263+
/**
264+
* Backend name to be shown in user management
265+
* @return string the name of the backend to be shown
266+
*/
267+
public function getBackendName(){
268+
return 'Database';
269+
}
270+
263271
}

lib/private/user/dummy.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
/**
2525
* dummy user backend, does not keep state, only for testing use
2626
*/
27-
class OC_User_Dummy extends OC_User_Backend {
27+
class OC_User_Dummy extends OC_User_Backend implements \OCP\IUserBackend {
2828
private $users = array();
2929
private $displayNames = array();
3030

@@ -156,4 +156,12 @@ public function setDisplayName($uid, $displayName) {
156156
public function getDisplayName($uid) {
157157
return isset($this->displayNames[$uid])? $this->displayNames[$uid]: $uid;
158158
}
159+
160+
/**
161+
* Backend name to be shown in user management
162+
* @return string the name of the backend to be shown
163+
*/
164+
public function getBackendName(){
165+
return 'Dummy';
166+
}
159167
}

lib/private/user/http.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
/**
2525
* user backend using http auth requests
2626
*/
27-
class OC_User_HTTP extends OC_User_Backend {
27+
class OC_User_HTTP extends OC_User_Backend implements \OCP\IUserBackend {
2828
/**
2929
* split http://user@host/path into a user and url part
3030
* @param string $url
@@ -109,4 +109,12 @@ public function getHome($uid) {
109109
return false;
110110
}
111111
}
112+
113+
/**
114+
* Backend name to be shown in user management
115+
* @return string the name of the backend to be shown
116+
*/
117+
public function getBackendName(){
118+
return 'HTTP';
119+
}
112120
}

lib/private/user/manager.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,15 @@ public function countUsers() {
279279
if ($backend->implementsActions(\OC_User_Backend::COUNT_USERS)) {
280280
$backendusers = $backend->countUsers();
281281
if($backendusers !== false) {
282-
if(isset($userCountStatistics[get_class($backend)])) {
283-
$userCountStatistics[get_class($backend)] += $backendusers;
282+
if($backend instanceof \OCP\IUserBackend) {
283+
$name = $backend->getBackendName();
284284
} else {
285-
$userCountStatistics[get_class($backend)] = $backendusers;
285+
$name = get_class($backend);
286+
}
287+
if(isset($userCountStatistics[$name])) {
288+
$userCountStatistics[$name] += $backendusers;
289+
} else {
290+
$userCountStatistics[$name] = $backendusers;
286291
}
287292
}
288293
}

lib/private/user/user.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ public function getHome() {
225225
* @return string
226226
*/
227227
public function getBackendClassName() {
228+
if($this->backend instanceof \OCP\IUserBackend) {
229+
return $this->backend->getBackendName();
230+
}
228231
return get_class($this->backend);
229232
}
230233

lib/public/iuserbackend.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Copyright (c) 2014 Morris Jobke <[email protected]>
4+
* This file is licensed under the Affero General Public License version 3 or
5+
* later.
6+
* See the COPYING-README file.
7+
*/
8+
9+
/**
10+
* Public interface of ownCloud for apps to use.
11+
* User Interface version 2
12+
*
13+
*/
14+
15+
// use OCP namespace for all classes that are considered public.
16+
// This means that they should be used by apps instead of the internal ownCloud classes
17+
namespace OCP;
18+
19+
interface IUserBackend {
20+
21+
/**
22+
* Backend name to be shown in user management
23+
* @return string the name of the backend to be shown
24+
*/
25+
public function getBackendName();
26+
27+
}

tests/lib/user/manager.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,10 @@ public function testCountUsersOneBackend() {
380380
->with(\OC_USER_BACKEND_COUNT_USERS)
381381
->will($this->returnValue(true));
382382

383+
$backend->expects($this->once())
384+
->method('getBackendName')
385+
->will($this->returnValue('Mock_OC_User_Dummy'));
386+
383387
$manager = new \OC\User\Manager();
384388
$manager->registerBackend($backend);
385389

@@ -404,6 +408,9 @@ public function testCountUsersTwoBackends() {
404408
->method('implementsActions')
405409
->with(\OC_USER_BACKEND_COUNT_USERS)
406410
->will($this->returnValue(true));
411+
$backend1->expects($this->once())
412+
->method('getBackendName')
413+
->will($this->returnValue('Mock_OC_User_Dummy'));
407414

408415
$backend2 = $this->getMock('\OC_User_Dummy');
409416
$backend2->expects($this->once())
@@ -414,6 +421,9 @@ public function testCountUsersTwoBackends() {
414421
->method('implementsActions')
415422
->with(\OC_USER_BACKEND_COUNT_USERS)
416423
->will($this->returnValue(true));
424+
$backend2->expects($this->once())
425+
->method('getBackendName')
426+
->will($this->returnValue('Mock_OC_User_Dummy'));
417427

418428
$manager = new \OC\User\Manager();
419429
$manager->registerBackend($backend1);

0 commit comments

Comments
 (0)