diff options
Diffstat (limited to 'apps/files_sharing/lib')
52 files changed, 584 insertions, 466 deletions
diff --git a/apps/files_sharing/lib/Activity/Filter.php b/apps/files_sharing/lib/Activity/Filter.php index b27b0d3993f..da4539384cf 100644 --- a/apps/files_sharing/lib/Activity/Filter.php +++ b/apps/files_sharing/lib/Activity/Filter.php @@ -2,6 +2,7 @@ /** * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> * + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Joas Schilling <coding@schilljs.com> * * @license GNU AGPL version 3 or any later version @@ -23,14 +24,13 @@ namespace OCA\Files_Sharing\Activity; - use OCP\Activity\IFilter; use OCP\IL10N; use OCP\IURLGenerator; class Filter implements IFilter { - const TYPE_REMOTE_SHARE = 'remote_share'; - const TYPE_SHARED = 'shared'; + public const TYPE_REMOTE_SHARE = 'remote_share'; + public const TYPE_SHARED = 'shared'; /** @var IL10N */ protected $l; diff --git a/apps/files_sharing/lib/Activity/Providers/Base.php b/apps/files_sharing/lib/Activity/Providers/Base.php index b63eb346f7c..843a0c447f1 100644 --- a/apps/files_sharing/lib/Activity/Providers/Base.php +++ b/apps/files_sharing/lib/Activity/Providers/Base.php @@ -2,6 +2,7 @@ /** * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> * + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Joas Schilling <coding@schilljs.com> * * @license GNU AGPL version 3 or any later version @@ -147,7 +148,7 @@ abstract class Base implements IProvider { if (is_array($parameter)) { $path = reset($parameter); $id = (string) key($parameter); - } else if ($event !== null) { + } elseif ($event !== null) { // Legacy from before ownCloud 8.2 $path = $parameter; $id = $event->getObjectId(); diff --git a/apps/files_sharing/lib/Activity/Providers/Downloads.php b/apps/files_sharing/lib/Activity/Providers/Downloads.php index 706945060de..be019bdcd65 100644 --- a/apps/files_sharing/lib/Activity/Providers/Downloads.php +++ b/apps/files_sharing/lib/Activity/Providers/Downloads.php @@ -2,6 +2,7 @@ /** * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> * + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Joas Schilling <coding@schilljs.com> * * @license GNU AGPL version 3 or any later version @@ -26,13 +27,11 @@ namespace OCA\Files_Sharing\Activity\Providers; use OCP\Activity\IEvent; class Downloads extends Base { + public const SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED = 'public_shared_file_downloaded'; + public const SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED = 'public_shared_folder_downloaded'; - - const SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED = 'public_shared_file_downloaded'; - const SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED = 'public_shared_folder_downloaded'; - - const SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED = 'file_shared_with_email_downloaded'; - const SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED = 'folder_shared_with_email_downloaded'; + public const SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED = 'file_shared_with_email_downloaded'; + public const SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED = 'folder_shared_with_email_downloaded'; /** * @param IEvent $event @@ -46,7 +45,7 @@ class Downloads extends Base { if ($event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED || $event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED) { $subject = $this->l->t('Downloaded via public link'); - } else if ($event->getSubject() === self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED || + } elseif ($event->getSubject() === self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED || $event->getSubject() === self::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED) { $subject = $this->l->t('Downloaded by {email}'); } else { @@ -75,7 +74,7 @@ class Downloads extends Base { if ($event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED || $event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED) { $subject = $this->l->t('{file} downloaded via public link'); - } else if ($event->getSubject() === self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED || + } elseif ($event->getSubject() === self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED || $event->getSubject() === self::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED) { $subject = $this->l->t('{email} downloaded {file}'); } else { diff --git a/apps/files_sharing/lib/Activity/Providers/Groups.php b/apps/files_sharing/lib/Activity/Providers/Groups.php index 8a061f9373d..53336057e37 100644 --- a/apps/files_sharing/lib/Activity/Providers/Groups.php +++ b/apps/files_sharing/lib/Activity/Providers/Groups.php @@ -2,6 +2,7 @@ /** * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> * + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Joas Schilling <coding@schilljs.com> * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> * @@ -35,14 +36,13 @@ use OCP\IUserManager; use OCP\L10N\IFactory; class Groups extends Base { + public const SUBJECT_SHARED_GROUP_SELF = 'shared_group_self'; + public const SUBJECT_RESHARED_GROUP_BY = 'reshared_group_by'; - const SUBJECT_SHARED_GROUP_SELF = 'shared_group_self'; - const SUBJECT_RESHARED_GROUP_BY = 'reshared_group_by'; + public const SUBJECT_UNSHARED_GROUP_SELF = 'unshared_group_self'; + public const SUBJECT_UNSHARED_GROUP_BY = 'unshared_group_by'; - const SUBJECT_UNSHARED_GROUP_SELF = 'unshared_group_self'; - const SUBJECT_UNSHARED_GROUP_BY = 'unshared_group_by'; - - const SUBJECT_EXPIRED_GROUP = 'expired_group'; + public const SUBJECT_EXPIRED_GROUP = 'expired_group'; /** @var IGroupManager */ protected $groupManager; @@ -72,13 +72,13 @@ class Groups extends Base { if ($event->getSubject() === self::SUBJECT_SHARED_GROUP_SELF) { $subject = $this->l->t('Shared with group {group}'); - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_SELF) { + } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_SELF) { $subject = $this->l->t('Removed share for group {group}'); - } else if ($event->getSubject() === self::SUBJECT_RESHARED_GROUP_BY) { + } elseif ($event->getSubject() === self::SUBJECT_RESHARED_GROUP_BY) { $subject = $this->l->t('{actor} shared with group {group}'); - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_BY) { + } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_BY) { $subject = $this->l->t('{actor} removed share for group {group}'); - } else if ($event->getSubject() === self::SUBJECT_EXPIRED_GROUP) { + } elseif ($event->getSubject() === self::SUBJECT_EXPIRED_GROUP) { $subject = $this->l->t('Share for group {group} expired'); } else { throw new \InvalidArgumentException(); @@ -105,13 +105,13 @@ class Groups extends Base { if ($event->getSubject() === self::SUBJECT_SHARED_GROUP_SELF) { $subject = $this->l->t('You shared {file} with group {group}'); - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_SELF) { + } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_SELF) { $subject = $this->l->t('You removed group {group} from {file}'); - } else if ($event->getSubject() === self::SUBJECT_RESHARED_GROUP_BY) { + } elseif ($event->getSubject() === self::SUBJECT_RESHARED_GROUP_BY) { $subject = $this->l->t('{actor} shared {file} with group {group}'); - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_BY) { + } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_BY) { $subject = $this->l->t('{actor} removed group {group} from {file}'); - } else if ($event->getSubject() === self::SUBJECT_EXPIRED_GROUP) { + } elseif ($event->getSubject() === self::SUBJECT_EXPIRED_GROUP) { $subject = $this->l->t('Share for file {file} with group {group} expired'); } else { throw new \InvalidArgumentException(); diff --git a/apps/files_sharing/lib/Activity/Providers/PublicLinks.php b/apps/files_sharing/lib/Activity/Providers/PublicLinks.php index 20b8414bee9..2742ded4007 100644 --- a/apps/files_sharing/lib/Activity/Providers/PublicLinks.php +++ b/apps/files_sharing/lib/Activity/Providers/PublicLinks.php @@ -2,6 +2,7 @@ /** * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> * + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Joas Schilling <coding@schilljs.com> * * @license GNU AGPL version 3 or any later version @@ -26,13 +27,12 @@ namespace OCA\Files_Sharing\Activity\Providers; use OCP\Activity\IEvent; class PublicLinks extends Base { - - const SUBJECT_SHARED_LINK_SELF = 'shared_link_self'; - const SUBJECT_RESHARED_LINK_BY = 'reshared_link_by'; - const SUBJECT_UNSHARED_LINK_SELF = 'unshared_link_self'; - const SUBJECT_UNSHARED_LINK_BY = 'unshared_link_by'; - const SUBJECT_LINK_EXPIRED = 'link_expired'; - const SUBJECT_LINK_BY_EXPIRED = 'link_by_expired'; + public const SUBJECT_SHARED_LINK_SELF = 'shared_link_self'; + public const SUBJECT_RESHARED_LINK_BY = 'reshared_link_by'; + public const SUBJECT_UNSHARED_LINK_SELF = 'unshared_link_self'; + public const SUBJECT_UNSHARED_LINK_BY = 'unshared_link_by'; + public const SUBJECT_LINK_EXPIRED = 'link_expired'; + public const SUBJECT_LINK_BY_EXPIRED = 'link_by_expired'; /** * @param IEvent $event @@ -45,17 +45,16 @@ class PublicLinks extends Base { if ($event->getSubject() === self::SUBJECT_SHARED_LINK_SELF) { $subject = $this->l->t('Shared as public link'); - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_SELF) { + } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_SELF) { $subject = $this->l->t('Removed public link'); - } else if ($event->getSubject() === self::SUBJECT_LINK_EXPIRED) { + } elseif ($event->getSubject() === self::SUBJECT_LINK_EXPIRED) { $subject = $this->l->t('Public link expired'); - } else if ($event->getSubject() === self::SUBJECT_RESHARED_LINK_BY) { + } elseif ($event->getSubject() === self::SUBJECT_RESHARED_LINK_BY) { $subject = $this->l->t('{actor} shared as public link'); - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_BY) { + } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_BY) { $subject = $this->l->t('{actor} removed public link'); - } else if ($event->getSubject() === self::SUBJECT_LINK_BY_EXPIRED) { + } elseif ($event->getSubject() === self::SUBJECT_LINK_BY_EXPIRED) { $subject = $this->l->t('Public link of {actor} expired'); - } else { throw new \InvalidArgumentException(); } @@ -81,17 +80,16 @@ class PublicLinks extends Base { if ($event->getSubject() === self::SUBJECT_SHARED_LINK_SELF) { $subject = $this->l->t('You shared {file} as public link'); - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_SELF) { + } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_SELF) { $subject = $this->l->t('You removed public link for {file}'); - } else if ($event->getSubject() === self::SUBJECT_LINK_EXPIRED) { + } elseif ($event->getSubject() === self::SUBJECT_LINK_EXPIRED) { $subject = $this->l->t('Public link expired for {file}'); - } else if ($event->getSubject() === self::SUBJECT_RESHARED_LINK_BY) { + } elseif ($event->getSubject() === self::SUBJECT_RESHARED_LINK_BY) { $subject = $this->l->t('{actor} shared {file} as public link'); - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_BY) { + } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_BY) { $subject = $this->l->t('{actor} removed public link for {file}'); - } else if ($event->getSubject() === self::SUBJECT_LINK_BY_EXPIRED) { + } elseif ($event->getSubject() === self::SUBJECT_LINK_BY_EXPIRED) { $subject = $this->l->t('Public link of {actor} for {file} expired'); - } else { throw new \InvalidArgumentException(); } @@ -127,5 +125,4 @@ class PublicLinks extends Base { } return []; } - } diff --git a/apps/files_sharing/lib/Activity/Providers/RemoteShares.php b/apps/files_sharing/lib/Activity/Providers/RemoteShares.php index 36d4dbbb8fd..f2217f423ef 100644 --- a/apps/files_sharing/lib/Activity/Providers/RemoteShares.php +++ b/apps/files_sharing/lib/Activity/Providers/RemoteShares.php @@ -2,6 +2,7 @@ /** * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> * + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Joas Schilling <coding@schilljs.com> * @author Robin Appelman <robin@icewind.nl> * @@ -33,11 +34,10 @@ use OCP\IUserManager; use OCP\L10N\IFactory; class RemoteShares extends Base { - - const SUBJECT_REMOTE_SHARE_ACCEPTED = 'remote_share_accepted'; - const SUBJECT_REMOTE_SHARE_DECLINED = 'remote_share_declined'; - const SUBJECT_REMOTE_SHARE_RECEIVED = 'remote_share_received'; - const SUBJECT_REMOTE_SHARE_UNSHARED = 'remote_share_unshared'; + public const SUBJECT_REMOTE_SHARE_ACCEPTED = 'remote_share_accepted'; + public const SUBJECT_REMOTE_SHARE_DECLINED = 'remote_share_declined'; + public const SUBJECT_REMOTE_SHARE_RECEIVED = 'remote_share_received'; + public const SUBJECT_REMOTE_SHARE_UNSHARED = 'remote_share_unshared'; public function __construct(IFactory $languageFactory, IURLGenerator $url, @@ -60,7 +60,7 @@ class RemoteShares extends Base { if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_ACCEPTED) { $subject = $this->l->t('{user} accepted the remote share'); - } else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_DECLINED) { + } elseif ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_DECLINED) { $subject = $this->l->t('{user} declined the remote share'); } else { throw new \InvalidArgumentException(); @@ -87,11 +87,11 @@ class RemoteShares extends Base { if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_RECEIVED) { $subject = $this->l->t('You received a new remote share {file} from {user}'); - } else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_ACCEPTED) { + } elseif ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_ACCEPTED) { $subject = $this->l->t('{user} accepted the remote share of {file}'); - } else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_DECLINED) { + } elseif ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_DECLINED) { $subject = $this->l->t('{user} declined the remote share of {file}'); - } else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_UNSHARED) { + } elseif ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_UNSHARED) { $subject = $this->l->t('{user} unshared {file} from you'); } else { throw new \InvalidArgumentException(); diff --git a/apps/files_sharing/lib/Activity/Providers/Users.php b/apps/files_sharing/lib/Activity/Providers/Users.php index 82c1cca9f8c..828befc471b 100644 --- a/apps/files_sharing/lib/Activity/Providers/Users.php +++ b/apps/files_sharing/lib/Activity/Providers/Users.php @@ -2,6 +2,7 @@ /** * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> * + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Joas Schilling <coding@schilljs.com> * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> * @author Kevin Ndung'u <kevgathuku@gmail.com> @@ -28,20 +29,18 @@ namespace OCA\Files_Sharing\Activity\Providers; use OCP\Activity\IEvent; class Users extends Base { + public const SUBJECT_SHARED_USER_SELF = 'shared_user_self'; + public const SUBJECT_RESHARED_USER_BY = 'reshared_user_by'; + public const SUBJECT_UNSHARED_USER_SELF = 'unshared_user_self'; + public const SUBJECT_UNSHARED_USER_BY = 'unshared_user_by'; + public const SUBJECT_SHARED_WITH_BY = 'shared_with_by'; + public const SUBJECT_UNSHARED_BY = 'unshared_by'; + public const SUBJECT_SELF_UNSHARED = 'self_unshared'; + public const SUBJECT_SELF_UNSHARED_BY = 'self_unshared_by'; - const SUBJECT_SHARED_USER_SELF = 'shared_user_self'; - const SUBJECT_RESHARED_USER_BY = 'reshared_user_by'; - const SUBJECT_UNSHARED_USER_SELF = 'unshared_user_self'; - const SUBJECT_UNSHARED_USER_BY = 'unshared_user_by'; - - const SUBJECT_SHARED_WITH_BY = 'shared_with_by'; - const SUBJECT_UNSHARED_BY = 'unshared_by'; - const SUBJECT_SELF_UNSHARED = 'self_unshared'; - const SUBJECT_SELF_UNSHARED_BY = 'self_unshared_by'; - - const SUBJECT_EXPIRED_USER = 'expired_user'; - const SUBJECT_EXPIRED = 'expired'; + public const SUBJECT_EXPIRED_USER = 'expired_user'; + public const SUBJECT_EXPIRED = 'expired'; /** * @param IEvent $event @@ -54,23 +53,23 @@ class Users extends Base { if ($event->getSubject() === self::SUBJECT_SHARED_USER_SELF) { $subject = $this->l->t('Shared with {user}'); - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_USER_SELF) { + } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_USER_SELF) { $subject = $this->l->t('Removed share for {user}'); - } else if ($event->getSubject() === self::SUBJECT_SELF_UNSHARED) { + } elseif ($event->getSubject() === self::SUBJECT_SELF_UNSHARED) { $subject = $this->l->t('You removed yourself'); - } else if ($event->getSubject() === self::SUBJECT_SELF_UNSHARED_BY) { + } elseif ($event->getSubject() === self::SUBJECT_SELF_UNSHARED_BY) { $subject = $this->l->t('{actor} removed themselves'); - } else if ($event->getSubject() === self::SUBJECT_RESHARED_USER_BY) { + } elseif ($event->getSubject() === self::SUBJECT_RESHARED_USER_BY) { $subject = $this->l->t('{actor} shared with {user}'); - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_USER_BY) { + } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_USER_BY) { $subject = $this->l->t('{actor} removed share for {user}'); - } else if ($event->getSubject() === self::SUBJECT_SHARED_WITH_BY) { + } elseif ($event->getSubject() === self::SUBJECT_SHARED_WITH_BY) { $subject = $this->l->t('Shared by {actor}'); - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_BY) { + } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_BY) { $subject = $this->l->t('{actor} removed share'); - } else if ($event->getSubject() === self::SUBJECT_EXPIRED_USER) { + } elseif ($event->getSubject() === self::SUBJECT_EXPIRED_USER) { $subject = $this->l->t('Share for {user} expired'); - } else if ($event->getSubject() === self::SUBJECT_EXPIRED) { + } elseif ($event->getSubject() === self::SUBJECT_EXPIRED) { $subject = $this->l->t('Share expired'); } else { throw new \InvalidArgumentException(); @@ -97,25 +96,24 @@ class Users extends Base { if ($event->getSubject() === self::SUBJECT_SHARED_USER_SELF) { $subject = $this->l->t('You shared {file} with {user}'); - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_USER_SELF) { + } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_USER_SELF) { $subject = $this->l->t('You removed {user} from {file}'); - } else if ($event->getSubject() === self::SUBJECT_SELF_UNSHARED) { + } elseif ($event->getSubject() === self::SUBJECT_SELF_UNSHARED) { $subject = $this->l->t('You removed yourself from {file}'); - } else if ($event->getSubject() === self::SUBJECT_SELF_UNSHARED_BY) { + } elseif ($event->getSubject() === self::SUBJECT_SELF_UNSHARED_BY) { $subject = $this->l->t('{actor} removed themselves from {file}'); - } else if ($event->getSubject() === self::SUBJECT_RESHARED_USER_BY) { + } elseif ($event->getSubject() === self::SUBJECT_RESHARED_USER_BY) { $subject = $this->l->t('{actor} shared {file} with {user}'); - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_USER_BY) { + } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_USER_BY) { $subject = $this->l->t('{actor} removed {user} from {file}'); - } else if ($event->getSubject() === self::SUBJECT_SHARED_WITH_BY) { + } elseif ($event->getSubject() === self::SUBJECT_SHARED_WITH_BY) { $subject = $this->l->t('{actor} shared {file} with you'); - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_BY) { + } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_BY) { $subject = $this->l->t('{actor} removed you from the share named {file}'); - } else if ($event->getSubject() === self::SUBJECT_EXPIRED_USER) { + } elseif ($event->getSubject() === self::SUBJECT_EXPIRED_USER) { $subject = $this->l->t('Share for file {file} with {user} expired'); - } else if ($event->getSubject() === self::SUBJECT_EXPIRED) { + } elseif ($event->getSubject() === self::SUBJECT_EXPIRED) { $subject = $this->l->t('Share for file {file} expired'); - } else { throw new \InvalidArgumentException(); } diff --git a/apps/files_sharing/lib/Activity/Settings/PublicLinks.php b/apps/files_sharing/lib/Activity/Settings/PublicLinks.php index 9b882cee6c5..60094b656e1 100644 --- a/apps/files_sharing/lib/Activity/Settings/PublicLinks.php +++ b/apps/files_sharing/lib/Activity/Settings/PublicLinks.php @@ -23,7 +23,6 @@ namespace OCA\Files_Sharing\Activity\Settings; - use OCP\Activity\ISetting; use OCP\IL10N; diff --git a/apps/files_sharing/lib/Activity/Settings/RemoteShare.php b/apps/files_sharing/lib/Activity/Settings/RemoteShare.php index 41054afd318..319b4ebfef3 100644 --- a/apps/files_sharing/lib/Activity/Settings/RemoteShare.php +++ b/apps/files_sharing/lib/Activity/Settings/RemoteShare.php @@ -24,7 +24,6 @@ namespace OCA\Files_Sharing\Activity\Settings; - use OCP\Activity\ISetting; use OCP\IL10N; diff --git a/apps/files_sharing/lib/Activity/Settings/Shared.php b/apps/files_sharing/lib/Activity/Settings/Shared.php index 1889e7c6f03..1eb6270af3d 100644 --- a/apps/files_sharing/lib/Activity/Settings/Shared.php +++ b/apps/files_sharing/lib/Activity/Settings/Shared.php @@ -24,7 +24,6 @@ namespace OCA\Files_Sharing\Activity\Settings; - use OCP\Activity\ISetting; use OCP\IL10N; diff --git a/apps/files_sharing/lib/AppInfo/Application.php b/apps/files_sharing/lib/AppInfo/Application.php index d8019cba240..98515409186 100644 --- a/apps/files_sharing/lib/AppInfo/Application.php +++ b/apps/files_sharing/lib/AppInfo/Application.php @@ -3,11 +3,10 @@ * @copyright Copyright (c) 2016, ownCloud, Inc. * * @author Bjoern Schiessle <bjoern@schiessle.org> - * @author Björn Schießle <bjoern@schiessle.org> + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Joas Schilling <coding@schilljs.com> * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> * @author Julius Härtl <jus@bitgrid.net> - * @author Lukas Reschke <lukas@statuscode.ch> * @author Morris Jobke <hey@morrisjobke.de> * @author Robin Appelman <robin@icewind.nl> * @author Roeland Jago Douma <roeland@famdouma.nl> @@ -33,12 +32,11 @@ namespace OCA\Files_Sharing\AppInfo; use OC\AppFramework\Utility\SimpleContainer; use OCA\Files_Sharing\Capabilities; -use OCA\Files_Sharing\Controller\ExternalSharesController; -use OCA\Files_Sharing\Controller\ShareController; use OCA\Files_Sharing\External\Manager; -use OCA\Files_Sharing\Listener\GlobalShareAcceptanceListener; use OCA\Files_Sharing\Listener\LoadAdditionalListener; use OCA\Files_Sharing\Listener\LoadSidebarListener; +use OCA\Files_Sharing\Listener\ShareInteractionListener; +use OCA\Files_Sharing\Listener\UserAddedToGroupListener; use OCA\Files_Sharing\Listener\UserShareAcceptanceListener; use OCA\Files_Sharing\Middleware\OCSShareAPIMiddleware; use OCA\Files_Sharing\Middleware\ShareInfoMiddleware; @@ -49,11 +47,9 @@ use OCA\Files_Sharing\Notification\Notifier; use OCA\Files\Event\LoadAdditionalScriptsEvent; use OCA\Files\Event\LoadSidebar; use OCP\AppFramework\App; -use OCP\AppFramework\Utility\IControllerMethodReflector; -use OCP\Defaults; use OCP\EventDispatcher\IEventDispatcher; -use OCP\Federation\ICloudIdManager; use OCP\Files\Config\IMountProviderCollection; +use OCP\Group\Events\UserAddedEvent; use OCP\IContainer; use OCP\IGroup; use OCP\IServerContainer; @@ -62,8 +58,7 @@ use OCP\Util; use Symfony\Component\EventDispatcher\GenericEvent; class Application extends App { - - const APP_ID = 'files_sharing'; + public const APP_ID = 'files_sharing'; public function __construct(array $urlParams = []) { parent::__construct(self::APP_ID, $urlParams); @@ -79,47 +74,9 @@ class Application extends App { $notifications = $server->getNotificationManager(); /** - * Controllers - */ - $container->registerService('ShareController', function (SimpleContainer $c) use ($server) { - $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application(); - return new ShareController( - $c->query('AppName'), - $c->query('Request'), - $server->getConfig(), - $server->getURLGenerator(), - $server->getUserManager(), - $server->getLogger(), - $server->getActivityManager(), - $server->getShareManager(), - $server->getSession(), - $server->getPreviewManager(), - $server->getRootFolder(), - $federatedSharingApp->getFederatedShareProvider(), - $server->getEventDispatcher(), - $server->getL10N($c->query('AppName')), - $server->query(Defaults::class) - ); - }); - $container->registerService('ExternalSharesController', function (SimpleContainer $c) { - return new ExternalSharesController( - $c->query('AppName'), - $c->query('Request'), - $c->query('ExternalManager'), - $c->query('HttpClientService') - ); - }); - - /** * Core class wrappers */ - $container->registerService('HttpClientService', function (SimpleContainer $c) use ($server) { - return $server->getHTTPClientService(); - }); - $container->registerService(ICloudIdManager::class, function (SimpleContainer $c) use ($server) { - return $server->getCloudIdManager(); - }); - $container->registerService('ExternalManager', function (SimpleContainer $c) use ($server) { + $container->registerService(Manager::class, function (SimpleContainer $c) use ($server) { $user = $server->getUserSession()->getUser(); $uid = $user ? $user->getUID() : null; return new \OCA\Files_Sharing\External\Manager( @@ -136,50 +93,21 @@ class Application extends App { $uid ); }); - $container->registerAlias(Manager::class, 'ExternalManager'); /** * Middleware */ - $container->registerService('SharingCheckMiddleware', function (SimpleContainer $c) use ($server) { - return new SharingCheckMiddleware( - $c->query('AppName'), - $server->getConfig(), - $server->getAppManager(), - $server->query(IControllerMethodReflector::class), - $server->getShareManager(), - $server->getRequest() - ); - }); - - $container->registerService(ShareInfoMiddleware::class, function () use ($server) { - return new ShareInfoMiddleware( - $server->getShareManager() - ); - }); - - // Execute middlewares - $container->registerMiddleWare('SharingCheckMiddleware'); + $container->registerMiddleWare(SharingCheckMiddleware::class); $container->registerMiddleWare(OCSShareAPIMiddleware::class); $container->registerMiddleWare(ShareInfoMiddleware::class); - $container->registerService('MountProvider', function (IContainer $c) { - /** @var \OCP\IServerContainer $server */ - $server = $c->query('ServerContainer'); - return new MountProvider( - $server->getConfig(), - $server->getShareManager(), - $server->getLogger() - ); - }); - $container->registerService('ExternalMountProvider', function (IContainer $c) { /** @var \OCP\IServerContainer $server */ $server = $c->query('ServerContainer'); return new \OCA\Files_Sharing\External\MountProvider( $server->getDatabaseConnection(), - function() use ($c) { - return $c->query('ExternalManager'); + function () use ($c) { + return $c->query(Manager::class); }, $server->getCloudIdManager() ); @@ -203,7 +131,7 @@ class Application extends App { } protected function registerMountProviders(IMountProviderCollection $mountProviderCollection) { - $mountProviderCollection->registerProvider($this->getContainer()->query('MountProvider')); + $mountProviderCollection->registerProvider($this->getContainer()->query(MountProvider::class)); $mountProviderCollection->registerProvider($this->getContainer()->query('ExternalMountProvider')); } @@ -211,18 +139,20 @@ class Application extends App { // sidebar and files scripts $dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class); $dispatcher->addServiceListener(LoadSidebar::class, LoadSidebarListener::class); - $dispatcher->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', function() { + $dispatcher->addServiceListener(ShareCreatedEvent::class, ShareInteractionListener::class); + $dispatcher->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', function () { \OCP\Util::addScript('files_sharing', 'dist/collaboration'); }); $dispatcher->addServiceListener(ShareCreatedEvent::class, UserShareAcceptanceListener::class); + $dispatcher->addServiceListener(UserAddedEvent::class, UserAddedToGroupListener::class); // notifications api to accept incoming user shares - $dispatcher->addListener('OCP\Share::postShare', function(GenericEvent $event) { + $dispatcher->addListener('OCP\Share::postShare', function (GenericEvent $event) { /** @var Listener $listener */ $listener = $this->getContainer()->query(Listener::class); $listener->shareNotification($event); }); - $dispatcher->addListener(IGroup::class . '::postAddUser', function(GenericEvent $event) { + $dispatcher->addListener(IGroup::class . '::postAddUser', function (GenericEvent $event) { /** @var Listener $listener */ $listener = $this->getContainer()->query(Listener::class); $listener->userAddedToGroup($event); diff --git a/apps/files_sharing/lib/BackgroundJob/FederatedSharesDiscoverJob.php b/apps/files_sharing/lib/BackgroundJob/FederatedSharesDiscoverJob.php index 30530f15a5c..913dbf64284 100644 --- a/apps/files_sharing/lib/BackgroundJob/FederatedSharesDiscoverJob.php +++ b/apps/files_sharing/lib/BackgroundJob/FederatedSharesDiscoverJob.php @@ -5,6 +5,7 @@ declare(strict_types=1); /** * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl> * + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Roeland Jago Douma <roeland@famdouma.nl> * * @license GNU AGPL version 3 or any later version @@ -51,7 +52,7 @@ class FederatedSharesDiscoverJob extends TimedJob { ->from('share_external'); $result = $qb->execute(); - while($row = $result->fetch()) { + while ($row = $result->fetch()) { $this->discoveryService->discover($row['remote'], 'FEDERATED_SHARING', true); } $result->closeCursor(); diff --git a/apps/files_sharing/lib/Collaboration/ShareRecipientSorter.php b/apps/files_sharing/lib/Collaboration/ShareRecipientSorter.php index 1d81e468c67..5fbeba7dd01 100644 --- a/apps/files_sharing/lib/Collaboration/ShareRecipientSorter.php +++ b/apps/files_sharing/lib/Collaboration/ShareRecipientSorter.php @@ -3,6 +3,7 @@ * @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de> * * @author Arthur Schiwon <blizzz@arthur-schiwon.de> + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * * @license GNU AGPL version 3 or any later version * @@ -23,7 +24,6 @@ namespace OCA\Files_Sharing\Collaboration; - use OCP\Collaboration\AutoComplete\ISorter; use OCP\Files\Folder; use OCP\Files\IRootFolder; @@ -52,36 +52,36 @@ class ShareRecipientSorter implements ISorter { public function sort(array &$sortArray, array $context) { // let's be tolerant. Comments uses "files" by default, other usages are often singular - if($context['itemType'] !== 'files' && $context['itemType'] !== 'file') { + if ($context['itemType'] !== 'files' && $context['itemType'] !== 'file') { return; } $user = $this->userSession->getUser(); - if($user === null) { + if ($user === null) { return; } $userFolder = $this->rootFolder->getUserFolder($user->getUID()); /** @var Node[] $nodes */ $nodes = $userFolder->getById((int)$context['itemId']); - if(count($nodes) === 0) { + if (count($nodes) === 0) { return; } $al = $this->shareManager->getAccessList($nodes[0]); foreach ($sortArray as $type => &$byType) { - if(!isset($al[$type]) || !is_array($al[$type])) { + if (!isset($al[$type]) || !is_array($al[$type])) { continue; } // at least on PHP 5.6 usort turned out to be not stable. So we add // the current index to the value and compare it on a draw $i = 0; - $workArray = array_map(function($element) use (&$i) { + $workArray = array_map(function ($element) use (&$i) { return [$i++, $element]; }, $byType); usort($workArray, function ($a, $b) use ($al, $type) { $result = $this->compare($a[1], $b[1], $al[$type]); - if($result === 0) { + if ($result === 0) { $result = $a[0] - $b[0]; } return $result; diff --git a/apps/files_sharing/lib/Command/CleanupRemoteStorages.php b/apps/files_sharing/lib/Command/CleanupRemoteStorages.php index 309f882e65c..2eb79f87762 100644 --- a/apps/files_sharing/lib/Command/CleanupRemoteStorages.php +++ b/apps/files_sharing/lib/Command/CleanupRemoteStorages.php @@ -60,7 +60,6 @@ class CleanupRemoteStorages extends Command { } public function execute(InputInterface $input, OutputInterface $output) { - $remoteStorages = $this->getRemoteStorages(); $output->writeln(count($remoteStorages) . ' remote storage(s) need(s) to be checked'); @@ -138,7 +137,6 @@ class CleanupRemoteStorages extends Command { } public function getRemoteStorages() { - $queryBuilder = $this->connection->getQueryBuilder(); $queryBuilder->select(['id', 'numeric_id']) ->from('storages') @@ -166,7 +164,6 @@ class CleanupRemoteStorages extends Command { } public function getRemoteShareIds() { - $queryBuilder = $this->connection->getQueryBuilder(); $queryBuilder->select(['id', 'share_token', 'remote']) ->from('share_external'); diff --git a/apps/files_sharing/lib/Command/ExiprationNotification.php b/apps/files_sharing/lib/Command/ExiprationNotification.php index e228975a9b5..6fd04bcdccc 100644 --- a/apps/files_sharing/lib/Command/ExiprationNotification.php +++ b/apps/files_sharing/lib/Command/ExiprationNotification.php @@ -95,6 +95,4 @@ class ExiprationNotification extends Command { $this->notificationManager->notify($notification); } } - - } diff --git a/apps/files_sharing/lib/Controller/DeletedShareAPIController.php b/apps/files_sharing/lib/Controller/DeletedShareAPIController.php index 5f31459384e..bb33711c757 100644 --- a/apps/files_sharing/lib/Controller/DeletedShareAPIController.php +++ b/apps/files_sharing/lib/Controller/DeletedShareAPIController.php @@ -5,6 +5,7 @@ declare(strict_types=1); /** * * + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Daniel Calviño Sánchez <danxuliu@gmail.com> * @author Joas Schilling <coding@schilljs.com> * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> @@ -93,7 +94,6 @@ class DeletedShareAPIController extends OCSController { * @suppress PhanUndeclaredClassMethod */ private function formatShare(IShare $share): array { - $result = [ 'id' => $share->getFullId(), 'share_type' => $share->getShareType(), @@ -121,7 +121,7 @@ class DeletedShareAPIController extends OCSController { } $result['path'] = $userFolder->getRelativePath($node->getPath()); - if ($node instanceOf \OCP\Files\Folder) { + if ($node instanceof \OCP\Files\Folder) { $result['item_type'] = 'folder'; } else { $result['item_type'] = 'file'; @@ -143,7 +143,7 @@ class DeletedShareAPIController extends OCSController { $group = $this->groupManager->get($share->getSharedWith()); $result['share_with'] = $share->getSharedWith(); $result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith(); - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_ROOM) { + } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_ROOM) { $result['share_with'] = $share->getSharedWith(); $result['share_with_displayname'] = ''; @@ -154,7 +154,6 @@ class DeletedShareAPIController extends OCSController { } return $result; - } /** diff --git a/apps/files_sharing/lib/Controller/ExternalSharesController.php b/apps/files_sharing/lib/Controller/ExternalSharesController.php index 122ad0f7cf4..96b9ebffac8 100644 --- a/apps/files_sharing/lib/Controller/ExternalSharesController.php +++ b/apps/files_sharing/lib/Controller/ExternalSharesController.php @@ -3,6 +3,7 @@ * @copyright Copyright (c) 2016, ownCloud, Inc. * * @author Björn Schießle <bjoern@schiessle.org> + * @author Joas Schilling <coding@schilljs.com> * @author Lukas Reschke <lukas@statuscode.ch> * @author Morris Jobke <hey@morrisjobke.de> * @author Robin Appelman <robin@icewind.nl> @@ -130,7 +131,7 @@ class ExternalSharesController extends Controller { * @return DataResponse */ public function testRemote($remote) { - if (strpos($remote, '#') !== false || strpos($remote, '?') !== false) { + if (strpos($remote, '#') !== false || strpos($remote, '?') !== false || strpos($remote, ';') !== false) { return new DataResponse(false); } @@ -150,5 +151,4 @@ class ExternalSharesController extends Controller { return new DataResponse(false); } } - } diff --git a/apps/files_sharing/lib/Controller/PublicPreviewController.php b/apps/files_sharing/lib/Controller/PublicPreviewController.php index 076b3a381f8..0e58057351f 100644 --- a/apps/files_sharing/lib/Controller/PublicPreviewController.php +++ b/apps/files_sharing/lib/Controller/PublicPreviewController.php @@ -25,7 +25,6 @@ namespace OCA\Files_Sharing\Controller; -use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\FileDisplayResponse; @@ -97,7 +96,6 @@ class PublicPreviewController extends PublicShareController { int $y = 32, $a = false ) { - if ($token === '' || $x === 0 || $y === 0) { return new DataResponse([], Http::STATUS_BAD_REQUEST); } diff --git a/apps/files_sharing/lib/Controller/RemoteController.php b/apps/files_sharing/lib/Controller/RemoteController.php index 499c6d9c2e6..72eb8667b96 100644 --- a/apps/files_sharing/lib/Controller/RemoteController.php +++ b/apps/files_sharing/lib/Controller/RemoteController.php @@ -3,6 +3,7 @@ * @copyright Copyright (c) 2016, ownCloud, Inc. * * @author Bjoern Schiessle <bjoern@schiessle.org> + * @author Joas Schilling <coding@schilljs.com> * @author Roeland Jago Douma <roeland@famdouma.nl> * * @license AGPL-3.0 diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index 68729db6de8..0fbd57b4713 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -6,6 +6,7 @@ declare(strict_types=1); * @copyright Copyright (c) 2016, ownCloud, Inc. * * @author Bjoern Schiessle <bjoern@schiessle.org> + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Daniel Calviño Sánchez <danxuliu@gmail.com> * @author Joas Schilling <coding@schilljs.com> * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> @@ -52,6 +53,7 @@ use OCP\AppFramework\QueryException; use OCP\Constants; use OCP\Files\InvalidPathException; use OCP\Files\IRootFolder; +use OCP\Files\Folder; use OCP\Files\Node; use OCP\Files\NotFoundException; use OCP\IConfig; @@ -154,7 +156,7 @@ class ShareAPIController extends OCSController { * * @suppress PhanUndeclaredClassMethod */ - protected function formatShare(\OCP\Share\IShare $share, Node $recipientNode = null): array { + protected function formatShare(IShare $share, Node $recipientNode = null): array { $sharedBy = $this->userManager->get($share->getSharedBy()); $shareOwner = $this->userManager->get($share->getShareOwner()); @@ -195,7 +197,7 @@ class ShareAPIController extends OCSController { } $result['path'] = $userFolder->getRelativePath($node->getPath()); - if ($node instanceof \OCP\Files\Folder) { + if ($node instanceof Folder) { $result['item_type'] = 'folder'; } else { $result['item_type'] = 'file'; @@ -214,15 +216,15 @@ class ShareAPIController extends OCSController { $result['expiration'] = $expiration->format('Y-m-d 00:00:00'); } - if ($share->getShareType() === Share::SHARE_TYPE_USER) { + if ($share->getShareType() === IShare::TYPE_USER) { $sharedWith = $this->userManager->get($share->getSharedWith()); $result['share_with'] = $share->getSharedWith(); $result['share_with_displayname'] = $sharedWith !== null ? $sharedWith->getDisplayName() : $share->getSharedWith(); - } else if ($share->getShareType() === Share::SHARE_TYPE_GROUP) { + } elseif ($share->getShareType() === IShare::TYPE_GROUP) { $group = $this->groupManager->get($share->getSharedWith()); $result['share_with'] = $share->getSharedWith(); $result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith(); - } else if ($share->getShareType() === IShare::TYPE_LINK) { + } elseif ($share->getShareType() === IShare::TYPE_LINK) { // "share_with" and "share_with_displayname" for passwords of link // shares was deprecated in Nextcloud 15, use "password" instead. @@ -235,17 +237,17 @@ class ShareAPIController extends OCSController { $result['token'] = $share->getToken(); $result['url'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]); - } else if ($share->getShareType() === Share::SHARE_TYPE_REMOTE || $share->getShareType() === Share::SHARE_TYPE_REMOTE_GROUP) { + } elseif ($share->getShareType() === IShare::TYPE_REMOTE || $share->getShareType() === IShare::TYPE_REMOTE_GROUP) { $result['share_with'] = $share->getSharedWith(); $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'CLOUD'); $result['token'] = $share->getToken(); - } else if ($share->getShareType() === Share::SHARE_TYPE_EMAIL) { + } elseif ($share->getShareType() === IShare::TYPE_EMAIL) { $result['share_with'] = $share->getSharedWith(); $result['password'] = $share->getPassword(); $result['send_password_by_talk'] = $share->getSendPasswordByTalk(); $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL'); $result['token'] = $share->getToken(); - } else if ($share->getShareType() === Share::SHARE_TYPE_CIRCLE) { + } elseif ($share->getShareType() === IShare::TYPE_CIRCLE) { // getSharedWith() returns either "name (type, owner)" or // "name (type, owner) [id]", depending on the Circles app version. $hasCircleId = (substr($share->getSharedWith(), -1) === ']'); @@ -264,13 +266,14 @@ class ShareAPIController extends OCSController { $shareWithLength = -1; } $result['share_with'] = substr($share->getSharedWith(), $shareWithStart, $shareWithLength); - } else if ($share->getShareType() === Share::SHARE_TYPE_ROOM) { + } elseif ($share->getShareType() === IShare::TYPE_ROOM) { $result['share_with'] = $share->getSharedWith(); $result['share_with_displayname'] = ''; try { $result = array_merge($result, $this->getRoomShareHelper()->formatShare($share)); - } catch (QueryException $e) {} + } catch (QueryException $e) { + } } @@ -454,14 +457,14 @@ class ShareAPIController extends OCSController { $permissions &= ~($permissions & ~$path->getPermissions()); } - if ($shareType === Share::SHARE_TYPE_USER) { + if ($shareType === IShare::TYPE_USER) { // Valid user is required to share if ($shareWith === null || !$this->userManager->userExists($shareWith)) { throw new OCSNotFoundException($this->l->t('Please specify a valid user')); } $share->setSharedWith($shareWith); $share->setPermissions($permissions); - } else if ($shareType === Share::SHARE_TYPE_GROUP) { + } elseif ($shareType === IShare::TYPE_GROUP) { if (!$this->shareManager->allowGroupSharing()) { throw new OCSNotFoundException($this->l->t('Group sharing is disabled by the administrator')); } @@ -472,8 +475,8 @@ class ShareAPIController extends OCSController { } $share->setSharedWith($shareWith); $share->setPermissions($permissions); - } else if ($shareType === Share::SHARE_TYPE_LINK - || $shareType === Share::SHARE_TYPE_EMAIL) { + } elseif ($shareType === IShare::TYPE_LINK + || $shareType === IShare::TYPE_EMAIL) { // Can we even share links? if (!$this->shareManager->shareApiAllowLinks()) { @@ -491,23 +494,28 @@ class ShareAPIController extends OCSController { throw new OCSNotFoundException($this->l->t('Public upload is only possible for publicly shared folders')); } - $share->setPermissions( - Constants::PERMISSION_READ | + $permissions = Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | - Constants::PERMISSION_DELETE - ); + Constants::PERMISSION_DELETE; } else { - $share->setPermissions(Constants::PERMISSION_READ); + $permissions = Constants::PERMISSION_READ; } + // TODO: It might make sense to have a dedicated setting to allow/deny converting link shares into federated ones + if (($permissions & Constants::PERMISSION_READ) && $this->shareManager->outgoingServer2ServerSharesAllowed()) { + $permissions |= Constants::PERMISSION_SHARE; + } + + $share->setPermissions($permissions); + // Set password if ($password !== '') { $share->setPassword($password); } // Only share by mail have a recipient - if ($shareType === Share::SHARE_TYPE_EMAIL) { + if ($shareType === IShare::TYPE_EMAIL) { $share->setSharedWith($shareWith); } else { // Only link share have a label @@ -533,21 +541,21 @@ class ShareAPIController extends OCSController { throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD')); } } - } else if ($shareType === Share::SHARE_TYPE_REMOTE) { + } elseif ($shareType === IShare::TYPE_REMOTE) { if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) { throw new OCSForbiddenException($this->l->t('Sharing %1$s failed because the back end does not allow shares from type %2$s', [$path->getPath(), $shareType])); } $share->setSharedWith($shareWith); $share->setPermissions($permissions); - } else if ($shareType === Share::SHARE_TYPE_REMOTE_GROUP) { + } elseif ($shareType === IShare::TYPE_REMOTE_GROUP) { if (!$this->shareManager->outgoingServer2ServerGroupSharesAllowed()) { throw new OCSForbiddenException($this->l->t('Sharing %1$s failed because the back end does not allow shares from type %2$s', [$path->getPath(), $shareType])); } $share->setSharedWith($shareWith); $share->setPermissions($permissions); - } else if ($shareType === Share::SHARE_TYPE_CIRCLE) { + } elseif ($shareType === IShare::TYPE_CIRCLE) { if (!\OC::$server->getAppManager()->isEnabledForUser('circles') || !class_exists('\OCA\Circles\ShareByCircleProvider')) { throw new OCSNotFoundException($this->l->t('You cannot share to a Circle if the app is not enabled')); } @@ -560,7 +568,7 @@ class ShareAPIController extends OCSController { } $share->setSharedWith($shareWith); $share->setPermissions($permissions); - } else if ($shareType === Share::SHARE_TYPE_ROOM) { + } elseif ($shareType === IShare::TYPE_ROOM) { try { $this->getRoomShareHelper()->createShare($share, $shareWith, $permissions, $expireDate); } catch (QueryException $e) { @@ -594,20 +602,19 @@ class ShareAPIController extends OCSController { * @return array */ private function getSharedWithMe($node, bool $includeTags): array { - - $userShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_USER, $node, -1, 0); - $groupShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_GROUP, $node, -1, 0); - $circleShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_CIRCLE, $node, -1, 0); - $roomShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_ROOM, $node, -1, 0); + $userShares = $this->shareManager->getSharedWith($this->currentUser, IShare::TYPE_USER, $node, -1, 0); + $groupShares = $this->shareManager->getSharedWith($this->currentUser, IShare::TYPE_GROUP, $node, -1, 0); + $circleShares = $this->shareManager->getSharedWith($this->currentUser, IShare::TYPE_CIRCLE, $node, -1, 0); + $roomShares = $this->shareManager->getSharedWith($this->currentUser, IShare::TYPE_ROOM, $node, -1, 0); $shares = array_merge($userShares, $groupShares, $circleShares, $roomShares); - $shares = array_filter($shares, function(IShare $share) { + $filteredShares = array_filter($shares, function (IShare $share) { return $share->getShareOwner() !== $this->currentUser; }); $formatted = []; - foreach ($shares as $share) { + foreach ($filteredShares as $share) { if ($this->canAccessShare($share)) { try { $formatted[] = $this->formatShare($share); @@ -639,7 +646,7 @@ class ShareAPIController extends OCSController { $nodes = $folder->getDirectoryListing(); /** @var \OCP\Share\IShare[] $shares */ - $shares = array_reduce($nodes, function($carry, $node) { + $shares = array_reduce($nodes, function ($carry, $node) { $carry = array_merge($carry, $this->getAllShares($node, true)); return $carry; }, []); @@ -709,7 +716,6 @@ class ShareAPIController extends OCSController { string $path = '', string $include_tags = 'false' ): DataResponse { - $node = null; if ($path !== '') { $userFolder = $this->rootFolder->getUserFolder($this->currentUser); @@ -751,10 +757,13 @@ class ShareAPIController extends OCSController { * @throws OCSBadRequestException */ private function getFormattedShares( - string $viewer, $node = null, bool $sharedWithMe = false, bool $reShares = false, - bool $subFiles = false, bool $includeTags = false + string $viewer, + $node = null, + bool $sharedWithMe = false, + bool $reShares = false, + bool $subFiles = false, + bool $includeTags = false ): array { - if ($sharedWithMe) { return $this->getSharedWithMe($node, $includeTags); } @@ -773,12 +782,13 @@ class ShareAPIController extends OCSController { } catch (NotFoundException $e) { /* * Ignore shares where we can't get the node - * For example delted shares + * For example deleted shares */ continue; } - if (in_array($share->getId(), $known) || $share->getSharedWith() === $this->currentUser) { + if (in_array($share->getId(), $known) + || ($share->getSharedWith() === $this->currentUser && $share->getShareType() === IShare::TYPE_USER)) { continue; } @@ -851,8 +861,12 @@ class ShareAPIController extends OCSController { throw new OCSNotFoundException($this->l->t('Could not lock path')); } - // current User has resharing rights ? - $this->confirmSharingRights($node); + if (!($node->getPermissions() & Constants::PERMISSION_SHARE)) { + throw new SharingRightsException('no sharing rights on this item'); + } + + // The current top parent we have access to + $parent = $node; // initiate real owner. $owner = $node->getOwner() @@ -880,10 +894,25 @@ class ShareAPIController extends OCSController { $nodes[] = $node; } + // The user that is requesting this list + $currentUserFolder = $this->rootFolder->getUserFolder($this->currentUser); + // for each nodes, retrieve shares. $shares = []; + foreach ($nodes as $node) { $getShares = $this->getFormattedShares($owner, $node, false, true); + + $currentUserNodes = $currentUserFolder->getById($node->getId()); + if (!empty($currentUserNodes)) { + $parent = array_pop($currentUserNodes); + } + + $subPath = $currentUserFolder->getRelativePath($parent->getPath()); + foreach ($getShares as &$share) { + $share['via_fileid'] = $parent->getId(); + $share['via_path'] = $subPath; + } $this->mergeFormattedShares($shares, $getShares); } @@ -957,8 +986,8 @@ class ShareAPIController extends OCSController { /** * expirationdate, password and publicUpload only make sense for link shares */ - if ($share->getShareType() === Share::SHARE_TYPE_LINK - || $share->getShareType() === Share::SHARE_TYPE_EMAIL) { + if ($share->getShareType() === IShare::TYPE_LINK + || $share->getShareType() === IShare::TYPE_EMAIL) { /** * We do not allow editing link shares that the current user @@ -975,14 +1004,14 @@ class ShareAPIController extends OCSController { // Update hide download state if ($hideDownload === 'true') { $share->setHideDownload(true); - } else if ($hideDownload === 'false') { + } elseif ($hideDownload === 'false') { $share->setHideDownload(false); } $newPermissions = null; if ($publicUpload === 'true') { $newPermissions = Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE; - } else if ($publicUpload === 'false') { + } elseif ($publicUpload === 'false') { $newPermissions = Constants::PERMISSION_READ; } @@ -1022,13 +1051,18 @@ class ShareAPIController extends OCSController { } if ($newPermissions !== null) { + // TODO: It might make sense to have a dedicated setting to allow/deny converting link shares into federated ones + if (($newPermissions & Constants::PERMISSION_READ) && $this->shareManager->outgoingServer2ServerSharesAllowed()) { + $newPermissions |= Constants::PERMISSION_SHARE; + } + $share->setPermissions($newPermissions); $permissions = $newPermissions; } if ($expireDate === '') { $share->setExpirationDate(null); - } else if ($expireDate !== null) { + } elseif ($expireDate !== null) { try { $expireDate = $this->parseDate($expireDate); } catch (\Exception $e) { @@ -1039,12 +1073,12 @@ class ShareAPIController extends OCSController { if ($password === '') { $share->setPassword(null); - } else if ($password !== null) { + } elseif ($password !== null) { $share->setPassword($password); } // only link shares have labels - if ($share->getShareType() === Share::SHARE_TYPE_LINK && $label !== null) { + if ($share->getShareType() === IShare::TYPE_LINK && $label !== null) { $share->setLabel($label); } @@ -1054,7 +1088,7 @@ class ShareAPIController extends OCSController { } $share->setSendPasswordByTalk(true); - } else if ($sendPasswordByTalk !== null) { + } elseif ($sendPasswordByTalk !== null) { $share->setSendPasswordByTalk(false); } } @@ -1068,7 +1102,7 @@ class ShareAPIController extends OCSController { if ($expireDate === '') { $share->setExpirationDate(null); - } else if ($expireDate !== null) { + } elseif ($expireDate !== null) { try { $expireDate = $this->parseDate($expireDate); } catch (\Exception $e) { @@ -1195,7 +1229,7 @@ class ShareAPIController extends OCSController { } // If the share is shared with you, you can access it! - if ($share->getShareType() === Share::SHARE_TYPE_USER + if ($share->getShareType() === IShare::TYPE_USER && $share->getSharedWith() === $this->currentUser) { return true; } @@ -1209,7 +1243,7 @@ class ShareAPIController extends OCSController { } // If in the recipient group, you can see the share - if ($checkGroups && $share->getShareType() === Share::SHARE_TYPE_GROUP) { + if ($checkGroups && $share->getShareType() === IShare::TYPE_GROUP) { $sharedWith = $this->groupManager->get($share->getSharedWith()); $user = $this->userManager->get($this->currentUser); if ($user !== null && $sharedWith !== null && $sharedWith->inGroup($user)) { @@ -1217,12 +1251,12 @@ class ShareAPIController extends OCSController { } } - if ($share->getShareType() === Share::SHARE_TYPE_CIRCLE) { + if ($share->getShareType() === IShare::TYPE_CIRCLE) { // TODO: have a sanity check like above? return true; } - if ($share->getShareType() === Share::SHARE_TYPE_ROOM) { + if ($share->getShareType() === IShare::TYPE_ROOM) { try { return $this->getRoomShareHelper()->canAccessShare($share, $this->currentUser); } catch (QueryException $e) { @@ -1274,7 +1308,7 @@ class ShareAPIController extends OCSController { // if the user is the recipient, i can unshare // the share with self - if ($share->getShareType() === Share::SHARE_TYPE_USER && + if ($share->getShareType() === IShare::TYPE_USER && $share->getSharedWith() === $this->currentUser ) { return true; @@ -1318,7 +1352,7 @@ class ShareAPIController extends OCSController { } // If in the recipient group, you can delete the share from self - if ($share->getShareType() === Share::SHARE_TYPE_GROUP) { + if ($share->getShareType() === IShare::TYPE_GROUP) { $sharedWith = $this->groupManager->get($share->getSharedWith()); $user = $this->userManager->get($this->currentUser); if ($user !== null && $sharedWith !== null && $sharedWith->inGroup($user)) { @@ -1326,7 +1360,7 @@ class ShareAPIController extends OCSController { } } - if ($share->getShareType() === Share::SHARE_TYPE_ROOM) { + if ($share->getShareType() === IShare::TYPE_ROOM) { try { return $this->getRoomShareHelper()->canAccessShare($share, $this->currentUser); } catch (QueryException $e) { @@ -1384,7 +1418,7 @@ class ShareAPIController extends OCSController { try { - if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_CIRCLE)) { + if ($this->shareManager->shareProviderExists(IShare::TYPE_CIRCLE)) { $share = $this->shareManager->getShareById('ocCircleShare:' . $id, $this->currentUser); return $share; } @@ -1393,7 +1427,7 @@ class ShareAPIController extends OCSController { } try { - if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) { + if ($this->shareManager->shareProviderExists(IShare::TYPE_EMAIL)) { $share = $this->shareManager->getShareById('ocMailShare:' . $id, $this->currentUser); return $share; } @@ -1463,15 +1497,14 @@ class ShareAPIController extends OCSController { * @return IShare[] */ private function getSharesFromNode(string $viewer, $node, bool $reShares): array { - $providers = [ - Share::SHARE_TYPE_USER, - Share::SHARE_TYPE_GROUP, - Share::SHARE_TYPE_LINK, - Share::SHARE_TYPE_EMAIL, - Share::SHARE_TYPE_EMAIL, - Share::SHARE_TYPE_CIRCLE, - Share::SHARE_TYPE_ROOM + IShare::TYPE_USER, + IShare::TYPE_GROUP, + IShare::TYPE_LINK, + IShare::TYPE_EMAIL, + IShare::TYPE_EMAIL, + IShare::TYPE_CIRCLE, + IShare::TYPE_ROOM ]; // Should we assume that the (currentUser) viewer is the owner of the node !? @@ -1488,14 +1521,14 @@ class ShareAPIController extends OCSController { if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { $federatedShares = $this->shareManager->getSharesBy( - $this->currentUser, Share::SHARE_TYPE_REMOTE, $node, $reShares, -1, 0 + $this->currentUser, IShare::TYPE_REMOTE, $node, $reShares, -1, 0 ); $shares = array_merge($shares, $federatedShares); } if ($this->shareManager->outgoingServer2ServerGroupSharesAllowed()) { $federatedShares = $this->shareManager->getSharesBy( - $this->currentUser, Share::SHARE_TYPE_REMOTE_GROUP, $node, $reShares, -1, 0 + $this->currentUser, IShare::TYPE_REMOTE_GROUP, $node, $reShares, -1, 0 ); $shares = array_merge($shares, $federatedShares); } @@ -1570,17 +1603,16 @@ class ShareAPIController extends OCSController { return false; } - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && $share->getSharedWith() === $userId) { + if ($share->getShareType() === \OCP\IShare::TYPE_USER && $share->getSharedWith() === $userId) { return true; } - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP && $this->groupManager->isInGroup($userId, $share->getSharedWith())) { + if ($share->getShareType() === \OCP\IShare::TYPE_GROUP && $this->groupManager->isInGroup($userId, $share->getSharedWith())) { return true; } - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE && \OC::$server->getAppManager()->isEnabledForUser('circles') + if ($share->getShareType() === \OCP\IShare::TYPE_CIRCLE && \OC::$server->getAppManager()->isEnabledForUser('circles') && class_exists('\OCA\Circles\Api\v1\Circles')) { - $hasCircleId = (substr($share->getSharedWith(), -1) === ']'); $shareWithStart = ($hasCircleId ? strrpos($share->getSharedWith(), '[') + 1 : 0); $shareWithLength = ($hasCircleId ? -1 : strpos($share->getSharedWith(), ' ')); @@ -1611,27 +1643,27 @@ class ShareAPIController extends OCSController { */ private function getAllShares(?Node $path = null, bool $reshares = false) { // Get all shares - $userShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_USER, $path, $reshares, -1, 0); - $groupShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_GROUP, $path, $reshares, -1, 0); - $linkShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_LINK, $path, $reshares, -1, 0); + $userShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_USER, $path, $reshares, -1, 0); + $groupShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_GROUP, $path, $reshares, -1, 0); + $linkShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_LINK, $path, $reshares, -1, 0); // EMAIL SHARES - $mailShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_EMAIL, $path, $reshares, -1, 0); + $mailShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_EMAIL, $path, $reshares, -1, 0); // CIRCLE SHARES - $circleShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_CIRCLE, $path, $reshares, -1, 0); + $circleShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_CIRCLE, $path, $reshares, -1, 0); // TALK SHARES - $roomShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_ROOM, $path, $reshares, -1, 0); + $roomShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_ROOM, $path, $reshares, -1, 0); // FEDERATION if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { - $federatedShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_REMOTE, $path, $reshares, -1, 0); + $federatedShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_REMOTE, $path, $reshares, -1, 0); } else { $federatedShares = []; } if ($this->shareManager->outgoingServer2ServerGroupSharesAllowed()) { - $federatedGroupShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_REMOTE_GROUP, $path, $reshares, -1, 0); + $federatedGroupShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_REMOTE_GROUP, $path, $reshares, -1, 0); } else { $federatedGroupShares = []; } @@ -1655,5 +1687,4 @@ class ShareAPIController extends OCSController { } } } - } diff --git a/apps/files_sharing/lib/Controller/ShareController.php b/apps/files_sharing/lib/Controller/ShareController.php index 3feb98f7f02..2c6b043c028 100644 --- a/apps/files_sharing/lib/Controller/ShareController.php +++ b/apps/files_sharing/lib/Controller/ShareController.php @@ -5,8 +5,10 @@ * @author Arthur Schiwon <blizzz@arthur-schiwon.de> * @author Bjoern Schiessle <bjoern@schiessle.org> * @author Björn Schießle <bjoern@schiessle.org> + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Daniel Calviño Sánchez <danxuliu@gmail.com> * @author Georg Ehrke <oc.list@georgehrke.com> + * @author j3l11234 <297259024@qq.com> * @author Joas Schilling <coding@schilljs.com> * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> * @author Jonas Sulzer <jonas@violoncello.ch> @@ -47,6 +49,7 @@ use OC\Security\CSP\ContentSecurityPolicy; use OCA\FederatedFileSharing\FederatedShareProvider; use OCA\Files_Sharing\Activity\Providers\Downloads; use OCA\Viewer\Event\LoadViewer; +use OCP\Accounts\IAccountManager; use OCP\AppFramework\AuthPublicShareController; use OCP\AppFramework\Http\NotFoundResponse; use OCP\AppFramework\Http\Template\ExternalShareMenuAction; @@ -55,6 +58,7 @@ use OCP\AppFramework\Http\Template\PublicTemplateResponse; use OCP\AppFramework\Http\Template\SimpleMenuAction; use OCP\AppFramework\Http\TemplateResponse; use OCP\Defaults; +use OCP\Files\Folder; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; use OCP\IConfig; @@ -64,6 +68,7 @@ use OCP\IPreview; use OCP\IRequest; use OCP\ISession; use OCP\IURLGenerator; +use OCP\IUser; use OCP\IUserManager; use OCP\Share; use OCP\Share\Exceptions\ShareNotFound; @@ -93,6 +98,8 @@ class ShareController extends AuthPublicShareController { protected $rootFolder; /** @var FederatedShareProvider */ protected $federatedShareProvider; + /** @var IAccountManager */ + protected $accountManager; /** @var EventDispatcherInterface */ protected $eventDispatcher; /** @var IL10N */ @@ -118,6 +125,7 @@ class ShareController extends AuthPublicShareController { * @param IPreview $previewManager * @param IRootFolder $rootFolder * @param FederatedShareProvider $federatedShareProvider + * @param IAccountManager $accountManager * @param EventDispatcherInterface $eventDispatcher * @param IL10N $l10n * @param Defaults $defaults @@ -134,6 +142,7 @@ class ShareController extends AuthPublicShareController { IPreview $previewManager, IRootFolder $rootFolder, FederatedShareProvider $federatedShareProvider, + IAccountManager $accountManager, EventDispatcherInterface $eventDispatcher, IL10N $l10n, Defaults $defaults) { @@ -146,6 +155,7 @@ class ShareController extends AuthPublicShareController { $this->previewManager = $previewManager; $this->rootFolder = $rootFolder; $this->federatedShareProvider = $federatedShareProvider; + $this->accountManager = $accountManager; $this->eventDispatcher = $eventDispatcher; $this->l10n = $l10n; $this->defaults = $defaults; @@ -241,7 +251,7 @@ class ShareController extends AuthPublicShareController { $itemType = $itemSource = $uidOwner = ''; $token = $share; $exception = null; - if($share instanceof \OCP\Share\IShare) { + if ($share instanceof \OCP\Share\IShare) { try { $token = $share->getToken(); $uidOwner = $share->getSharedBy(); @@ -260,7 +270,7 @@ class ShareController extends AuthPublicShareController { 'errorCode' => $errorCode, 'errorMessage' => $errorMessage, ]); - if(!is_null($exception)) { + if (!is_null($exception)) { throw $exception; } } @@ -291,7 +301,7 @@ class ShareController extends AuthPublicShareController { * @PublicPage * @NoCSRFRequired * - + * * @param string $path * @return TemplateResponse * @throws NotFoundException @@ -326,8 +336,20 @@ class ShareController extends AuthPublicShareController { } $shareTmpl = []; - $shareTmpl['displayName'] = $this->userManager->get($share->getShareOwner())->getDisplayName(); - $shareTmpl['owner'] = $share->getShareOwner(); + $shareTmpl['owner'] = ''; + $shareTmpl['shareOwner'] = ''; + + $owner = $this->userManager->get($share->getShareOwner()); + if ($owner instanceof IUser) { + $ownerAccount = $this->accountManager->getAccount($owner); + + $ownerName = $ownerAccount->getProperty(IAccountManager::PROPERTY_DISPLAYNAME); + if ($ownerName->getScope() === IAccountManager::VISIBILITY_PUBLIC) { + $shareTmpl['owner'] = $owner->getUID(); + $shareTmpl['shareOwner'] = $owner->getDisplayName(); + } + } + $shareTmpl['filename'] = $shareNode->getName(); $shareTmpl['directory_path'] = $share->getTarget(); $shareTmpl['note'] = $share->getNote(); @@ -345,7 +367,6 @@ class ShareController extends AuthPublicShareController { $hideFileList = false; if ($shareNode instanceof \OCP\Files\Folder) { - $shareIsFolder = true; try { @@ -394,7 +415,6 @@ class ShareController extends AuthPublicShareController { $shareTmpl['showgridview'] = false; $shareTmpl['hideFileList'] = $hideFileList; - $shareTmpl['shareOwner'] = $this->userManager->get($share->getShareOwner())->getDisplayName(); $shareTmpl['downloadURL'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.downloadShare', ['token' => $this->getToken()]); $shareTmpl['shareUrl'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $this->getToken()]); $shareTmpl['maxSizeAnimateGif'] = $this->config->getSystemValue('max_filesize_animated_gifs_public_sharing', 10); @@ -405,7 +425,7 @@ class ShareController extends AuthPublicShareController { $shareTmpl['previewURL'] = $shareTmpl['downloadURL']; if ($shareTmpl['previewSupported']) { - $shareTmpl['previewImage'] = $this->urlGenerator->linkToRouteAbsolute( 'files_sharing.PublicPreview.getPreview', + $shareTmpl['previewImage'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.PublicPreview.getPreview', ['x' => 200, 'y' => 200, 'file' => $shareTmpl['directory_path'], 'token' => $shareTmpl['dirToken']]); $ogPreview = $shareTmpl['previewImage']; @@ -477,7 +497,9 @@ class ShareController extends AuthPublicShareController { $response = new PublicTemplateResponse($this->appName, 'public', $shareTmpl); $response->setHeaderTitle($shareTmpl['filename']); - $response->setHeaderDetails($this->l10n->t('shared by %s', [$shareTmpl['displayName']])); + if ($shareTmpl['shareOwner'] !== '') { + $response->setHeaderDetails($this->l10n->t('shared by %s', [$shareTmpl['shareOwner']])); + } $isNoneFileDropFolder = $shareIsFolder === false || $share->getPermissions() !== \OCP\Constants::PERMISSION_CREATE; @@ -489,7 +511,7 @@ class ShareController extends AuthPublicShareController { $download = new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download', $shareTmpl['downloadURL'], 10, $shareTmpl['fileSize']); $downloadAll = new SimpleMenuAction('download', $this->l10n->t('Download all files'), 'icon-download', $shareTmpl['downloadURL'], 10, $shareTmpl['fileSize']); $directLink = new LinkMenuAction($this->l10n->t('Direct link'), 'icon-public', $shareTmpl['previewURL']); - $externalShare = new ExternalShareMenuAction($this->l10n->t('Add to your Nextcloud'), 'icon-external', $shareTmpl['owner'], $shareTmpl['displayName'], $shareTmpl['filename']); + $externalShare = new ExternalShareMenuAction($this->l10n->t('Add to your Nextcloud'), 'icon-external', $shareTmpl['owner'], $shareTmpl['shareOwner'], $shareTmpl['filename']); $responseComposer = []; @@ -518,6 +540,7 @@ class ShareController extends AuthPublicShareController { /** * @PublicPage * @NoCSRFRequired + * @NoSameSiteCookieRequired * * @param string $token * @param string $files @@ -531,7 +554,7 @@ class ShareController extends AuthPublicShareController { $share = $this->shareManager->getShareByToken($token); - if(!($share->getPermissions() & \OCP\Constants::PERMISSION_READ)) { + if (!($share->getPermissions() & \OCP\Constants::PERMISSION_READ)) { return new \OCP\AppFramework\Http\DataResponse('Share is read-only'); } @@ -582,16 +605,16 @@ class ShareController extends AuthPublicShareController { // Single file download $this->singleFileDownloaded($share, $share->getNode()); } else { - if ($share->getHideDownload()) { + try { + if (!empty($files_list)) { + $this->fileListDownloaded($share, $files_list, $node); + } else { + // The folder is downloaded + $this->singleFileDownloaded($share, $share->getNode()); + } + } catch (NotFoundException $e) { return new NotFoundResponse(); } - - if (!empty($files_list)) { - $this->fileListDownloaded($share, $files_list, $node); - } else { - // The folder is downloaded - $this->singleFileDownloaded($share, $share->getNode()); - } } } @@ -614,7 +637,7 @@ class ShareController extends AuthPublicShareController { $this->emitAccessShareHook($share); - $server_params = array( 'head' => $this->request->getMethod() === 'HEAD' ); + $server_params = [ 'head' => $this->request->getMethod() === 'HEAD' ]; /** * Http range requests support @@ -643,21 +666,29 @@ class ShareController extends AuthPublicShareController { * @param Share\IShare $share * @param array $files_list * @param \OCP\Files\Folder $node + * @throws NotFoundException when trying to download a folder or multiple files of a "hide download" share */ protected function fileListDownloaded(Share\IShare $share, array $files_list, \OCP\Files\Folder $node) { + if ($share->getHideDownload() && count($files_list) > 1) { + throw new NotFoundException('Downloading more than 1 file'); + } + foreach ($files_list as $file) { $subNode = $node->get($file); $this->singleFileDownloaded($share, $subNode); } - } /** * create activity if a single file was downloaded from a link share * * @param Share\IShare $share + * @throws NotFoundException when trying to download a folder of a "hide download" share */ protected function singleFileDownloaded(Share\IShare $share, \OCP\Files\Node $node) { + if ($share->getHideDownload() && $node instanceof Folder) { + throw new NotFoundException('Downloading a folder'); + } $fileId = $node->getId(); @@ -707,7 +738,6 @@ class ShareController extends AuthPublicShareController { $affectedUser, $fileId, $filePath) { - $event = $this->activityManager->generateEvent(); $event->setApp('files_sharing') ->setType('public_links') @@ -716,6 +746,4 @@ class ShareController extends AuthPublicShareController { ->setObject('files', $fileId, $filePath); $this->activityManager->publish($event); } - - } diff --git a/apps/files_sharing/lib/Controller/ShareInfoController.php b/apps/files_sharing/lib/Controller/ShareInfoController.php index 31f98f91c03..315a562abef 100644 --- a/apps/files_sharing/lib/Controller/ShareInfoController.php +++ b/apps/files_sharing/lib/Controller/ShareInfoController.php @@ -88,7 +88,6 @@ class ShareInfoController extends ApiController { try { $node = $node->get($dir); } catch (NotFoundException $e) { - } } diff --git a/apps/files_sharing/lib/Controller/ShareesAPIController.php b/apps/files_sharing/lib/Controller/ShareesAPIController.php index 61678e67c17..b523dd3d37d 100644 --- a/apps/files_sharing/lib/Controller/ShareesAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareesAPIController.php @@ -11,6 +11,7 @@ declare(strict_types=1); * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Daniel Calviño Sánchez <danxuliu@gmail.com> * @author Joas Schilling <coding@schilljs.com> + * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> * @author Maxence Lange <maxence@nextcloud.com> * @author Morris Jobke <hey@morrisjobke.de> * @author Robin Appelman <robin@icewind.nl> @@ -34,7 +35,6 @@ declare(strict_types=1); namespace OCA\Files_Sharing\Controller; -use function array_filter; use function array_slice; use function array_values; use Generator; @@ -48,7 +48,7 @@ use OCP\Collaboration\Collaborators\SearchResultType; use OCP\IConfig; use OCP\IRequest; use OCP\IURLGenerator; -use OCP\Share; +use OCP\Share\IShare; use OCP\Share\IManager; use function usort; @@ -66,12 +66,6 @@ class ShareesAPIController extends OCSController { /** @var IManager */ protected $shareManager; - /** @var bool */ - protected $shareWithGroupOnly = false; - - /** @var bool */ - protected $shareeEnumeration = true; - /** @var int */ protected $offset = 0; @@ -163,50 +157,48 @@ class ShareesAPIController extends OCSController { } $shareTypes = [ - Share::SHARE_TYPE_USER, + IShare::TYPE_USER, ]; if ($itemType === null) { throw new OCSBadRequestException('Missing itemType'); } elseif ($itemType === 'file' || $itemType === 'folder') { if ($this->shareManager->allowGroupSharing()) { - $shareTypes[] = Share::SHARE_TYPE_GROUP; + $shareTypes[] = IShare::TYPE_GROUP; } if ($this->isRemoteSharingAllowed($itemType)) { - $shareTypes[] = Share::SHARE_TYPE_REMOTE; + $shareTypes[] = IShare::TYPE_REMOTE; } if ($this->isRemoteGroupSharingAllowed($itemType)) { - $shareTypes[] = Share::SHARE_TYPE_REMOTE_GROUP; + $shareTypes[] = IShare::TYPE_REMOTE_GROUP; } - if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) { - $shareTypes[] = Share::SHARE_TYPE_EMAIL; + if ($this->shareManager->shareProviderExists(IShare::TYPE_EMAIL)) { + $shareTypes[] = IShare::TYPE_EMAIL; } - if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_ROOM)) { - $shareTypes[] = Share::SHARE_TYPE_ROOM; + if ($this->shareManager->shareProviderExists(IShare::TYPE_ROOM)) { + $shareTypes[] = IShare::TYPE_ROOM; } } else { - $shareTypes[] = Share::SHARE_TYPE_GROUP; - $shareTypes[] = Share::SHARE_TYPE_EMAIL; + $shareTypes[] = IShare::TYPE_GROUP; + $shareTypes[] = IShare::TYPE_EMAIL; } // FIXME: DI if (\OC::$server->getAppManager()->isEnabledForUser('circles') && class_exists('\OCA\Circles\ShareByCircleProvider')) { - $shareTypes[] = Share::SHARE_TYPE_CIRCLE; + $shareTypes[] = IShare::TYPE_CIRCLE; } if ($shareType !== null && is_array($shareType)) { $shareTypes = array_intersect($shareTypes, $shareType); - } else if (is_numeric($shareType)) { + } elseif (is_numeric($shareType)) { $shareTypes = array_intersect($shareTypes, [(int) $shareType]); } sort($shareTypes); - $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; - $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; $this->limit = (int) $perPage; $this->offset = $perPage * ($page - 1); @@ -221,7 +213,7 @@ class ShareesAPIController extends OCSController { list($result, $hasMoreResults) = $this->collaboratorSearch->search($search, $shareTypes, $lookup, $this->limit, $this->offset); // extra treatment for 'exact' subarray, with a single merge expected keys might be lost - if(isset($result['exact'])) { + if (isset($result['exact'])) { $result['exact'] = array_merge($this->result['exact'], $result['exact']); } $this->result = array_merge($this->result, $result); @@ -266,18 +258,18 @@ class ShareesAPIController extends OCSController { } private function sortShareesByFrequency(array $sharees): array { - usort($sharees, function(array $s1, array $s2) { + usort($sharees, function (array $s1, array $s2) { return $s2['count'] - $s1['count']; }); return $sharees; } private $searchResultTypeMap = [ - Share::SHARE_TYPE_USER => 'users', - Share::SHARE_TYPE_GROUP => 'groups', - Share::SHARE_TYPE_REMOTE => 'remotes', - Share::SHARE_TYPE_REMOTE_GROUP => 'remote_groups', - Share::SHARE_TYPE_EMAIL => 'emails', + IShare::TYPE_USER => 'users', + IShare::TYPE_GROUP => 'groups', + IShare::TYPE_REMOTE => 'remotes', + IShare::TYPE_REMOTE_GROUP => 'remote_groups', + IShare::TYPE_EMAIL => 'emails', ]; private function getAllSharees(string $user, array $shareTypes): ISearchResult { @@ -333,45 +325,45 @@ class ShareesAPIController extends OCSController { */ public function findRecommended(string $itemType = null, $shareType = null): DataResponse { $shareTypes = [ - Share::SHARE_TYPE_USER, + IShare::TYPE_USER, ]; if ($itemType === null) { throw new OCSBadRequestException('Missing itemType'); } elseif ($itemType === 'file' || $itemType === 'folder') { if ($this->shareManager->allowGroupSharing()) { - $shareTypes[] = Share::SHARE_TYPE_GROUP; + $shareTypes[] = IShare::TYPE_GROUP; } if ($this->isRemoteSharingAllowed($itemType)) { - $shareTypes[] = Share::SHARE_TYPE_REMOTE; + $shareTypes[] = IShare::TYPE_REMOTE; } if ($this->isRemoteGroupSharingAllowed($itemType)) { - $shareTypes[] = Share::SHARE_TYPE_REMOTE_GROUP; + $shareTypes[] = IShare::TYPE_REMOTE_GROUP; } - if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) { - $shareTypes[] = Share::SHARE_TYPE_EMAIL; + if ($this->shareManager->shareProviderExists(IShare::TYPE_EMAIL)) { + $shareTypes[] = IShare::TYPE_EMAIL; } - if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_ROOM)) { - $shareTypes[] = Share::SHARE_TYPE_ROOM; + if ($this->shareManager->shareProviderExists(IShare::TYPE_ROOM)) { + $shareTypes[] = IShare::TYPE_ROOM; } } else { - $shareTypes[] = Share::SHARE_TYPE_GROUP; - $shareTypes[] = Share::SHARE_TYPE_EMAIL; + $shareTypes[] = IShare::TYPE_GROUP; + $shareTypes[] = IShare::TYPE_EMAIL; } // FIXME: DI if (\OC::$server->getAppManager()->isEnabledForUser('circles') && class_exists('\OCA\Circles\ShareByCircleProvider')) { - $shareTypes[] = Share::SHARE_TYPE_CIRCLE; + $shareTypes[] = IShare::TYPE_CIRCLE; } if (isset($_GET['shareType']) && is_array($_GET['shareType'])) { $shareTypes = array_intersect($shareTypes, $_GET['shareType']); sort($shareTypes); - } else if (is_numeric($shareType)) { + } elseif (is_numeric($shareType)) { $shareTypes = array_intersect($shareTypes, [(int) $shareType]); sort($shareTypes); } @@ -391,7 +383,7 @@ class ShareesAPIController extends OCSController { try { // FIXME: static foo makes unit testing unnecessarily difficult $backend = \OC\Share\Share::getBackend($itemType); - return $backend->isShareTypeAllowed(Share::SHARE_TYPE_REMOTE); + return $backend->isShareTypeAllowed(IShare::TYPE_REMOTE); } catch (\Exception $e) { return false; } @@ -401,7 +393,7 @@ class ShareesAPIController extends OCSController { try { // FIXME: static foo makes unit testing unnecessarily difficult $backend = \OC\Share\Share::getBackend($itemType); - return $backend->isShareTypeAllowed(Share::SHARE_TYPE_REMOTE_GROUP); + return $backend->isShareTypeAllowed(IShare::TYPE_REMOTE_GROUP); } catch (\Exception $e) { return false; } diff --git a/apps/files_sharing/lib/DeleteOrphanedSharesJob.php b/apps/files_sharing/lib/DeleteOrphanedSharesJob.php index 548da79b9e1..1e2d1ce5a8f 100644 --- a/apps/files_sharing/lib/DeleteOrphanedSharesJob.php +++ b/apps/files_sharing/lib/DeleteOrphanedSharesJob.php @@ -2,6 +2,7 @@ /** * @copyright Copyright (c) 2016, ownCloud, Inc. * + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Joas Schilling <coding@schilljs.com> * @author Morris Jobke <hey@morrisjobke.de> * @author Vincent Petry <pvince81@owncloud.com> @@ -41,7 +42,7 @@ class DeleteOrphanedSharesJob extends TimedJob { /** * sets the correct interval for this timed job */ - public function __construct(){ + public function __construct() { $this->interval = $this->defaultIntervalMin * 60; } @@ -62,5 +63,4 @@ class DeleteOrphanedSharesJob extends TimedJob { $deletedEntries = $connection->executeUpdate($sql); $logger->debug("$deletedEntries orphaned share(s) deleted", ['app' => 'DeleteOrphanedSharesJob']); } - } diff --git a/apps/files_sharing/lib/Exceptions/BrokenPath.php b/apps/files_sharing/lib/Exceptions/BrokenPath.php index 33fb242a36a..c0679c83314 100644 --- a/apps/files_sharing/lib/Exceptions/BrokenPath.php +++ b/apps/files_sharing/lib/Exceptions/BrokenPath.php @@ -3,6 +3,7 @@ * @copyright Copyright (c) 2016, ownCloud, Inc. * * @author Björn Schießle <bjoern@schiessle.org> + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Morris Jobke <hey@morrisjobke.de> * * @license AGPL-3.0 @@ -27,7 +28,7 @@ namespace OCA\Files_Sharing\Exceptions; * Expected path with a different root * Possible Error Codes: * 10 - Path not relative to data/ and point to the users file directory - + * */ class BrokenPath extends \Exception { } diff --git a/apps/files_sharing/lib/Exceptions/SharingRightsException.php b/apps/files_sharing/lib/Exceptions/SharingRightsException.php index 868ead81e7f..db346774bdb 100644 --- a/apps/files_sharing/lib/Exceptions/SharingRightsException.php +++ b/apps/files_sharing/lib/Exceptions/SharingRightsException.php @@ -25,7 +25,6 @@ namespace OCA\Files_Sharing\Exceptions; use Exception; - /** * Sharing and Resharing rights. * @@ -34,6 +33,4 @@ use Exception; * @package OCA\Files_Sharing\Exceptions */ class SharingRightsException extends Exception { - } - diff --git a/apps/files_sharing/lib/ExpireSharesJob.php b/apps/files_sharing/lib/ExpireSharesJob.php index ef90a04dba1..4ca3b80e343 100644 --- a/apps/files_sharing/lib/ExpireSharesJob.php +++ b/apps/files_sharing/lib/ExpireSharesJob.php @@ -2,6 +2,7 @@ /** * @copyright Copyright (c) 2016, ownCloud, Inc. * + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Morris Jobke <hey@morrisjobke.de> * @author Roeland Jago Douma <roeland@famdouma.nl> * @@ -68,10 +69,9 @@ class ExpireSharesJob extends TimedJob { ); $shares = $qb->execute(); - while($share = $shares->fetch()) { + while ($share = $shares->fetch()) { \OC\Share\Share::unshare($share['item_type'], $share['file_source'], \OCP\Share::SHARE_TYPE_LINK, null, $share['uid_owner']); } $shares->closeCursor(); } - } diff --git a/apps/files_sharing/lib/External/Manager.php b/apps/files_sharing/lib/External/Manager.php index c58e6e7b98a..8331787c6df 100644 --- a/apps/files_sharing/lib/External/Manager.php +++ b/apps/files_sharing/lib/External/Manager.php @@ -4,6 +4,7 @@ * * @author Bjoern Schiessle <bjoern@schiessle.org> * @author Björn Schießle <bjoern@schiessle.org> + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Daniel Hansson <daniel@techandme.se> * @author Joas Schilling <coding@schilljs.com> * @author Jörn Friedrich Dreyer <jfd@butonic.de> @@ -47,7 +48,7 @@ use OCP\Share; use OCP\Share\IShare; class Manager { - const STORAGE = '\OCA\Files_Sharing\External\Storage'; + public const STORAGE = '\OCA\Files_Sharing\External\Storage'; /** * @var string @@ -150,12 +151,11 @@ class Manager { * @throws \Doctrine\DBAL\DBALException */ public function addShare($remote, $token, $password, $name, $owner, $shareType, $accepted=false, $user = null, $remoteId = -1, $parent = -1) { - $user = $user ? $user : $this->uid; $accepted = $accepted ? IShare::STATUS_ACCEPTED : IShare::STATUS_PENDING; $name = Filesystem::normalizePath('/' . $name); - if ($accepted !== IShare::STATUS_ACCEPTED) { + if ($accepted !== IShare::STATUS_ACCEPTED) { // To avoid conflicts with the mount point generation later, // we only use a temporary mount point name here. The real // mount point name will be generated when accepting the share, @@ -193,13 +193,13 @@ class Manager { $this->writeShareToDb($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId, $parent, $shareType); - $options = array( + $options = [ 'remote' => $remote, 'token' => $token, 'password' => $password, 'mountpoint' => $mountPoint, 'owner' => $owner - ); + ]; return $this->mountShare($options); } @@ -226,7 +226,7 @@ class Manager { (`remote`, `share_token`, `password`, `name`, `owner`, `user`, `mountpoint`, `mountpoint_hash`, `accepted`, `remote_id`, `parent`, `share_type`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) '); - return $query->execute(array($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId, $parent, $shareType)); + return $query->execute([$remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId, $parent, $shareType]); } /** @@ -240,7 +240,7 @@ class Manager { SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted`, `parent`, `share_type`, `password`, `mountpoint_hash` FROM `*PREFIX*share_external` WHERE `id` = ?'); - $result = $getShare->execute(array($id)); + $result = $getShare->execute([$id]); $share = $result ? $getShare->fetch() : []; @@ -249,7 +249,7 @@ class Manager { // check if the user is allowed to access it if ($validShare && (int)$share['share_type'] === Share::SHARE_TYPE_USER && $share['user'] === $this->uid) { return $share; - } else if ($validShare && (int)$share['share_type'] === Share::SHARE_TYPE_GROUP) { + } elseif ($validShare && (int)$share['share_type'] === Share::SHARE_TYPE_GROUP) { $user = $this->userManager->get($this->uid); if ($this->groupManager->get($share['user'])->inGroup($user)) { return $share; @@ -257,7 +257,6 @@ class Manager { } return false; - } /** @@ -267,7 +266,6 @@ class Manager { * @return bool True if the share could be accepted, false otherwise */ public function acceptShare($id) { - $share = $this->getShare($id); $result = false; @@ -279,14 +277,14 @@ class Manager { $hash = md5($mountPoint); $userShareAccepted = false; - if((int)$share['share_type'] === Share::SHARE_TYPE_USER) { + if ((int)$share['share_type'] === Share::SHARE_TYPE_USER) { $acceptShare = $this->connection->prepare(' UPDATE `*PREFIX*share_external` SET `accepted` = ?, `mountpoint` = ?, `mountpoint_hash` = ? WHERE `id` = ? AND `user` = ?'); - $userShareAccepted = $acceptShare->execute(array(1, $mountPoint, $hash, $id, $this->uid)); + $userShareAccepted = $acceptShare->execute([1, $mountPoint, $hash, $id, $this->uid]); } else { $result = $this->writeShareToDb( $share['remote'], @@ -320,19 +318,18 @@ class Manager { * @return bool True if the share could be declined, false otherwise */ public function declineShare($id) { - $share = $this->getShare($id); $result = false; if ($share && (int)$share['share_type'] === Share::SHARE_TYPE_USER) { $removeShare = $this->connection->prepare(' DELETE FROM `*PREFIX*share_external` WHERE `id` = ? AND `user` = ?'); - $removeShare->execute(array($id, $this->uid)); + $removeShare->execute([$id, $this->uid]); $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); $this->processNotification($id); $result = true; - } else if ($share && (int)$share['share_type'] === Share::SHARE_TYPE_GROUP) { + } elseif ($share && (int)$share['share_type'] === Share::SHARE_TYPE_GROUP) { $result = $this->writeShareToDb( $share['remote'], $share['share_token'], @@ -373,10 +370,9 @@ class Manager { * @return boolean */ private function sendFeedbackToRemote($remote, $token, $remoteId, $feedback) { - $result = $this->tryOCMEndPoint($remote, $token, $remoteId, $feedback); - if($result === true) { + if ($result === true) { return true; } @@ -384,7 +380,7 @@ class Manager { $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; $url = rtrim($remote, '/') . $endpoint . '/' . $remoteId . '/' . $feedback . '?format=' . Share::RESPONSE_FORMAT; - $fields = array('token' => $token); + $fields = ['token' => $token]; $client = $this->clientService->newClient(); @@ -445,7 +441,6 @@ class Manager { } return false; - } @@ -502,13 +497,12 @@ class Manager { WHERE `mountpoint_hash` = ? AND `user` = ? '); - $result = (bool)$query->execute(array($target, $targetHash, $sourceHash, $this->uid)); + $result = (bool)$query->execute([$target, $targetHash, $sourceHash, $this->uid]); return $result; } public function removeShare($mountPoint) { - $mountPointObj = $this->mountManager->find($mountPoint); $id = $mountPointObj->getStorage()->getCache()->getId(''); @@ -519,7 +513,7 @@ class Manager { SELECT `remote`, `share_token`, `remote_id`, `share_type`, `id` FROM `*PREFIX*share_external` WHERE `mountpoint_hash` = ? AND `user` = ?'); - $result = $getShare->execute(array($hash, $this->uid)); + $result = $getShare->execute([$hash, $this->uid]); $share = $getShare->fetch(); $getShare->closeCursor(); @@ -535,16 +529,16 @@ class Manager { DELETE FROM `*PREFIX*share_external` WHERE `id` = ? '); - $result = (bool)$query->execute(array((int)$share['id'])); - } else if ($result && (int)$share['share_type'] === Share::SHARE_TYPE_GROUP) { + $result = (bool)$query->execute([(int)$share['id']]); + } elseif ($result && (int)$share['share_type'] === Share::SHARE_TYPE_GROUP) { $query = $this->connection->prepare(' UPDATE `*PREFIX*share_external` SET `accepted` = ? WHERE `id` = ?'); - $result = (bool)$query->execute(array(0, (int)$share['id'])); + $result = (bool)$query->execute([0, (int)$share['id']]); } - if($result) { + if ($result) { $this->removeReShares($id); } @@ -585,11 +579,11 @@ class Manager { SELECT `remote`, `share_token`, `remote_id` FROM `*PREFIX*share_external` WHERE `user` = ?'); - $result = $getShare->execute(array($uid)); + $result = $getShare->execute([$uid]); if ($result) { $shares = $getShare->fetchAll(); - foreach($shares as $share) { + foreach ($shares as $share) { $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); } } @@ -598,7 +592,7 @@ class Manager { DELETE FROM `*PREFIX*share_external` WHERE `user` = ? '); - return (bool)$query->execute(array($uid)); + return (bool)$query->execute([$uid]); } /** diff --git a/apps/files_sharing/lib/External/MountProvider.php b/apps/files_sharing/lib/External/MountProvider.php index 992aba48c66..ecff358abe5 100644 --- a/apps/files_sharing/lib/External/MountProvider.php +++ b/apps/files_sharing/lib/External/MountProvider.php @@ -2,6 +2,7 @@ /** * @copyright Copyright (c) 2016, ownCloud, Inc. * + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Lukas Reschke <lukas@statuscode.ch> * @author Robin Appelman <robin@icewind.nl> * @@ -30,7 +31,7 @@ use OCP\IDBConnection; use OCP\IUser; class MountProvider implements IMountProvider { - const STORAGE = '\OCA\Files_Sharing\External\Storage'; + public const STORAGE = '\OCA\Files_Sharing\External\Storage'; /** * @var \OCP\IDBConnection diff --git a/apps/files_sharing/lib/External/Scanner.php b/apps/files_sharing/lib/External/Scanner.php index afa8687d280..0051a1b76bf 100644 --- a/apps/files_sharing/lib/External/Scanner.php +++ b/apps/files_sharing/lib/External/Scanner.php @@ -2,6 +2,7 @@ /** * @copyright Copyright (c) 2016, ownCloud, Inc. * + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Lukas Reschke <lukas@statuscode.ch> * @author Morris Jobke <hey@morrisjobke.de> * @author Olivier Paroz <github@oparoz.com> @@ -37,7 +38,7 @@ class Scanner extends \OC\Files\Cache\Scanner { /** {@inheritDoc} */ public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true) { - if(!$this->storage->remoteIsOwnCloud()) { + if (!$this->storage->remoteIsOwnCloud()) { return parent::scan($path, $recursive, $recursive, $lock); } @@ -57,7 +58,7 @@ class Scanner extends \OC\Files\Cache\Scanner { * @param bool $lock set to false to disable getting an additional read lock during scanning * @return array an array of metadata of the scanned file */ - public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true) { + public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true, $data = null) { try { return parent::scanFile($file, $reuseExisting); } catch (ForbiddenException $e) { diff --git a/apps/files_sharing/lib/External/Storage.php b/apps/files_sharing/lib/External/Storage.php index 97870f73343..0d5f620ddf2 100644 --- a/apps/files_sharing/lib/External/Storage.php +++ b/apps/files_sharing/lib/External/Storage.php @@ -4,6 +4,7 @@ * * @author Bjoern Schiessle <bjoern@schiessle.org> * @author Björn Schießle <bjoern@schiessle.org> + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Joas Schilling <coding@schilljs.com> * @author Lukas Reschke <lukas@statuscode.ch> * @author Morris Jobke <hey@morrisjobke.de> @@ -85,13 +86,13 @@ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage { $this->mountPoint = $options['mountpoint']; $this->token = $options['token']; - parent::__construct(array( + parent::__construct([ 'secure' => $secure, 'host' => $host, 'root' => $root, 'user' => $options['token'], 'password' => (string)$options['password'] - )); + ]); } public function getWatcher($path = '', $storage = null) { @@ -265,7 +266,7 @@ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage { */ private function testRemoteUrl($url) { $cache = $this->memcacheFactory->createDistributed('files_sharing_remote_url'); - if($cache->hasKey($url)) { + if ($cache->hasKey($url)) { return (bool)$cache->get($url); } @@ -296,7 +297,7 @@ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage { * @return bool */ public function remoteIsOwnCloud() { - if(defined('PHPUNIT_RUN') || !$this->testRemoteUrl($this->getRemote() . '/status.php')) { + if (defined('PHPUNIT_RUN') || !$this->testRemoteUrl($this->getRemote() . '/status.php')) { return false; } return true; @@ -314,7 +315,7 @@ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage { $password = $this->getPassword(); // If remote is not an ownCloud do not try to get any share info - if(!$this->remoteIsOwnCloud()) { + if (!$this->remoteIsOwnCloud()) { return ['status' => 'unsupported']; } @@ -360,7 +361,7 @@ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage { // old federated sharing permissions if (isset($response['{http://open-collaboration-services.org/ns}share-permissions'])) { $permissions = $response['{http://open-collaboration-services.org/ns}share-permissions']; - } else if (isset($response['{http://open-cloud-mesh.org/ns}share-permissions'])) { + } elseif (isset($response['{http://open-cloud-mesh.org/ns}share-permissions'])) { // permissions provided by the OCM API $permissions = $this->ocmPermissions2ncPermissions($response['{http://open-collaboration-services.org/ns}share-permissions']); } else { @@ -386,7 +387,7 @@ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage { try { $ocmPermissions = json_decode($ocmPermissions); $ncPermissions = 0; - foreach($ocmPermissions as $permission) { + foreach ($ocmPermissions as $permission) { switch (strtolower($permission)) { case 'read': $ncPermissions += Constants::PERMISSION_READ; diff --git a/apps/files_sharing/lib/Helper.php b/apps/files_sharing/lib/Helper.php index b487aab6d7f..d3c6deeec2e 100644 --- a/apps/files_sharing/lib/Helper.php +++ b/apps/files_sharing/lib/Helper.php @@ -29,12 +29,8 @@ namespace OCA\Files_Sharing; use OC\Files\Filesystem; use OC\Files\View; -use OCP\Files\NotFoundException; -use OCP\Share\Exceptions\ShareNotFound; -use OCP\User; class Helper { - public static function registerHooks() { \OCP\Util::connectHook('OC_Filesystem', 'post_rename', '\OCA\Files_Sharing\Updater', 'renameHook'); \OCP\Util::connectHook('OC_Filesystem', 'post_delete', '\OCA\Files_Sharing\Hooks', 'unshareChildren'); @@ -89,7 +85,6 @@ class Helper { } return $shareFolder; - } /** @@ -100,5 +95,4 @@ class Helper { public static function setShareFolder($shareFolder) { \OC::$server->getConfig()->setSystemValue('share_folder', $shareFolder); } - } diff --git a/apps/files_sharing/lib/Hooks.php b/apps/files_sharing/lib/Hooks.php index 831e37e7e06..a37a497f2bd 100644 --- a/apps/files_sharing/lib/Hooks.php +++ b/apps/files_sharing/lib/Hooks.php @@ -5,7 +5,6 @@ * @author Bjoern Schiessle <bjoern@schiessle.org> * @author Björn Schießle <bjoern@schiessle.org> * @author Joas Schilling <coding@schilljs.com> - * @author Lukas Reschke <lukas@statuscode.ch> * @author Morris Jobke <hey@morrisjobke.de> * @author Robin Appelman <robin@icewind.nl> * @author Roeland Jago Douma <roeland@famdouma.nl> @@ -29,10 +28,8 @@ namespace OCA\Files_Sharing; use OC\Files\Filesystem; -use OCA\FederatedFileSharing\DiscoveryManager; class Hooks { - public static function deleteUser($params) { $manager = new External\Manager( \OC::$server->getDatabaseConnection(), diff --git a/apps/files_sharing/lib/ISharedStorage.php b/apps/files_sharing/lib/ISharedStorage.php index 2f0888589ca..07c012fd6ff 100644 --- a/apps/files_sharing/lib/ISharedStorage.php +++ b/apps/files_sharing/lib/ISharedStorage.php @@ -2,6 +2,7 @@ /** * @copyright Copyright (c) 2016, ownCloud, Inc. * + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Morris Jobke <hey@morrisjobke.de> * @author Robin Appelman <robin@icewind.nl> * @@ -23,6 +24,5 @@ namespace OCA\Files_Sharing; -interface ISharedStorage{ - +interface ISharedStorage { } diff --git a/apps/files_sharing/lib/Listener/LoadSidebarListener.php b/apps/files_sharing/lib/Listener/LoadSidebarListener.php index ba2ce54eeb4..636a8c7757e 100644 --- a/apps/files_sharing/lib/Listener/LoadSidebarListener.php +++ b/apps/files_sharing/lib/Listener/LoadSidebarListener.php @@ -40,5 +40,4 @@ class LoadSidebarListener implements IEventListener { Util::addScript(Application::APP_ID, 'dist/files_sharing_tab'); } - } diff --git a/apps/files_sharing/lib/Listener/ShareInteractionListener.php b/apps/files_sharing/lib/Listener/ShareInteractionListener.php new file mode 100644 index 00000000000..e698d16d823 --- /dev/null +++ b/apps/files_sharing/lib/Listener/ShareInteractionListener.php @@ -0,0 +1,94 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\Files_Sharing\Listener; + +use OCP\Contacts\Events\ContactInteractedWithEvent; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\EventDispatcher\IEventListener; +use OCP\ILogger; +use OCP\IUserManager; +use OCP\Share\Events\ShareCreatedEvent; +use OCP\Share\IShare; +use function in_array; + +class ShareInteractionListener implements IEventListener { + private const SUPPORTED_SHARE_TYPES = [ + IShare::TYPE_USER, + IShare::TYPE_EMAIL, + IShare::TYPE_REMOTE, + ]; + + /** @var IEventDispatcher */ + private $dispatcher; + + /** @var IUserManager */ + private $userManager; + + /** @var ILogger */ + private $logger; + + public function __construct(IEventDispatcher $dispatcher, + IUserManager $userManager, + ILogger $logger) { + $this->dispatcher = $dispatcher; + $this->userManager = $userManager; + $this->logger = $logger; + } + + public function handle(Event $event): void { + if (!($event instanceof ShareCreatedEvent)) { + // Unrelated + return; + } + + $share = $event->getShare(); + if (!in_array($share->getShareType(), self::SUPPORTED_SHARE_TYPES, true)) { + $this->logger->debug('Share type does not allow to emit interaction event'); + return; + } + $actor = $this->userManager->get($share->getSharedBy()); + if ($actor === null) { + $this->logger->warning('Share was not created by a user, can\'t emit interaction event'); + return; + } + $interactionEvent = new ContactInteractedWithEvent($actor); + switch ($share->getShareType()) { + case IShare::TYPE_USER: + $interactionEvent->setUid($share->getSharedWith()); + break; + case IShare::TYPE_EMAIL: + $interactionEvent->setEmail($share->getSharedWith()); + break; + case IShare::TYPE_REMOTE: + $interactionEvent->setFederatedCloudId($share->getSharedWith()); + break; + } + + $this->dispatcher->dispatchTyped($interactionEvent); + } +} diff --git a/apps/files_sharing/lib/Listener/UserAddedToGroupListener.php b/apps/files_sharing/lib/Listener/UserAddedToGroupListener.php new file mode 100644 index 00000000000..623591da310 --- /dev/null +++ b/apps/files_sharing/lib/Listener/UserAddedToGroupListener.php @@ -0,0 +1,83 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2020, Roeland Jago Douma <roeland@famdouma.nl> + * + * @author Roeland Jago Douma <roeland@famdouma.nl> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\Files_Sharing\Listener; + +use OCA\Files_Sharing\AppInfo\Application; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\Group\Events\UserAddedEvent; +use OCP\IConfig; +use OCP\Share\IManager; +use OCP\Share\IShare; + +class UserAddedToGroupListener implements IEventListener { + + /** @var IManager */ + private $shareManager; + + /** @var IConfig */ + private $config; + + public function __construct(IManager $shareManager, IConfig $config) { + $this->shareManager = $shareManager; + $this->config = $config; + } + + public function handle(Event $event): void { + if (!($event instanceof UserAddedEvent)) { + return; + } + + $user = $event->getUser(); + $group = $event->getGroup(); + + // This user doesn't have autoaccept so we can skip it all + if (!$this->hasAutoAccept($user->getUID())) { + return; + } + + // Get all group shares this user has access to now to filter later + $shares = $this->shareManager->getSharedWith($user->getUID(), IShare::TYPE_GROUP); + + foreach ($shares as $share) { + // If this is not the new group we can skip it + if ($share->getSharedWith() !== $group->getGID()) { + continue; + } + + // Accept the share if needed + $this->shareManager->acceptShare($share, $user->getUID()); + } + } + + + private function hasAutoAccept(string $userId): bool { + $defaultAcceptSystemConfig = $this->config->getSystemValueBool('sharing.enable_share_accept', false) ? 'no' : 'yes'; + $acceptDefault = $this->config->getUserValue($userId, Application::APP_ID, 'default_accept', $defaultAcceptSystemConfig) === 'yes'; + return (!$this->config->getSystemValueBool('sharing.force_share_accept', false) && $acceptDefault); + } +} diff --git a/apps/files_sharing/lib/Listener/UserShareAcceptanceListener.php b/apps/files_sharing/lib/Listener/UserShareAcceptanceListener.php index 382f0b61793..91c0aa494bb 100644 --- a/apps/files_sharing/lib/Listener/UserShareAcceptanceListener.php +++ b/apps/files_sharing/lib/Listener/UserShareAcceptanceListener.php @@ -5,6 +5,8 @@ declare(strict_types=1); /** * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl> * + * @author Christoph Wurst <christoph@winzerhof-wurst.at> + * @author Julius Härtl <jus@bitgrid.net> * @author Roeland Jago Douma <roeland@famdouma.nl> * * @license GNU AGPL version 3 or any later version @@ -59,7 +61,7 @@ class UserShareAcceptanceListener implements IEventListener { if ($share->getShareType() === IShare::TYPE_USER) { $this->handleAutoAccept($share, $share->getSharedWith()); - } else if ($share->getShareType() === IShare::TYPE_GROUP) { + } elseif ($share->getShareType() === IShare::TYPE_GROUP) { $group = $this->groupManager->get($share->getSharedWith()); if ($group === null) { @@ -71,7 +73,6 @@ class UserShareAcceptanceListener implements IEventListener { $this->handleAutoAccept($share, $user->getUID()); } } - } private function handleAutoAccept(IShare $share, string $userId) { @@ -81,5 +82,4 @@ class UserShareAcceptanceListener implements IEventListener { $this->shareManager->acceptShare($share, $userId); } } - } diff --git a/apps/files_sharing/lib/Middleware/SharingCheckMiddleware.php b/apps/files_sharing/lib/Middleware/SharingCheckMiddleware.php index de168c43f52..c58496a46d7 100644 --- a/apps/files_sharing/lib/Middleware/SharingCheckMiddleware.php +++ b/apps/files_sharing/lib/Middleware/SharingCheckMiddleware.php @@ -3,6 +3,7 @@ * @copyright Copyright (c) 2016, ownCloud, Inc. * * @author Bjoern Schiessle <bjoern@schiessle.org> + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Lukas Reschke <lukas@statuscode.ch> * @author Morris Jobke <hey@morrisjobke.de> * @author Roeland Jago Douma <roeland@famdouma.nl> @@ -27,7 +28,6 @@ namespace OCA\Files_Sharing\Middleware; use OCA\Files_Sharing\Controller\ExternalSharesController; -use OCA\Files_Sharing\Controller\ShareController; use OCA\Files_Sharing\Exceptions\S2SException; use OCP\App\IAppManager; use OCP\AppFramework\Controller; @@ -94,7 +94,7 @@ class SharingCheckMiddleware extends Middleware { * @throws ShareNotFound */ public function beforeController($controller, $methodName) { - if(!$this->isSharingEnabled()) { + if (!$this->isSharingEnabled()) { throw new NotFoundException('Sharing is disabled.'); } @@ -114,7 +114,7 @@ class SharingCheckMiddleware extends Middleware { * @throws \Exception */ public function afterException($controller, $methodName, \Exception $exception) { - if(is_a($exception, NotFoundException::class)) { + if (is_a($exception, NotFoundException::class)) { return new NotFoundResponse(); } @@ -130,14 +130,13 @@ class SharingCheckMiddleware extends Middleware { * @return bool */ private function externalSharesChecks() { - if (!$this->reflector->hasAnnotation('NoIncomingFederatedSharingRequired') && $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') !== 'yes') { return false; } if (!$this->reflector->hasAnnotation('NoOutgoingFederatedSharingRequired') && - $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') !== 'yes') { + $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') !== 'yes') { return false; } @@ -151,13 +150,10 @@ class SharingCheckMiddleware extends Middleware { private function isSharingEnabled() { // FIXME: This check is done here since the route is globally defined and not inside the files_sharing app // Check whether the sharing application is enabled - if(!$this->appManager->isEnabledForUser($this->appName)) { + if (!$this->appManager->isEnabledForUser($this->appName)) { return false; } return true; } - - - } diff --git a/apps/files_sharing/lib/Migration/OwncloudGuestShareType.php b/apps/files_sharing/lib/Migration/OwncloudGuestShareType.php index 9b0fee38bac..237c6aca243 100644 --- a/apps/files_sharing/lib/Migration/OwncloudGuestShareType.php +++ b/apps/files_sharing/lib/Migration/OwncloudGuestShareType.php @@ -79,5 +79,4 @@ class OwncloudGuestShareType implements IRepairStep { return $appVersion === '0.10.0' || $this->config->getAppValue('core', 'vendor', '') === 'owncloud'; } - } diff --git a/apps/files_sharing/lib/Migration/SetAcceptedStatus.php b/apps/files_sharing/lib/Migration/SetAcceptedStatus.php index a48ca8fa6a8..386f7299d40 100644 --- a/apps/files_sharing/lib/Migration/SetAcceptedStatus.php +++ b/apps/files_sharing/lib/Migration/SetAcceptedStatus.php @@ -77,5 +77,4 @@ class SetAcceptedStatus implements IRepairStep { $appVersion = $this->config->getAppValue('files_sharing', 'installed_version', '0.0.0'); return version_compare($appVersion, '1.10.1', '<'); } - } diff --git a/apps/files_sharing/lib/Migration/SetPasswordColumn.php b/apps/files_sharing/lib/Migration/SetPasswordColumn.php index a666aa4dd3e..5580bd46a5b 100644 --- a/apps/files_sharing/lib/Migration/SetPasswordColumn.php +++ b/apps/files_sharing/lib/Migration/SetPasswordColumn.php @@ -86,12 +86,10 @@ class SetPasswordColumn implements IRepairStep { ->where($clearQuery->expr()->eq('share_type', $clearQuery->createNamedParameter(Share::SHARE_TYPE_LINK))); $clearQuery->execute(); - } protected function shouldRun() { $appVersion = $this->config->getAppValue('files_sharing', 'installed_version', '0.0.0'); return version_compare($appVersion, '1.4.0', '<'); } - } diff --git a/apps/files_sharing/lib/MountProvider.php b/apps/files_sharing/lib/MountProvider.php index 9845611b180..43306fe2e7e 100644 --- a/apps/files_sharing/lib/MountProvider.php +++ b/apps/files_sharing/lib/MountProvider.php @@ -2,6 +2,7 @@ /** * @copyright Copyright (c) 2016, ownCloud, Inc. * + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Daniel Calviño Sánchez <danxuliu@gmail.com> * @author Joas Schilling <coding@schilljs.com> * @author Maxence Lange <maxence@nextcloud.com> @@ -74,7 +75,6 @@ class MountProvider implements IMountProvider { * @return \OCP\Files\Mount\IMountPoint[] */ public function getMountsForUser(IUser $user, IStorageFactory $storageFactory) { - $shares = $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_USER, null, -1); $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_GROUP, null, -1)); $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_CIRCLE, null, -1)); @@ -155,7 +155,7 @@ class MountProvider implements IMountProvider { $result = []; // sort by stime, the super share will be based on the least recent share foreach ($tmp as &$tmp2) { - @usort($tmp2, function($a, $b) { + @usort($tmp2, function ($a, $b) { if ($a->getShareTime() <= $b->getShareTime()) { return -1; } diff --git a/apps/files_sharing/lib/Notification/Listener.php b/apps/files_sharing/lib/Notification/Listener.php index 8f5dccdd20f..385612959a9 100644 --- a/apps/files_sharing/lib/Notification/Listener.php +++ b/apps/files_sharing/lib/Notification/Listener.php @@ -5,6 +5,7 @@ declare(strict_types=1); /** * @copyright Copyright (c) 2019, Joas Schilling <coding@schilljs.com> * + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Joas Schilling <coding@schilljs.com> * * @license GNU AGPL version 3 or any later version @@ -66,7 +67,7 @@ class Listener { $notification->setSubject(Notifier::INCOMING_USER_SHARE) ->setUser($share->getSharedWith()); $this->notificationManager->notify($notification); - } else if ($share->getShareType() === IShare::TYPE_GROUP) { + } elseif ($share->getShareType() === IShare::TYPE_GROUP) { $notification->setSubject(Notifier::INCOMING_GROUP_SHARE); $group = $this->groupManager->get($share->getSharedWith()); diff --git a/apps/files_sharing/lib/Notification/Notifier.php b/apps/files_sharing/lib/Notification/Notifier.php index a47b04e5b14..9b636c8d30d 100644 --- a/apps/files_sharing/lib/Notification/Notifier.php +++ b/apps/files_sharing/lib/Notification/Notifier.php @@ -6,6 +6,7 @@ declare(strict_types=1); * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl> * @copyright Copyright (c) 2019, Joas Schilling <coding@schilljs.com> * + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Joas Schilling <coding@schilljs.com> * @author Roeland Jago Douma <roeland@famdouma.nl> * @@ -149,12 +150,11 @@ class Notifier implements INotifier { } protected function parseShareInvitation(IShare $share, INotification $notification, IL10N $l): INotification { - if ($share->getShareType() === IShare::TYPE_USER) { if ($share->getStatus() !== IShare::STATUS_PENDING) { throw new AlreadyProcessedException(); } - } else if ($share->getShareType() === IShare::TYPE_GROUP) { + } elseif ($share->getShareType() === IShare::TYPE_GROUP) { if ($share->getStatus() !== IShare::STATUS_PENDING) { throw new AlreadyProcessedException(); } diff --git a/apps/files_sharing/lib/Scanner.php b/apps/files_sharing/lib/Scanner.php index 7115b602aed..36a412800e5 100644 --- a/apps/files_sharing/lib/Scanner.php +++ b/apps/files_sharing/lib/Scanner.php @@ -71,7 +71,7 @@ class Scanner extends \OC\Files\Cache\Scanner { } } - public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true) { + public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true, $data = null) { $sourceScanner = $this->getSourceScanner(); if ($sourceScanner instanceof NoopScanner) { return []; diff --git a/apps/files_sharing/lib/Settings/Personal.php b/apps/files_sharing/lib/Settings/Personal.php index d6fd7f5f9ca..bfca0b46e07 100644 --- a/apps/files_sharing/lib/Settings/Personal.php +++ b/apps/files_sharing/lib/Settings/Personal.php @@ -5,6 +5,7 @@ declare(strict_types=1); /** * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl> * + * @author Julius Härtl <jus@bitgrid.net> * @author Roeland Jago Douma <roeland@famdouma.nl> * * @license GNU AGPL version 3 or any later version @@ -63,5 +64,4 @@ class Personal implements ISettings { public function getPriority(): int { return 90; } - } diff --git a/apps/files_sharing/lib/ShareBackend/File.php b/apps/files_sharing/lib/ShareBackend/File.php index a3a041142eb..a15391162ff 100644 --- a/apps/files_sharing/lib/ShareBackend/File.php +++ b/apps/files_sharing/lib/ShareBackend/File.php @@ -6,6 +6,7 @@ * @author Bart Visscher <bartv@thisnet.nl> * @author Bjoern Schiessle <bjoern@schiessle.org> * @author Björn Schießle <bjoern@schiessle.org> + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Joas Schilling <coding@schilljs.com> * @author Lukas Reschke <lukas@statuscode.ch> * @author Michael Gapczynski <GapczynskiM@gmail.com> @@ -36,14 +37,13 @@ namespace OCA\Files_Sharing\ShareBackend; use OCA\FederatedFileSharing\FederatedShareProvider; class File implements \OCP\Share_Backend_File_Dependent { - - const FORMAT_SHARED_STORAGE = 0; - const FORMAT_GET_FOLDER_CONTENTS = 1; - const FORMAT_FILE_APP_ROOT = 2; - const FORMAT_OPENDIR = 3; - const FORMAT_GET_ALL = 4; - const FORMAT_PERMISSIONS = 5; - const FORMAT_TARGET_NAMES = 6; + public const FORMAT_SHARED_STORAGE = 0; + public const FORMAT_GET_FOLDER_CONTENTS = 1; + public const FORMAT_FILE_APP_ROOT = 2; + public const FORMAT_OPENDIR = 3; + public const FORMAT_GET_ALL = 4; + public const FORMAT_PERMISSIONS = 5; + public const FORMAT_TARGET_NAMES = 6; private $path; @@ -117,7 +117,7 @@ class File implements \OCP\Share_Backend_File_Dependent { } } - $excludeList = is_array($exclude) ? $exclude : array(); + $excludeList = is_array($exclude) ? $exclude : []; return \OCA\Files_Sharing\Helper::generateUniqueTarget($target, $excludeList, $view); } @@ -126,17 +126,17 @@ class File implements \OCP\Share_Backend_File_Dependent { if ($format === self::FORMAT_SHARED_STORAGE) { // Only 1 item should come through for this format call $item = array_shift($items); - return array( + return [ 'parent' => $item['parent'], 'path' => $item['path'], 'storage' => $item['storage'], 'permissions' => $item['permissions'], 'uid_owner' => $item['uid_owner'], - ); - } else if ($format === self::FORMAT_GET_FOLDER_CONTENTS) { - $files = array(); + ]; + } elseif ($format === self::FORMAT_GET_FOLDER_CONTENTS) { + $files = []; foreach ($items as $item) { - $file = array(); + $file = []; $file['fileid'] = $item['file_source']; $file['storage'] = $item['storage']; $file['path'] = $item['file_target']; @@ -156,32 +156,32 @@ class File implements \OCP\Share_Backend_File_Dependent { $files[] = $file; } return $files; - } else if ($format === self::FORMAT_OPENDIR) { - $files = array(); + } elseif ($format === self::FORMAT_OPENDIR) { + $files = []; foreach ($items as $item) { $files[] = basename($item['file_target']); } return $files; - } else if ($format === self::FORMAT_GET_ALL) { - $ids = array(); + } elseif ($format === self::FORMAT_GET_ALL) { + $ids = []; foreach ($items as $item) { $ids[] = $item['file_source']; } return $ids; - } else if ($format === self::FORMAT_PERMISSIONS) { - $filePermissions = array(); + } elseif ($format === self::FORMAT_PERMISSIONS) { + $filePermissions = []; foreach ($items as $item) { $filePermissions[$item['file_source']] = $item['permissions']; } return $filePermissions; - } else if ($format === self::FORMAT_TARGET_NAMES) { - $targets = array(); + } elseif ($format === self::FORMAT_TARGET_NAMES) { + $targets = []; foreach ($items as $item) { $targets[] = $item['file_target']; } return $targets; } - return array(); + return []; } /** diff --git a/apps/files_sharing/lib/ShareBackend/Folder.php b/apps/files_sharing/lib/ShareBackend/Folder.php index fd4bb2491fa..c51740cd6d0 100644 --- a/apps/files_sharing/lib/ShareBackend/Folder.php +++ b/apps/files_sharing/lib/ShareBackend/Folder.php @@ -4,6 +4,7 @@ * * @author Bart Visscher <bartv@thisnet.nl> * @author Björn Schießle <bjoern@schiessle.org> + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Joas Schilling <coding@schilljs.com> * @author Michael Gapczynski <GapczynskiM@gmail.com> * @author Morris Jobke <hey@morrisjobke.de> @@ -39,7 +40,7 @@ class Folder extends File implements \OCP\Share_Backend_Collection { * @return array with shares */ public function getParents($itemSource, $shareWith = null, $owner = null) { - $result = array(); + $result = []; $parent = $this->getParentId($itemSource); $userManager = \OC::$server->getUserManager(); @@ -89,8 +90,8 @@ class Folder extends File implements \OCP\Share_Backend_Collection { } public function getChildren($itemSource) { - $children = array(); - $parents = array($itemSource); + $children = []; + $parents = [$itemSource]; $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); $qb->select('id') @@ -108,10 +109,9 @@ class Folder extends File implements \OCP\Share_Backend_Collection { $mimetype = -1; } while (!empty($parents)) { - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); - $parents = array_map(function($parent) use ($qb) { + $parents = array_map(function ($parent) use ($qb) { return $qb->createNamedParameter($parent); }, $parents); @@ -123,9 +123,9 @@ class Folder extends File implements \OCP\Share_Backend_Collection { $result = $qb->execute(); - $parents = array(); + $parents = []; while ($file = $result->fetch()) { - $children[] = array('source' => $file['fileid'], 'file_path' => $file['name']); + $children[] = ['source' => $file['fileid'], 'file_path' => $file['name']]; // If a child folder is found look inside it if ((int) $file['mimetype'] === $mimetype) { $parents[] = $file['fileid']; @@ -135,5 +135,4 @@ class Folder extends File implements \OCP\Share_Backend_Collection { } return $children; } - } diff --git a/apps/files_sharing/lib/SharedMount.php b/apps/files_sharing/lib/SharedMount.php index 91f3c39ba05..487011584c7 100644 --- a/apps/files_sharing/lib/SharedMount.php +++ b/apps/files_sharing/lib/SharedMount.php @@ -89,7 +89,6 @@ class SharedMount extends MountPoint implements MoveableMount { * @return string */ private function verifyMountPoint(\OCP\Share\IShare $share, array $mountpoints, CappedMemoryCache $folderExistCache) { - $mountPoint = basename($share->getTarget()); $parent = dirname($share->getTarget()); @@ -193,7 +192,6 @@ class SharedMount extends MountPoint implements MoveableMount { * @return bool */ public function moveMount($target) { - $relTargetPath = $this->stripUserFilesPath($target); $share = $this->storage->getShare(); diff --git a/apps/files_sharing/lib/SharedStorage.php b/apps/files_sharing/lib/SharedStorage.php index 0baa36ac985..d40e94e36db 100644 --- a/apps/files_sharing/lib/SharedStorage.php +++ b/apps/files_sharing/lib/SharedStorage.php @@ -4,6 +4,7 @@ * * @author Bart Visscher <bartv@thisnet.nl> * @author Björn Schießle <bjoern@schiessle.org> + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Joas Schilling <coding@schilljs.com> * @author Michael Gapczynski <GapczynskiM@gmail.com> * @author Morris Jobke <hey@morrisjobke.de> @@ -285,11 +286,11 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto } } } - $info = array( + $info = [ 'target' => $this->getMountPoint() . $path, 'source' => $source, 'mode' => $mode, - ); + ]; \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'fopen', $info); return $this->nonMaskedStorage->fopen($this->getUnjailedPath($path), $mode); } diff --git a/apps/files_sharing/lib/Updater.php b/apps/files_sharing/lib/Updater.php index 652ff171880..84e31494c92 100644 --- a/apps/files_sharing/lib/Updater.php +++ b/apps/files_sharing/lib/Updater.php @@ -3,6 +3,7 @@ * @copyright Copyright (c) 2016, ownCloud, Inc. * * @author Björn Schießle <bjoern@schiessle.org> + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Daniel Calviño Sánchez <danxuliu@gmail.com> * @author Michael Gapczynski <GapczynskiM@gmail.com> * @author Morris Jobke <hey@morrisjobke.de> @@ -31,7 +32,7 @@ class Updater { /** * @param array $params */ - static public function renameHook($params) { + public static function renameHook($params) { self::renameChildren($params['oldpath'], $params['newpath']); self::moveShareToShare($params['newpath']); } @@ -46,7 +47,7 @@ class Updater { * * @param string $path */ - static private function moveShareToShare($path) { + private static function moveShareToShare($path) { $userFolder = \OC::$server->getUserFolder(); // If the user folder can't be constructed (e.g. link share) just return. @@ -90,8 +91,7 @@ class Updater { * @param string $oldPath old path relative to data/user/files * @param string $newPath new path relative to data/user/files */ - static private function renameChildren($oldPath, $newPath) { - + private static function renameChildren($oldPath, $newPath) { $absNewPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files/' . $newPath); $absOldPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files/' . $oldPath); @@ -105,5 +105,4 @@ class Updater { } } } - } |