* @author Bjoern Schiessle * @author Björn Schießle * @author Christoph Wurst * @author Daniel Calviño Sánchez * @author Georg Ehrke * @author j3l11234 <297259024@qq.com> * @author Joas Schilling * @author John Molakvoæ * @author Jonas Sulzer * @author Julius Härtl * @author Lukas Reschke * @author MartB * @author Maxence Lange * @author Michael Weimann * @author Morris Jobke * @author Piotr Filiciak * @author Robin Appelman * @author Roeland Jago Douma * @author Sascha Sambale * @author Thomas Müller * @author Vincent Petry * * @license AGPL-3.0 * * This code is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License, version 3, * as published by the Free Software Foundation. * * 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, version 3, * along with this program. If not, see * */ namespace OCA\Files_Sharing\Controller; use OC_Files; use OC_Util; use OC\Security\CSP\ContentSecurityPolicy; use OCA\FederatedFileSharing\FederatedShareProvider; use OCA\Files_Sharing\Activity\Providers\Downloads; use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent; use OCA\Viewer\Event\LoadViewer; use OCP\Accounts\IAccountManager; use OCP\AppFramework\AuthPublicShareController; use OCP\AppFramework\Http\NotFoundResponse; use OCP\AppFramework\Http\Template\ExternalShareMenuAction; use OCP\AppFramework\Http\Template\LinkMenuAction; use OCP\AppFramework\Http\Template\PublicTemplateResponse; use OCP\AppFramework\Http\Template\SimpleMenuAction; use OCP\AppFramework\Http\TemplateResponse; use OCP\Defaults; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Folder; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; use OCP\IConfig; use OCP\IL10N; use OCP\ILogger; 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; use OCP\Share\IManager as ShareManager; use OCP\Share\IShare; use OCP\Template; /** * Class ShareController * * @package OCA\Files_Sharing\Controllers */ class ShareController extends AuthPublicShareController { /** @var IConfig */ protected $config; /** @var IUserManager */ protected $userManager; /** @var ILogger */ protected $logger; /** @var \OCP\Activity\IManager */ protected $activityManager; /** @var IPreview */ protected $previewManager; /** @var IRootFolder */ protected $rootFolder; /** @var FederatedShareProvider */ protected $federatedShareProvider; /** @var IAccountManager */ protected $accountManager; /** @var IEventDispatcher */ protected $eventDispatcher; /** @var IL10N */ protected $l10n; /** @var Defaults */ protected $defaults; /** @var ShareManager */ protected $shareManager; /** @var Share\IShare */ protected $share; /** * @param string $appName * @param IRequest $request * @param IConfig $config * @param IURLGenerator $urlGenerator * @param IUserManager $userManager * @param ILogger $logger * @param \OCP\Activity\IManager $activityManager * @param \OCP\Share\IManager $shareManager * @param ISession $session * @param IPreview $previewManager * @param IRootFolder $rootFolder * @param FederatedShareProvider $federatedShareProvider * @param IAccountManager $accountManager * @param IEventDispatcher $eventDispatcher * @param IL10N $l10n * @param Defaults $defaults */ public function __construct(string $appName, IRequest $request, IConfig $config, IURLGenerator $urlGenerator, IUserManager $userManager, ILogger $logger, \OCP\Activity\IManager $activityManager, ShareManager $shareManager, ISession $session, IPreview $previewManager, IRootFolder $rootFolder, FederatedShareProvider $federatedShareProvider, IAccountManager $accountManager, IEventDispatcher $eventDispatcher, IL10N $l10n, Defaults $defaults) { parent::__construct($appName, $request, $session, $urlGenerator); $this->config = $config; $this->userManager = $userManager; $this->logger = $logger; $this->activityManager = $activityManager; $this->previewManager = $previewManager; $this->rootFolder = $rootFolder; $this->federatedShareProvider = $federatedShareProvider; $this->accountManager = $accountManager; $this->eventDispatcher = $eventDispatcher; $this->l10n = $l10n; $this->defaults = $defaults; $this->shareManager = $shareManager; } /** * @PublicPage * @NoCSRFRequired * * Show the authentication page * The form has to submit to the authenticate method route */ public function showAuthenticate(): TemplateResponse { $templateParameters = ['share' => $this->share]; $this->eventDispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($this->share, BeforeTemplateRenderedEvent::SCOPE_PUBLIC_SHARE_AUTH)); $response = new TemplateResponse('core', 'publicshareauth', $templateParameters, 'guest'); if ($this->share->getSendPasswordByTalk()) { $csp = new ContentSecurityPolicy(); $csp->addAllowedConnectDomain('*'); $csp->addAllowedMediaDomain('blob:'); $response->setContentSecurityPolicy($csp); } return $response; } /** * The template to show when authentication failed */ protected function showAuthFailed(): TemplateResponse { $templateParameters = ['share' => $this->share, 'wrongpw' => true]; $this->eventDispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($this->share, BeforeTemplateRenderedEvent::SCOPE_PUBLIC_SHARE_AUTH)); $response = new TemplateResponse('core', 'publicshareauth', $templateParameters, 'guest'); if ($this->share->getSendPasswordByTalk()) { $csp = new ContentSecurityPolicy(); $csp->addAllowedConnectDomain('*'); $csp->addAllowedMediaDomain('blob:'); $response->setContentSecurityPolicy($csp); } return $response; } protected function verifyPassword(string $password): bool { return $this->shareManager->checkPassword($this->share, $password); } protected function getPasswordHash(): string { return $this->share->getPassword(); } public function isValidToken(): bool { try { $this->share = $this->shareManager->getShareByToken($this->getToken()); } catch (ShareNotFound $e) { return false; } return true; } protected function isPasswordProtected(): bool { return $this->share->getPassword() !== null; } protected function authSucceeded() { // For share this was always set so it is still used in othe
/*
 * selectable_options.js
 */
(function($) {

module("selectable: options");

test("autoRefresh", function() {
	expect(3);
	el = $("#selectable1");
	var actual, sel = $("*", el), selected = function() { actual += 1 };

	actual = 0;
	el = $("#selectable1").selectable({ autoRefresh: false,	selected: selected });
	sel.hide();
	drag(1000, 1000);
	equals(actual, sel.length);
	el.selectable("destroy");

	actual = 0;
	sel.show();
	el = $("#selectable1").selectable({ autoRefresh: true,	selected: selected });
	sel.hide();
	drag(1000, 1000);
	equals(actual, 0);
	sel.show();
	drag(1000, 1000);
	equals(actual, sel.length);
	el.selectable("destroy");
	sel.show();
});

test("filter", function() {
	expect(2);
	el = $("#selectable1");
	var actual, sel = $("*", el), selected = function() { actual += 1 };

	actual = 0;
	el = $("#selectable1").selectable({ filter: '.special', selected: selected });
	drag(1000, 1000);
	ok(sel.length != 1, "this test assumes more than 1 selectee");
	equals(actual, 1);
	el.selectable("destroy");
});

})(jQuery);
$server_params = [ 'head' => $this->request->getMethod() === 'HEAD' ]; /** * Http range requests support */ if (isset($_SERVER['HTTP_RANGE'])) { $server_params['range'] = $this->request->getHeader('Range'); } // download selected files if (!is_null($files) && $files !== '') { // FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well // after dispatching the request which results in a "Cannot modify header information" notice. OC_Files::get($originalSharePath, $files_list, $server_params); exit(); } else { // FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well // after dispatching the request which results in a "Cannot modify header information" notice. OC_Files::get(dirname($originalSharePath), basename($originalSharePath), $server_params); exit(); } } /** * create activity for every downloaded file * * @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(); $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); $userNodeList = $userFolder->getById($fileId); $userNode = $userNodeList[0]; $ownerFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); $userPath = $userFolder->getRelativePath($userNode->getPath()); $ownerPath = $ownerFolder->getRelativePath($node->getPath()); $parameters = [$userPath]; if ($share->getShareType() === IShare::TYPE_EMAIL) { if ($node instanceof \OCP\Files\File) { $subject = Downloads::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED; } else { $subject = Downloads::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED; } $parameters[] = $share->getSharedWith(); } else { if ($node instanceof \OCP\Files\File) { $subject = Downloads::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED; } else { $subject = Downloads::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED; } } $this->publishActivity($subject, $parameters, $share->getSharedBy(), $fileId, $userPath); if ($share->getShareOwner() !== $share->getSharedBy()) { $parameters[0] = $ownerPath; $this->publishActivity($subject, $parameters, $share->getShareOwner(), $fileId, $ownerPath); } } /** * publish activity * * @param string $subject * @param array $parameters * @param string $affectedUser * @param int $fileId * @param string $filePath */ protected function publishActivity($subject, array $parameters, $affectedUser, $fileId, $filePath) { $event = $this->activityManager->generateEvent(); $event->setApp('files_sharing') ->setType('public_links') ->setSubject($subject, $parameters) ->setAffectedUser($affectedUser) ->setObject('files', $fileId, $filePath); $this->activityManager->publish($event); } }