-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Hoang Pham <[email protected]>
- Loading branch information
Showing
12 changed files
with
1,718 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
/vendor/ | ||
/node_modules/ | ||
/backup/ | ||
/recordings/ | ||
|
||
.php-cs-fixer.cache | ||
.phpunit.result.cache | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Whiteboard\Listener; | ||
|
||
use OC\Share\Constants as ShareConstants; | ||
use OCP\AppFramework\Http\Response; | ||
use OCP\Constants; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IEventListener; | ||
use OCP\Files\NotFoundException; | ||
use OCP\Share; | ||
use Psr\Log\LoggerInterface; | ||
use OCP\Files\Events\Node\NodeCreatedEvent; | ||
|
||
|
||
/** @template-implements IEventListener<NodeCreatedEvent|Event> */ | ||
/** | ||
* @psalm-suppress UndefinedClass | ||
* @psalm-suppress MissingTemplateParam | ||
*/ | ||
class NodeCreatedListener implements IEventListener { | ||
public function __construct( | ||
private Share\IManager $shareManager, | ||
private Response $response, | ||
private LoggerInterface $logger | ||
) { | ||
|
||
} | ||
|
||
/** | ||
* @throws NotFoundException | ||
* @throws \Exception | ||
*/ | ||
public function handle(Event $event): void { | ||
if (!($event instanceof NodeCreatedEvent)) { | ||
return; | ||
} | ||
|
||
$node = $event->getNode(); | ||
$existingShares = $this->shareManager->getSharedWith(null, ShareConstants::SHARE_TYPE_LINK, $node->getId()); | ||
Check failure on line 47 in lib/Listener/NodeCreatedListener.php
|
||
if(!empty($existingShares)) { | ||
$this->logger->critical('Whiteboard share already exists for node ' . $node->getId()); | ||
return; | ||
} | ||
|
||
$this->logger->critical('Creating whiteboard share for node ' . $node->getId()); | ||
|
||
$share = $this->shareManager->newShare(); | ||
$share->setNode($node); | ||
$share->setShareType(ShareConstants::SHARE_TYPE_LINK); | ||
$share->setPermissions(Constants::PERMISSION_READ); | ||
$this->shareManager->createShare($share); | ||
} | ||
} |
Oops, something went wrong.