Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unified search implementation #2200

Merged
merged 13 commits into from
Sep 1, 2020
39 changes: 0 additions & 39 deletions appinfo/app.php

This file was deleted.

9 changes: 9 additions & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,13 @@
<provider min-version="16">OCA\Deck\Provider\DeckProvider</provider>
</fulltextsearch>

<navigations>
<navigation>
<name>Deck</name>
<route>deck.page.index</route>
<icon>deck.svg</icon>
<order>10</order>
</navigation>
</navigations>

</info>
1 change: 1 addition & 0 deletions css/deck.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@include icon-black-white('deck', 'deck', 1);
248 changes: 5 additions & 243 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,249 +23,11 @@

namespace OCA\Deck\AppInfo;

use Exception;
use OC_Util;
use OCA\Deck\Activity\CommentEventHandler;
use OCA\Deck\Capabilities;
use OCA\Deck\Collaboration\Resources\ResourceProvider;
use OCA\Deck\Collaboration\Resources\ResourceProviderCard;
use OCA\Deck\Dashboard\DeckWidget;
use OCA\Deck\Db\Acl;
use OCA\Deck\Db\AclMapper;
use OCA\Deck\Db\AssignedUsersMapper;
use OCA\Deck\Db\BoardMapper;
use OCA\Deck\Db\CardMapper;
use OCA\Deck\Middleware\DefaultBoardMiddleware;
use OCA\Deck\Middleware\ExceptionMiddleware;
use OCA\Deck\Notification\Notifier;
use OCA\Deck\Service\FullTextSearchService;
use OCA\Deck\Service\PermissionService;
use OCP\AppFramework\App;
use OCP\Collaboration\Resources\IManager;
use OCP\Collaboration\Resources\IProviderManager;
use OCP\Comments\CommentsEntityEvent;
use OCP\Dashboard\RegisterWidgetEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\FullTextSearch\IFullTextSearchManager;
use OCP\IGroup;
use OCP\IServerContainer;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IURLGenerator;
use OCP\Util;

