|
|
|
|
@ -35,7 +35,6 @@ use OCA\User_LDAP\Access; |
|
|
|
|
use OCA\User_LDAP\Connection; |
|
|
|
|
use OCA\User_LDAP\Exceptions\AttributeNotSet; |
|
|
|
|
use OCA\User_LDAP\FilesystemHelper; |
|
|
|
|
use OCA\User_LDAP\LogWrapper; |
|
|
|
|
use OCP\IAvatarManager; |
|
|
|
|
use OCP\IConfig; |
|
|
|
|
use OCP\ILogger; |
|
|
|
|
@ -43,6 +42,7 @@ use OCP\Image; |
|
|
|
|
use OCP\IUser; |
|
|
|
|
use OCP\IUserManager; |
|
|
|
|
use OCP\Notification\IManager as INotificationManager; |
|
|
|
|
use Psr\Log\LoggerInterface; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* User |
|
|
|
|
@ -71,9 +71,9 @@ class User { |
|
|
|
|
*/ |
|
|
|
|
protected $image; |
|
|
|
|
/** |
|
|
|
|
* @var LogWrapper |
|
|
|
|
* @var LoggerInterface |
|
|
|
|
*/ |
|
|
|
|
protected $log; |
|
|
|
|
private $logger; |
|
|
|
|
/** |
|
|
|
|
* @var IAvatarManager |
|
|
|
|
*/ |
|
|
|
|
@ -112,24 +112,16 @@ class User { |
|
|
|
|
* @brief constructor, make sure the subclasses call this one! |
|
|
|
|
* @param string $username the internal username |
|
|
|
|
* @param string $dn the LDAP DN |
|
|
|
|
* @param Access $access |
|
|
|
|
* @param IConfig $config |
|
|
|
|
* @param FilesystemHelper $fs |
|
|
|
|
* @param Image $image any empty instance |
|
|
|
|
* @param LogWrapper $log |
|
|
|
|
* @param IAvatarManager $avatarManager |
|
|
|
|
* @param IUserManager $userManager |
|
|
|
|
* @param INotificationManager $notificationManager |
|
|
|
|
*/ |
|
|
|
|
public function __construct($username, $dn, Access $access, |
|
|
|
|
IConfig $config, FilesystemHelper $fs, Image $image, |
|
|
|
|
LogWrapper $log, IAvatarManager $avatarManager, IUserManager $userManager, |
|
|
|
|
LoggerInterface $logger, IAvatarManager $avatarManager, IUserManager $userManager, |
|
|
|
|
INotificationManager $notificationManager) { |
|
|
|
|
if ($username === null) { |
|
|
|
|
$log->log("uid for '$dn' must not be null!", ILogger::ERROR); |
|
|
|
|
$logger->error("uid for '$dn' must not be null!", ['app' => 'user_ldap']); |
|
|
|
|
throw new \InvalidArgumentException('uid must not be null!'); |
|
|
|
|
} elseif ($username === '') { |
|
|
|
|
$log->log("uid for '$dn' must not be an empty string", ILogger::ERROR); |
|
|
|
|
$logger->error("uid for '$dn' must not be an empty string", ['app' => 'user_ldap']); |
|
|
|
|
throw new \InvalidArgumentException('uid must not be an empty string!'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -140,7 +132,7 @@ class User { |
|
|
|
|
$this->dn = $dn; |
|
|
|
|
$this->uid = $username; |
|
|
|
|
$this->image = $image; |
|
|
|
|
$this->log = $log; |
|
|
|
|
$this->logger = $logger; |
|
|
|
|
$this->avatarManager = $avatarManager; |
|
|
|
|
$this->userManager = $userManager; |
|
|
|
|
$this->notificationManager = $notificationManager; |
|
|
|
|
@ -493,19 +485,19 @@ class User { |
|
|
|
|
if ($aQuota && (count($aQuota) > 0) && $this->verifyQuotaValue($aQuota[0])) { |
|
|
|
|
$quota = $aQuota[0]; |
|
|
|
|
} elseif (is_array($aQuota) && isset($aQuota[0])) { |
|
|
|
|
$this->log->log('no suitable LDAP quota found for user ' . $this->uid . ': [' . $aQuota[0] . ']', ILogger::DEBUG); |
|
|
|
|
$this->logger->debug('no suitable LDAP quota found for user ' . $this->uid . ': [' . $aQuota[0] . ']', ['app' => 'user_ldap']); |
|
|
|
|
} |
|
|
|
|
} elseif ($this->verifyQuotaValue($valueFromLDAP)) { |
|
|
|
|
$quota = $valueFromLDAP; |
|
|
|
|
} else { |
|
|
|
|
$this->log->log('no suitable LDAP quota found for user ' . $this->uid . ': [' . $valueFromLDAP . ']', ILogger::DEBUG); |
|
|
|
|
$this->logger->debug('no suitable LDAP quota found for user ' . $this->uid . ': [' . $valueFromLDAP . ']', ['app' => 'user_ldap']); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($quota === false && $this->verifyQuotaValue($defaultQuota)) { |
|
|
|
|
// quota not found using the LDAP attribute (or not parseable). Try the default quota |
|
|
|
|
$quota = $defaultQuota; |
|
|
|
|
} elseif ($quota === false) { |
|
|
|
|
$this->log->log('no suitable default quota found for user ' . $this->uid . ': [' . $defaultQuota . ']', ILogger::DEBUG); |
|
|
|
|
$this->logger->debug('no suitable default quota found for user ' . $this->uid . ': [' . $defaultQuota . ']', ['app' => 'user_ldap']); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -513,7 +505,7 @@ class User { |
|
|
|
|
if ($targetUser instanceof IUser) { |
|
|
|
|
$targetUser->setQuota($quota); |
|
|
|
|
} else { |
|
|
|
|
$this->log->log('trying to set a quota for user ' . $this->uid . ' but the user is missing', ILogger::INFO); |
|
|
|
|
$this->logger->info('trying to set a quota for user ' . $this->uid . ' but the user is missing', ['app' => 'user_ldap']); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -573,7 +565,7 @@ class User { |
|
|
|
|
*/ |
|
|
|
|
private function setOwnCloudAvatar() { |
|
|
|
|
if (!$this->image->valid()) { |
|
|
|
|
$this->log->log('avatar image data from LDAP invalid for '.$this->dn, ILogger::ERROR); |
|
|
|
|
$this->logger->error('avatar image data from LDAP invalid for '.$this->dn, ['app' => 'user_ldap']); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -581,7 +573,7 @@ class User { |
|
|
|
|
//make sure it is a square and not bigger than 128x128 |
|
|
|
|
$size = min([$this->image->width(), $this->image->height(), 128]); |
|
|
|
|
if (!$this->image->centerCrop($size)) { |
|
|
|
|
$this->log->log('croping image for avatar failed for '.$this->dn, ILogger::ERROR); |
|
|
|
|
$this->logger->error('croping image for avatar failed for '.$this->dn, ['app' => 'user_ldap']); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|