From 6de0eb0b741ff1cf0b735480a6c2d2fbcb1e70ca Mon Sep 17 00:00:00 2001
From: Joas Schilling <coding@schilljs.com>
Date: Thu, 15 Dec 2016 15:53:48 +0100
Subject: [PATCH] Remove leading slash from sharing activity

Signed-off-by: Joas Schilling <coding@schilljs.com>
---
 apps/comments/lib/Activity/Provider.php                   | 2 +-
 apps/files/lib/Activity/FavoriteProvider.php              | 5 +++--
 apps/files/lib/Activity/Provider.php                      | 5 +++--
 apps/files_sharing/lib/Activity/Providers/Downloads.php   | 2 +-
 apps/files_sharing/lib/Activity/Providers/Groups.php      | 2 +-
 apps/files_sharing/lib/Activity/Providers/PublicLinks.php | 2 +-
 apps/files_sharing/lib/Activity/Providers/Users.php       | 2 +-
 apps/sharebymail/lib/Activity.php                         | 2 +-
 lib/public/RichObjectStrings/Definitions.php              | 2 +-
 9 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/apps/comments/lib/Activity/Provider.php b/apps/comments/lib/Activity/Provider.php
index 170b20d7c27..c55982827b3 100644
--- a/apps/comments/lib/Activity/Provider.php
+++ b/apps/comments/lib/Activity/Provider.php
@@ -206,7 +206,7 @@ class Provider implements IProvider {
 			'type' => 'file',
 			'id' => $id,
 			'name' => basename($path),
-			'path' => $path,
+			'path' => trim($path, '/'),
 			'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]),
 		];
 	}
diff --git a/apps/files/lib/Activity/FavoriteProvider.php b/apps/files/lib/Activity/FavoriteProvider.php
index 8047eb1319e..ed00d50f221 100644
--- a/apps/files/lib/Activity/FavoriteProvider.php
+++ b/apps/files/lib/Activity/FavoriteProvider.php
@@ -142,10 +142,11 @@ class FavoriteProvider implements IProvider {
 			'type' => 'file',
 			'id' => $event->getObjectId(),
 			'name' => basename($event->getObjectName()),
-			'path' => $event->getObjectName(),
+			'path' => trim($event->getObjectName(), '/'),
+			'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $event->getObjectId()]),
 		];
 
-		$event->setParsedSubject(str_replace('{file}', trim($parameter['path'], '/'), $subject))
+		$event->setParsedSubject(str_replace('{file}', $parameter['path'], $subject))
 			->setRichSubject($subject, ['file' => $parameter]);
 	}
 }
diff --git a/apps/files/lib/Activity/Provider.php b/apps/files/lib/Activity/Provider.php
index 92686ec0c36..ae303034610 100644
--- a/apps/files/lib/Activity/Provider.php
+++ b/apps/files/lib/Activity/Provider.php
@@ -201,7 +201,7 @@ class Provider implements IProvider {
 		foreach ($parameters as $placeholder => $parameter) {
 			$placeholders[] = '{' . $placeholder . '}';
 			if ($parameter['type'] === 'file') {
-				$replacements[] = trim($parameter['path'], '/');
+				$replacements[] = $parameter['path'];
 			} else {
 				$replacements[] = $parameter['name'];
 			}
@@ -253,7 +253,8 @@ class Provider implements IProvider {
 			'type' => 'file',
 			'id' => $id,
 			'name' => basename($path),
-			'path' => $path,
+			'path' => trim($path, '/'),
+			'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]),
 		];
 	}
 
diff --git a/apps/files_sharing/lib/Activity/Providers/Downloads.php b/apps/files_sharing/lib/Activity/Providers/Downloads.php
index e1a25156441..01012e4785b 100644
--- a/apps/files_sharing/lib/Activity/Providers/Downloads.php
+++ b/apps/files_sharing/lib/Activity/Providers/Downloads.php
@@ -187,7 +187,7 @@ class Downloads implements IProvider {
 			'type' => 'file',
 			'id' => $id,
 			'name' => basename($path),
-			'path' => $path,
+			'path' => trim($path, '/'),
 			'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]),
 		];
 	}
diff --git a/apps/files_sharing/lib/Activity/Providers/Groups.php b/apps/files_sharing/lib/Activity/Providers/Groups.php
index 326ebba9ef7..6c25572d0d4 100644
--- a/apps/files_sharing/lib/Activity/Providers/Groups.php
+++ b/apps/files_sharing/lib/Activity/Providers/Groups.php
@@ -232,7 +232,7 @@ class Groups implements IProvider {
 			'type' => 'file',
 			'id' => $id,
 			'name' => basename($path),
-			'path' => $path,
+			'path' => trim($path, '/'),
 			'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]),
 		];
 	}
diff --git a/apps/files_sharing/lib/Activity/Providers/PublicLinks.php b/apps/files_sharing/lib/Activity/Providers/PublicLinks.php
index ec8152c5a32..20070970bca 100644
--- a/apps/files_sharing/lib/Activity/Providers/PublicLinks.php
+++ b/apps/files_sharing/lib/Activity/Providers/PublicLinks.php
@@ -239,7 +239,7 @@ class PublicLinks implements IProvider {
 			'type' => 'file',
 			'id' => $id,
 			'name' => basename($path),
-			'path' => $path,
+			'path' => trim($path, '/'),
 			'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]),
 		];
 	}
diff --git a/apps/files_sharing/lib/Activity/Providers/Users.php b/apps/files_sharing/lib/Activity/Providers/Users.php
index d85eeadc315..4db72136a85 100644
--- a/apps/files_sharing/lib/Activity/Providers/Users.php
+++ b/apps/files_sharing/lib/Activity/Providers/Users.php
@@ -260,7 +260,7 @@ class Users implements IProvider {
 			'type' => 'file',
 			'id' => $id,
 			'name' => basename($path),
-			'path' => $path,
+			'path' => trim($path, '/'),
 			'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]),
 		];
 	}
diff --git a/apps/sharebymail/lib/Activity.php b/apps/sharebymail/lib/Activity.php
index 5342d013ade..1c2f37dc382 100644
--- a/apps/sharebymail/lib/Activity.php
+++ b/apps/sharebymail/lib/Activity.php
@@ -196,7 +196,7 @@ class Activity implements IProvider {
 			'type' => 'file',
 			'id' => $id,
 			'name' => basename($path),
-			'path' => $path,
+			'path' => trim($path, '/'),
 			'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]),
 		];
 	}
diff --git a/lib/public/RichObjectStrings/Definitions.php b/lib/public/RichObjectStrings/Definitions.php
index fbde439c47a..4b5b0da978e 100644
--- a/lib/public/RichObjectStrings/Definitions.php
+++ b/lib/public/RichObjectStrings/Definitions.php
@@ -191,7 +191,7 @@ class Definitions {
 				'path' => [
 					'since' => '11.0.0',
 					'required' => true,
-					'description' => 'The full path of the file for the user',
+					'description' => 'The full path of the file for the user, should not start with a slash',
 					'example' => 'path/to/file.txt',
 				],
 				'link' => [
-- 
GitLab