From 058180d386903f2aac27306db90a39da993a3915 Mon Sep 17 00:00:00 2001 From: Tim Obert Date: Fri, 14 Feb 2020 12:12:04 +0100 Subject: [PATCH 1/2] Change the route generation of AuthPublicShareController.php and adjust the routes for file sharing Signed-off-by: Tim Obert --- core/routes.php | 8 ++++---- .../AppFramework/AuthPublicShareController.php | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/core/routes.php b/core/routes.php index 5fb13bc298..49938d6a36 100644 --- a/core/routes.php +++ b/core/routes.php @@ -88,10 +88,10 @@ $application->registerRoutes($this, [ // Legacy routes that need to be globally available while they are handled by an app ['name' => 'viewcontroller#showFile', 'url' => '/f/{fileid}', 'verb' => 'GET', 'app' => 'files'], - ['name' => 'sharecontroller#showShare', 'url' => '/s/{token}', 'verb' => 'GET', 'app' => 'files_sharing'], - ['name' => 'sharecontroller#showAuthenticate', 'url' => '/s/{token}/authenticate/{redirect}', 'verb' => 'GET', 'app' => 'files_sharing'], - ['name' => 'sharecontroller#authenticate', 'url' => '/s/{token}/authenticate/{redirect}', 'verb' => 'POST', 'app' => 'files_sharing'], - ['name' => 'sharecontroller#downloadShare', 'url' => '/s/{token}/download', 'verb' => 'GET', 'app' => 'files_sharing'], + ['name' => 'share#showShare', 'url' => '/s/{token}', 'verb' => 'GET', 'app' => 'files_sharing'], + ['name' => 'share#showAuthenticate', 'url' => '/s/{token}/authenticate/{redirect}', 'verb' => 'GET', 'app' => 'files_sharing'], + ['name' => 'share#authenticate', 'url' => '/s/{token}/authenticate/{redirect}', 'verb' => 'POST', 'app' => 'files_sharing'], + ['name' => 'share#downloadShare', 'url' => '/s/{token}/download', 'verb' => 'GET', 'app' => 'files_sharing'], ['name' => 'publicpreview#directLink', 'url' => '/s/{token}/preview', 'verb' => 'GET', 'app' => 'files_sharing'], ['name' => 'requesthandlercontroller#addShare', 'url' => '/ocm/shares', 'verb' => 'POST', 'app' => 'cloud_federation_api'], ['name' => 'requesthandlercontroller#receiveNotification', 'url' => '/ocm/notifications', 'verb' => 'POST', 'app' => 'cloud_federation_api'], diff --git a/lib/public/AppFramework/AuthPublicShareController.php b/lib/public/AppFramework/AuthPublicShareController.php index 09337ad101..969fd0bfe6 100644 --- a/lib/public/AppFramework/AuthPublicShareController.php +++ b/lib/public/AppFramework/AuthPublicShareController.php @@ -156,14 +156,24 @@ abstract class AuthPublicShareController extends PublicShareController { ); } + /** + * @param $string + * @return string + */ + private function camelCaseToLowerCaseUnderscored($string) + { + $value = preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $string); + return mb_strtolower($value, 'utf-8'); + } + /** * @since 14.0.0 */ private function getRoute(string $function): string { $app = strtolower($this->appName); - $class = strtolower((new \ReflectionClass($this))->getShortName()); - - return $app . '.' . $class . '.' . $function; + $class = (new \ReflectionClass($this))->getShortName(); + // $class = $this->camelCaseToLowerCaseUnderscored(substr($class, 0, strpos($class, 'Controller'))); + return $app .'.'. $class .'.'. $function; } /** From 4c1834daced86f114b3c810e4c4ce08fc0790adc Mon Sep 17 00:00:00 2001 From: TimObert Date: Fri, 14 Feb 2020 14:12:01 +0100 Subject: [PATCH 2/2] Fix requested changes Signed-off-by: Tim Obert --- core/routes.php | 8 ++++---- .../AppFramework/AuthPublicShareController.php | 15 +++++---------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/core/routes.php b/core/routes.php index 49938d6a36..5fb13bc298 100644 --- a/core/routes.php +++ b/core/routes.php @@ -88,10 +88,10 @@ $application->registerRoutes($this, [ // Legacy routes that need to be globally available while they are handled by an app ['name' => 'viewcontroller#showFile', 'url' => '/f/{fileid}', 'verb' => 'GET', 'app' => 'files'], - ['name' => 'share#showShare', 'url' => '/s/{token}', 'verb' => 'GET', 'app' => 'files_sharing'], - ['name' => 'share#showAuthenticate', 'url' => '/s/{token}/authenticate/{redirect}', 'verb' => 'GET', 'app' => 'files_sharing'], - ['name' => 'share#authenticate', 'url' => '/s/{token}/authenticate/{redirect}', 'verb' => 'POST', 'app' => 'files_sharing'], - ['name' => 'share#downloadShare', 'url' => '/s/{token}/download', 'verb' => 'GET', 'app' => 'files_sharing'], + ['name' => 'sharecontroller#showShare', 'url' => '/s/{token}', 'verb' => 'GET', 'app' => 'files_sharing'], + ['name' => 'sharecontroller#showAuthenticate', 'url' => '/s/{token}/authenticate/{redirect}', 'verb' => 'GET', 'app' => 'files_sharing'], + ['name' => 'sharecontroller#authenticate', 'url' => '/s/{token}/authenticate/{redirect}', 'verb' => 'POST', 'app' => 'files_sharing'], + ['name' => 'sharecontroller#downloadShare', 'url' => '/s/{token}/download', 'verb' => 'GET', 'app' => 'files_sharing'], ['name' => 'publicpreview#directLink', 'url' => '/s/{token}/preview', 'verb' => 'GET', 'app' => 'files_sharing'], ['name' => 'requesthandlercontroller#addShare', 'url' => '/ocm/shares', 'verb' => 'POST', 'app' => 'cloud_federation_api'], ['name' => 'requesthandlercontroller#receiveNotification', 'url' => '/ocm/notifications', 'verb' => 'POST', 'app' => 'cloud_federation_api'], diff --git a/lib/public/AppFramework/AuthPublicShareController.php b/lib/public/AppFramework/AuthPublicShareController.php index 969fd0bfe6..9e8daa8d34 100644 --- a/lib/public/AppFramework/AuthPublicShareController.php +++ b/lib/public/AppFramework/AuthPublicShareController.php @@ -156,15 +156,6 @@ abstract class AuthPublicShareController extends PublicShareController { ); } - /** - * @param $string - * @return string - */ - private function camelCaseToLowerCaseUnderscored($string) - { - $value = preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $string); - return mb_strtolower($value, 'utf-8'); - } /** * @since 14.0.0 @@ -172,7 +163,11 @@ abstract class AuthPublicShareController extends PublicShareController { private function getRoute(string $function): string { $app = strtolower($this->appName); $class = (new \ReflectionClass($this))->getShortName(); - // $class = $this->camelCaseToLowerCaseUnderscored(substr($class, 0, strpos($class, 'Controller'))); + if ($this->appName === 'files_sharing') { + $class = strtolower($class); + } else if (substr($class, -10) === 'Controller') { + $class = substr($class, 0, -10); + } return $app .'.'. $class .'.'. $function; }