Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
use OCA\Talk\PublicShareAuth\TemplateLoader as PublicShareAuthTemplateLoader;
use OCA\Talk\Room;
use OCA\Talk\Settings\Personal;
use OCA\Talk\Share\Listener as ShareListener;
use OCA\Talk\Share\RoomShareProvider;
use OCA\Talk\Signaling\Listener as SignalingListener;
use OCP\AppFramework\App;
Expand Down Expand Up @@ -103,6 +104,7 @@ public function register(): void {
CollaboratorsListener::register($dispatcher);
ResourceListener::register($dispatcher);
ChangelogListener::register($dispatcher);
ShareListener::register($dispatcher);
Operation::register($dispatcher);

$dispatcher->addServiceListener(AddContentSecurityPolicyEvent::class, Listener\CSPListener::class);
Expand Down
89 changes: 89 additions & 0 deletions lib/Share/Listener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Joas Schilling <coding@schilljs.com>
*
* @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\Talk\Share;

use OC\Files\Filesystem;
use OCA\Talk\Config;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Share\Events\VerifyMountPointEvent;
use OCP\Share\IShare;
use Symfony\Component\EventDispatcher\GenericEvent;

class Listener {

public static function register(IEventDispatcher $dispatcher): void {
$dispatcher->addListener('OCP\Share::preShare', [self::class, 'listenPreShare'], 1000);
$dispatcher->addListener(VerifyMountPointEvent::class, [self::class, 'listenVerifyMountPointEvent'], 1000);
}

public static function listenPreShare(GenericEvent $event): void {
/** @var self $listener */
$listener = \OC::$server->query(self::class);
$listener->overwriteShareTarget($event);
}

public static function listenVerifyMountPointEvent(VerifyMountPointEvent $event): void {
/** @var self $listener */
$listener = \OC::$server->query(self::class);
$listener->overwriteMountPoint($event);
}

/** @var Config */
protected $config;

public function __construct(Config $config) {
$this->config = $config;
}

public function overwriteShareTarget(GenericEvent $event): void {
/** @var IShare $share */
$share = $event->getSubject();

if ($share->getShareType() !== IShare::TYPE_ROOM
&& $share->getShareType() !== RoomShareProvider::SHARE_TYPE_USERROOM) {
return;
}

$target = RoomShareProvider::TALK_FOLDER_PLACEHOLDER . '/' . $share->getNode()->getName();
$target = Filesystem::normalizePath($target);
$share->setTarget($target);
}

public function overwriteMountPoint(VerifyMountPointEvent $event): void {
$share = $event->getShare();
$view = $event->getView();

if ($share->getShareType() !== IShare::TYPE_ROOM
&& $share->getShareType() !== RoomShareProvider::SHARE_TYPE_USERROOM) {
return;
}

if ($event->getParent() === RoomShareProvider::TALK_FOLDER_PLACEHOLDER) {
$parent = $this->config->getAttachmentFolder($view->getOwner('/'));
$event->setParent($parent);
if (!$event->getView()->is_dir($parent)) {
$event->getView()->mkdir($parent);
}
}
}
}
3 changes: 3 additions & 0 deletions lib/Share/RoomShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class RoomShareProvider implements IShareProvider {
// Special share type for user modified room shares
public const SHARE_TYPE_USERROOM = 11;

public const TALK_FOLDER = '/Talk';
public const TALK_FOLDER_PLACEHOLDER = '/{TALK_PLACEHOLDER}';

/** @var IDBConnection */
private $dbConnection;
/** @var ISecureRandom */
Expand Down
10 changes: 9 additions & 1 deletion tests/integration/features/bootstrap/SharingContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,15 @@ public function shareXIsReturnedWith(int $number, TableNode $body) {

$returnedShare = $this->getXmlResponse()->data[0];
if ($returnedShare->element) {
$returnedShare = $returnedShare->element[$number];
$returnedShare = (array) $returnedShare;
$returnedShare = $returnedShare['element'];
if (is_array($returnedShare)) {
usort($returnedShare, static function($share1, $share2) {
return (int) $share1->id - (int) $share2->id;
});
}

$returnedShare = $returnedShare[$number];
}

$defaultExpectedFields = [
Expand Down
Loading