Merge pull request #12470 from owncloud/jenkins-12447

Jenkins 12447
This commit is contained in:
Lukas Reschke 2014-11-27 15:16:14 +01:00
commit af56429a9a
8 changed files with 80 additions and 33 deletions

View File

@ -23,29 +23,51 @@
/**
* error code for functions not provided by the group backend
* @deprecated Use \OC_Group_Backend::NOT_IMPLEMENTED instead
*/
define('OC_GROUP_BACKEND_NOT_IMPLEMENTED', -501);
/**
* actions that user backends can define
*/
/** @deprecated Use \OC_Group_Backend::CREATE_GROUP instead */
define('OC_GROUP_BACKEND_CREATE_GROUP', 0x00000001);
/** @deprecated Use \OC_Group_Backend::DELETE_GROUP instead */
define('OC_GROUP_BACKEND_DELETE_GROUP', 0x00000010);
/** @deprecated Use \OC_Group_Backend::ADD_TO_GROUP instead */
define('OC_GROUP_BACKEND_ADD_TO_GROUP', 0x00000100);
/** @deprecated Use \OC_Group_Backend::REMOVE_FROM_GOUP instead */
define('OC_GROUP_BACKEND_REMOVE_FROM_GOUP', 0x00001000);
/** @deprecated Obsolete */
define('OC_GROUP_BACKEND_GET_DISPLAYNAME', 0x00010000); //OBSOLETE
/** @deprecated Use \OC_Group_Backend::COUNT_USERS instead */
define('OC_GROUP_BACKEND_COUNT_USERS', 0x00100000);
/**
* Abstract base class for user management
*/
abstract class OC_Group_Backend implements OC_Group_Interface {
/**
* error code for functions not provided by the group backend
*/
const NOT_IMPLEMENTED = -501;
/**
* actions that user backends can define
*/
const CREATE_GROUP = 0x00000001;
const DELETE_GROUP = 0x00000010;
const ADD_TO_GROUP = 0x00000100;
const REMOVE_FROM_GOUP = 0x00001000;
//OBSOLETE const GET_DISPLAYNAME = 0x00010000;
const COUNT_USERS = 0x00100000;
protected $possibleActions = array(
OC_GROUP_BACKEND_CREATE_GROUP => 'createGroup',
OC_GROUP_BACKEND_DELETE_GROUP => 'deleteGroup',
OC_GROUP_BACKEND_ADD_TO_GROUP => 'addToGroup',
OC_GROUP_BACKEND_REMOVE_FROM_GOUP => 'removeFromGroup',
OC_GROUP_BACKEND_COUNT_USERS => 'countUsersInGroup',
self::CREATE_GROUP => 'createGroup',
self::DELETE_GROUP => 'deleteGroup',
self::ADD_TO_GROUP => 'addToGroup',
self::REMOVE_FROM_GOUP => 'removeFromGroup',
self::COUNT_USERS => 'countUsersInGroup',
);
/**

View File

@ -118,7 +118,7 @@ class Group implements IGroup {
$this->emitter->emit('\OC\Group', 'preAddUser', array($this, $user));
}
foreach ($this->backends as $backend) {
if ($backend->implementsActions(OC_GROUP_BACKEND_ADD_TO_GROUP)) {
if ($backend->implementsActions(\OC_Group_Backend::ADD_TO_GROUP)) {
$backend->addToGroup($user->getUID(), $this->gid);
if ($this->users) {
$this->users[$user->getUID()] = $user;
@ -142,7 +142,7 @@ class Group implements IGroup {
$this->emitter->emit('\OC\Group', 'preRemoveUser', array($this, $user));
}
foreach ($this->backends as $backend) {
if ($backend->implementsActions(OC_GROUP_BACKEND_REMOVE_FROM_GOUP) and $backend->inGroup($user->getUID(), $this->gid)) {
if ($backend->implementsActions(\OC_Group_Backend::REMOVE_FROM_GOUP) and $backend->inGroup($user->getUID(), $this->gid)) {
$backend->removeFromGroup($user->getUID(), $this->gid);
$result = true;
}
@ -191,7 +191,7 @@ class Group implements IGroup {
public function count($search = '') {
$users = false;
foreach ($this->backends as $backend) {
if($backend->implementsActions(OC_GROUP_BACKEND_COUNT_USERS)) {
if($backend->implementsActions(\OC_Group_Backend::COUNT_USERS)) {
if($users === false) {
//we could directly add to a bool variable, but this would
//be ugly
@ -234,7 +234,7 @@ class Group implements IGroup {
$this->emitter->emit('\OC\Group', 'preDelete', array($this));
}
foreach ($this->backends as $backend) {
if ($backend->implementsActions(OC_GROUP_BACKEND_DELETE_GROUP)) {
if ($backend->implementsActions(\OC_Group_Backend::DELETE_GROUP)) {
$result = true;
$backend->deleteGroup($this->gid);
}

View File

@ -28,7 +28,7 @@ interface OC_Group_Interface {
* @return boolean
*
* Returns the supported actions as int to be
* compared with OC_GROUP_BACKEND_CREATE_GROUP etc.
* compared with \OC_Group_Backend::CREATE_GROUP etc.
*/
public function implementsActions($actions);

View File

@ -134,7 +134,7 @@ class Manager extends PublicEmitter implements IGroupManager {
} else {
$this->emit('\OC\Group', 'preCreate', array($gid));
foreach ($this->backends as $backend) {
if ($backend->implementsActions(OC_GROUP_BACKEND_CREATE_GROUP)) {
if ($backend->implementsActions(\OC_Group_Backend::CREATE_GROUP)) {
$backend->createGroup($gid);
$group = $this->getGroupObject($gid);
$this->emit('\OC\Group', 'postCreate', array($group));

View File

@ -25,19 +25,28 @@
/**
* error code for functions not provided by the user backend
* @deprecated Use \OC_User_Backend::NOT_IMPLEMENTED instead
*/
define('OC_USER_BACKEND_NOT_IMPLEMENTED', -501);
/**
* actions that user backends can define
*/
/** @deprecated Use \OC_User_Backend::CREATE_USER instead */
define('OC_USER_BACKEND_CREATE_USER', 1 << 0);
/** @deprecated Use \OC_User_Backend::SET_PASSWORD instead */
define('OC_USER_BACKEND_SET_PASSWORD', 1 << 4);
/** @deprecated Use \OC_User_Backend::CHECK_PASSWORD instead */
define('OC_USER_BACKEND_CHECK_PASSWORD', 1 << 8);
/** @deprecated Use \OC_User_Backend::GET_HOME instead */
define('OC_USER_BACKEND_GET_HOME', 1 << 12);
/** @deprecated Use \OC_User_Backend::GET_DISPLAYNAME instead */
define('OC_USER_BACKEND_GET_DISPLAYNAME', 1 << 16);
/** @deprecated Use \OC_User_Backend::SET_DISPLAYNAME instead */
define('OC_USER_BACKEND_SET_DISPLAYNAME', 1 << 20);
/** @deprecated Use \OC_User_Backend::PROVIDE_AVATAR instead */
define('OC_USER_BACKEND_PROVIDE_AVATAR', 1 << 24);
/** @deprecated Use \OC_User_Backend::COUNT_USERS instead */
define('OC_USER_BACKEND_COUNT_USERS', 1 << 28);
/**
@ -47,16 +56,32 @@ define('OC_USER_BACKEND_COUNT_USERS', 1 << 28);
* Subclass this for your own backends, and see OC_User_Example for descriptions
*/
abstract class OC_User_Backend implements OC_User_Interface {
/**
* error code for functions not provided by the user backend
*/
const NOT_IMPLEMENTED = -501;
/**
* actions that user backends can define
*/
const CREATE_USER = 1; // 1 << 0
const SET_PASSWORD = 16; // 1 << 4
const CHECK_PASSWORD = 256; // 1 << 8
const GET_HOME = 4096; // 1 << 12
const GET_DISPLAYNAME = 65536; // 1 << 16
const SET_DISPLAYNAME = 1048576; // 1 << 20
const PROVIDE_AVATAR = 16777216; // 1 << 24
const COUNT_USERS = 268435456; // 1 << 28
protected $possibleActions = array(
OC_USER_BACKEND_CREATE_USER => 'createUser',
OC_USER_BACKEND_SET_PASSWORD => 'setPassword',
OC_USER_BACKEND_CHECK_PASSWORD => 'checkPassword',
OC_USER_BACKEND_GET_HOME => 'getHome',
OC_USER_BACKEND_GET_DISPLAYNAME => 'getDisplayName',
OC_USER_BACKEND_SET_DISPLAYNAME => 'setDisplayName',
OC_USER_BACKEND_PROVIDE_AVATAR => 'canChangeAvatar',
OC_USER_BACKEND_COUNT_USERS => 'countUsers',
self::CREATE_USER => 'createUser',
self::SET_PASSWORD => 'setPassword',
self::CHECK_PASSWORD => 'checkPassword',
self::GET_HOME => 'getHome',
self::GET_DISPLAYNAME => 'getDisplayName',
self::SET_DISPLAYNAME => 'setDisplayName',
self::PROVIDE_AVATAR => 'canChangeAvatar',
self::COUNT_USERS => 'countUsers',
);
/**
@ -64,7 +89,7 @@ abstract class OC_User_Backend implements OC_User_Interface {
* @return int bitwise-or'ed actions
*
* Returns the supported actions as int to be
* compared with OC_USER_BACKEND_CREATE_USER etc.
* compared with self::CREATE_USER etc.
*/
public function getSupportedActions() {
$actions = 0;
@ -83,7 +108,7 @@ abstract class OC_User_Backend implements OC_User_Interface {
* @return boolean
*
* Returns the supported actions as int to be
* compared with OC_USER_BACKEND_CREATE_USER etc.
* compared with self::CREATE_USER etc.
*/
public function implementsActions($actions) {
return (bool)($this->getSupportedActions() & $actions);

View File

@ -25,11 +25,11 @@ interface OC_User_Interface {
/**
* Check if backend implements actions
* @param $actions bitwise-or'ed actions
* @param int $actions bitwise-or'ed actions
* @return boolean
*
* Returns the supported actions as int to be
* compared with OC_USER_BACKEND_CREATE_USER etc.
* compared with \OC_User_Backend::CREATE_USER etc.
*/
public function implementsActions($actions);

View File

@ -143,7 +143,7 @@ class Manager extends PublicEmitter implements IUserManager {
*/
public function checkPassword($loginname, $password) {
foreach ($this->backends as $backend) {
if ($backend->implementsActions(\OC_USER_BACKEND_CHECK_PASSWORD)) {
if ($backend->implementsActions(\OC_User_Backend::CHECK_PASSWORD)) {
$uid = $backend->checkPassword($loginname, $password);
if ($uid !== false) {
return $this->getUserObject($uid, $backend);
@ -246,7 +246,7 @@ class Manager extends PublicEmitter implements IUserManager {
$this->emit('\OC\User', 'preCreateUser', array($uid, $password));
foreach ($this->backends as $backend) {
if ($backend->implementsActions(\OC_USER_BACKEND_CREATE_USER)) {
if ($backend->implementsActions(\OC_User_Backend::CREATE_USER)) {
$backend->createUser($uid, $password);
$user = $this->getUserObject($uid, $backend);
$this->emit('\OC\User', 'postCreateUser', array($user, $password));
@ -264,7 +264,7 @@ class Manager extends PublicEmitter implements IUserManager {
public function countUsers() {
$userCountStatistics = array();
foreach ($this->backends as $backend) {
if ($backend->implementsActions(\OC_USER_BACKEND_COUNT_USERS)) {
if ($backend->implementsActions(\OC_User_Backend::COUNT_USERS)) {
$backendusers = $backend->countUsers();
if($backendusers !== false) {
if(isset($userCountStatistics[get_class($backend)])) {

View File

@ -90,7 +90,7 @@ class User implements IUser {
public function getDisplayName() {
if (!isset($this->displayName)) {
$displayName = '';
if ($this->backend and $this->backend->implementsActions(OC_USER_BACKEND_GET_DISPLAYNAME)) {
if ($this->backend and $this->backend->implementsActions(\OC_User_Backend::GET_DISPLAYNAME)) {
// get display name and strip whitespace from the beginning and end of it
$backendDisplayName = $this->backend->getDisplayName($this->uid);
if (is_string($backendDisplayName)) {
@ -115,7 +115,7 @@ class User implements IUser {
*/
public function setDisplayName($displayName) {
$displayName = trim($displayName);
if ($this->backend->implementsActions(\OC_USER_BACKEND_SET_DISPLAYNAME) && !empty($displayName)) {
if ($this->backend->implementsActions(\OC_User_Backend::SET_DISPLAYNAME) && !empty($displayName)) {
$this->displayName = $displayName;
$result = $this->backend->setDisplayName($this->uid, $displayName);
return $result !== false;
@ -170,7 +170,7 @@ class User implements IUser {
if ($this->emitter) {
$this->emitter->emit('\OC\User', 'preSetPassword', array($this, $password, $recoveryPassword));
}
if ($this->backend->implementsActions(\OC_USER_BACKEND_SET_PASSWORD)) {
if ($this->backend->implementsActions(\OC_User_Backend::SET_PASSWORD)) {
$result = $this->backend->setPassword($this->uid, $password);
if ($this->emitter) {
$this->emitter->emit('\OC\User', 'postSetPassword', array($this, $password, $recoveryPassword));
@ -188,7 +188,7 @@ class User implements IUser {
*/
public function getHome() {
if (!$this->home) {
if ($this->backend->implementsActions(\OC_USER_BACKEND_GET_HOME) and $home = $this->backend->getHome($this->uid)) {
if ($this->backend->implementsActions(\OC_User_Backend::GET_HOME) and $home = $this->backend->getHome($this->uid)) {
$this->home = $home;
} elseif ($this->config) {
$this->home = $this->config->getSystemValue('datadirectory') . '/' . $this->uid;
@ -205,7 +205,7 @@ class User implements IUser {
* @return bool
*/
public function canChangeAvatar() {
if ($this->backend->implementsActions(\OC_USER_BACKEND_PROVIDE_AVATAR)) {
if ($this->backend->implementsActions(\OC_User_Backend::PROVIDE_AVATAR)) {
return $this->backend->canChangeAvatar($this->uid);
}
return true;
@ -217,7 +217,7 @@ class User implements IUser {
* @return bool
*/
public function canChangePassword() {
return $this->backend->implementsActions(\OC_USER_BACKEND_SET_PASSWORD);
return $this->backend->implementsActions(\OC_User_Backend::SET_PASSWORD);
}
/**
@ -229,7 +229,7 @@ class User implements IUser {
if ($this->config and $this->config->getSystemValue('allow_user_to_change_display_name') === false) {
return false;
} else {
return $this->backend->implementsActions(\OC_USER_BACKEND_SET_DISPLAYNAME);
return $this->backend->implementsActions(\OC_User_Backend::SET_DISPLAYNAME);
}
}