Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce names for user backends - via IUserBackend #12819

Merged
merged 1 commit into from Dec 19, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion apps/user_ldap/user_ldap.php
Expand Up @@ -27,7 +27,7 @@

use OCA\user_ldap\lib\BackendUtility;

class USER_LDAP extends BackendUtility implements \OCP\UserInterface {
class USER_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserInterface {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is also necessary for user_proxy.php, i can take care of it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done with fed45af

/**
* checks whether the user is allowed to change his avatar in ownCloud
* @param string $uid the ownCloud user name
Expand Down Expand Up @@ -299,4 +299,13 @@ public function countUsers() {
$this->access->connection->writeToCache($cacheKey, $entries);
return $entries;
}

/**
* Backend name to be shown in user management
* @return string the name of the backend to be shown
*/
public function getBackendName(){
return 'LDAP';
}

}
10 changes: 9 additions & 1 deletion apps/user_ldap/user_proxy.php
Expand Up @@ -25,7 +25,7 @@

use OCA\user_ldap\lib\ILDAPWrapper;

class User_Proxy extends lib\Proxy implements \OCP\UserInterface {
class User_Proxy extends lib\Proxy implements \OCP\IUserBackend, \OCP\UserInterface {
private $backends = array();
private $refBackend = null;

Expand Down Expand Up @@ -117,6 +117,14 @@ public function implementsActions($actions) {
return $this->refBackend->implementsActions($actions);
}

/**
* Backend name to be shown in user management
* @return string the name of the backend to be shown
*/
public function getBackendName() {
return $this->refBackend->getBackendName();
}

/**
* Get a list of all users
* @return string[] with all uids
Expand Down
10 changes: 9 additions & 1 deletion apps/user_webdavauth/user_webdavauth.php
Expand Up @@ -21,7 +21,7 @@
*
*/

class OC_USER_WEBDAVAUTH extends OC_User_Backend {
class OC_USER_WEBDAVAUTH extends OC_User_Backend implements \OCP\IUserBackend {
protected $webdavauth_url;

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

return $returnArray;
}

/**
* Backend name to be shown in user management
* @return string the name of the backend to be shown
*/
public function getBackendName(){
return 'WebDAV';
}
}
10 changes: 9 additions & 1 deletion lib/private/user/database.php
Expand Up @@ -36,7 +36,7 @@
/**
* Class for user management in a SQL Database (e.g. MySQL, SQLite)
*/
class OC_User_Database extends OC_User_Backend {
class OC_User_Database extends OC_User_Backend implements \OCP\IUserBackend {
private $cache = array();

/**
Expand Down Expand Up @@ -260,4 +260,12 @@ public function countUsers() {
return $result->fetchOne();
}

/**
* Backend name to be shown in user management
* @return string the name of the backend to be shown
*/
public function getBackendName(){
return 'Database';
}

}
10 changes: 9 additions & 1 deletion lib/private/user/dummy.php
Expand Up @@ -24,7 +24,7 @@
/**
* dummy user backend, does not keep state, only for testing use
*/
class OC_User_Dummy extends OC_User_Backend {
class OC_User_Dummy extends OC_User_Backend implements \OCP\IUserBackend {
private $users = array();
private $displayNames = array();

Expand Down Expand Up @@ -156,4 +156,12 @@ public function setDisplayName($uid, $displayName) {
public function getDisplayName($uid) {
return isset($this->displayNames[$uid])? $this->displayNames[$uid]: $uid;
}

/**
* Backend name to be shown in user management
* @return string the name of the backend to be shown
*/
public function getBackendName(){
return 'Dummy';
}
}
10 changes: 9 additions & 1 deletion lib/private/user/http.php
Expand Up @@ -24,7 +24,7 @@
/**
* user backend using http auth requests
*/
class OC_User_HTTP extends OC_User_Backend {
class OC_User_HTTP extends OC_User_Backend implements \OCP\IUserBackend {
/**
* split http://user@host/path into a user and url part
* @param string $url
Expand Down Expand Up @@ -109,4 +109,12 @@ public function getHome($uid) {
return false;
}
}

/**
* Backend name to be shown in user management
* @return string the name of the backend to be shown
*/
public function getBackendName(){
return 'HTTP';
}
}
11 changes: 8 additions & 3 deletions lib/private/user/manager.php
Expand Up @@ -279,10 +279,15 @@ public function countUsers() {
if ($backend->implementsActions(\OC_User_Backend::COUNT_USERS)) {
$backendusers = $backend->countUsers();
if($backendusers !== false) {
if(isset($userCountStatistics[get_class($backend)])) {
$userCountStatistics[get_class($backend)] += $backendusers;
if($backend instanceof \OCP\IUserBackend) {
$name = $backend->getBackendName();
} else {
$userCountStatistics[get_class($backend)] = $backendusers;
$name = get_class($backend);
}
if(isset($userCountStatistics[$name])) {
$userCountStatistics[$name] += $backendusers;
} else {
$userCountStatistics[$name] = $backendusers;
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions lib/private/user/user.php
Expand Up @@ -225,6 +225,9 @@ public function getHome() {
* @return string
*/
public function getBackendClassName() {
if($this->backend instanceof \OCP\IUserBackend) {
return $this->backend->getBackendName();
}
return get_class($this->backend);
}

Expand Down
27 changes: 27 additions & 0 deletions lib/public/iuserbackend.php
@@ -0,0 +1,27 @@
<?php
/**
* Copyright (c) 2014 Morris Jobke <hey@morrisjobke.de>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/

/**
* Public interface of ownCloud for apps to use.
* User Interface version 2
*
*/

// use OCP namespace for all classes that are considered public.
// This means that they should be used by apps instead of the internal ownCloud classes
namespace OCP;

interface IUserBackend {

/**
* Backend name to be shown in user management
* @return string the name of the backend to be shown
*/
public function getBackendName();

}
10 changes: 10 additions & 0 deletions tests/lib/user/manager.php
Expand Up @@ -380,6 +380,10 @@ public function testCountUsersOneBackend() {
->with(\OC_USER_BACKEND_COUNT_USERS)
->will($this->returnValue(true));

$backend->expects($this->once())
->method('getBackendName')
->will($this->returnValue('Mock_OC_User_Dummy'));

$manager = new \OC\User\Manager();
$manager->registerBackend($backend);

Expand All @@ -404,6 +408,9 @@ public function testCountUsersTwoBackends() {
->method('implementsActions')
->with(\OC_USER_BACKEND_COUNT_USERS)
->will($this->returnValue(true));
$backend1->expects($this->once())
->method('getBackendName')
->will($this->returnValue('Mock_OC_User_Dummy'));

$backend2 = $this->getMock('\OC_User_Dummy');
$backend2->expects($this->once())
Expand All @@ -414,6 +421,9 @@ public function testCountUsersTwoBackends() {
->method('implementsActions')
->with(\OC_USER_BACKEND_COUNT_USERS)
->will($this->returnValue(true));
$backend2->expects($this->once())
->method('getBackendName')
->will($this->returnValue('Mock_OC_User_Dummy'));

$manager = new \OC\User\Manager();
$manager->registerBackend($backend1);
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/user/user.php
Expand Up @@ -217,9 +217,9 @@ public function testGetHome() {

public function testGetBackendClassName() {
$user = new \OC\User\User('foo', new \OC_User_Dummy());
$this->assertEquals('OC_User_Dummy', $user->getBackendClassName());
$this->assertEquals('Dummy', $user->getBackendClassName());
$user = new \OC\User\User('foo', new \OC_User_Database());
$this->assertEquals('OC_User_Database', $user->getBackendClassName());
$this->assertEquals('Database', $user->getBackendClassName());
}

public function testGetHomeNotSupported() {
Expand Down