@@ -43,84 +43,84 @@ |
||
| 43 | 43 | use OCP\WorkflowEngine\IOperationCompat; |
| 44 | 44 | |
| 45 | 45 | class Application extends App implements IBootstrap { |
| 46 | - public const APP_ID = 'workflowengine'; |
|
| 46 | + public const APP_ID = 'workflowengine'; |
|
| 47 | 47 | |
| 48 | - public function __construct() { |
|
| 49 | - parent::__construct(self::APP_ID); |
|
| 50 | - } |
|
| 48 | + public function __construct() { |
|
| 49 | + parent::__construct(self::APP_ID); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - public function register(IRegistrationContext $context): void { |
|
| 53 | - $context->registerServiceAlias('RequestTimeController', RequestTime::class); |
|
| 54 | - $context->registerEventListener( |
|
| 55 | - LoadSettingsScriptsEvent::class, |
|
| 56 | - LoadAdditionalSettingsScriptsListener::class, |
|
| 57 | - -100 |
|
| 58 | - ); |
|
| 59 | - } |
|
| 52 | + public function register(IRegistrationContext $context): void { |
|
| 53 | + $context->registerServiceAlias('RequestTimeController', RequestTime::class); |
|
| 54 | + $context->registerEventListener( |
|
| 55 | + LoadSettingsScriptsEvent::class, |
|
| 56 | + LoadAdditionalSettingsScriptsListener::class, |
|
| 57 | + -100 |
|
| 58 | + ); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - public function boot(IBootContext $context): void { |
|
| 62 | - $context->injectFn(Closure::fromCallable([$this, 'registerRuleListeners'])); |
|
| 63 | - } |
|
| 61 | + public function boot(IBootContext $context): void { |
|
| 62 | + $context->injectFn(Closure::fromCallable([$this, 'registerRuleListeners'])); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - private function registerRuleListeners(IEventDispatcher $dispatcher, |
|
| 66 | - IServerContainer $container, |
|
| 67 | - ILogger $logger): void { |
|
| 68 | - $manager = $container->query(Manager::class); |
|
| 69 | - $configuredEvents = $manager->getAllConfiguredEvents(); |
|
| 65 | + private function registerRuleListeners(IEventDispatcher $dispatcher, |
|
| 66 | + IServerContainer $container, |
|
| 67 | + ILogger $logger): void { |
|
| 68 | + $manager = $container->query(Manager::class); |
|
| 69 | + $configuredEvents = $manager->getAllConfiguredEvents(); |
|
| 70 | 70 | |
| 71 | - foreach ($configuredEvents as $operationClass => $events) { |
|
| 72 | - foreach ($events as $entityClass => $eventNames) { |
|
| 73 | - array_map(function (string $eventName) use ($manager, $container, $dispatcher, $logger, $operationClass, $entityClass) { |
|
| 74 | - $dispatcher->addListener( |
|
| 75 | - $eventName, |
|
| 76 | - function ($event) use ($manager, $container, $eventName, $logger, $operationClass, $entityClass) { |
|
| 77 | - $ruleMatcher = $manager->getRuleMatcher(); |
|
| 78 | - try { |
|
| 79 | - /** @var IEntity $entity */ |
|
| 80 | - $entity = $container->query($entityClass); |
|
| 81 | - /** @var IOperation $operation */ |
|
| 82 | - $operation = $container->query($operationClass); |
|
| 71 | + foreach ($configuredEvents as $operationClass => $events) { |
|
| 72 | + foreach ($events as $entityClass => $eventNames) { |
|
| 73 | + array_map(function (string $eventName) use ($manager, $container, $dispatcher, $logger, $operationClass, $entityClass) { |
|
| 74 | + $dispatcher->addListener( |
|
| 75 | + $eventName, |
|
| 76 | + function ($event) use ($manager, $container, $eventName, $logger, $operationClass, $entityClass) { |
|
| 77 | + $ruleMatcher = $manager->getRuleMatcher(); |
|
| 78 | + try { |
|
| 79 | + /** @var IEntity $entity */ |
|
| 80 | + $entity = $container->query($entityClass); |
|
| 81 | + /** @var IOperation $operation */ |
|
| 82 | + $operation = $container->query($operationClass); |
|
| 83 | 83 | |
| 84 | - $ruleMatcher->setEntity($entity); |
|
| 85 | - $ruleMatcher->setOperation($operation); |
|
| 84 | + $ruleMatcher->setEntity($entity); |
|
| 85 | + $ruleMatcher->setOperation($operation); |
|
| 86 | 86 | |
| 87 | - $ctx = new LogContext(); |
|
| 88 | - $ctx |
|
| 89 | - ->setOperation($operation) |
|
| 90 | - ->setEntity($entity) |
|
| 91 | - ->setEventName($eventName); |
|
| 87 | + $ctx = new LogContext(); |
|
| 88 | + $ctx |
|
| 89 | + ->setOperation($operation) |
|
| 90 | + ->setEntity($entity) |
|
| 91 | + ->setEventName($eventName); |
|
| 92 | 92 | |
| 93 | - /** @var Logger $flowLogger */ |
|
| 94 | - $flowLogger = $container->query(Logger::class); |
|
| 95 | - $flowLogger->logEventInit($ctx); |
|
| 93 | + /** @var Logger $flowLogger */ |
|
| 94 | + $flowLogger = $container->query(Logger::class); |
|
| 95 | + $flowLogger->logEventInit($ctx); |
|
| 96 | 96 | |
| 97 | - if ($event instanceof Event) { |
|
| 98 | - $entity->prepareRuleMatcher($ruleMatcher, $eventName, $event); |
|
| 99 | - $operation->onEvent($eventName, $event, $ruleMatcher); |
|
| 100 | - } elseif ($entity instanceof IEntityCompat && $operation instanceof IOperationCompat) { |
|
| 101 | - // TODO: Remove this block (and the compat classes) in the first major release in 2023 |
|
| 102 | - $entity->prepareRuleMatcherCompat($ruleMatcher, $eventName, $event); |
|
| 103 | - $operation->onEventCompat($eventName, $event, $ruleMatcher); |
|
| 104 | - } else { |
|
| 105 | - $logger->debug( |
|
| 106 | - 'Cannot handle event {name} of {event} against entity {entity} and operation {operation}', |
|
| 107 | - [ |
|
| 108 | - 'app' => self::APP_ID, |
|
| 109 | - 'name' => $eventName, |
|
| 110 | - 'event' => get_class($event), |
|
| 111 | - 'entity' => $entityClass, |
|
| 112 | - 'operation' => $operationClass, |
|
| 113 | - ] |
|
| 114 | - ); |
|
| 115 | - } |
|
| 116 | - $flowLogger->logEventDone($ctx); |
|
| 117 | - } catch (QueryException $e) { |
|
| 118 | - // Ignore query exceptions since they might occur when an entity/operation were setup before by an app that is disabled now |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - ); |
|
| 122 | - }, $eventNames ?? []); |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - } |
|
| 97 | + if ($event instanceof Event) { |
|
| 98 | + $entity->prepareRuleMatcher($ruleMatcher, $eventName, $event); |
|
| 99 | + $operation->onEvent($eventName, $event, $ruleMatcher); |
|
| 100 | + } elseif ($entity instanceof IEntityCompat && $operation instanceof IOperationCompat) { |
|
| 101 | + // TODO: Remove this block (and the compat classes) in the first major release in 2023 |
|
| 102 | + $entity->prepareRuleMatcherCompat($ruleMatcher, $eventName, $event); |
|
| 103 | + $operation->onEventCompat($eventName, $event, $ruleMatcher); |
|
| 104 | + } else { |
|
| 105 | + $logger->debug( |
|
| 106 | + 'Cannot handle event {name} of {event} against entity {entity} and operation {operation}', |
|
| 107 | + [ |
|
| 108 | + 'app' => self::APP_ID, |
|
| 109 | + 'name' => $eventName, |
|
| 110 | + 'event' => get_class($event), |
|
| 111 | + 'entity' => $entityClass, |
|
| 112 | + 'operation' => $operationClass, |
|
| 113 | + ] |
|
| 114 | + ); |
|
| 115 | + } |
|
| 116 | + $flowLogger->logEventDone($ctx); |
|
| 117 | + } catch (QueryException $e) { |
|
| 118 | + // Ignore query exceptions since they might occur when an entity/operation were setup before by an app that is disabled now |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + ); |
|
| 122 | + }, $eventNames ?? []); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | 126 | } |
@@ -42,153 +42,153 @@ |
||
| 42 | 42 | use OCP\WorkflowEngine\ISpecificOperation; |
| 43 | 43 | |
| 44 | 44 | abstract class ASettings implements ISettings { |
| 45 | - /** @var IL10N */ |
|
| 46 | - private $l10n; |
|
| 47 | - |
|
| 48 | - /** @var string */ |
|
| 49 | - private $appName; |
|
| 50 | - |
|
| 51 | - /** @var IEventDispatcher */ |
|
| 52 | - private $eventDispatcher; |
|
| 53 | - |
|
| 54 | - /** @var Manager */ |
|
| 55 | - protected $manager; |
|
| 56 | - |
|
| 57 | - /** @var IInitialStateService */ |
|
| 58 | - private $initialStateService; |
|
| 59 | - |
|
| 60 | - /** @var IConfig */ |
|
| 61 | - private $config; |
|
| 62 | - |
|
| 63 | - public function __construct( |
|
| 64 | - string $appName, |
|
| 65 | - IL10N $l, |
|
| 66 | - IEventDispatcher $eventDispatcher, |
|
| 67 | - Manager $manager, |
|
| 68 | - IInitialStateService $initialStateService, |
|
| 69 | - IConfig $config |
|
| 70 | - ) { |
|
| 71 | - $this->appName = $appName; |
|
| 72 | - $this->l10n = $l; |
|
| 73 | - $this->eventDispatcher = $eventDispatcher; |
|
| 74 | - $this->manager = $manager; |
|
| 75 | - $this->initialStateService = $initialStateService; |
|
| 76 | - $this->config = $config; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - abstract public function getScope(): int; |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @return TemplateResponse |
|
| 83 | - */ |
|
| 84 | - public function getForm() { |
|
| 85 | - // @deprecated in 20.0.0: retire this one in favor of the typed event |
|
| 86 | - $this->eventDispatcher->dispatch( |
|
| 87 | - 'OCP\WorkflowEngine::loadAdditionalSettingScripts', |
|
| 88 | - new LoadSettingsScriptsEvent() |
|
| 89 | - ); |
|
| 90 | - $this->eventDispatcher->dispatchTyped(new LoadSettingsScriptsEvent()); |
|
| 91 | - |
|
| 92 | - $entities = $this->manager->getEntitiesList(); |
|
| 93 | - $this->initialStateService->provideInitialState( |
|
| 94 | - Application::APP_ID, |
|
| 95 | - 'entities', |
|
| 96 | - $this->entitiesToArray($entities) |
|
| 97 | - ); |
|
| 98 | - |
|
| 99 | - $operators = $this->manager->getOperatorList(); |
|
| 100 | - $this->initialStateService->provideInitialState( |
|
| 101 | - Application::APP_ID, |
|
| 102 | - 'operators', |
|
| 103 | - $this->operatorsToArray($operators) |
|
| 104 | - ); |
|
| 105 | - |
|
| 106 | - $checks = $this->manager->getCheckList(); |
|
| 107 | - $this->initialStateService->provideInitialState( |
|
| 108 | - Application::APP_ID, |
|
| 109 | - 'checks', |
|
| 110 | - $this->checksToArray($checks) |
|
| 111 | - ); |
|
| 112 | - |
|
| 113 | - $this->initialStateService->provideInitialState( |
|
| 114 | - Application::APP_ID, |
|
| 115 | - 'scope', |
|
| 116 | - $this->getScope() |
|
| 117 | - ); |
|
| 118 | - |
|
| 119 | - $this->initialStateService->provideInitialState( |
|
| 120 | - Application::APP_ID, |
|
| 121 | - 'appstoreenabled', |
|
| 122 | - $this->config->getSystemValueBool('appstoreenabled', true) |
|
| 123 | - ); |
|
| 124 | - |
|
| 125 | - return new TemplateResponse(Application::APP_ID, 'settings', [], 'blank'); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @return string the section ID, e.g. 'sharing' |
|
| 130 | - */ |
|
| 131 | - public function getSection() { |
|
| 132 | - return 'workflow'; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * @return int whether the form should be rather on the top or bottom of |
|
| 137 | - * the admin section. The forms are arranged in ascending order of the |
|
| 138 | - * priority values. It is required to return a value between 0 and 100. |
|
| 139 | - * |
|
| 140 | - * E.g.: 70 |
|
| 141 | - */ |
|
| 142 | - public function getPriority() { |
|
| 143 | - return 0; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - private function entitiesToArray(array $entities) { |
|
| 147 | - return array_map(function (IEntity $entity) { |
|
| 148 | - $events = array_map(function (IEntityEvent $entityEvent) { |
|
| 149 | - return [ |
|
| 150 | - 'eventName' => $entityEvent->getEventName(), |
|
| 151 | - 'displayName' => $entityEvent->getDisplayName() |
|
| 152 | - ]; |
|
| 153 | - }, $entity->getEvents()); |
|
| 154 | - |
|
| 155 | - return [ |
|
| 156 | - 'id' => get_class($entity), |
|
| 157 | - 'icon' => $entity->getIcon(), |
|
| 158 | - 'name' => $entity->getName(), |
|
| 159 | - 'events' => $events, |
|
| 160 | - ]; |
|
| 161 | - }, $entities); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - private function operatorsToArray(array $operators) { |
|
| 165 | - $operators = array_filter($operators, function (IOperation $operator) { |
|
| 166 | - return $operator->isAvailableForScope($this->getScope()); |
|
| 167 | - }); |
|
| 168 | - |
|
| 169 | - return array_map(function (IOperation $operator) { |
|
| 170 | - return [ |
|
| 171 | - 'id' => get_class($operator), |
|
| 172 | - 'icon' => $operator->getIcon(), |
|
| 173 | - 'name' => $operator->getDisplayName(), |
|
| 174 | - 'description' => $operator->getDescription(), |
|
| 175 | - 'fixedEntity' => $operator instanceof ISpecificOperation ? $operator->getEntityId() : '', |
|
| 176 | - 'isComplex' => $operator instanceof IComplexOperation, |
|
| 177 | - 'triggerHint' => $operator instanceof IComplexOperation ? $operator->getTriggerHint() : '', |
|
| 178 | - ]; |
|
| 179 | - }, $operators); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - private function checksToArray(array $checks) { |
|
| 183 | - $checks = array_filter($checks, function (ICheck $check) { |
|
| 184 | - return $check->isAvailableForScope($this->getScope()); |
|
| 185 | - }); |
|
| 186 | - |
|
| 187 | - return array_map(function (ICheck $check) { |
|
| 188 | - return [ |
|
| 189 | - 'id' => get_class($check), |
|
| 190 | - 'supportedEntities' => $check->supportedEntities(), |
|
| 191 | - ]; |
|
| 192 | - }, $checks); |
|
| 193 | - } |
|
| 45 | + /** @var IL10N */ |
|
| 46 | + private $l10n; |
|
| 47 | + |
|
| 48 | + /** @var string */ |
|
| 49 | + private $appName; |
|
| 50 | + |
|
| 51 | + /** @var IEventDispatcher */ |
|
| 52 | + private $eventDispatcher; |
|
| 53 | + |
|
| 54 | + /** @var Manager */ |
|
| 55 | + protected $manager; |
|
| 56 | + |
|
| 57 | + /** @var IInitialStateService */ |
|
| 58 | + private $initialStateService; |
|
| 59 | + |
|
| 60 | + /** @var IConfig */ |
|
| 61 | + private $config; |
|
| 62 | + |
|
| 63 | + public function __construct( |
|
| 64 | + string $appName, |
|
| 65 | + IL10N $l, |
|
| 66 | + IEventDispatcher $eventDispatcher, |
|
| 67 | + Manager $manager, |
|
| 68 | + IInitialStateService $initialStateService, |
|
| 69 | + IConfig $config |
|
| 70 | + ) { |
|
| 71 | + $this->appName = $appName; |
|
| 72 | + $this->l10n = $l; |
|
| 73 | + $this->eventDispatcher = $eventDispatcher; |
|
| 74 | + $this->manager = $manager; |
|
| 75 | + $this->initialStateService = $initialStateService; |
|
| 76 | + $this->config = $config; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + abstract public function getScope(): int; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @return TemplateResponse |
|
| 83 | + */ |
|
| 84 | + public function getForm() { |
|
| 85 | + // @deprecated in 20.0.0: retire this one in favor of the typed event |
|
| 86 | + $this->eventDispatcher->dispatch( |
|
| 87 | + 'OCP\WorkflowEngine::loadAdditionalSettingScripts', |
|
| 88 | + new LoadSettingsScriptsEvent() |
|
| 89 | + ); |
|
| 90 | + $this->eventDispatcher->dispatchTyped(new LoadSettingsScriptsEvent()); |
|
| 91 | + |
|
| 92 | + $entities = $this->manager->getEntitiesList(); |
|
| 93 | + $this->initialStateService->provideInitialState( |
|
| 94 | + Application::APP_ID, |
|
| 95 | + 'entities', |
|
| 96 | + $this->entitiesToArray($entities) |
|
| 97 | + ); |
|
| 98 | + |
|
| 99 | + $operators = $this->manager->getOperatorList(); |
|
| 100 | + $this->initialStateService->provideInitialState( |
|
| 101 | + Application::APP_ID, |
|
| 102 | + 'operators', |
|
| 103 | + $this->operatorsToArray($operators) |
|
| 104 | + ); |
|
| 105 | + |
|
| 106 | + $checks = $this->manager->getCheckList(); |
|
| 107 | + $this->initialStateService->provideInitialState( |
|
| 108 | + Application::APP_ID, |
|
| 109 | + 'checks', |
|
| 110 | + $this->checksToArray($checks) |
|
| 111 | + ); |
|
| 112 | + |
|
| 113 | + $this->initialStateService->provideInitialState( |
|
| 114 | + Application::APP_ID, |
|
| 115 | + 'scope', |
|
| 116 | + $this->getScope() |
|
| 117 | + ); |
|
| 118 | + |
|
| 119 | + $this->initialStateService->provideInitialState( |
|
| 120 | + Application::APP_ID, |
|
| 121 | + 'appstoreenabled', |
|
| 122 | + $this->config->getSystemValueBool('appstoreenabled', true) |
|
| 123 | + ); |
|
| 124 | + |
|
| 125 | + return new TemplateResponse(Application::APP_ID, 'settings', [], 'blank'); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * @return string the section ID, e.g. 'sharing' |
|
| 130 | + */ |
|
| 131 | + public function getSection() { |
|
| 132 | + return 'workflow'; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * @return int whether the form should be rather on the top or bottom of |
|
| 137 | + * the admin section. The forms are arranged in ascending order of the |
|
| 138 | + * priority values. It is required to return a value between 0 and 100. |
|
| 139 | + * |
|
| 140 | + * E.g.: 70 |
|
| 141 | + */ |
|
| 142 | + public function getPriority() { |
|
| 143 | + return 0; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + private function entitiesToArray(array $entities) { |
|
| 147 | + return array_map(function (IEntity $entity) { |
|
| 148 | + $events = array_map(function (IEntityEvent $entityEvent) { |
|
| 149 | + return [ |
|
| 150 | + 'eventName' => $entityEvent->getEventName(), |
|
| 151 | + 'displayName' => $entityEvent->getDisplayName() |
|
| 152 | + ]; |
|
| 153 | + }, $entity->getEvents()); |
|
| 154 | + |
|
| 155 | + return [ |
|
| 156 | + 'id' => get_class($entity), |
|
| 157 | + 'icon' => $entity->getIcon(), |
|
| 158 | + 'name' => $entity->getName(), |
|
| 159 | + 'events' => $events, |
|
| 160 | + ]; |
|
| 161 | + }, $entities); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + private function operatorsToArray(array $operators) { |
|
| 165 | + $operators = array_filter($operators, function (IOperation $operator) { |
|
| 166 | + return $operator->isAvailableForScope($this->getScope()); |
|
| 167 | + }); |
|
| 168 | + |
|
| 169 | + return array_map(function (IOperation $operator) { |
|
| 170 | + return [ |
|
| 171 | + 'id' => get_class($operator), |
|
| 172 | + 'icon' => $operator->getIcon(), |
|
| 173 | + 'name' => $operator->getDisplayName(), |
|
| 174 | + 'description' => $operator->getDescription(), |
|
| 175 | + 'fixedEntity' => $operator instanceof ISpecificOperation ? $operator->getEntityId() : '', |
|
| 176 | + 'isComplex' => $operator instanceof IComplexOperation, |
|
| 177 | + 'triggerHint' => $operator instanceof IComplexOperation ? $operator->getTriggerHint() : '', |
|
| 178 | + ]; |
|
| 179 | + }, $operators); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + private function checksToArray(array $checks) { |
|
| 183 | + $checks = array_filter($checks, function (ICheck $check) { |
|
| 184 | + return $check->isAvailableForScope($this->getScope()); |
|
| 185 | + }); |
|
| 186 | + |
|
| 187 | + return array_map(function (ICheck $check) { |
|
| 188 | + return [ |
|
| 189 | + 'id' => get_class($check), |
|
| 190 | + 'supportedEntities' => $check->supportedEntities(), |
|
| 191 | + ]; |
|
| 192 | + }, $checks); |
|
| 193 | + } |
|
| 194 | 194 | } |
@@ -62,291 +62,291 @@ |
||
| 62 | 62 | * @package OCA\Files\Controller |
| 63 | 63 | */ |
| 64 | 64 | class ViewController extends Controller { |
| 65 | - /** @var string */ |
|
| 66 | - protected $appName; |
|
| 67 | - /** @var IRequest */ |
|
| 68 | - protected $request; |
|
| 69 | - /** @var IURLGenerator */ |
|
| 70 | - protected $urlGenerator; |
|
| 71 | - /** @var IL10N */ |
|
| 72 | - protected $l10n; |
|
| 73 | - /** @var IConfig */ |
|
| 74 | - protected $config; |
|
| 75 | - /** @var IEventDispatcher */ |
|
| 76 | - protected $eventDispatcher; |
|
| 77 | - /** @var IUserSession */ |
|
| 78 | - protected $userSession; |
|
| 79 | - /** @var IAppManager */ |
|
| 80 | - protected $appManager; |
|
| 81 | - /** @var IRootFolder */ |
|
| 82 | - protected $rootFolder; |
|
| 83 | - /** @var Helper */ |
|
| 84 | - protected $activityHelper; |
|
| 85 | - |
|
| 86 | - public function __construct(string $appName, |
|
| 87 | - IRequest $request, |
|
| 88 | - IURLGenerator $urlGenerator, |
|
| 89 | - IL10N $l10n, |
|
| 90 | - IConfig $config, |
|
| 91 | - IEventDispatcher $eventDispatcher, |
|
| 92 | - IUserSession $userSession, |
|
| 93 | - IAppManager $appManager, |
|
| 94 | - IRootFolder $rootFolder, |
|
| 95 | - Helper $activityHelper |
|
| 96 | - ) { |
|
| 97 | - parent::__construct($appName, $request); |
|
| 98 | - $this->appName = $appName; |
|
| 99 | - $this->request = $request; |
|
| 100 | - $this->urlGenerator = $urlGenerator; |
|
| 101 | - $this->l10n = $l10n; |
|
| 102 | - $this->config = $config; |
|
| 103 | - $this->eventDispatcher = $eventDispatcher; |
|
| 104 | - $this->userSession = $userSession; |
|
| 105 | - $this->appManager = $appManager; |
|
| 106 | - $this->rootFolder = $rootFolder; |
|
| 107 | - $this->activityHelper = $activityHelper; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * @param string $appName |
|
| 112 | - * @param string $scriptName |
|
| 113 | - * @return string |
|
| 114 | - */ |
|
| 115 | - protected function renderScript($appName, $scriptName) { |
|
| 116 | - $content = ''; |
|
| 117 | - $appPath = \OC_App::getAppPath($appName); |
|
| 118 | - $scriptPath = $appPath . '/' . $scriptName; |
|
| 119 | - if (file_exists($scriptPath)) { |
|
| 120 | - // TODO: sanitize path / script name ? |
|
| 121 | - ob_start(); |
|
| 122 | - include $scriptPath; |
|
| 123 | - $content = ob_get_contents(); |
|
| 124 | - @ob_end_clean(); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - return $content; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * FIXME: Replace with non static code |
|
| 132 | - * |
|
| 133 | - * @return array |
|
| 134 | - * @throws \OCP\Files\NotFoundException |
|
| 135 | - */ |
|
| 136 | - protected function getStorageInfo() { |
|
| 137 | - $dirInfo = \OC\Files\Filesystem::getFileInfo('/', false); |
|
| 138 | - |
|
| 139 | - return \OC_Helper::getStorageInfo('/', $dirInfo); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @NoCSRFRequired |
|
| 144 | - * @NoAdminRequired |
|
| 145 | - * |
|
| 146 | - * @param string $fileid |
|
| 147 | - * @return TemplateResponse|RedirectResponse |
|
| 148 | - * @throws NotFoundException |
|
| 149 | - */ |
|
| 150 | - public function showFile(string $fileid = null): Response { |
|
| 151 | - // This is the entry point from the `/f/{fileid}` URL which is hardcoded in the server. |
|
| 152 | - try { |
|
| 153 | - return $this->redirectToFile($fileid); |
|
| 154 | - } catch (NotFoundException $e) { |
|
| 155 | - return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true])); |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * @NoCSRFRequired |
|
| 161 | - * @NoAdminRequired |
|
| 162 | - * |
|
| 163 | - * @param string $dir |
|
| 164 | - * @param string $view |
|
| 165 | - * @param string $fileid |
|
| 166 | - * @param bool $fileNotFound |
|
| 167 | - * @return TemplateResponse|RedirectResponse |
|
| 168 | - * @throws NotFoundException |
|
| 169 | - */ |
|
| 170 | - public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false) { |
|
| 171 | - if ($fileid !== null) { |
|
| 172 | - try { |
|
| 173 | - return $this->redirectToFile($fileid); |
|
| 174 | - } catch (NotFoundException $e) { |
|
| 175 | - return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true])); |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - $nav = new \OCP\Template('files', 'appnavigation', ''); |
|
| 180 | - |
|
| 181 | - // Load the files we need |
|
| 182 | - \OCP\Util::addStyle('files', 'merged'); |
|
| 183 | - \OCP\Util::addScript('files', 'merged-index'); |
|
| 184 | - |
|
| 185 | - // mostly for the home storage's free space |
|
| 186 | - // FIXME: Make non static |
|
| 187 | - $storageInfo = $this->getStorageInfo(); |
|
| 188 | - |
|
| 189 | - $user = $this->userSession->getUser()->getUID(); |
|
| 190 | - |
|
| 191 | - // Get all the user favorites to create a submenu |
|
| 192 | - try { |
|
| 193 | - $favElements = $this->activityHelper->getFavoriteFilePaths($this->userSession->getUser()->getUID()); |
|
| 194 | - } catch (\RuntimeException $e) { |
|
| 195 | - $favElements['folders'] = []; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - $collapseClasses = ''; |
|
| 199 | - if (count($favElements['folders']) > 0) { |
|
| 200 | - $collapseClasses = 'collapsible'; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - $favoritesSublistArray = []; |
|
| 204 | - |
|
| 205 | - $navBarPositionPosition = 6; |
|
| 206 | - $currentCount = 0; |
|
| 207 | - foreach ($favElements['folders'] as $dir) { |
|
| 208 | - $link = $this->urlGenerator->linkToRoute('files.view.index', ['dir' => $dir, 'view' => 'files']); |
|
| 209 | - $sortingValue = ++$currentCount; |
|
| 210 | - $element = [ |
|
| 211 | - 'id' => str_replace('/', '-', $dir), |
|
| 212 | - 'view' => 'files', |
|
| 213 | - 'href' => $link, |
|
| 214 | - 'dir' => $dir, |
|
| 215 | - 'order' => $navBarPositionPosition, |
|
| 216 | - 'folderPosition' => $sortingValue, |
|
| 217 | - 'name' => basename($dir), |
|
| 218 | - 'icon' => 'files', |
|
| 219 | - 'quickaccesselement' => 'true' |
|
| 220 | - ]; |
|
| 221 | - |
|
| 222 | - array_push($favoritesSublistArray, $element); |
|
| 223 | - $navBarPositionPosition++; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - $navItems = \OCA\Files\App::getNavigationManager()->getAll(); |
|
| 227 | - |
|
| 228 | - // add the favorites entry in menu |
|
| 229 | - $navItems['favorites']['sublist'] = $favoritesSublistArray; |
|
| 230 | - $navItems['favorites']['classes'] = $collapseClasses; |
|
| 231 | - |
|
| 232 | - // parse every menu and add the expandedState user value |
|
| 233 | - foreach ($navItems as $key => $item) { |
|
| 234 | - if (isset($item['expandedState'])) { |
|
| 235 | - $navItems[$key]['defaultExpandedState'] = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', $item['expandedState'], '0') === '1'; |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - $nav->assign('navigationItems', $navItems); |
|
| 240 | - |
|
| 241 | - $nav->assign('usage', \OC_Helper::humanFileSize($storageInfo['used'])); |
|
| 242 | - if ($storageInfo['quota'] === \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
| 243 | - $totalSpace = $this->l10n->t('Unlimited'); |
|
| 244 | - } else { |
|
| 245 | - $totalSpace = \OC_Helper::humanFileSize($storageInfo['total']); |
|
| 246 | - } |
|
| 247 | - $nav->assign('total_space', $totalSpace); |
|
| 248 | - $nav->assign('quota', $storageInfo['quota']); |
|
| 249 | - $nav->assign('usage_relative', $storageInfo['relative']); |
|
| 250 | - |
|
| 251 | - $nav->assign('webdav_url', \OCP\Util::linkToRemote('dav/files/' . $user)); |
|
| 252 | - |
|
| 253 | - $contentItems = []; |
|
| 254 | - |
|
| 255 | - // render the container content for every navigation item |
|
| 256 | - foreach ($navItems as $item) { |
|
| 257 | - $content = ''; |
|
| 258 | - if (isset($item['script'])) { |
|
| 259 | - $content = $this->renderScript($item['appname'], $item['script']); |
|
| 260 | - } |
|
| 261 | - // parse submenus |
|
| 262 | - if (isset($item['sublist'])) { |
|
| 263 | - foreach ($item['sublist'] as $subitem) { |
|
| 264 | - $subcontent = ''; |
|
| 265 | - if (isset($subitem['script'])) { |
|
| 266 | - $subcontent = $this->renderScript($subitem['appname'], $subitem['script']); |
|
| 267 | - } |
|
| 268 | - $contentItems[$subitem['id']] = [ |
|
| 269 | - 'id' => $subitem['id'], |
|
| 270 | - 'content' => $subcontent |
|
| 271 | - ]; |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - $contentItems[$item['id']] = [ |
|
| 275 | - 'id' => $item['id'], |
|
| 276 | - 'content' => $content |
|
| 277 | - ]; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - $event = new LoadAdditionalScriptsEvent(); |
|
| 281 | - $this->eventDispatcher->dispatchTyped($event); |
|
| 282 | - $this->eventDispatcher->dispatchTyped(new LoadSidebar()); |
|
| 283 | - // Load Viewer scripts |
|
| 284 | - if (class_exists(LoadViewer::class)) { |
|
| 285 | - $this->eventDispatcher->dispatchTyped(new LoadViewer()); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - $params = []; |
|
| 289 | - $params['usedSpacePercent'] = (int) $storageInfo['relative']; |
|
| 290 | - $params['owner'] = $storageInfo['owner'] ?? ''; |
|
| 291 | - $params['ownerDisplayName'] = $storageInfo['ownerDisplayName'] ?? ''; |
|
| 292 | - $params['isPublic'] = false; |
|
| 293 | - $params['allowShareWithLink'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'); |
|
| 294 | - $params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name'); |
|
| 295 | - $params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc'); |
|
| 296 | - $params['showgridview'] = $this->config->getUserValue($user, 'files', 'show_grid', false); |
|
| 297 | - $params['isIE'] = \OCP\Util::isIE(); |
|
| 298 | - $showHidden = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false); |
|
| 299 | - $params['showHiddenFiles'] = $showHidden ? 1 : 0; |
|
| 300 | - $params['fileNotFound'] = $fileNotFound ? 1 : 0; |
|
| 301 | - $params['appNavigation'] = $nav; |
|
| 302 | - $params['appContents'] = $contentItems; |
|
| 303 | - $params['hiddenFields'] = $event->getHiddenFields(); |
|
| 304 | - |
|
| 305 | - $response = new TemplateResponse( |
|
| 306 | - $this->appName, |
|
| 307 | - 'index', |
|
| 308 | - $params |
|
| 309 | - ); |
|
| 310 | - $policy = new ContentSecurityPolicy(); |
|
| 311 | - $policy->addAllowedFrameDomain('\'self\''); |
|
| 312 | - $response->setContentSecurityPolicy($policy); |
|
| 313 | - |
|
| 314 | - return $response; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * Redirects to the file list and highlight the given file id |
|
| 319 | - * |
|
| 320 | - * @param string $fileId file id to show |
|
| 321 | - * @return RedirectResponse redirect response or not found response |
|
| 322 | - * @throws \OCP\Files\NotFoundException |
|
| 323 | - */ |
|
| 324 | - private function redirectToFile($fileId) { |
|
| 325 | - $uid = $this->userSession->getUser()->getUID(); |
|
| 326 | - $baseFolder = $this->rootFolder->getUserFolder($uid); |
|
| 327 | - $files = $baseFolder->getById($fileId); |
|
| 328 | - $params = []; |
|
| 329 | - |
|
| 330 | - if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) { |
|
| 331 | - $baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/'); |
|
| 332 | - $files = $baseFolder->getById($fileId); |
|
| 333 | - $params['view'] = 'trashbin'; |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - if (!empty($files)) { |
|
| 337 | - $file = current($files); |
|
| 338 | - if ($file instanceof Folder) { |
|
| 339 | - // set the full path to enter the folder |
|
| 340 | - $params['dir'] = $baseFolder->getRelativePath($file->getPath()); |
|
| 341 | - } else { |
|
| 342 | - // set parent path as dir |
|
| 343 | - $params['dir'] = $baseFolder->getRelativePath($file->getParent()->getPath()); |
|
| 344 | - // and scroll to the entry |
|
| 345 | - $params['scrollto'] = $file->getName(); |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params)); |
|
| 349 | - } |
|
| 350 | - throw new \OCP\Files\NotFoundException(); |
|
| 351 | - } |
|
| 65 | + /** @var string */ |
|
| 66 | + protected $appName; |
|
| 67 | + /** @var IRequest */ |
|
| 68 | + protected $request; |
|
| 69 | + /** @var IURLGenerator */ |
|
| 70 | + protected $urlGenerator; |
|
| 71 | + /** @var IL10N */ |
|
| 72 | + protected $l10n; |
|
| 73 | + /** @var IConfig */ |
|
| 74 | + protected $config; |
|
| 75 | + /** @var IEventDispatcher */ |
|
| 76 | + protected $eventDispatcher; |
|
| 77 | + /** @var IUserSession */ |
|
| 78 | + protected $userSession; |
|
| 79 | + /** @var IAppManager */ |
|
| 80 | + protected $appManager; |
|
| 81 | + /** @var IRootFolder */ |
|
| 82 | + protected $rootFolder; |
|
| 83 | + /** @var Helper */ |
|
| 84 | + protected $activityHelper; |
|
| 85 | + |
|
| 86 | + public function __construct(string $appName, |
|
| 87 | + IRequest $request, |
|
| 88 | + IURLGenerator $urlGenerator, |
|
| 89 | + IL10N $l10n, |
|
| 90 | + IConfig $config, |
|
| 91 | + IEventDispatcher $eventDispatcher, |
|
| 92 | + IUserSession $userSession, |
|
| 93 | + IAppManager $appManager, |
|
| 94 | + IRootFolder $rootFolder, |
|
| 95 | + Helper $activityHelper |
|
| 96 | + ) { |
|
| 97 | + parent::__construct($appName, $request); |
|
| 98 | + $this->appName = $appName; |
|
| 99 | + $this->request = $request; |
|
| 100 | + $this->urlGenerator = $urlGenerator; |
|
| 101 | + $this->l10n = $l10n; |
|
| 102 | + $this->config = $config; |
|
| 103 | + $this->eventDispatcher = $eventDispatcher; |
|
| 104 | + $this->userSession = $userSession; |
|
| 105 | + $this->appManager = $appManager; |
|
| 106 | + $this->rootFolder = $rootFolder; |
|
| 107 | + $this->activityHelper = $activityHelper; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * @param string $appName |
|
| 112 | + * @param string $scriptName |
|
| 113 | + * @return string |
|
| 114 | + */ |
|
| 115 | + protected function renderScript($appName, $scriptName) { |
|
| 116 | + $content = ''; |
|
| 117 | + $appPath = \OC_App::getAppPath($appName); |
|
| 118 | + $scriptPath = $appPath . '/' . $scriptName; |
|
| 119 | + if (file_exists($scriptPath)) { |
|
| 120 | + // TODO: sanitize path / script name ? |
|
| 121 | + ob_start(); |
|
| 122 | + include $scriptPath; |
|
| 123 | + $content = ob_get_contents(); |
|
| 124 | + @ob_end_clean(); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + return $content; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * FIXME: Replace with non static code |
|
| 132 | + * |
|
| 133 | + * @return array |
|
| 134 | + * @throws \OCP\Files\NotFoundException |
|
| 135 | + */ |
|
| 136 | + protected function getStorageInfo() { |
|
| 137 | + $dirInfo = \OC\Files\Filesystem::getFileInfo('/', false); |
|
| 138 | + |
|
| 139 | + return \OC_Helper::getStorageInfo('/', $dirInfo); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @NoCSRFRequired |
|
| 144 | + * @NoAdminRequired |
|
| 145 | + * |
|
| 146 | + * @param string $fileid |
|
| 147 | + * @return TemplateResponse|RedirectResponse |
|
| 148 | + * @throws NotFoundException |
|
| 149 | + */ |
|
| 150 | + public function showFile(string $fileid = null): Response { |
|
| 151 | + // This is the entry point from the `/f/{fileid}` URL which is hardcoded in the server. |
|
| 152 | + try { |
|
| 153 | + return $this->redirectToFile($fileid); |
|
| 154 | + } catch (NotFoundException $e) { |
|
| 155 | + return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true])); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * @NoCSRFRequired |
|
| 161 | + * @NoAdminRequired |
|
| 162 | + * |
|
| 163 | + * @param string $dir |
|
| 164 | + * @param string $view |
|
| 165 | + * @param string $fileid |
|
| 166 | + * @param bool $fileNotFound |
|
| 167 | + * @return TemplateResponse|RedirectResponse |
|
| 168 | + * @throws NotFoundException |
|
| 169 | + */ |
|
| 170 | + public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false) { |
|
| 171 | + if ($fileid !== null) { |
|
| 172 | + try { |
|
| 173 | + return $this->redirectToFile($fileid); |
|
| 174 | + } catch (NotFoundException $e) { |
|
| 175 | + return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true])); |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + $nav = new \OCP\Template('files', 'appnavigation', ''); |
|
| 180 | + |
|
| 181 | + // Load the files we need |
|
| 182 | + \OCP\Util::addStyle('files', 'merged'); |
|
| 183 | + \OCP\Util::addScript('files', 'merged-index'); |
|
| 184 | + |
|
| 185 | + // mostly for the home storage's free space |
|
| 186 | + // FIXME: Make non static |
|
| 187 | + $storageInfo = $this->getStorageInfo(); |
|
| 188 | + |
|
| 189 | + $user = $this->userSession->getUser()->getUID(); |
|
| 190 | + |
|
| 191 | + // Get all the user favorites to create a submenu |
|
| 192 | + try { |
|
| 193 | + $favElements = $this->activityHelper->getFavoriteFilePaths($this->userSession->getUser()->getUID()); |
|
| 194 | + } catch (\RuntimeException $e) { |
|
| 195 | + $favElements['folders'] = []; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + $collapseClasses = ''; |
|
| 199 | + if (count($favElements['folders']) > 0) { |
|
| 200 | + $collapseClasses = 'collapsible'; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + $favoritesSublistArray = []; |
|
| 204 | + |
|
| 205 | + $navBarPositionPosition = 6; |
|
| 206 | + $currentCount = 0; |
|
| 207 | + foreach ($favElements['folders'] as $dir) { |
|
| 208 | + $link = $this->urlGenerator->linkToRoute('files.view.index', ['dir' => $dir, 'view' => 'files']); |
|
| 209 | + $sortingValue = ++$currentCount; |
|
| 210 | + $element = [ |
|
| 211 | + 'id' => str_replace('/', '-', $dir), |
|
| 212 | + 'view' => 'files', |
|
| 213 | + 'href' => $link, |
|
| 214 | + 'dir' => $dir, |
|
| 215 | + 'order' => $navBarPositionPosition, |
|
| 216 | + 'folderPosition' => $sortingValue, |
|
| 217 | + 'name' => basename($dir), |
|
| 218 | + 'icon' => 'files', |
|
| 219 | + 'quickaccesselement' => 'true' |
|
| 220 | + ]; |
|
| 221 | + |
|
| 222 | + array_push($favoritesSublistArray, $element); |
|
| 223 | + $navBarPositionPosition++; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + $navItems = \OCA\Files\App::getNavigationManager()->getAll(); |
|
| 227 | + |
|
| 228 | + // add the favorites entry in menu |
|
| 229 | + $navItems['favorites']['sublist'] = $favoritesSublistArray; |
|
| 230 | + $navItems['favorites']['classes'] = $collapseClasses; |
|
| 231 | + |
|
| 232 | + // parse every menu and add the expandedState user value |
|
| 233 | + foreach ($navItems as $key => $item) { |
|
| 234 | + if (isset($item['expandedState'])) { |
|
| 235 | + $navItems[$key]['defaultExpandedState'] = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', $item['expandedState'], '0') === '1'; |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + $nav->assign('navigationItems', $navItems); |
|
| 240 | + |
|
| 241 | + $nav->assign('usage', \OC_Helper::humanFileSize($storageInfo['used'])); |
|
| 242 | + if ($storageInfo['quota'] === \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
| 243 | + $totalSpace = $this->l10n->t('Unlimited'); |
|
| 244 | + } else { |
|
| 245 | + $totalSpace = \OC_Helper::humanFileSize($storageInfo['total']); |
|
| 246 | + } |
|
| 247 | + $nav->assign('total_space', $totalSpace); |
|
| 248 | + $nav->assign('quota', $storageInfo['quota']); |
|
| 249 | + $nav->assign('usage_relative', $storageInfo['relative']); |
|
| 250 | + |
|
| 251 | + $nav->assign('webdav_url', \OCP\Util::linkToRemote('dav/files/' . $user)); |
|
| 252 | + |
|
| 253 | + $contentItems = []; |
|
| 254 | + |
|
| 255 | + // render the container content for every navigation item |
|
| 256 | + foreach ($navItems as $item) { |
|
| 257 | + $content = ''; |
|
| 258 | + if (isset($item['script'])) { |
|
| 259 | + $content = $this->renderScript($item['appname'], $item['script']); |
|
| 260 | + } |
|
| 261 | + // parse submenus |
|
| 262 | + if (isset($item['sublist'])) { |
|
| 263 | + foreach ($item['sublist'] as $subitem) { |
|
| 264 | + $subcontent = ''; |
|
| 265 | + if (isset($subitem['script'])) { |
|
| 266 | + $subcontent = $this->renderScript($subitem['appname'], $subitem['script']); |
|
| 267 | + } |
|
| 268 | + $contentItems[$subitem['id']] = [ |
|
| 269 | + 'id' => $subitem['id'], |
|
| 270 | + 'content' => $subcontent |
|
| 271 | + ]; |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + $contentItems[$item['id']] = [ |
|
| 275 | + 'id' => $item['id'], |
|
| 276 | + 'content' => $content |
|
| 277 | + ]; |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + $event = new LoadAdditionalScriptsEvent(); |
|
| 281 | + $this->eventDispatcher->dispatchTyped($event); |
|
| 282 | + $this->eventDispatcher->dispatchTyped(new LoadSidebar()); |
|
| 283 | + // Load Viewer scripts |
|
| 284 | + if (class_exists(LoadViewer::class)) { |
|
| 285 | + $this->eventDispatcher->dispatchTyped(new LoadViewer()); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + $params = []; |
|
| 289 | + $params['usedSpacePercent'] = (int) $storageInfo['relative']; |
|
| 290 | + $params['owner'] = $storageInfo['owner'] ?? ''; |
|
| 291 | + $params['ownerDisplayName'] = $storageInfo['ownerDisplayName'] ?? ''; |
|
| 292 | + $params['isPublic'] = false; |
|
| 293 | + $params['allowShareWithLink'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'); |
|
| 294 | + $params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name'); |
|
| 295 | + $params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc'); |
|
| 296 | + $params['showgridview'] = $this->config->getUserValue($user, 'files', 'show_grid', false); |
|
| 297 | + $params['isIE'] = \OCP\Util::isIE(); |
|
| 298 | + $showHidden = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false); |
|
| 299 | + $params['showHiddenFiles'] = $showHidden ? 1 : 0; |
|
| 300 | + $params['fileNotFound'] = $fileNotFound ? 1 : 0; |
|
| 301 | + $params['appNavigation'] = $nav; |
|
| 302 | + $params['appContents'] = $contentItems; |
|
| 303 | + $params['hiddenFields'] = $event->getHiddenFields(); |
|
| 304 | + |
|
| 305 | + $response = new TemplateResponse( |
|
| 306 | + $this->appName, |
|
| 307 | + 'index', |
|
| 308 | + $params |
|
| 309 | + ); |
|
| 310 | + $policy = new ContentSecurityPolicy(); |
|
| 311 | + $policy->addAllowedFrameDomain('\'self\''); |
|
| 312 | + $response->setContentSecurityPolicy($policy); |
|
| 313 | + |
|
| 314 | + return $response; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * Redirects to the file list and highlight the given file id |
|
| 319 | + * |
|
| 320 | + * @param string $fileId file id to show |
|
| 321 | + * @return RedirectResponse redirect response or not found response |
|
| 322 | + * @throws \OCP\Files\NotFoundException |
|
| 323 | + */ |
|
| 324 | + private function redirectToFile($fileId) { |
|
| 325 | + $uid = $this->userSession->getUser()->getUID(); |
|
| 326 | + $baseFolder = $this->rootFolder->getUserFolder($uid); |
|
| 327 | + $files = $baseFolder->getById($fileId); |
|
| 328 | + $params = []; |
|
| 329 | + |
|
| 330 | + if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) { |
|
| 331 | + $baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/'); |
|
| 332 | + $files = $baseFolder->getById($fileId); |
|
| 333 | + $params['view'] = 'trashbin'; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + if (!empty($files)) { |
|
| 337 | + $file = current($files); |
|
| 338 | + if ($file instanceof Folder) { |
|
| 339 | + // set the full path to enter the folder |
|
| 340 | + $params['dir'] = $baseFolder->getRelativePath($file->getPath()); |
|
| 341 | + } else { |
|
| 342 | + // set parent path as dir |
|
| 343 | + $params['dir'] = $baseFolder->getRelativePath($file->getParent()->getPath()); |
|
| 344 | + // and scroll to the entry |
|
| 345 | + $params['scrollto'] = $file->getName(); |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params)); |
|
| 349 | + } |
|
| 350 | + throw new \OCP\Files\NotFoundException(); |
|
| 351 | + } |
|
| 352 | 352 | } |
@@ -31,48 +31,48 @@ |
||
| 31 | 31 | use OCP\Security\FeaturePolicy\AddFeaturePolicyEvent; |
| 32 | 32 | |
| 33 | 33 | class FeaturePolicyManager { |
| 34 | - /** @var EmptyFeaturePolicy[] */ |
|
| 35 | - private $policies = []; |
|
| 34 | + /** @var EmptyFeaturePolicy[] */ |
|
| 35 | + private $policies = []; |
|
| 36 | 36 | |
| 37 | - /** @var IEventDispatcher */ |
|
| 38 | - private $dispatcher; |
|
| 37 | + /** @var IEventDispatcher */ |
|
| 38 | + private $dispatcher; |
|
| 39 | 39 | |
| 40 | - public function __construct(IEventDispatcher $dispatcher) { |
|
| 41 | - $this->dispatcher = $dispatcher; |
|
| 42 | - } |
|
| 40 | + public function __construct(IEventDispatcher $dispatcher) { |
|
| 41 | + $this->dispatcher = $dispatcher; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - public function addDefaultPolicy(EmptyFeaturePolicy $policy): void { |
|
| 45 | - $this->policies[] = $policy; |
|
| 46 | - } |
|
| 44 | + public function addDefaultPolicy(EmptyFeaturePolicy $policy): void { |
|
| 45 | + $this->policies[] = $policy; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - public function getDefaultPolicy(): FeaturePolicy { |
|
| 49 | - $event = new AddFeaturePolicyEvent($this); |
|
| 50 | - $this->dispatcher->dispatchTyped($event); |
|
| 48 | + public function getDefaultPolicy(): FeaturePolicy { |
|
| 49 | + $event = new AddFeaturePolicyEvent($this); |
|
| 50 | + $this->dispatcher->dispatchTyped($event); |
|
| 51 | 51 | |
| 52 | - $defaultPolicy = new FeaturePolicy(); |
|
| 53 | - foreach ($this->policies as $policy) { |
|
| 54 | - $defaultPolicy = $this->mergePolicies($defaultPolicy, $policy); |
|
| 55 | - } |
|
| 56 | - return $defaultPolicy; |
|
| 57 | - } |
|
| 52 | + $defaultPolicy = new FeaturePolicy(); |
|
| 53 | + foreach ($this->policies as $policy) { |
|
| 54 | + $defaultPolicy = $this->mergePolicies($defaultPolicy, $policy); |
|
| 55 | + } |
|
| 56 | + return $defaultPolicy; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Merges the first given policy with the second one |
|
| 61 | - * |
|
| 62 | - */ |
|
| 63 | - public function mergePolicies(FeaturePolicy $defaultPolicy, |
|
| 64 | - EmptyFeaturePolicy $originalPolicy): FeaturePolicy { |
|
| 65 | - foreach ((object)(array)$originalPolicy as $name => $value) { |
|
| 66 | - $setter = 'set' . ucfirst($name); |
|
| 67 | - if (\is_array($value)) { |
|
| 68 | - $getter = 'get' . ucfirst($name); |
|
| 69 | - $currentValues = \is_array($defaultPolicy->$getter()) ? $defaultPolicy->$getter() : []; |
|
| 70 | - $defaultPolicy->$setter(\array_values(\array_unique(\array_merge($currentValues, $value)))); |
|
| 71 | - } elseif (\is_bool($value)) { |
|
| 72 | - $defaultPolicy->$setter($value); |
|
| 73 | - } |
|
| 74 | - } |
|
| 59 | + /** |
|
| 60 | + * Merges the first given policy with the second one |
|
| 61 | + * |
|
| 62 | + */ |
|
| 63 | + public function mergePolicies(FeaturePolicy $defaultPolicy, |
|
| 64 | + EmptyFeaturePolicy $originalPolicy): FeaturePolicy { |
|
| 65 | + foreach ((object)(array)$originalPolicy as $name => $value) { |
|
| 66 | + $setter = 'set' . ucfirst($name); |
|
| 67 | + if (\is_array($value)) { |
|
| 68 | + $getter = 'get' . ucfirst($name); |
|
| 69 | + $currentValues = \is_array($defaultPolicy->$getter()) ? $defaultPolicy->$getter() : []; |
|
| 70 | + $defaultPolicy->$setter(\array_values(\array_unique(\array_merge($currentValues, $value)))); |
|
| 71 | + } elseif (\is_bool($value)) { |
|
| 72 | + $defaultPolicy->$setter($value); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - return $defaultPolicy; |
|
| 77 | - } |
|
| 76 | + return $defaultPolicy; |
|
| 77 | + } |
|
| 78 | 78 | } |
@@ -34,58 +34,58 @@ |
||
| 34 | 34 | use OCP\Security\IContentSecurityPolicyManager; |
| 35 | 35 | |
| 36 | 36 | class ContentSecurityPolicyManager implements IContentSecurityPolicyManager { |
| 37 | - /** @var ContentSecurityPolicy[] */ |
|
| 38 | - private $policies = []; |
|
| 37 | + /** @var ContentSecurityPolicy[] */ |
|
| 38 | + private $policies = []; |
|
| 39 | 39 | |
| 40 | - /** @var IEventDispatcher */ |
|
| 41 | - private $dispatcher; |
|
| 40 | + /** @var IEventDispatcher */ |
|
| 41 | + private $dispatcher; |
|
| 42 | 42 | |
| 43 | - public function __construct(IEventDispatcher $dispatcher) { |
|
| 44 | - $this->dispatcher = $dispatcher; |
|
| 45 | - } |
|
| 43 | + public function __construct(IEventDispatcher $dispatcher) { |
|
| 44 | + $this->dispatcher = $dispatcher; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** {@inheritdoc} */ |
|
| 48 | - public function addDefaultPolicy(EmptyContentSecurityPolicy $policy) { |
|
| 49 | - $this->policies[] = $policy; |
|
| 50 | - } |
|
| 47 | + /** {@inheritdoc} */ |
|
| 48 | + public function addDefaultPolicy(EmptyContentSecurityPolicy $policy) { |
|
| 49 | + $this->policies[] = $policy; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Get the configured default policy. This is not in the public namespace |
|
| 54 | - * as it is only supposed to be used by core itself. |
|
| 55 | - * |
|
| 56 | - * @return ContentSecurityPolicy |
|
| 57 | - */ |
|
| 58 | - public function getDefaultPolicy(): ContentSecurityPolicy { |
|
| 59 | - $event = new AddContentSecurityPolicyEvent($this); |
|
| 60 | - $this->dispatcher->dispatchTyped($event); |
|
| 52 | + /** |
|
| 53 | + * Get the configured default policy. This is not in the public namespace |
|
| 54 | + * as it is only supposed to be used by core itself. |
|
| 55 | + * |
|
| 56 | + * @return ContentSecurityPolicy |
|
| 57 | + */ |
|
| 58 | + public function getDefaultPolicy(): ContentSecurityPolicy { |
|
| 59 | + $event = new AddContentSecurityPolicyEvent($this); |
|
| 60 | + $this->dispatcher->dispatchTyped($event); |
|
| 61 | 61 | |
| 62 | - $defaultPolicy = new \OC\Security\CSP\ContentSecurityPolicy(); |
|
| 63 | - foreach ($this->policies as $policy) { |
|
| 64 | - $defaultPolicy = $this->mergePolicies($defaultPolicy, $policy); |
|
| 65 | - } |
|
| 66 | - return $defaultPolicy; |
|
| 67 | - } |
|
| 62 | + $defaultPolicy = new \OC\Security\CSP\ContentSecurityPolicy(); |
|
| 63 | + foreach ($this->policies as $policy) { |
|
| 64 | + $defaultPolicy = $this->mergePolicies($defaultPolicy, $policy); |
|
| 65 | + } |
|
| 66 | + return $defaultPolicy; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Merges the first given policy with the second one |
|
| 71 | - * |
|
| 72 | - * @param ContentSecurityPolicy $defaultPolicy |
|
| 73 | - * @param EmptyContentSecurityPolicy $originalPolicy |
|
| 74 | - * @return ContentSecurityPolicy |
|
| 75 | - */ |
|
| 76 | - public function mergePolicies(ContentSecurityPolicy $defaultPolicy, |
|
| 77 | - EmptyContentSecurityPolicy $originalPolicy): ContentSecurityPolicy { |
|
| 78 | - foreach ((object)(array)$originalPolicy as $name => $value) { |
|
| 79 | - $setter = 'set'.ucfirst($name); |
|
| 80 | - if (\is_array($value)) { |
|
| 81 | - $getter = 'get'.ucfirst($name); |
|
| 82 | - $currentValues = \is_array($defaultPolicy->$getter()) ? $defaultPolicy->$getter() : []; |
|
| 83 | - $defaultPolicy->$setter(array_values(array_unique(array_merge($currentValues, $value)))); |
|
| 84 | - } elseif (\is_bool($value)) { |
|
| 85 | - $defaultPolicy->$setter($value); |
|
| 86 | - } |
|
| 87 | - } |
|
| 69 | + /** |
|
| 70 | + * Merges the first given policy with the second one |
|
| 71 | + * |
|
| 72 | + * @param ContentSecurityPolicy $defaultPolicy |
|
| 73 | + * @param EmptyContentSecurityPolicy $originalPolicy |
|
| 74 | + * @return ContentSecurityPolicy |
|
| 75 | + */ |
|
| 76 | + public function mergePolicies(ContentSecurityPolicy $defaultPolicy, |
|
| 77 | + EmptyContentSecurityPolicy $originalPolicy): ContentSecurityPolicy { |
|
| 78 | + foreach ((object)(array)$originalPolicy as $name => $value) { |
|
| 79 | + $setter = 'set'.ucfirst($name); |
|
| 80 | + if (\is_array($value)) { |
|
| 81 | + $getter = 'get'.ucfirst($name); |
|
| 82 | + $currentValues = \is_array($defaultPolicy->$getter()) ? $defaultPolicy->$getter() : []; |
|
| 83 | + $defaultPolicy->$setter(array_values(array_unique(array_merge($currentValues, $value)))); |
|
| 84 | + } elseif (\is_bool($value)) { |
|
| 85 | + $defaultPolicy->$setter($value); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - return $defaultPolicy; |
|
| 90 | - } |
|
| 89 | + return $defaultPolicy; |
|
| 90 | + } |
|
| 91 | 91 | } |