Skip to content

Commit

Permalink
Following logic
Browse files Browse the repository at this point in the history
Signed-off-by: Hoang Pham <[email protected]>
  • Loading branch information
hweihwang committed Jan 6, 2025
1 parent 4aadede commit 4d9dc6f
Show file tree
Hide file tree
Showing 12 changed files with 1,669 additions and 159 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/vendor/
/node_modules/
/backup/
/recordings/

.php-cs-fixer.cache
.phpunit.result.cache
Expand Down
6 changes: 6 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
use OCP\IL10N;
use OCP\Security\CSP\AddContentSecurityPolicyEvent;
use OCP\Util;
use Psr\Container\ContainerExceptionInterface;
use Throwable;

/**
* @psalm-suppress UndefinedClass
Expand All @@ -46,6 +48,10 @@ public function register(IRegistrationContext $context): void {
$context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
}

/**
* @throws ContainerExceptionInterface
* @throws Throwable
*/
public function boot(IBootContext $context): void {
[$major] = Util::getVersion();
if ($major < 30) {
Expand Down
17 changes: 15 additions & 2 deletions lib/Listener/BeforeTemplateRenderedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/


namespace OCA\Whiteboard\Listener;

use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Services\IInitialState;
use OCP\Constants;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Files\NotFoundException;
use OCP\Share;
use OC_Response;
use OCP\Share\IShare;

/** @template-implements IEventListener<BeforeTemplateRenderedEvent|Event> */
/**
Expand All @@ -24,20 +28,29 @@
class BeforeTemplateRenderedListener implements IEventListener {
public function __construct(
private IInitialState $initialState,
private Share\IManager $shareManager
) {
}

/**
* @throws NotFoundException
* @throws \Exception
*/
public function handle(Event $event): void {
if (!($event instanceof BeforeTemplateRenderedEvent)) {
return;
}

$file = $event->getShare()->getNode();
$share = $this->shareManager->newShare();
$share->setNode($file);
$share->setShareType(ISHARE::TYPE_LINK);
$share->setPermissions(Constants::PERMISSION_READ);
$this->shareManager->createShare($share);
$fileId = $event->getShare()->getNodeId();
$this->initialState->provideInitialState(
'file_id',
$event->getShare()->getNodeId()
$fileId
);
}
}
Loading

0 comments on commit 4d9dc6f

Please sign in to comment.