@@ -6,5 +6,5 @@ |
||
| 6 | 6 | $baseDir = $vendorDir; |
| 7 | 7 | |
| 8 | 8 | return array( |
| 9 | - 'OCA\\UserStatus\\' => array($baseDir . '/../lib'), |
|
| 9 | + 'OCA\\UserStatus\\' => array($baseDir.'/../lib'), |
|
| 10 | 10 | ); |
@@ -370,18 +370,18 @@ discard block |
||
| 370 | 370 | private function findFileWithExtension($class, $ext) |
| 371 | 371 | { |
| 372 | 372 | // PSR-4 lookup |
| 373 | - $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; |
|
| 373 | + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR).$ext; |
|
| 374 | 374 | |
| 375 | 375 | $first = $class[0]; |
| 376 | 376 | if (isset($this->prefixLengthsPsr4[$first])) { |
| 377 | 377 | $subPath = $class; |
| 378 | 378 | while (false !== $lastPos = strrpos($subPath, '\\')) { |
| 379 | 379 | $subPath = substr($subPath, 0, $lastPos); |
| 380 | - $search = $subPath . '\\'; |
|
| 380 | + $search = $subPath.'\\'; |
|
| 381 | 381 | if (isset($this->prefixDirsPsr4[$search])) { |
| 382 | - $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); |
|
| 382 | + $pathEnd = DIRECTORY_SEPARATOR.substr($logicalPathPsr4, $lastPos + 1); |
|
| 383 | 383 | foreach ($this->prefixDirsPsr4[$search] as $dir) { |
| 384 | - if (file_exists($file = $dir . $pathEnd)) { |
|
| 384 | + if (file_exists($file = $dir.$pathEnd)) { |
|
| 385 | 385 | return $file; |
| 386 | 386 | } |
| 387 | 387 | } |
@@ -391,7 +391,7 @@ discard block |
||
| 391 | 391 | |
| 392 | 392 | // PSR-4 fallback dirs |
| 393 | 393 | foreach ($this->fallbackDirsPsr4 as $dir) { |
| 394 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { |
|
| 394 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr4)) { |
|
| 395 | 395 | return $file; |
| 396 | 396 | } |
| 397 | 397 | } |
@@ -403,14 +403,14 @@ discard block |
||
| 403 | 403 | . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); |
| 404 | 404 | } else { |
| 405 | 405 | // PEAR-like class name |
| 406 | - $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; |
|
| 406 | + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR).$ext; |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | if (isset($this->prefixesPsr0[$first])) { |
| 410 | 410 | foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { |
| 411 | 411 | if (0 === strpos($class, $prefix)) { |
| 412 | 412 | foreach ($dirs as $dir) { |
| 413 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
| 413 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
| 414 | 414 | return $file; |
| 415 | 415 | } |
| 416 | 416 | } |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | |
| 421 | 421 | // PSR-0 fallback dirs |
| 422 | 422 | foreach ($this->fallbackDirsPsr0 as $dir) { |
| 423 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
| 423 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
| 424 | 424 | return $file; |
| 425 | 425 | } |
| 426 | 426 | } |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | * @return string|null |
| 86 | 86 | * @since 20.0.0 |
| 87 | 87 | */ |
| 88 | - public function getMessage():?string; |
|
| 88 | + public function getMessage(): ?string; |
|
| 89 | 89 | |
| 90 | 90 | /** |
| 91 | 91 | * Get a custom icon provided by the user |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | * @return string|null |
| 94 | 94 | * @since 20.0.0 |
| 95 | 95 | */ |
| 96 | - public function getIcon():?string; |
|
| 96 | + public function getIcon(): ?string; |
|
| 97 | 97 | |
| 98 | 98 | /** |
| 99 | 99 | * Gets the time that the custom status will be cleared at |
@@ -101,5 +101,5 @@ discard block |
||
| 101 | 101 | * @return DateTimeImmutable|null |
| 102 | 102 | * @since 20.0.0 |
| 103 | 103 | */ |
| 104 | - public function getClearAt():?DateTimeImmutable; |
|
| 104 | + public function getClearAt(): ?DateTimeImmutable; |
|
| 105 | 105 | } |
@@ -16,119 +16,119 @@ |
||
| 16 | 16 | * @since 20.0.0 |
| 17 | 17 | */ |
| 18 | 18 | interface IUserStatus { |
| 19 | - /** |
|
| 20 | - * @var string |
|
| 21 | - * @since 20.0.0 |
|
| 22 | - */ |
|
| 23 | - public const ONLINE = 'online'; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @var string |
|
| 27 | - * @since 20.0.0 |
|
| 28 | - */ |
|
| 29 | - public const AWAY = 'away'; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var string |
|
| 33 | - * @since 20.0.0 |
|
| 34 | - */ |
|
| 35 | - public const DND = 'dnd'; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @var string |
|
| 39 | - * @since 28.0.0 |
|
| 40 | - */ |
|
| 41 | - public const BUSY = 'busy'; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @var string |
|
| 45 | - * @since 20.0.0 |
|
| 46 | - */ |
|
| 47 | - public const OFFLINE = 'offline'; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @var string |
|
| 51 | - * @since 20.0.0 |
|
| 52 | - */ |
|
| 53 | - public const INVISIBLE = 'invisible'; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @var string |
|
| 57 | - * @since 25.0.0 |
|
| 58 | - */ |
|
| 59 | - public const MESSAGE_CALL = 'call'; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @var string |
|
| 63 | - * @since 25.0.0 |
|
| 64 | - */ |
|
| 65 | - public const MESSAGE_AVAILABILITY = 'availability'; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @var string |
|
| 69 | - * @since 28.0.1 |
|
| 70 | - */ |
|
| 71 | - public const MESSAGE_OUT_OF_OFFICE = 'out-of-office'; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @var string |
|
| 75 | - * @since 28.0.0 |
|
| 76 | - */ |
|
| 77 | - public const MESSAGE_VACATION = 'vacationing'; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @var string |
|
| 81 | - * @since 28.0.0 |
|
| 82 | - */ |
|
| 83 | - public const MESSAGE_CALENDAR_BUSY = 'meeting'; |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @var string |
|
| 87 | - * @since 28.0.0 |
|
| 88 | - */ |
|
| 89 | - public const MESSAGE_CALENDAR_BUSY_TENTATIVE = 'busy-tentative'; |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Get the user this status is connected to |
|
| 93 | - * |
|
| 94 | - * @return string |
|
| 95 | - * @since 20.0.0 |
|
| 96 | - */ |
|
| 97 | - public function getUserId():string; |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Get the status |
|
| 101 | - * |
|
| 102 | - * It will return one of the constants defined above. |
|
| 103 | - * It will never return invisible. In case a user marked |
|
| 104 | - * themselves as invisible, it will return offline. |
|
| 105 | - * |
|
| 106 | - * @return string See IUserStatus constants |
|
| 107 | - * @since 20.0.0 |
|
| 108 | - */ |
|
| 109 | - public function getStatus():string; |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Get a custom message provided by the user |
|
| 113 | - * |
|
| 114 | - * @return string|null |
|
| 115 | - * @since 20.0.0 |
|
| 116 | - */ |
|
| 117 | - public function getMessage():?string; |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Get a custom icon provided by the user |
|
| 121 | - * |
|
| 122 | - * @return string|null |
|
| 123 | - * @since 20.0.0 |
|
| 124 | - */ |
|
| 125 | - public function getIcon():?string; |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Gets the time that the custom status will be cleared at |
|
| 129 | - * |
|
| 130 | - * @return DateTimeImmutable|null |
|
| 131 | - * @since 20.0.0 |
|
| 132 | - */ |
|
| 133 | - public function getClearAt():?DateTimeImmutable; |
|
| 19 | + /** |
|
| 20 | + * @var string |
|
| 21 | + * @since 20.0.0 |
|
| 22 | + */ |
|
| 23 | + public const ONLINE = 'online'; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @var string |
|
| 27 | + * @since 20.0.0 |
|
| 28 | + */ |
|
| 29 | + public const AWAY = 'away'; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var string |
|
| 33 | + * @since 20.0.0 |
|
| 34 | + */ |
|
| 35 | + public const DND = 'dnd'; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @var string |
|
| 39 | + * @since 28.0.0 |
|
| 40 | + */ |
|
| 41 | + public const BUSY = 'busy'; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @var string |
|
| 45 | + * @since 20.0.0 |
|
| 46 | + */ |
|
| 47 | + public const OFFLINE = 'offline'; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @var string |
|
| 51 | + * @since 20.0.0 |
|
| 52 | + */ |
|
| 53 | + public const INVISIBLE = 'invisible'; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @var string |
|
| 57 | + * @since 25.0.0 |
|
| 58 | + */ |
|
| 59 | + public const MESSAGE_CALL = 'call'; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @var string |
|
| 63 | + * @since 25.0.0 |
|
| 64 | + */ |
|
| 65 | + public const MESSAGE_AVAILABILITY = 'availability'; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @var string |
|
| 69 | + * @since 28.0.1 |
|
| 70 | + */ |
|
| 71 | + public const MESSAGE_OUT_OF_OFFICE = 'out-of-office'; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @var string |
|
| 75 | + * @since 28.0.0 |
|
| 76 | + */ |
|
| 77 | + public const MESSAGE_VACATION = 'vacationing'; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @var string |
|
| 81 | + * @since 28.0.0 |
|
| 82 | + */ |
|
| 83 | + public const MESSAGE_CALENDAR_BUSY = 'meeting'; |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @var string |
|
| 87 | + * @since 28.0.0 |
|
| 88 | + */ |
|
| 89 | + public const MESSAGE_CALENDAR_BUSY_TENTATIVE = 'busy-tentative'; |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Get the user this status is connected to |
|
| 93 | + * |
|
| 94 | + * @return string |
|
| 95 | + * @since 20.0.0 |
|
| 96 | + */ |
|
| 97 | + public function getUserId():string; |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Get the status |
|
| 101 | + * |
|
| 102 | + * It will return one of the constants defined above. |
|
| 103 | + * It will never return invisible. In case a user marked |
|
| 104 | + * themselves as invisible, it will return offline. |
|
| 105 | + * |
|
| 106 | + * @return string See IUserStatus constants |
|
| 107 | + * @since 20.0.0 |
|
| 108 | + */ |
|
| 109 | + public function getStatus():string; |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Get a custom message provided by the user |
|
| 113 | + * |
|
| 114 | + * @return string|null |
|
| 115 | + * @since 20.0.0 |
|
| 116 | + */ |
|
| 117 | + public function getMessage():?string; |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Get a custom icon provided by the user |
|
| 121 | + * |
|
| 122 | + * @return string|null |
|
| 123 | + * @since 20.0.0 |
|
| 124 | + */ |
|
| 125 | + public function getIcon():?string; |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Gets the time that the custom status will be cleared at |
|
| 129 | + * |
|
| 130 | + * @return DateTimeImmutable|null |
|
| 131 | + * @since 20.0.0 |
|
| 132 | + */ |
|
| 133 | + public function getClearAt():?DateTimeImmutable; |
|
| 134 | 134 | } |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | |
| 116 | 116 | $result = []; |
| 117 | 117 | foreach ($storagesByMountpoint as $storageList) { |
| 118 | - $storage = array_reduce($storageList, function ($carry, $item) { |
|
| 118 | + $storage = array_reduce($storageList, function($carry, $item) { |
|
| 119 | 119 | if (isset($carry)) { |
| 120 | 120 | $carryPriorityType = $this->getPriorityType($carry); |
| 121 | 121 | $itemPriorityType = $this->getPriorityType($item); |
@@ -191,11 +191,11 @@ discard block |
||
| 191 | 191 | $groupIds = $this->groupManager->getUserGroupIds($user); |
| 192 | 192 | $mounts = $this->dbConfig->getMountsForUser($user->getUID(), $groupIds); |
| 193 | 193 | $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts); |
| 194 | - $configs = array_filter($configs, function ($config) { |
|
| 194 | + $configs = array_filter($configs, function($config) { |
|
| 195 | 195 | return $config instanceof StorageConfig; |
| 196 | 196 | }); |
| 197 | 197 | |
| 198 | - $keys = array_map(function (StorageConfig $config) { |
|
| 198 | + $keys = array_map(function(StorageConfig $config) { |
|
| 199 | 199 | return $config->getId(); |
| 200 | 200 | }, $configs); |
| 201 | 201 | |
@@ -18,169 +18,169 @@ |
||
| 18 | 18 | * Read-only access available, attempting to write will throw DomainException |
| 19 | 19 | */ |
| 20 | 20 | class UserGlobalStoragesService extends GlobalStoragesService { |
| 21 | - use UserTrait; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * @param BackendService $backendService |
|
| 25 | - * @param DBConfigService $dbConfig |
|
| 26 | - * @param IUserSession $userSession |
|
| 27 | - * @param IGroupManager $groupManager |
|
| 28 | - * @param IUserMountCache $userMountCache |
|
| 29 | - * @param IEventDispatcher $eventDispatcher |
|
| 30 | - */ |
|
| 31 | - public function __construct( |
|
| 32 | - BackendService $backendService, |
|
| 33 | - DBConfigService $dbConfig, |
|
| 34 | - IUserSession $userSession, |
|
| 35 | - protected IGroupManager $groupManager, |
|
| 36 | - IUserMountCache $userMountCache, |
|
| 37 | - IEventDispatcher $eventDispatcher, |
|
| 38 | - ) { |
|
| 39 | - parent::__construct($backendService, $dbConfig, $userMountCache, $eventDispatcher); |
|
| 40 | - $this->userSession = $userSession; |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Replace config hash ID with real IDs, for migrating legacy storages |
|
| 45 | - * |
|
| 46 | - * @param StorageConfig[] $storages Storages with real IDs |
|
| 47 | - * @param StorageConfig[] $storagesWithConfigHash Storages with config hash IDs |
|
| 48 | - */ |
|
| 49 | - protected function setRealStorageIds(array &$storages, array $storagesWithConfigHash) { |
|
| 50 | - // as a read-only view, storage IDs don't need to be real |
|
| 51 | - foreach ($storagesWithConfigHash as $storage) { |
|
| 52 | - $storages[$storage->getId()] = $storage; |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - protected function readDBConfig() { |
|
| 57 | - $userMounts = $this->dbConfig->getAdminMountsFor(DBConfigService::APPLICABLE_TYPE_USER, $this->getUser()->getUID()); |
|
| 58 | - $globalMounts = $this->dbConfig->getAdminMountsFor(DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
| 59 | - $groups = $this->groupManager->getUserGroupIds($this->getUser()); |
|
| 60 | - if (count($groups) !== 0) { |
|
| 61 | - $groupMounts = $this->dbConfig->getAdminMountsForMultiple(DBConfigService::APPLICABLE_TYPE_GROUP, $groups); |
|
| 62 | - } else { |
|
| 63 | - $groupMounts = []; |
|
| 64 | - } |
|
| 65 | - return array_merge($userMounts, $groupMounts, $globalMounts); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - public function addStorage(StorageConfig $newStorage) { |
|
| 69 | - throw new \DomainException('UserGlobalStoragesService writing disallowed'); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - public function updateStorage(StorageConfig $updatedStorage) { |
|
| 73 | - throw new \DomainException('UserGlobalStoragesService writing disallowed'); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @param integer $id |
|
| 78 | - */ |
|
| 79 | - public function removeStorage($id) { |
|
| 80 | - throw new \DomainException('UserGlobalStoragesService writing disallowed'); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Get unique storages, in case two are defined with the same mountpoint |
|
| 85 | - * Higher priority storages take precedence |
|
| 86 | - * |
|
| 87 | - * @return StorageConfig[] |
|
| 88 | - */ |
|
| 89 | - public function getUniqueStorages() { |
|
| 90 | - $storages = $this->getStorages(); |
|
| 91 | - |
|
| 92 | - $storagesByMountpoint = []; |
|
| 93 | - foreach ($storages as $storage) { |
|
| 94 | - $storagesByMountpoint[$storage->getMountPoint()][] = $storage; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - $result = []; |
|
| 98 | - foreach ($storagesByMountpoint as $storageList) { |
|
| 99 | - $storage = array_reduce($storageList, function ($carry, $item) { |
|
| 100 | - if (isset($carry)) { |
|
| 101 | - $carryPriorityType = $this->getPriorityType($carry); |
|
| 102 | - $itemPriorityType = $this->getPriorityType($item); |
|
| 103 | - if ($carryPriorityType > $itemPriorityType) { |
|
| 104 | - return $carry; |
|
| 105 | - } elseif ($carryPriorityType === $itemPriorityType) { |
|
| 106 | - if ($carry->getPriority() > $item->getPriority()) { |
|
| 107 | - return $carry; |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - return $item; |
|
| 112 | - }); |
|
| 113 | - $result[$storage->getID()] = $storage; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - return $result; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Get a priority 'type', where a bigger number means higher priority |
|
| 121 | - * user applicable > group applicable > 'all' |
|
| 122 | - * |
|
| 123 | - * @param StorageConfig $storage |
|
| 124 | - * @return int |
|
| 125 | - */ |
|
| 126 | - protected function getPriorityType(StorageConfig $storage) { |
|
| 127 | - $applicableUsers = $storage->getApplicableUsers(); |
|
| 128 | - $applicableGroups = $storage->getApplicableGroups(); |
|
| 129 | - |
|
| 130 | - if ($applicableUsers && $applicableUsers[0] !== 'all') { |
|
| 131 | - return 2; |
|
| 132 | - } |
|
| 133 | - if ($applicableGroups) { |
|
| 134 | - return 1; |
|
| 135 | - } |
|
| 136 | - return 0; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - protected function isApplicable(StorageConfig $config) { |
|
| 140 | - $applicableUsers = $config->getApplicableUsers(); |
|
| 141 | - $applicableGroups = $config->getApplicableGroups(); |
|
| 142 | - |
|
| 143 | - if (count($applicableUsers) === 0 && count($applicableGroups) === 0) { |
|
| 144 | - return true; |
|
| 145 | - } |
|
| 146 | - if (in_array($this->getUser()->getUID(), $applicableUsers, true)) { |
|
| 147 | - return true; |
|
| 148 | - } |
|
| 149 | - $groupIds = $this->groupManager->getUserGroupIds($this->getUser()); |
|
| 150 | - foreach ($groupIds as $groupId) { |
|
| 151 | - if (in_array($groupId, $applicableGroups, true)) { |
|
| 152 | - return true; |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - return false; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Gets all storages for the user, admin, personal, global, etc |
|
| 161 | - * |
|
| 162 | - * @param IUser|null $user user to get the storages for, if not set the currently logged in user will be used |
|
| 163 | - * @return StorageConfig[] array of storage configs |
|
| 164 | - */ |
|
| 165 | - public function getAllStoragesForUser(?IUser $user = null) { |
|
| 166 | - if (is_null($user)) { |
|
| 167 | - $user = $this->getUser(); |
|
| 168 | - } |
|
| 169 | - if (is_null($user)) { |
|
| 170 | - return []; |
|
| 171 | - } |
|
| 172 | - $groupIds = $this->groupManager->getUserGroupIds($user); |
|
| 173 | - $mounts = $this->dbConfig->getMountsForUser($user->getUID(), $groupIds); |
|
| 174 | - $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts); |
|
| 175 | - $configs = array_filter($configs, function ($config) { |
|
| 176 | - return $config instanceof StorageConfig; |
|
| 177 | - }); |
|
| 178 | - |
|
| 179 | - $keys = array_map(function (StorageConfig $config) { |
|
| 180 | - return $config->getId(); |
|
| 181 | - }, $configs); |
|
| 182 | - |
|
| 183 | - $storages = array_combine($keys, $configs); |
|
| 184 | - return array_filter($storages, [$this, 'validateStorage']); |
|
| 185 | - } |
|
| 21 | + use UserTrait; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * @param BackendService $backendService |
|
| 25 | + * @param DBConfigService $dbConfig |
|
| 26 | + * @param IUserSession $userSession |
|
| 27 | + * @param IGroupManager $groupManager |
|
| 28 | + * @param IUserMountCache $userMountCache |
|
| 29 | + * @param IEventDispatcher $eventDispatcher |
|
| 30 | + */ |
|
| 31 | + public function __construct( |
|
| 32 | + BackendService $backendService, |
|
| 33 | + DBConfigService $dbConfig, |
|
| 34 | + IUserSession $userSession, |
|
| 35 | + protected IGroupManager $groupManager, |
|
| 36 | + IUserMountCache $userMountCache, |
|
| 37 | + IEventDispatcher $eventDispatcher, |
|
| 38 | + ) { |
|
| 39 | + parent::__construct($backendService, $dbConfig, $userMountCache, $eventDispatcher); |
|
| 40 | + $this->userSession = $userSession; |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Replace config hash ID with real IDs, for migrating legacy storages |
|
| 45 | + * |
|
| 46 | + * @param StorageConfig[] $storages Storages with real IDs |
|
| 47 | + * @param StorageConfig[] $storagesWithConfigHash Storages with config hash IDs |
|
| 48 | + */ |
|
| 49 | + protected function setRealStorageIds(array &$storages, array $storagesWithConfigHash) { |
|
| 50 | + // as a read-only view, storage IDs don't need to be real |
|
| 51 | + foreach ($storagesWithConfigHash as $storage) { |
|
| 52 | + $storages[$storage->getId()] = $storage; |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + protected function readDBConfig() { |
|
| 57 | + $userMounts = $this->dbConfig->getAdminMountsFor(DBConfigService::APPLICABLE_TYPE_USER, $this->getUser()->getUID()); |
|
| 58 | + $globalMounts = $this->dbConfig->getAdminMountsFor(DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
| 59 | + $groups = $this->groupManager->getUserGroupIds($this->getUser()); |
|
| 60 | + if (count($groups) !== 0) { |
|
| 61 | + $groupMounts = $this->dbConfig->getAdminMountsForMultiple(DBConfigService::APPLICABLE_TYPE_GROUP, $groups); |
|
| 62 | + } else { |
|
| 63 | + $groupMounts = []; |
|
| 64 | + } |
|
| 65 | + return array_merge($userMounts, $groupMounts, $globalMounts); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + public function addStorage(StorageConfig $newStorage) { |
|
| 69 | + throw new \DomainException('UserGlobalStoragesService writing disallowed'); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + public function updateStorage(StorageConfig $updatedStorage) { |
|
| 73 | + throw new \DomainException('UserGlobalStoragesService writing disallowed'); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @param integer $id |
|
| 78 | + */ |
|
| 79 | + public function removeStorage($id) { |
|
| 80 | + throw new \DomainException('UserGlobalStoragesService writing disallowed'); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Get unique storages, in case two are defined with the same mountpoint |
|
| 85 | + * Higher priority storages take precedence |
|
| 86 | + * |
|
| 87 | + * @return StorageConfig[] |
|
| 88 | + */ |
|
| 89 | + public function getUniqueStorages() { |
|
| 90 | + $storages = $this->getStorages(); |
|
| 91 | + |
|
| 92 | + $storagesByMountpoint = []; |
|
| 93 | + foreach ($storages as $storage) { |
|
| 94 | + $storagesByMountpoint[$storage->getMountPoint()][] = $storage; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + $result = []; |
|
| 98 | + foreach ($storagesByMountpoint as $storageList) { |
|
| 99 | + $storage = array_reduce($storageList, function ($carry, $item) { |
|
| 100 | + if (isset($carry)) { |
|
| 101 | + $carryPriorityType = $this->getPriorityType($carry); |
|
| 102 | + $itemPriorityType = $this->getPriorityType($item); |
|
| 103 | + if ($carryPriorityType > $itemPriorityType) { |
|
| 104 | + return $carry; |
|
| 105 | + } elseif ($carryPriorityType === $itemPriorityType) { |
|
| 106 | + if ($carry->getPriority() > $item->getPriority()) { |
|
| 107 | + return $carry; |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + return $item; |
|
| 112 | + }); |
|
| 113 | + $result[$storage->getID()] = $storage; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + return $result; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Get a priority 'type', where a bigger number means higher priority |
|
| 121 | + * user applicable > group applicable > 'all' |
|
| 122 | + * |
|
| 123 | + * @param StorageConfig $storage |
|
| 124 | + * @return int |
|
| 125 | + */ |
|
| 126 | + protected function getPriorityType(StorageConfig $storage) { |
|
| 127 | + $applicableUsers = $storage->getApplicableUsers(); |
|
| 128 | + $applicableGroups = $storage->getApplicableGroups(); |
|
| 129 | + |
|
| 130 | + if ($applicableUsers && $applicableUsers[0] !== 'all') { |
|
| 131 | + return 2; |
|
| 132 | + } |
|
| 133 | + if ($applicableGroups) { |
|
| 134 | + return 1; |
|
| 135 | + } |
|
| 136 | + return 0; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + protected function isApplicable(StorageConfig $config) { |
|
| 140 | + $applicableUsers = $config->getApplicableUsers(); |
|
| 141 | + $applicableGroups = $config->getApplicableGroups(); |
|
| 142 | + |
|
| 143 | + if (count($applicableUsers) === 0 && count($applicableGroups) === 0) { |
|
| 144 | + return true; |
|
| 145 | + } |
|
| 146 | + if (in_array($this->getUser()->getUID(), $applicableUsers, true)) { |
|
| 147 | + return true; |
|
| 148 | + } |
|
| 149 | + $groupIds = $this->groupManager->getUserGroupIds($this->getUser()); |
|
| 150 | + foreach ($groupIds as $groupId) { |
|
| 151 | + if (in_array($groupId, $applicableGroups, true)) { |
|
| 152 | + return true; |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + return false; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Gets all storages for the user, admin, personal, global, etc |
|
| 161 | + * |
|
| 162 | + * @param IUser|null $user user to get the storages for, if not set the currently logged in user will be used |
|
| 163 | + * @return StorageConfig[] array of storage configs |
|
| 164 | + */ |
|
| 165 | + public function getAllStoragesForUser(?IUser $user = null) { |
|
| 166 | + if (is_null($user)) { |
|
| 167 | + $user = $this->getUser(); |
|
| 168 | + } |
|
| 169 | + if (is_null($user)) { |
|
| 170 | + return []; |
|
| 171 | + } |
|
| 172 | + $groupIds = $this->groupManager->getUserGroupIds($user); |
|
| 173 | + $mounts = $this->dbConfig->getMountsForUser($user->getUID(), $groupIds); |
|
| 174 | + $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts); |
|
| 175 | + $configs = array_filter($configs, function ($config) { |
|
| 176 | + return $config instanceof StorageConfig; |
|
| 177 | + }); |
|
| 178 | + |
|
| 179 | + $keys = array_map(function (StorageConfig $config) { |
|
| 180 | + return $config->getId(); |
|
| 181 | + }, $configs); |
|
| 182 | + |
|
| 183 | + $storages = array_combine($keys, $configs); |
|
| 184 | + return array_filter($storages, [$this, 'validateStorage']); |
|
| 185 | + } |
|
| 186 | 186 | } |
@@ -31,45 +31,45 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | trait UserTrait { |
| 33 | 33 | |
| 34 | - /** @var IUserSession */ |
|
| 35 | - protected $userSession; |
|
| 34 | + /** @var IUserSession */ |
|
| 35 | + protected $userSession; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * User override |
|
| 39 | - * |
|
| 40 | - * @var IUser|null |
|
| 41 | - */ |
|
| 42 | - private $user = null; |
|
| 37 | + /** |
|
| 38 | + * User override |
|
| 39 | + * |
|
| 40 | + * @var IUser|null |
|
| 41 | + */ |
|
| 42 | + private $user = null; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @return IUser|null |
|
| 46 | - */ |
|
| 47 | - protected function getUser() { |
|
| 48 | - if ($this->user) { |
|
| 49 | - return $this->user; |
|
| 50 | - } |
|
| 51 | - return $this->userSession->getUser(); |
|
| 52 | - } |
|
| 44 | + /** |
|
| 45 | + * @return IUser|null |
|
| 46 | + */ |
|
| 47 | + protected function getUser() { |
|
| 48 | + if ($this->user) { |
|
| 49 | + return $this->user; |
|
| 50 | + } |
|
| 51 | + return $this->userSession->getUser(); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Override the user from the session |
|
| 56 | - * Unset with ->resetUser() when finished! |
|
| 57 | - * |
|
| 58 | - * @param IUser $user |
|
| 59 | - * @return self |
|
| 60 | - */ |
|
| 61 | - public function setUser(IUser $user) { |
|
| 62 | - $this->user = $user; |
|
| 63 | - return $this; |
|
| 64 | - } |
|
| 54 | + /** |
|
| 55 | + * Override the user from the session |
|
| 56 | + * Unset with ->resetUser() when finished! |
|
| 57 | + * |
|
| 58 | + * @param IUser $user |
|
| 59 | + * @return self |
|
| 60 | + */ |
|
| 61 | + public function setUser(IUser $user) { |
|
| 62 | + $this->user = $user; |
|
| 63 | + return $this; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Reset the user override |
|
| 68 | - * |
|
| 69 | - * @return self |
|
| 70 | - */ |
|
| 71 | - public function resetUser() { |
|
| 72 | - $this->user = null; |
|
| 73 | - return $this; |
|
| 74 | - } |
|
| 66 | + /** |
|
| 67 | + * Reset the user override |
|
| 68 | + * |
|
| 69 | + * @return self |
|
| 70 | + */ |
|
| 71 | + public function resetUser() { |
|
| 72 | + $this->user = null; |
|
| 73 | + return $this; |
|
| 74 | + } |
|
| 75 | 75 | } |
@@ -31,11 +31,11 @@ |
||
| 31 | 31 | * @since 20.0.0 |
| 32 | 32 | */ |
| 33 | 33 | interface IRootMountProvider { |
| 34 | - /** |
|
| 35 | - * Get all root mountpoints of this provider |
|
| 36 | - * |
|
| 37 | - * @return \OCP\Files\Mount\IMountPoint[] |
|
| 38 | - * @since 20.0.0 |
|
| 39 | - */ |
|
| 40 | - public function getRootMounts(IStorageFactory $loader): array; |
|
| 34 | + /** |
|
| 35 | + * Get all root mountpoints of this provider |
|
| 36 | + * |
|
| 37 | + * @return \OCP\Files\Mount\IMountPoint[] |
|
| 38 | + * @since 20.0.0 |
|
| 39 | + */ |
|
| 40 | + public function getRootMounts(IStorageFactory $loader): array; |
|
| 41 | 41 | } |
@@ -36,56 +36,56 @@ |
||
| 36 | 36 | * @since 18.0.0 |
| 37 | 37 | */ |
| 38 | 38 | interface IRuleMatcher extends IFileCheck { |
| 39 | - /** |
|
| 40 | - * This method is left for backwards compatibility and easier porting of |
|
| 41 | - * apps. Please use 'getFlows' instead (and setOperation if you implement |
|
| 42 | - * an IComplexOperation). |
|
| 43 | - * |
|
| 44 | - * @since 18.0.0 |
|
| 45 | - * @deprecated 18.0.0 |
|
| 46 | - */ |
|
| 47 | - public function getMatchingOperations(string $class, bool $returnFirstMatchingOperationOnly = true): array; |
|
| 39 | + /** |
|
| 40 | + * This method is left for backwards compatibility and easier porting of |
|
| 41 | + * apps. Please use 'getFlows' instead (and setOperation if you implement |
|
| 42 | + * an IComplexOperation). |
|
| 43 | + * |
|
| 44 | + * @since 18.0.0 |
|
| 45 | + * @deprecated 18.0.0 |
|
| 46 | + */ |
|
| 47 | + public function getMatchingOperations(string $class, bool $returnFirstMatchingOperationOnly = true): array; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @throws RuntimeException |
|
| 51 | - * @since 18.0.0 |
|
| 52 | - */ |
|
| 53 | - public function getFlows(bool $returnFirstMatchingOperationOnly = true): array; |
|
| 49 | + /** |
|
| 50 | + * @throws RuntimeException |
|
| 51 | + * @since 18.0.0 |
|
| 52 | + */ |
|
| 53 | + public function getFlows(bool $returnFirstMatchingOperationOnly = true): array; |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * this method can only be called once and is typically called by the |
|
| 57 | - * Flow engine, unless for IComplexOperations. |
|
| 58 | - * |
|
| 59 | - * @throws RuntimeException |
|
| 60 | - * @since 18.0.0 |
|
| 61 | - */ |
|
| 62 | - public function setOperation(IOperation $operation): void; |
|
| 55 | + /** |
|
| 56 | + * this method can only be called once and is typically called by the |
|
| 57 | + * Flow engine, unless for IComplexOperations. |
|
| 58 | + * |
|
| 59 | + * @throws RuntimeException |
|
| 60 | + * @since 18.0.0 |
|
| 61 | + */ |
|
| 62 | + public function setOperation(IOperation $operation): void; |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * this method can only be called once and is typically called by the |
|
| 66 | - * Flow engine, unless for IComplexOperations. |
|
| 67 | - * |
|
| 68 | - * @throws RuntimeException |
|
| 69 | - * @since 18.0.0 |
|
| 70 | - */ |
|
| 71 | - public function setEntity(IEntity $entity): void; |
|
| 64 | + /** |
|
| 65 | + * this method can only be called once and is typically called by the |
|
| 66 | + * Flow engine, unless for IComplexOperations. |
|
| 67 | + * |
|
| 68 | + * @throws RuntimeException |
|
| 69 | + * @since 18.0.0 |
|
| 70 | + */ |
|
| 71 | + public function setEntity(IEntity $entity): void; |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * returns the entity which might provide more information, depending on |
|
| 75 | - * the interfaces it implements |
|
| 76 | - * |
|
| 77 | - * @return IEntity |
|
| 78 | - * @since 18.0.0 |
|
| 79 | - */ |
|
| 80 | - public function getEntity(): IEntity; |
|
| 73 | + /** |
|
| 74 | + * returns the entity which might provide more information, depending on |
|
| 75 | + * the interfaces it implements |
|
| 76 | + * |
|
| 77 | + * @return IEntity |
|
| 78 | + * @since 18.0.0 |
|
| 79 | + */ |
|
| 80 | + public function getEntity(): IEntity; |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * this method can be called once to set the event name that is currently |
|
| 84 | - * being processed. The workflow engine takes care of this usually, only an |
|
| 85 | - * IComplexOperation might want to make use of it. |
|
| 86 | - * |
|
| 87 | - * @throws RuntimeException |
|
| 88 | - * @since 20.0.0 |
|
| 89 | - */ |
|
| 90 | - public function setEventName(string $eventName): void; |
|
| 82 | + /** |
|
| 83 | + * this method can be called once to set the event name that is currently |
|
| 84 | + * being processed. The workflow engine takes care of this usually, only an |
|
| 85 | + * IComplexOperation might want to make use of it. |
|
| 86 | + * |
|
| 87 | + * @throws RuntimeException |
|
| 88 | + * @since 20.0.0 |
|
| 89 | + */ |
|
| 90 | + public function setEventName(string $eventName): void; |
|
| 91 | 91 | } |
@@ -36,22 +36,22 @@ |
||
| 36 | 36 | */ |
| 37 | 37 | class Version0002Date20200902144824 extends SimpleMigrationStep { |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @param IOutput $output |
|
| 41 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
| 42 | - * @param array $options |
|
| 43 | - * @return null|ISchemaWrapper |
|
| 44 | - * @since 20.0.0 |
|
| 45 | - */ |
|
| 46 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
| 47 | - /** @var ISchemaWrapper $schema */ |
|
| 48 | - $schema = $schemaClosure(); |
|
| 49 | - |
|
| 50 | - $statusTable = $schema->getTable('user_status'); |
|
| 51 | - |
|
| 52 | - $statusTable->addIndex(['status_timestamp'], 'user_status_tstmp_ix'); |
|
| 53 | - $statusTable->addIndex(['is_user_defined', 'status'], 'user_status_iud_ix'); |
|
| 54 | - |
|
| 55 | - return $schema; |
|
| 56 | - } |
|
| 39 | + /** |
|
| 40 | + * @param IOutput $output |
|
| 41 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
| 42 | + * @param array $options |
|
| 43 | + * @return null|ISchemaWrapper |
|
| 44 | + * @since 20.0.0 |
|
| 45 | + */ |
|
| 46 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
| 47 | + /** @var ISchemaWrapper $schema */ |
|
| 48 | + $schema = $schemaClosure(); |
|
| 49 | + |
|
| 50 | + $statusTable = $schema->getTable('user_status'); |
|
| 51 | + |
|
| 52 | + $statusTable->addIndex(['status_timestamp'], 'user_status_tstmp_ix'); |
|
| 53 | + $statusTable->addIndex(['is_user_defined', 'status'], 'user_status_iud_ix'); |
|
| 54 | + |
|
| 55 | + return $schema; |
|
| 56 | + } |
|
| 57 | 57 | } |
@@ -24,30 +24,30 @@ |
||
| 24 | 24 | namespace OC\Files\Cache; |
| 25 | 25 | |
| 26 | 26 | class NullWatcher extends Watcher { |
| 27 | - private $policy; |
|
| 27 | + private $policy; |
|
| 28 | 28 | |
| 29 | - public function __construct() { |
|
| 30 | - } |
|
| 29 | + public function __construct() { |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - public function setPolicy($policy) { |
|
| 33 | - $this->policy = $policy; |
|
| 34 | - } |
|
| 32 | + public function setPolicy($policy) { |
|
| 33 | + $this->policy = $policy; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - public function getPolicy() { |
|
| 37 | - return $this->policy; |
|
| 38 | - } |
|
| 36 | + public function getPolicy() { |
|
| 37 | + return $this->policy; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - public function checkUpdate($path, $cachedEntry = null) { |
|
| 41 | - return false; |
|
| 42 | - } |
|
| 40 | + public function checkUpdate($path, $cachedEntry = null) { |
|
| 41 | + return false; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - public function update($path, $cachedData) { |
|
| 45 | - } |
|
| 44 | + public function update($path, $cachedData) { |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - public function needsUpdate($path, $cachedData) { |
|
| 48 | - return false; |
|
| 49 | - } |
|
| 47 | + public function needsUpdate($path, $cachedData) { |
|
| 48 | + return false; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - public function cleanFolder($path) { |
|
| 52 | - } |
|
| 51 | + public function cleanFolder($path) { |
|
| 52 | + } |
|
| 53 | 53 | } |