summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-12-02 16:17:58 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2015-12-02 16:17:58 +0100
commitdf5872ec50a68de5d99bd6b5cf17ceb94f2ef833 (patch)
treeeedcfa1459f9cf6ef67bec10787883875ed1fc3f /lib/private
parentc35a450cb1c0df0f77dea4c69182a381543b679a (diff)
parent28ceab2f616d45a53dcc00c2cff53d5524bf0e9e (diff)
downloadnextcloud-server-df5872ec50a68de5d99bd6b5cf17ceb94f2ef833.tar.gz
nextcloud-server-df5872ec50a68de5d99bd6b5cf17ceb94f2ef833.zip
Merge pull request #20719 from owncloud/adding-system-addressbook-of-users
Adding system addressbook for users of this instance - a occ command …
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/avatar.php4
-rw-r--r--lib/private/user/manager.php34
-rw-r--r--lib/private/user/user.php100
3 files changed, 106 insertions, 32 deletions
diff --git a/lib/private/avatar.php b/lib/private/avatar.php
index 872da35f947..37a813f3ff8 100644
--- a/lib/private/avatar.php
+++ b/lib/private/avatar.php
@@ -79,7 +79,9 @@ class Avatar implements \OCP\IAvatar {
/** @var File $node */
$node = $this->folder->get('avatar.' . $ext);
$avatar->loadFromData($node->getContent());
- $avatar->resize($size);
+ if ($size > 0) {
+ $avatar->resize($size);
+ }
$this->folder->newFile('avatar.' . $size . '.' . $ext)->putContent($avatar->data());
}
return $avatar;
diff --git a/lib/private/user/manager.php b/lib/private/user/manager.php
index 109f08f47a0..2cb866d0056 100644
--- a/lib/private/user/manager.php
+++ b/lib/private/user/manager.php
@@ -294,21 +294,47 @@ class Manager extends PublicEmitter implements IUserManager {
$userCountStatistics = array();
foreach ($this->backends as $backend) {
if ($backend->implementsActions(\OC_User_Backend::COUNT_USERS)) {
- $backendusers = $backend->countUsers();
- if($backendusers !== false) {
+ $backendUsers = $backend->countUsers();
+ if($backendUsers !== false) {
if($backend instanceof \OCP\IUserBackend) {
$name = $backend->getBackendName();
} else {
$name = get_class($backend);
}
if(isset($userCountStatistics[$name])) {
- $userCountStatistics[$name] += $backendusers;
+ $userCountStatistics[$name] += $backendUsers;
} else {
- $userCountStatistics[$name] = $backendusers;
+ $userCountStatistics[$name] = $backendUsers;
}
}
}
}
return $userCountStatistics;
}
+
+ /**
+ * The callback is executed for each user on each backend.
+ * If the callback returns false no further users will be retrieved.
+ *
+ * @param \Closure $callback
+ * @return void
+ * @since 9.0.0
+ */
+ public function callForAllUsers(\Closure $callback, $search = '') {
+ foreach($this->getBackends() as $backend) {
+ $limit = 500;
+ $offset = 0;
+ do {
+ $users = $backend->getUsers($search, $limit, $offset);
+ foreach ($users as $user) {
+ $user = $this->get($user);
+ $return = $callback($user);
+ if ($return === false) {
+ break;
+ }
+ }
+ $offset += $limit;
+ } while (count($users) >= $limit);
+ }
+ }
}
diff --git a/lib/private/user/user.php b/lib/private/user/user.php
index 2740b25d5d3..d1fa641504c 100644
--- a/lib/private/user/user.php
+++ b/lib/private/user/user.php
@@ -30,61 +30,56 @@
namespace OC\User;
use OC\Hooks\Emitter;
+use OCP\IAvatarManager;
+use OCP\IImage;
+use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IConfig;
class User implements IUser {
- /**
- * @var string $uid
- */
+ /** @var string $uid */
private $uid;
- /**
- * @var string $displayName
- */
+ /** @var string $displayName */
private $displayName;
- /**
- * @var \OC_User_Interface $backend
- */
+ /** @var \OC_User_Interface $backend */
private $backend;
- /**
- * @var bool $enabled
- */
+ /** @var bool $enabled */
private $enabled;
- /**
- * @var Emitter|Manager $emitter
- */
+ /** @var Emitter|Manager $emitter */
private $emitter;
- /**
- * @var string $home
- */
+ /** @var string $home */
private $home;
- /**
- * @var int $lastLogin
- */
+ /** @var int $lastLogin */
private $lastLogin;
- /**
- * @var \OCP\IConfig $config
- */
+ /** @var \OCP\IConfig $config */
private $config;
+ /** @var IAvatarManager */
+ private $avatarManager;
+
+ /** @var IURLGenerator */
+ private $urlGenerator;
+
/**
* @param string $uid
* @param \OC_User_Interface $backend
* @param \OC\Hooks\Emitter $emitter
- * @param \OCP\IConfig $config
+ * @param IConfig|null $config
+ * @param IURLGenerator $urlGenerator
*/
- public function __construct($uid, $backend, $emitter = null, IConfig $config = null) {
+ public function __construct($uid, $backend, $emitter = null, IConfig $config = null, $urlGenerator = null) {
$this->uid = $uid;
$this->backend = $backend;
$this->emitter = $emitter;
$this->config = $config;
+ $this->urlGenerator = $urlGenerator;
if ($this->config) {
$enabled = $this->config->getUserValue($uid, 'core', 'enabled', 'true');
$this->enabled = ($enabled === 'true');
@@ -93,6 +88,9 @@ class User implements IUser {
$this->enabled = true;
$this->lastLogin = \OC::$server->getConfig()->getUserValue($uid, 'login', 'lastLogin', 0);
}
+ if (is_null($this->urlGenerator)) {
+ $this->urlGenerator = \OC::$server->getURLGenerator();
+ }
}
/**
@@ -105,7 +103,7 @@ class User implements IUser {
}
/**
- * get the displayname for the user, if no specific displayname is set it will fallback to the user id
+ * get the display name for the user, if no specific display name is set it will fallback to the user id
*
* @return string
*/
@@ -316,4 +314,52 @@ class User implements IUser {
public function getEMailAddress() {
return $this->config->getUserValue($this->uid, 'settings', 'email');
}
+
+ /**
+ * get the avatar image if it exists
+ *
+ * @param int $size
+ * @return IImage|null
+ * @since 9.0.0
+ */
+ public function getAvatarImage($size) {
+ // delay the initialization
+ if (is_null($this->avatarManager)) {
+ $this->avatarManager = \OC::$server->getAvatarManager();
+ }
+
+ $avatar = $this->avatarManager->getAvatar($this->uid);
+ $image = $avatar->get(-1);
+ if ($image) {
+ return $image;
+ }
+
+ return null;
+ }
+
+ /**
+ * get the federation cloud id
+ *
+ * @return string
+ * @since 9.0.0
+ */
+ public function getCloudId() {
+ $uid = $this->getUID();
+ $server = $this->urlGenerator->getAbsoluteURL('/');
+ return $uid . '@' . rtrim( $this->removeProtocolFromUrl($server), '/');
+ }
+
+ /**
+ * @param string $url
+ * @return string
+ */
+ private function removeProtocolFromUrl($url) {
+ if (strpos($url, 'https://') === 0) {
+ return substr($url, strlen('https://'));
+ } else if (strpos($url, 'http://') === 0) {
+ return substr($url, strlen('http://'));
+ }
+
+ return $url;
+ }
}