123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- <?php
- namespace OCA\User_LDAP\User;
- use OCA\User_LDAP\Mapping\UserMapping;
- use OCP\IConfig;
- use OCP\IDBConnection;
- use OCP\Share\IManager;
- use OCP\Share\IShare;
- class OfflineUser {
-
- protected $dn;
-
- protected $uid;
-
- protected $displayName;
-
- protected $homePath;
-
- protected $lastLogin;
-
- protected $foundDeleted;
- protected ?string $extStorageHome = null;
-
- protected $email;
-
- protected $hasActiveShares;
-
- protected $db;
-
- public function __construct(
- protected $ocName,
- protected IConfig $config,
- protected UserMapping $mapping,
- private IManager $shareManager,
- ) {
- }
-
- public function unmark() {
- $this->config->deleteUserValue($this->ocName, 'user_ldap', 'isDeleted');
- $this->config->deleteUserValue($this->ocName, 'user_ldap', 'foundDeleted');
- }
-
- public function export() {
- $data = [];
- $data['ocName'] = $this->getOCName();
- $data['dn'] = $this->getDN();
- $data['uid'] = $this->getUID();
- $data['displayName'] = $this->getDisplayName();
- $data['homePath'] = $this->getHomePath();
- $data['lastLogin'] = $this->getLastLogin();
- $data['email'] = $this->getEmail();
- $data['hasActiveShares'] = $this->getHasActiveShares();
- return $data;
- }
-
- public function getOCName() {
- return $this->ocName;
- }
-
- public function getUID() {
- if ($this->uid === null) {
- $this->fetchDetails();
- }
- return $this->uid;
- }
-
- public function getDN() {
- if ($this->dn === null) {
- $dn = $this->mapping->getDNByName($this->ocName);
- $this->dn = ($dn !== false) ? $dn : '';
- }
- return $this->dn;
- }
-
- public function getDisplayName() {
- if ($this->displayName === null) {
- $this->fetchDetails();
- }
- return $this->displayName;
- }
-
- public function getEmail() {
- if ($this->email === null) {
- $this->fetchDetails();
- }
- return $this->email;
- }
-
- public function getHomePath() {
- if ($this->homePath === null) {
- $this->fetchDetails();
- }
- return $this->homePath;
- }
-
- public function getLastLogin() {
- if ($this->lastLogin === null) {
- $this->fetchDetails();
- }
- return (int)$this->lastLogin;
- }
-
- public function getDetectedOn() {
- if ($this->foundDeleted === null) {
- $this->fetchDetails();
- }
- return (int)$this->foundDeleted;
- }
- public function getExtStorageHome(): string {
- if ($this->extStorageHome === null) {
- $this->fetchDetails();
- }
- return (string)$this->extStorageHome;
- }
-
- public function getHasActiveShares() {
- if ($this->hasActiveShares === null) {
- $this->determineShares();
- }
- return $this->hasActiveShares;
- }
-
- protected function fetchDetails() {
- $properties = [
- 'displayName' => 'user_ldap',
- 'uid' => 'user_ldap',
- 'homePath' => 'user_ldap',
- 'foundDeleted' => 'user_ldap',
- 'extStorageHome' => 'user_ldap',
- 'email' => 'settings',
- 'lastLogin' => 'login',
- ];
- foreach ($properties as $property => $app) {
- $this->$property = $this->config->getUserValue($this->ocName, $app, $property, '');
- }
- }
-
- protected function determineShares() {
- $shareInterface = new \ReflectionClass(IShare::class);
- $shareConstants = $shareInterface->getConstants();
- foreach ($shareConstants as $constantName => $constantValue) {
- if (!str_starts_with($constantName, 'TYPE_')
- || $constantValue === IShare::TYPE_USERGROUP
- ) {
- continue;
- }
- $shares = $this->shareManager->getSharesBy(
- $this->ocName,
- $constantValue,
- null,
- false,
- 1
- );
- if (!empty($shares)) {
- $this->hasActiveShares = true;
- return;
- }
- }
- $this->hasActiveShares = false;
- }
- }
|