class Application extends App {
public const APP_ID = 'deck';

public const COMMENT_ENTITY_TYPE = 'deckCard';

/** @var IServerContainer */
private $server;

/** @var FullTextSearchService */
private $fullTextSearchService;

/** @var IFullTextSearchManager */
private $fullTextSearchManager;

public function __construct(array $urlParams = []) {
parent::__construct('deck', $urlParams);

$container = $this->getContainer();
$server = $this->getContainer()->getServer();

$this->server = $server;

$container->registerCapability(Capabilities::class);
$container->registerMiddleWare(ExceptionMiddleware::class);
$container->registerMiddleWare(DefaultBoardMiddleware::class);

$container->registerService('databaseType', static function () use ($server) {
return $server->getConfig()->getSystemValue('dbtype', 'sqlite');
});
$container->registerService('database4ByteSupport', static function () use ($server) {
return $server->getDatabaseConnection()->supports4ByteText();
});

$version = OC_Util::getVersion()[0];
if ($version >= 20) {
/** @var IEventDispatcher $dispatcher */
$dispatcher = $container->getServer()->query(IEventDispatcher::class);
$dispatcher->addListener(RegisterWidgetEvent::class, function (RegisterWidgetEvent $event) use ($container) {
$event->registerWidget(DeckWidget::class);
});
}
}

public function register(): void {
$this->registerNavigationEntry();
$this->registerUserGroupHooks();
$this->registerNotifications();
$this->registerCommentsEntity();
$this->registerFullTextSearch();
$this->registerCollaborationResources();
}

public function registerNavigationEntry(): void {
$container = $this->getContainer();
$this->server->getNavigationManager()->add(static function () use ($container) {
$urlGenerator = $container->query(IURLGenerator::class);
return [
'id' => 'deck',
'order' => 10,
'href' => $urlGenerator->linkToRoute('deck.page.index'),
'icon' => $urlGenerator->imagePath('deck', 'deck.svg'),
'name' => 'Deck',
];
});
}

private function registerUserGroupHooks(): void {
$container = $this->getContainer();
// Delete user/group acl entries when they get deleted
/** @var IUserManager $userManager */
$userManager = $this->server->getUserManager();
$userManager->listen('\OC\User', 'postDelete', static function (IUser $user) use ($container) {
// delete existing acl entries for deleted user
/** @var AclMapper $aclMapper */
$aclMapper = $container->query(AclMapper::class);
$acls = $aclMapper->findByParticipant(Acl::PERMISSION_TYPE_USER, $user->getUID());
foreach ($acls as $acl) {
$aclMapper->delete($acl);
}
// delete existing user assignments
$assignmentMapper = $container->query(AssignedUsersMapper::class);
$assignments = $assignmentMapper->findByUserId($user->getUID());
foreach ($assignments as $assignment) {
$assignmentMapper->delete($assignment);
}

/** @var BoardMapper $boardMapper */
$boardMapper = $container->query(BoardMapper::class);
$boards = $boardMapper->findAllByOwner($user->getUID());
foreach ($boards as $board) {
$boardMapper->delete($board);
}
});

/** @var IUserManager $userManager */
$groupManager = $this->server->getGroupManager();
$groupManager->listen('\OC\Group', 'postDelete', static function (IGroup $group) use ($container) {
/** @var AclMapper $aclMapper */
$aclMapper = $container->query(AclMapper::class);
$aclMapper->findByParticipant(Acl::PERMISSION_TYPE_GROUP, $group->getGID());
$acls = $aclMapper->findByParticipant(Acl::PERMISSION_TYPE_GROUP, $group->getGID());
foreach ($acls as $acl) {
$aclMapper->delete($acl);
}
});
}

public function registerNotifications(): void {
$notificationManager = $this->server->getNotificationManager();
$notificationManager->registerNotifierService(Notifier::class);
}

public function registerCommentsEntity(): void {
$this->server->getEventDispatcher()->addListener(CommentsEntityEvent::EVENT_ENTITY, function (CommentsEntityEvent $event) {
$event->addEntityCollection(self::COMMENT_ENTITY_TYPE, function ($name) {
/** @var CardMapper */
$cardMapper = $this->getContainer()->query(CardMapper::class);
$permissionService = $this->getContainer()->query(PermissionService::class);

try {
return $permissionService->checkPermission($cardMapper, (int) $name, Acl::PERMISSION_READ);
} catch (\Exception $e) {
return false;
}
});
});
$this->registerCommentsEventHandler();
}

/**
*/
protected function registerCommentsEventHandler(): void {
$this->server->getCommentsManager()->registerEventHandler(function () {
return $this->getContainer()->query(CommentEventHandler::class);
});
$version = \OC_Util::getVersion()[0];
if ($version >= 20) {
class Application extends Application20 {
}

protected function registerCollaborationResources(): void {
$version = OC_Util::getVersion()[0];
if ($version < 16) {
return;
}

/**
* Register Collaboration ResourceProvider
*
* @Todo: Remove if min-version is 18
*/
if ($version < 18) {
/** @var IManager $resourceManager */
$resourceManager = $this->getContainer()->query(IManager::class);
} else {
/** @var IProviderManager $resourceManager */
$resourceManager = $this->getContainer()->query(IProviderManager::class);
}
$resourceManager->registerResourceProvider(ResourceProvider::class);
$resourceManager->registerResourceProvider(ResourceProviderCard::class);

$this->server->getEventDispatcher()->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', static function () {
Util::addScript('deck', 'collections');
});
}

public function registerFullTextSearch(): void {
if (Util::getVersion()[0] < 16) {
return;
}

$c = $this->getContainer();
try {
$this->fullTextSearchService = $c->query(FullTextSearchService::class);
$this->fullTextSearchManager = $c->query(IFullTextSearchManager::class);
} catch (Exception $e) {
return;
}

if (!$this->fullTextSearchManager->isAvailable()) {
return;
}

/** @var IEventDispatcher $eventDispatcher */
$eventDispatcher = $this->server->query(IEventDispatcher::class);
$eventDispatcher->addListener(
'\OCA\Deck\Card::onCreate', function (Event $e) {
$this->fullTextSearchService->onCardCreated($e);
}
);
$eventDispatcher->addListener(
'\OCA\Deck\Card::onUpdate', function (Event $e) {
$this->fullTextSearchService->onCardUpdated($e);
}
);
$eventDispatcher->addListener(
'\OCA\Deck\Card::onDelete', function (Event $e) {
$this->fullTextSearchService->onCardDeleted($e);
}
);
$eventDispatcher->addListener(
'\OCA\Deck\Board::onShareNew', function (Event $e) {
$this->fullTextSearchService->onBoardShares($e);
}
);
$eventDispatcher->addListener(
'\OCA\Deck\Board::onShareEdit', function (Event $e) {
$this->fullTextSearchService->onBoardShares($e);
}
);
$eventDispatcher->addListener(
'\OCA\Deck\Board::onShareDelete', function (Event $e) {
$this->fullTextSearchService->onBoardShares($e);
}
);
} else {
class Application extends ApplicationLegacy {
}
}
Loading