Merge branch 'master' into enh/cloneStack
This commit is contained in:
@@ -130,8 +130,8 @@ class DeckProvider implements IProvider {
|
||||
];
|
||||
|
||||
if (array_key_exists('board', $subjectParams)) {
|
||||
$archivedParam = $subjectParams['card']['archived'] ? 'archived' : '';
|
||||
$card['link'] = $this->deckUrl('/board/' . $subjectParams['board']['id'] . '/' . $archivedParam . '/card/' . $event->getObjectId());
|
||||
$archivedParam = $subjectParams['card']['archived'] ? 'archived/' : '';
|
||||
$card['link'] = $this->deckUrl('/board/' . $subjectParams['board']['id'] . '/' . $archivedParam . 'card/' . $event->getObjectId());
|
||||
}
|
||||
$params['card'] = $card;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
$version = \OC_Util::getVersion()[0];
|
||||
if ($version >= 20) {
|
||||
class Application extends Application20 {
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
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 {
|
||||
}
|
||||
}
|
||||
|
||||
233
lib/AppInfo/Application20.php
Normal file
233
lib/AppInfo/Application20.php
Normal file
@@ -0,0 +1,233 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @author Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @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\Deck\AppInfo;
|
||||
|
||||
use Closure;
|
||||
use Exception;
|
||||
use OC\EventDispatcher\SymfonyAdapter;
|
||||
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\Search\DeckProvider;
|
||||
use OCA\Deck\Service\FullTextSearchService;
|
||||
use OCA\Deck\Service\PermissionService;
|
||||
use OCP\AppFramework\App;
|
||||
use OCP\AppFramework\Bootstrap\IBootContext;
|
||||
use OCP\AppFramework\Bootstrap\IBootstrap;
|
||||
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
||||
use OCP\Collaboration\Resources\IProviderManager;
|
||||
use OCP\Comments\CommentsEntityEvent;
|
||||
use OCP\Comments\ICommentsManager;
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\FullTextSearch\IFullTextSearchManager;
|
||||
use OCP\IConfig;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IGroup;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IServerContainer;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Notification\IManager as NotificationManager;
|
||||
use OCP\Util;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
class Application20 extends App implements IBootstrap {
|
||||
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(self::APP_ID, $urlParams);
|
||||
|
||||
$this->server = \OC::$server;
|
||||
}
|
||||
|
||||
public function boot(IBootContext $context): void {
|
||||
Util::addStyle('deck', 'deck');
|
||||
|
||||
$context->injectFn(Closure::fromCallable([$this, 'registerUserGroupHooks']));
|
||||
$context->injectFn(Closure::fromCallable([$this, 'registerCommentsEntity']));
|
||||
$context->injectFn(Closure::fromCallable([$this, 'registerCommentsEventHandler']));
|
||||
$context->injectFn(Closure::fromCallable([$this, 'registerNotifications']));
|
||||
$context->injectFn(Closure::fromCallable([$this, 'registerFullTextSearch']));
|
||||
$context->injectFn(Closure::fromCallable([$this, 'registerCollaborationResources']));
|
||||
}
|
||||
|
||||
public function register(IRegistrationContext $context): void {
|
||||
if ((@include_once __DIR__ . '/../../vendor/autoload.php') === false) {
|
||||
throw new Exception('Cannot include autoload. Did you run install dependencies using composer?');
|
||||
}
|
||||
|
||||
$context->registerCapability(Capabilities::class);
|
||||
$context->registerMiddleWare(ExceptionMiddleware::class);
|
||||
$context->registerMiddleWare(DefaultBoardMiddleware::class);
|
||||
|
||||
$context->registerService('databaseType', static function (ContainerInterface $c) {
|
||||
return $c->get(IConfig::class)->getSystemValue('dbtype', 'sqlite');
|
||||
});
|
||||
$context->registerService('database4ByteSupport', static function (ContainerInterface $c) {
|
||||
return $c->get(IDBConnection::class)->supports4ByteText();
|
||||
});
|
||||
|
||||
$context->registerSearchProvider(DeckProvider::class);
|
||||
$context->registerDashboardWidget(DeckWidget::class);
|
||||
}
|
||||
|
||||
public function registerNotifications(NotificationManager $notificationManager): void {
|
||||
$notificationManager->registerNotifierService(Notifier::class);
|
||||
}
|
||||
|
||||
private function registerUserGroupHooks(IUserManager $userManager, IGroupManager $groupManager): void {
|
||||
$container = $this->getContainer();
|
||||
// Delete user/group acl entries when they get deleted
|
||||
$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);
|
||||
}
|
||||
});
|
||||
|
||||
$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 registerCommentsEntity(IEventDispatcher $eventDispatcher): void {
|
||||
$eventDispatcher->addListener(CommentsEntityEvent::EVENT_ENTITY, function (CommentsEntityEvent $event) {
|
||||
$event->addEntityCollection(self::COMMENT_ENTITY_TYPE, function ($name) {
|
||||
/** @var CardMapper */
|
||||
$cardMapper = $this->getContainer()->get(CardMapper::class);
|
||||
$permissionService = $this->getContainer()->get(PermissionService::class);
|
||||
|
||||
try {
|
||||
return $permissionService->checkPermission($cardMapper, (int) $name, Acl::PERMISSION_READ);
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
protected function registerCommentsEventHandler(ICommentsManager $commentsManager): void {
|
||||
$commentsManager->registerEventHandler(function () {
|
||||
return $this->getContainer()->query(CommentEventHandler::class);
|
||||
});
|
||||
}
|
||||
|
||||
protected function registerCollaborationResources(IProviderManager $resourceManager, SymfonyAdapter $symfonyAdapter): void {
|
||||
$resourceManager->registerResourceProvider(ResourceProvider::class);
|
||||
$resourceManager->registerResourceProvider(ResourceProviderCard::class);
|
||||
|
||||
$symfonyAdapter->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', static function () {
|
||||
Util::addScript('deck', 'collections');
|
||||
});
|
||||
}
|
||||
|
||||
public function registerFullTextSearch(IFullTextSearchManager $fullTextSearchManager, IEventDispatcher $eventDispatcher): void {
|
||||
if (!$fullTextSearchManager->isAvailable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME move to addServiceListener
|
||||
$server = $this->server;
|
||||
$eventDispatcher->addListener(
|
||||
'\OCA\Deck\Card::onCreate', function (Event $e) use ($server) {
|
||||
$fullTextSearchService = $server->get(FullTextSearchService::class);
|
||||
$fullTextSearchService->onCardCreated($e);
|
||||
}
|
||||
);
|
||||
$eventDispatcher->addListener(
|
||||
'\OCA\Deck\Card::onUpdate', function (Event $e) use ($server) {
|
||||
$fullTextSearchService = $server->get(FullTextSearchService::class);
|
||||
$fullTextSearchService->onCardUpdated($e);
|
||||
}
|
||||
);
|
||||
$eventDispatcher->addListener(
|
||||
'\OCA\Deck\Card::onDelete', function (Event $e) use ($server) {
|
||||
$fullTextSearchService = $server->get(FullTextSearchService::class);
|
||||
$fullTextSearchService->onCardDeleted($e);
|
||||
}
|
||||
);
|
||||
$eventDispatcher->addListener(
|
||||
'\OCA\Deck\Board::onShareNew', function (Event $e) {
|
||||
$fullTextSearchService = $server->get(FullTextSearchService::class);
|
||||
$fullTextSearchService->onBoardShares($e);
|
||||
}
|
||||
);
|
||||
$eventDispatcher->addListener(
|
||||
'\OCA\Deck\Board::onShareEdit', function (Event $e) use ($server) {
|
||||
$fullTextSearchService = $server->get(FullTextSearchService::class);
|
||||
$fullTextSearchService->onBoardShares($e);
|
||||
}
|
||||
);
|
||||
$eventDispatcher->addListener(
|
||||
'\OCA\Deck\Board::onShareDelete', function (Event $e) use ($server) {
|
||||
$fullTextSearchService = $server->get(FullTextSearchService::class);
|
||||
$fullTextSearchService->onBoardShares($e);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
250
lib/AppInfo/ApplicationLegacy.php
Normal file
250
lib/AppInfo/ApplicationLegacy.php
Normal file
@@ -0,0 +1,250 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @author Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @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\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\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\EventDispatcher\Event;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\FullTextSearch\IFullTextSearchManager;
|
||||
use OCP\IGroup;
|
||||
use OCP\IServerContainer;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Util;
|
||||
|
||||
if ((@include_once __DIR__ . '/../../vendor/autoload.php') === false) {
|
||||
throw new Exception('Cannot include autoload. Did you run install dependencies using composer?');
|
||||
}
|
||||
|
||||
class ApplicationLegacy 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();
|
||||
});
|
||||
|
||||
$this->register();
|
||||
}
|
||||
|
||||
public function register(): void {
|
||||
$this->registerUserGroupHooks();
|
||||
$this->registerNotifications();
|
||||
$this->registerCommentsEntity();
|
||||
$this->registerFullTextSearch();
|
||||
$this->registerCollaborationResources();
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -23,90 +23,42 @@
|
||||
|
||||
namespace OCA\Deck\Controller;
|
||||
|
||||
use OCA\Deck\Service\ConfigService;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\AppFramework\Http\NotFoundResponse;
|
||||
use OCP\IConfig;
|
||||
use OCP\IGroup;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\AppFramework\OCSController;
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\Controller;
|
||||
|
||||
class ConfigController extends Controller {
|
||||
private $config;
|
||||
private $userId;
|
||||
private $groupManager;
|
||||
class ConfigController extends OCSController {
|
||||
private $configService;
|
||||
|
||||
public function __construct(
|
||||
$AppName,
|
||||
IRequest $request,
|
||||
IConfig $config,
|
||||
IGroupManager $groupManager,
|
||||
$userId
|
||||
ConfigService $configService
|
||||
) {
|
||||
parent::__construct($AppName, $request);
|
||||
|
||||
$this->userId = $userId;
|
||||
$this->groupManager = $groupManager;
|
||||
$this->config = $config;
|
||||
$this->configService = $configService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function get() {
|
||||
$data = [
|
||||
'groupLimit' => $this->getGroupLimit(),
|
||||
];
|
||||
return new DataResponse($data);
|
||||
public function get(): DataResponse {
|
||||
return new DataResponse($this->configService->getAll());
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function setValue($key, $value) {
|
||||
switch ($key) {
|
||||
case 'groupLimit':
|
||||
$result = $this->setGroupLimit($value);
|
||||
break;
|
||||
}
|
||||
public function setValue(string $key, $value) {
|
||||
$result = $this->configService->set($key, $value);
|
||||
if ($result === null) {
|
||||
return new NotFoundResponse();
|
||||
}
|
||||
return new DataResponse($result);
|
||||
}
|
||||
|
||||
private function setGroupLimit($value) {
|
||||
$groups = [];
|
||||
foreach ($value as $group) {
|
||||
$groups[] = $group['id'];
|
||||
}
|
||||
$data = implode(',', $groups);
|
||||
$this->config->setAppValue($this->appName, 'groupLimit', $data);
|
||||
return $groups;
|
||||
}
|
||||
|
||||
private function getGroupLimitList() {
|
||||
$value = $this->config->getAppValue($this->appName, 'groupLimit', '');
|
||||
$groups = explode(',', $value);
|
||||
if ($value === '') {
|
||||
return [];
|
||||
}
|
||||
return $groups;
|
||||
}
|
||||
|
||||
private function getGroupLimit() {
|
||||
$groups = $this->getGroupLimitList();
|
||||
$groups = array_map(function ($groupId) {
|
||||
/** @var IGroup $groups */
|
||||
$group = $this->groupManager->get($groupId);
|
||||
if ($group === null) {
|
||||
return null;
|
||||
}
|
||||
return [
|
||||
'id' => $group->getGID(),
|
||||
'displayname' => $group->getDisplayName(),
|
||||
];
|
||||
}, $groups);
|
||||
return array_filter($groups);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,34 +24,33 @@
|
||||
namespace OCA\Deck\Controller;
|
||||
|
||||
use OCA\Deck\AppInfo\Application;
|
||||
use OCA\Deck\Service\ConfigService;
|
||||
use OCA\Deck\Service\PermissionService;
|
||||
use OCP\AppFramework\Http\ContentSecurityPolicy;
|
||||
use OCP\IInitialStateService;
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\IL10N;
|
||||
|
||||
class PageController extends Controller {
|
||||
private $permissionService;
|
||||
private $userId;
|
||||
private $l10n;
|
||||
private $initialState;
|
||||
private $configService;
|
||||
|
||||
public function __construct(
|
||||
$AppName,
|
||||
IRequest $request,
|
||||
PermissionService $permissionService,
|
||||
IInitialStateService $initialStateService,
|
||||
IL10N $l10n,
|
||||
$userId
|
||||
ConfigService $configService
|
||||
) {
|
||||
parent::__construct($AppName, $request);
|
||||
|
||||
$this->userId = $userId;
|
||||
$this->permissionService = $permissionService;
|
||||
$this->initialState = $initialStateService;
|
||||
$this->l10n = $l10n;
|
||||
$this->configService = $configService;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,6 +63,7 @@ class PageController extends Controller {
|
||||
public function index() {
|
||||
$this->initialState->provideInitialState(Application::APP_ID, 'maxUploadSize', (int)\OCP\Util::uploadLimit());
|
||||
$this->initialState->provideInitialState(Application::APP_ID, 'canCreate', $this->permissionService->canCreate());
|
||||
$this->initialState->provideInitialState(Application::APP_ID, 'config', $this->configService->getAll());
|
||||
|
||||
$response = new TemplateResponse('deck', 'main');
|
||||
|
||||
|
||||
211
lib/DAV/Calendar.php
Normal file
211
lib/DAV/Calendar.php
Normal file
@@ -0,0 +1,211 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright 2020, Georg Ehrke <oc.list@georgehrke.com>
|
||||
*
|
||||
* @author Georg Ehrke <oc.list@georgehrke.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\Deck\DAV;
|
||||
|
||||
use OCA\DAV\CalDAV\Integration\ExternalCalendar;
|
||||
use OCA\DAV\CalDAV\Plugin;
|
||||
use OCA\Deck\Db\Acl;
|
||||
use OCA\Deck\Db\Board;
|
||||
use Sabre\CalDAV\CalendarQueryValidator;
|
||||
use Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet;
|
||||
use Sabre\DAV\Exception\Forbidden;
|
||||
use Sabre\DAV\Exception\NotFound;
|
||||
use Sabre\DAV\PropPatch;
|
||||
use Sabre\VObject\InvalidDataException;
|
||||
use Sabre\VObject\Reader;
|
||||
|
||||
class Calendar extends ExternalCalendar {
|
||||
|
||||
/** @var string */
|
||||
private $principalUri;
|
||||
/** @var string[] */
|
||||
private $children;
|
||||
/** @var DeckCalendarBackend */
|
||||
private $backend;
|
||||
/** @var Board */
|
||||
private $board;
|
||||
|
||||
public function __construct(string $principalUri, string $calendarUri, Board $board, DeckCalendarBackend $backend) {
|
||||
parent::__construct('deck', $calendarUri);
|
||||
|
||||
$this->backend = $backend;
|
||||
$this->board = $board;
|
||||
|
||||
$this->principalUri = $principalUri;
|
||||
|
||||
if ($board) {
|
||||
$this->children = $this->backend->getChildren($board->getId());
|
||||
} else {
|
||||
$this->children = [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getOwner() {
|
||||
return $this->principalUri;
|
||||
}
|
||||
|
||||
public function getACL() {
|
||||
$acl = [
|
||||
[
|
||||
'privilege' => '{DAV:}read',
|
||||
'principal' => $this->getOwner(),
|
||||
'protected' => true,
|
||||
]
|
||||
];
|
||||
if ($this->backend->checkBoardPermission($this->board->getId(), Acl::PERMISSION_MANAGE)) {
|
||||
$acl[] = [
|
||||
'privilege' => '{DAV:}write-properties',
|
||||
'principal' => $this->getOwner(),
|
||||
'protected' => true,
|
||||
];
|
||||
}
|
||||
return $acl;
|
||||
}
|
||||
|
||||
public function setACL(array $acl) {
|
||||
throw new Forbidden('Setting ACL is not supported on this node');
|
||||
}
|
||||
|
||||
public function getSupportedPrivilegeSet() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function calendarQuery(array $filters) {
|
||||
$result = [];
|
||||
$objects = $this->getChildren();
|
||||
|
||||
foreach ($objects as $object) {
|
||||
if ($this->validateFilterForObject($object, $filters)) {
|
||||
$result[] = $object->getName();
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function validateFilterForObject($object, array $filters) {
|
||||
$vObject = Reader::read($object->get());
|
||||
|
||||
$validator = new CalendarQueryValidator();
|
||||
$result = $validator->validate($vObject, $filters);
|
||||
|
||||
// Destroy circular references so PHP will GC the object.
|
||||
$vObject->destroy();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function createFile($name, $data = null) {
|
||||
throw new Forbidden('Creating a new entry is not implemented');
|
||||
}
|
||||
|
||||
public function getChild($name) {
|
||||
if ($this->childExists($name)) {
|
||||
$card = array_values(array_filter(
|
||||
$this->children,
|
||||
function ($card) use (&$name) {
|
||||
return $card->getCalendarPrefix() . '-' . $card->getId() . '.ics' === $name;
|
||||
}
|
||||
));
|
||||
if (count($card) > 0) {
|
||||
return new CalendarObject($this, $name, $this->backend, $card[0]);
|
||||
}
|
||||
}
|
||||
throw new NotFound('Node not found');
|
||||
}
|
||||
|
||||
public function getChildren() {
|
||||
$childNames = array_map(function ($card) {
|
||||
return $card->getCalendarPrefix() . '-' . $card->getId() . '.ics';
|
||||
}, $this->children);
|
||||
|
||||
$children = [];
|
||||
|
||||
foreach ($childNames as $name) {
|
||||
$children[] = $this->getChild($name);
|
||||
}
|
||||
|
||||
return $children;
|
||||
}
|
||||
|
||||
public function childExists($name) {
|
||||
return count(array_filter(
|
||||
$this->children,
|
||||
function ($card) use (&$name) {
|
||||
return $card->getCalendarPrefix() . '-' . $card->getId() . '.ics' === $name;
|
||||
}
|
||||
)) > 0;
|
||||
}
|
||||
|
||||
|
||||
public function delete() {
|
||||
throw new Forbidden('Deleting an entry is not implemented');
|
||||
}
|
||||
|
||||
public function getLastModified() {
|
||||
return $this->board->getLastModified();
|
||||
}
|
||||
|
||||
public function getGroup() {
|
||||
return [];
|
||||
}
|
||||
|
||||
public function propPatch(PropPatch $propPatch) {
|
||||
$properties = [
|
||||
'{DAV:}displayname',
|
||||
'{http://apple.com/ns/ical/}calendar-color'
|
||||
];
|
||||
$propPatch->handle($properties, function ($properties) {
|
||||
foreach ($properties as $key => $value) {
|
||||
switch ($key) {
|
||||
case '{DAV:}displayname':
|
||||
if (mb_strpos($value, 'Deck: ') === 0) {
|
||||
$value = mb_substr($value, strlen('Deck: '));
|
||||
}
|
||||
$this->board->setTitle($value);
|
||||
break;
|
||||
case '{http://apple.com/ns/ical/}calendar-color':
|
||||
$color = substr($value, 1, 6);
|
||||
if (!preg_match('/[a-f0-9]{6}/i', $color)) {
|
||||
throw new InvalidDataException('No valid color provided');
|
||||
}
|
||||
$this->board->setColor($color);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $this->backend->updateBoard($this->board);
|
||||
});
|
||||
// We can just return here and let oc_properties handle everything
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getProperties($properties) {
|
||||
return [
|
||||
'{DAV:}displayname' => 'Deck: ' . ($this->board ? $this->board->getTitle() : 'no board object provided'),
|
||||
'{http://apple.com/ns/ical/}calendar-color' => '#' . $this->board->getColor(),
|
||||
'{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VTODO']),
|
||||
];
|
||||
}
|
||||
}
|
||||
110
lib/DAV/CalendarObject.php
Normal file
110
lib/DAV/CalendarObject.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright 2020, Georg Ehrke <oc.list@georgehrke.com>
|
||||
*
|
||||
* @author Georg Ehrke <oc.list@georgehrke.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\Deck\DAV;
|
||||
|
||||
use OCA\Deck\Db\Card;
|
||||
use OCA\Deck\Db\Stack;
|
||||
use Sabre\CalDAV\ICalendarObject;
|
||||
use Sabre\DAV\Exception\Forbidden;
|
||||
use Sabre\DAVACL\IACL;
|
||||
use Sabre\VObject\Component\VCalendar;
|
||||
|
||||
class CalendarObject implements ICalendarObject, IACL {
|
||||
|
||||
/** @var Calendar */
|
||||
private $calendar;
|
||||
/** @var string */
|
||||
private $name;
|
||||
/** @var Card|Stack */
|
||||
private $sourceItem;
|
||||
/** @var DeckCalendarBackend */
|
||||
private $backend;
|
||||
/** @var VCalendar */
|
||||
private $calendarObject;
|
||||
|
||||
public function __construct(Calendar $calendar, string $name, DeckCalendarBackend $backend, $sourceItem) {
|
||||
$this->calendar = $calendar;
|
||||
$this->name = $name;
|
||||
$this->sourceItem = $sourceItem;
|
||||
$this->backend = $backend;
|
||||
$this->calendarObject = $this->sourceItem->getCalendarObject();
|
||||
}
|
||||
|
||||
public function getOwner() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getGroup() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getACL() {
|
||||
return $this->calendar->getACL();
|
||||
}
|
||||
|
||||
public function setACL(array $acl) {
|
||||
throw new Forbidden('Setting ACL is not supported on this node');
|
||||
}
|
||||
|
||||
public function getSupportedPrivilegeSet() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function put($data) {
|
||||
throw new Forbidden('This calendar-object is read-only');
|
||||
}
|
||||
|
||||
public function get() {
|
||||
if ($this->sourceItem) {
|
||||
return $this->calendarObject->serialize();
|
||||
}
|
||||
}
|
||||
|
||||
public function getContentType() {
|
||||
return 'text/calendar; charset=utf-8';
|
||||
}
|
||||
|
||||
public function getETag() {
|
||||
return '"' . md5($this->sourceItem->getLastModified()) . '"';
|
||||
}
|
||||
|
||||
public function getSize() {
|
||||
return mb_strlen($this->calendarObject->serialize());
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
throw new Forbidden('This calendar-object is read-only');
|
||||
}
|
||||
|
||||
public function getName() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName($name) {
|
||||
throw new Forbidden('This calendar-object is read-only');
|
||||
}
|
||||
|
||||
public function getLastModified() {
|
||||
return $this->sourceItem->getLastModified();
|
||||
}
|
||||
}
|
||||
84
lib/DAV/CalendarPlugin.php
Normal file
84
lib/DAV/CalendarPlugin.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright 2020, Georg Ehrke <oc.list@georgehrke.com>
|
||||
*
|
||||
* @author Georg Ehrke <oc.list@georgehrke.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\Deck\DAV;
|
||||
|
||||
use OCA\DAV\CalDAV\Integration\ExternalCalendar;
|
||||
use OCA\DAV\CalDAV\Integration\ICalendarProvider;
|
||||
use OCA\Deck\Db\Board;
|
||||
use OCA\Deck\Service\ConfigService;
|
||||
use Sabre\DAV\Exception\NotFound;
|
||||
|
||||
class CalendarPlugin implements ICalendarProvider {
|
||||
|
||||
/** @var DeckCalendarBackend */
|
||||
private $backend;
|
||||
/** @var bool */
|
||||
private $calendarIntegrationEnabled;
|
||||
|
||||
public function __construct(DeckCalendarBackend $backend, ConfigService $configService) {
|
||||
$this->backend = $backend;
|
||||
$this->calendarIntegrationEnabled = $configService->get('calendar');
|
||||
}
|
||||
|
||||
public function getAppId(): string {
|
||||
return 'deck';
|
||||
}
|
||||
|
||||
public function fetchAllForCalendarHome(string $principalUri): array {
|
||||
if (!$this->calendarIntegrationEnabled) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return array_map(function (Board $board) use ($principalUri) {
|
||||
return new Calendar($principalUri, 'board-' . $board->getId(), $board, $this->backend);
|
||||
}, $this->backend->getBoards());
|
||||
}
|
||||
|
||||
public function hasCalendarInCalendarHome(string $principalUri, string $calendarUri): bool {
|
||||
if (!$this->calendarIntegrationEnabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$boards = array_map(static function (Board $board) {
|
||||
return 'board-' . $board->getId();
|
||||
}, $this->backend->getBoards());
|
||||
return in_array($calendarUri, $boards, true);
|
||||
}
|
||||
|
||||
public function getCalendarInCalendarHome(string $principalUri, string $calendarUri): ?ExternalCalendar {
|
||||
if (!$this->calendarIntegrationEnabled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($this->hasCalendarInCalendarHome($principalUri, $calendarUri)) {
|
||||
try {
|
||||
$board = $this->backend->getBoard((int)str_replace('board-', '', $calendarUri));
|
||||
return new Calendar($principalUri, $calendarUri, $board, $this->backend);
|
||||
} catch (NotFound $e) {
|
||||
// We can just return null if we have no matching board
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
89
lib/DAV/DeckCalendarBackend.php
Normal file
89
lib/DAV/DeckCalendarBackend.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @author Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace OCA\Deck\DAV;
|
||||
|
||||
use OCA\Deck\Db\Board;
|
||||
use OCA\Deck\Db\BoardMapper;
|
||||
use OCA\Deck\Service\BoardService;
|
||||
use OCA\Deck\Service\CardService;
|
||||
use OCA\Deck\Service\PermissionService;
|
||||
use OCA\Deck\Service\StackService;
|
||||
use Sabre\DAV\Exception\NotFound;
|
||||
|
||||
class DeckCalendarBackend {
|
||||
|
||||
/** @var BoardService */
|
||||
private $boardService;
|
||||
/** @var StackService */
|
||||
private $stackService;
|
||||
/** @var CardService */
|
||||
private $cardService;
|
||||
/** @var PermissionService */
|
||||
private $permissionService;
|
||||
/** @var BoardMapper */
|
||||
private $boardMapper;
|
||||
|
||||
public function __construct(
|
||||
BoardService $boardService, StackService $stackService, CardService $cardService, PermissionService $permissionService,
|
||||
BoardMapper $boardMapper
|
||||
) {
|
||||
$this->boardService = $boardService;
|
||||
$this->stackService = $stackService;
|
||||
$this->cardService = $cardService;
|
||||
$this->permissionService = $permissionService;
|
||||
$this->boardMapper = $boardMapper;
|
||||
}
|
||||
|
||||
public function getBoards(): array {
|
||||
return $this->boardService->findAll();
|
||||
}
|
||||
|
||||
public function getBoard(int $id): Board {
|
||||
try {
|
||||
return $this->boardService->find($id);
|
||||
} catch (\Exception $e) {
|
||||
throw new NotFound('Board with id ' . $id . ' not found');
|
||||
}
|
||||
}
|
||||
|
||||
public function checkBoardPermission(int $id, int $permission): bool {
|
||||
$permissions = $this->permissionService->getPermissions($id);
|
||||
return isset($permissions[$permission]) ? $permissions[$permission] : false;
|
||||
}
|
||||
|
||||
public function updateBoard(Board $board): bool {
|
||||
$this->boardMapper->update($board);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getChildren(int $id): array {
|
||||
return array_merge(
|
||||
$this->cardService->findCalendarEntries($id),
|
||||
$this->stackService->findCalendarEntries($id)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,8 @@
|
||||
namespace OCA\Deck\Db;
|
||||
|
||||
use DateTime;
|
||||
use DateTimeZone;
|
||||
use Sabre\VObject\Component\VCalendar;
|
||||
|
||||
class Card extends RelationalEntity {
|
||||
protected $title;
|
||||
@@ -117,4 +119,40 @@ class Card extends RelationalEntity {
|
||||
unset($json['descriptionPrev']);
|
||||
return $json;
|
||||
}
|
||||
|
||||
public function getCalendarObject(): VCalendar {
|
||||
$calendar = new VCalendar();
|
||||
$event = $calendar->createComponent('VTODO');
|
||||
$event->UID = 'deck-card-' . $this->getId();
|
||||
if ($this->getDuedate()) {
|
||||
$creationDate = new DateTime();
|
||||
$creationDate->setTimestamp($this->createdAt);
|
||||
$event->DTSTAMP = $creationDate;
|
||||
$event->DUE = new DateTime($this->getDuedate(true), new DateTimeZone('UTC'));
|
||||
}
|
||||
$event->add('RELATED-TO', 'deck-stack-' . $this->getStackId());
|
||||
|
||||
// FIXME: For write support: CANCELLED / IN-PROCESS handling
|
||||
$event->STATUS = $this->getArchived() ? "COMPLETED" : "NEEDS-ACTION";
|
||||
if ($this->getArchived()) {
|
||||
$date = new DateTime();
|
||||
$date->setTimestamp($this->getLastModified());
|
||||
$event->COMPLETED = $date;
|
||||
//$event->add('PERCENT-COMPLETE', 100);
|
||||
}
|
||||
if (count($this->getLabels()) > 0) {
|
||||
$event->CATEGORIES = array_map(function ($label) {
|
||||
return $label->getTitle();
|
||||
}, $this->getLabels());
|
||||
}
|
||||
|
||||
$event->SUMMARY = $this->getTitle();
|
||||
$event->DESCRIPTION = $this->getDescription();
|
||||
$calendar->add($event);
|
||||
return $calendar;
|
||||
}
|
||||
|
||||
public function getCalendarPrefix(): string {
|
||||
return 'card';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,12 +23,16 @@
|
||||
|
||||
namespace OCA\Deck\Db;
|
||||
|
||||
use Exception;
|
||||
use OCP\AppFramework\Db\Entity;
|
||||
|
||||
use OCP\AppFramework\Db\QBMapper;
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Notification\IManager;
|
||||
|
||||
class CardMapper extends DeckMapper implements IPermissionMapper {
|
||||
class CardMapper extends QBMapper implements IPermissionMapper {
|
||||
|
||||
/** @var LabelMapper */
|
||||
private $labelMapper;
|
||||
@@ -55,7 +59,7 @@ class CardMapper extends DeckMapper implements IPermissionMapper {
|
||||
$this->database4ByteSupport = $database4ByteSupport;
|
||||
}
|
||||
|
||||
public function insert(Entity $entity) {
|
||||
public function insert(Entity $entity): Entity {
|
||||
$entity->setDatabaseType($this->databaseType);
|
||||
$entity->setCreatedAt(time());
|
||||
$entity->setLastModified(time());
|
||||
@@ -66,7 +70,7 @@ class CardMapper extends DeckMapper implements IPermissionMapper {
|
||||
return parent::insert($entity);
|
||||
}
|
||||
|
||||
public function update(Entity $entity, $updateModified = true) {
|
||||
public function update(Entity $entity, $updateModified = true): Entity {
|
||||
if (!$this->database4ByteSupport) {
|
||||
$description = preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $entity->getDescription());
|
||||
$entity->setDescription($description);
|
||||
@@ -79,38 +83,40 @@ class CardMapper extends DeckMapper implements IPermissionMapper {
|
||||
|
||||
// make sure we only reset the notification flag if the duedate changes
|
||||
if (in_array('duedate', $entity->getUpdatedFields(), true)) {
|
||||
$existing = $this->find($entity->getId());
|
||||
if ($existing->getDuedate() !== $entity->getDuedate()) {
|
||||
$entity->setNotified(false);
|
||||
try {
|
||||
/** @var Card $existing */
|
||||
$existing = $this->find($entity->getId());
|
||||
if ($existing && $entity->getDuedate() !== $existing->getDuedate()) {
|
||||
$entity->setNotified(false);
|
||||
}
|
||||
// remove pending notifications
|
||||
$notification = $this->notificationManager->createNotification();
|
||||
$notification
|
||||
->setApp('deck')
|
||||
->setObject('card', $entity->getId());
|
||||
$this->notificationManager->markProcessed($notification);
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
// remove pending notifications
|
||||
$notification = $this->notificationManager->createNotification();
|
||||
$notification
|
||||
->setApp('deck')
|
||||
->setObject('card', $entity->getId());
|
||||
$this->notificationManager->markProcessed($notification);
|
||||
}
|
||||
return parent::update($entity);
|
||||
}
|
||||
|
||||
public function markNotified(Card $card) {
|
||||
public function markNotified(Card $card): Entity {
|
||||
$cardUpdate = new Card();
|
||||
$cardUpdate->setId($card->getId());
|
||||
$cardUpdate->setNotified(true);
|
||||
return parent::update($cardUpdate);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return RelationalEntity if not found
|
||||
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
|
||||
* @throws \OCP\AppFramework\Db\DoesNotExistException
|
||||
*/
|
||||
public function find($id) {
|
||||
$sql = 'SELECT * FROM `*PREFIX*deck_cards` ' .
|
||||
'WHERE `id` = ? ORDER BY `order`, `id`';
|
||||
public function find($id): Card {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select('*')
|
||||
->from('deck_cards')
|
||||
->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)))
|
||||
->orderBy('order')
|
||||
->addOrderBy('id');
|
||||
/** @var Card $card */
|
||||
$card = $this->findEntity($sql, [$id]);
|
||||
$card = $this->findEntity($qb);
|
||||
$labels = $this->labelMapper->findAssignedLabelsForCard($card->id);
|
||||
$card->setLabels($labels);
|
||||
$this->mapOwner($card);
|
||||
@@ -118,57 +124,158 @@ class CardMapper extends DeckMapper implements IPermissionMapper {
|
||||
}
|
||||
|
||||
public function findAll($stackId, $limit = null, $offset = null, $since = -1) {
|
||||
$sql = 'SELECT * FROM `*PREFIX*deck_cards`
|
||||
WHERE `stack_id` = ? AND NOT archived AND deleted_at = 0 AND last_modified > ? ORDER BY `order`, `id`';
|
||||
return $this->findEntities($sql, [$stackId, $since], $limit, $offset);
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select('*')
|
||||
->from('deck_cards')
|
||||
->where($qb->expr()->eq('stack_id', $qb->createNamedParameter($stackId, IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($qb->expr()->eq('archived', $qb->createNamedParameter(false, IQueryBuilder::PARAM_BOOL)))
|
||||
->andWhere($qb->expr()->eq('deleted_at', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($qb->expr()->gt('last_modified', $qb->createNamedParameter($since, IQueryBuilder::PARAM_INT)))
|
||||
->setMaxResults($limit)
|
||||
->setFirstResult($offset)
|
||||
->orderBy('order')
|
||||
->addOrderBy('id');
|
||||
return $this->findEntities($qb);
|
||||
}
|
||||
|
||||
public function queryCardsByBoard(int $boardId): IQueryBuilder {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select('c.*')
|
||||
->from('deck_cards', 'c')
|
||||
->innerJoin('c', 'deck_stacks', 's', 'c.stack_id = s.id')
|
||||
->where($qb->expr()->eq('s.board_id', $qb->createNamedParameter($boardId, IQueryBuilder::PARAM_INT)));
|
||||
return $qb;
|
||||
}
|
||||
|
||||
public function queryCardsByBoards(array $boardIds): IQueryBuilder {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select('c.*')
|
||||
->from('deck_cards', 'c')
|
||||
->innerJoin('c', 'deck_stacks', 's', $qb->expr()->eq('s.id', 'c.stack_id'))
|
||||
->andWhere($qb->expr()->in('s.board_id', $qb->createNamedParameter($boardIds, IQueryBuilder::PARAM_INT_ARRAY)));
|
||||
return $qb;
|
||||
}
|
||||
|
||||
public function findDeleted($boardId, $limit = null, $offset = null) {
|
||||
$sql = 'SELECT c.* FROM `*PREFIX*deck_cards` c
|
||||
INNER JOIN `*PREFIX*deck_stacks` s ON s.id = c.stack_id
|
||||
WHERE `s`.`board_id` = ? AND NOT c.archived AND NOT c.deleted_at = 0 ORDER BY `c`.`order`, `c`.`id`';
|
||||
return $this->findEntities($sql, [$boardId], $limit, $offset);
|
||||
$qb = $this->queryCardsByBoard($boardId);
|
||||
$qb->andWhere($qb->expr()->neq('c.deleted_at', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)))
|
||||
->setMaxResults($limit)
|
||||
->setFirstResult($offset)
|
||||
->orderBy('order')
|
||||
->addOrderBy('id');
|
||||
return $this->findEntities($qb);
|
||||
}
|
||||
|
||||
public function findCalendarEntries($boardId, $limit = null, $offset = null) {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select('c.*')
|
||||
->from('deck_cards', 'c')
|
||||
->join('c', 'deck_stacks', 's', 's.id = c.stack_id')
|
||||
->where($qb->expr()->eq('s.board_id', $qb->createNamedParameter($boardId)))
|
||||
->andWhere($qb->expr()->eq('c.deleted_at', $qb->createNamedParameter('0')))
|
||||
->orderBy('c.duedate')
|
||||
->setMaxResults($limit)
|
||||
->setFirstResult($offset);
|
||||
return $this->findEntities($qb);
|
||||
}
|
||||
|
||||
public function findAllArchived($stackId, $limit = null, $offset = null) {
|
||||
$sql = 'SELECT * FROM `*PREFIX*deck_cards` WHERE `stack_id`=? AND archived ORDER BY `last_modified`';
|
||||
return $this->findEntities($sql, [$stackId], $limit, $offset);
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select('*')
|
||||
->from('deck_cards')
|
||||
->where($qb->expr()->eq('stack_id', $qb->createNamedParameter($stackId, IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($qb->expr()->eq('archived', $qb->createNamedParameter(true, IQueryBuilder::PARAM_BOOL)))
|
||||
->andWhere($qb->expr()->eq('deleted_at', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)))
|
||||
->setMaxResults($limit)
|
||||
->setFirstResult($offset)
|
||||
->orderBy('last_modified');
|
||||
return $this->findEntities($qb);
|
||||
}
|
||||
|
||||
public function findAllByStack($stackId, $limit = null, $offset = null) {
|
||||
$sql = 'SELECT id FROM `*PREFIX*deck_cards`
|
||||
WHERE `stack_id` = ? ORDER BY `order`, `id`';
|
||||
return $this->findEntities($sql, [$stackId], $limit, $offset);
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select('*')
|
||||
->from('deck_cards')
|
||||
->where($qb->expr()->eq('stack_id', $qb->createNamedParameter($stackId, IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($qb->expr()->eq('archived', $qb->createNamedParameter(false, IQueryBuilder::PARAM_BOOL)))
|
||||
->setMaxResults($limit)
|
||||
->setFirstResult($offset)
|
||||
->orderBy('order')
|
||||
->addOrderBy('id');
|
||||
return $this->findEntities($qb);
|
||||
}
|
||||
|
||||
public function findAllWithDue($boardId) {
|
||||
$sql = 'SELECT c.* FROM `*PREFIX*deck_cards` c
|
||||
INNER JOIN `*PREFIX*deck_stacks` s ON s.id = c.stack_id
|
||||
INNER JOIN `*PREFIX*deck_boards` b ON b.id = s.board_id
|
||||
WHERE `s`.`board_id` = ? AND duedate IS NOT NULL AND NOT c.archived AND c.deleted_at = 0 AND s.deleted_at = 0 AND NOT b.archived AND b.deleted_at = 0';
|
||||
return $this->findEntities($sql, [$boardId]);
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select('c.*')
|
||||
->from('deck_cards', 'c')
|
||||
->innerJoin('c', 'deck_stacks', 's', 's.id = c.stack_id')
|
||||
->innerJoin('s', 'deck_boards', 'b', 'b.id = s.board_id')
|
||||
->where($qb->expr()->eq('s.board_id', $qb->createNamedParameter($boardId, IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($qb->expr()->isNotNull('c.duedate'))
|
||||
->andWhere($qb->expr()->eq('c.archived', $qb->createNamedParameter(false, IQueryBuilder::PARAM_BOOL)))
|
||||
->andWhere($qb->expr()->eq('c.deleted_at', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($qb->expr()->eq('b.archived', $qb->createNamedParameter(false, IQueryBuilder::PARAM_BOOL)))
|
||||
->andWhere($qb->expr()->eq('b.deleted_at', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)));
|
||||
return $this->findEntities($qb);
|
||||
}
|
||||
|
||||
public function findAssignedCards($boardId, $username) {
|
||||
$sql = 'SELECT c.* FROM `*PREFIX*deck_cards` c
|
||||
INNER JOIN `*PREFIX*deck_stacks` s ON s.id = c.stack_id
|
||||
INNER JOIN `*PREFIX*deck_boards` b ON b.id = s.board_id
|
||||
INNER JOIN `*PREFIX*deck_assigned_users` u ON c.id = card_id
|
||||
WHERE `s`.`board_id` = ? AND participant = ? AND NOT c.archived AND c.deleted_at = 0 AND s.deleted_at = 0 AND NOT b.archived AND b.deleted_at = 0';
|
||||
return $this->findEntities($sql, [$boardId, $username]);
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select('c.*')
|
||||
->from('deck_cards', 'c')
|
||||
->innerJoin('c', 'deck_stacks', 's', 's.id = c.stack_id')
|
||||
->innerJoin('s', 'deck_boards', 'b', 'b.id = s.board_id')
|
||||
->innerJoin('c', 'deck_assigned_users', 'u', 'c.id = u.card_id')
|
||||
->where($qb->expr()->eq('s.board_id', $qb->createNamedParameter($boardId, IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($qb->expr()->eq('u.participant', $qb->createNamedParameter($username, IQueryBuilder::PARAM_STR)))
|
||||
->andWhere($qb->expr()->eq('u.type', $qb->createNamedParameter(Acl::PERMISSION_TYPE_USER, IQueryBuilder::PARAM_INT)))
|
||||
// Filter out archived/deleted cards and board
|
||||
->andWhere($qb->expr()->eq('c.archived', $qb->createNamedParameter(false, IQueryBuilder::PARAM_BOOL)))
|
||||
->andWhere($qb->expr()->eq('c.deleted_at', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($qb->expr()->eq('b.archived', $qb->createNamedParameter(false, IQueryBuilder::PARAM_BOOL)))
|
||||
->andWhere($qb->expr()->eq('b.deleted_at', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)));
|
||||
return $this->findEntities($qb);
|
||||
}
|
||||
|
||||
public function findOverdue() {
|
||||
$sql = 'SELECT id,title,duedate,notified from `*PREFIX*deck_cards` WHERE duedate < NOW() AND NOT archived AND deleted_at = 0';
|
||||
return $this->findEntities($sql);
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select('id','title','duedate','notified')
|
||||
->from('deck_cards')
|
||||
->where($qb->expr()->lt('duedate', $qb->createFunction('NOW()')))
|
||||
->andWhere($qb->expr()->eq('archived', $qb->createNamedParameter(false, IQueryBuilder::PARAM_BOOL)))
|
||||
->andWhere($qb->expr()->eq('deleted_at', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)));
|
||||
return $this->findEntities($qb);
|
||||
}
|
||||
|
||||
public function findUnexposedDescriptionChances() {
|
||||
$sql = 'SELECT id,title,duedate,notified,description_prev,last_editor,description from `*PREFIX*deck_cards` WHERE last_editor IS NOT NULL AND description_prev IS NOT NULL';
|
||||
return $this->findEntities($sql);
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select('id','title','duedate','notified','description_prev','last_editor','description')
|
||||
->from('deck_cards')
|
||||
->where($qb->expr()->isNotNull('last_editor'))
|
||||
->andWhere($qb->expr()->isNotNull('description_prev'));
|
||||
return $this->findEntities($qb);
|
||||
}
|
||||
|
||||
public function delete(Entity $entity) {
|
||||
public function search($boardIds, $term, $limit = null, $offset = null) {
|
||||
$qb = $this->queryCardsByBoards($boardIds);
|
||||
$qb->andWhere($qb->expr()->eq('c.deleted_at', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)));
|
||||
$qb->andWhere(
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->iLike('c.title', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($term) . '%')),
|
||||
$qb->expr()->iLike('c.description', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($term) . '%'))
|
||||
)
|
||||
);
|
||||
if ($limit !== null) {
|
||||
$qb->setMaxResults($limit);
|
||||
}
|
||||
if ($offset !== null) {
|
||||
$qb->setFirstResult($offset);
|
||||
}
|
||||
return $this->findEntities($qb);
|
||||
}
|
||||
|
||||
public function delete(Entity $entity): Entity {
|
||||
// delete assigned labels
|
||||
$this->labelMapper->deleteLabelAssignmentsForCard($entity->getId());
|
||||
// delete card
|
||||
@@ -183,31 +290,37 @@ class CardMapper extends DeckMapper implements IPermissionMapper {
|
||||
}
|
||||
|
||||
public function assignLabel($card, $label) {
|
||||
$sql = 'INSERT INTO `*PREFIX*deck_assigned_labels` (`label_id`,`card_id`) VALUES (?,?)';
|
||||
$stmt = $this->db->prepare($sql);
|
||||
$stmt->bindParam(1, $label, \PDO::PARAM_INT);
|
||||
$stmt->bindParam(2, $card, \PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->insert('deck_assigned_labels')
|
||||
->values([
|
||||
'label_id' => $qb->createNamedParameter($label, IQueryBuilder::PARAM_INT),
|
||||
'card_id' => $qb->createNamedParameter($card, IQueryBuilder::PARAM_INT),
|
||||
]);
|
||||
$qb->execute();
|
||||
}
|
||||
|
||||
public function removeLabel($card, $label) {
|
||||
$sql = 'DELETE FROM `*PREFIX*deck_assigned_labels` WHERE card_id = ? AND label_id = ?';
|
||||
$stmt = $this->db->prepare($sql);
|
||||
$stmt->bindParam(1, $card, \PDO::PARAM_INT);
|
||||
$stmt->bindParam(2, $label, \PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->delete('deck_assigned_labels')
|
||||
->where($qb->expr()->eq('card_id', $qb->createNamedParameter($card, IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($qb->expr()->eq('label_id', $qb->createNamedParameter($label, IQueryBuilder::PARAM_INT)));
|
||||
$qb->execute();
|
||||
}
|
||||
|
||||
public function isOwner($userId, $cardId) {
|
||||
$sql = 'SELECT owner FROM `*PREFIX*deck_boards` WHERE `id` IN (SELECT board_id FROM `*PREFIX*deck_stacks` WHERE id IN (SELECT stack_id FROM `*PREFIX*deck_cards` WHERE id = ?))';
|
||||
$stmt = $this->execute($sql, [$cardId]);
|
||||
$stmt = $this->db->prepare($sql);
|
||||
$stmt->bindParam(1, $cardId, \PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
$row = $stmt->fetch();
|
||||
return ($row['owner'] === $userId);
|
||||
}
|
||||
|
||||
public function findBoardId($cardId) {
|
||||
$sql = 'SELECT id FROM `*PREFIX*deck_boards` WHERE `id` IN (SELECT board_id FROM `*PREFIX*deck_stacks` WHERE id IN (SELECT stack_id FROM `*PREFIX*deck_cards` WHERE id = ?))';
|
||||
$stmt = $this->execute($sql, [$cardId]);
|
||||
$stmt = $this->db->prepare($sql);
|
||||
$stmt->bindParam(1, $cardId, \PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
$row = $stmt->fetch();
|
||||
return $row['id'];
|
||||
}
|
||||
|
||||
@@ -29,10 +29,11 @@ use OCP\AppFramework\Db\Mapper;
|
||||
* Class DeckMapper
|
||||
*
|
||||
* @package OCA\Deck\Db
|
||||
* @deprecated use QBMapper
|
||||
*
|
||||
* TODO: Move to QBMapper once Nextcloud 14 is a minimum requirement
|
||||
*/
|
||||
abstract class DeckMapper extends Mapper {
|
||||
class DeckMapper extends Mapper {
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
|
||||
namespace OCA\Deck\Db;
|
||||
|
||||
use Sabre\VObject\Component\VCalendar;
|
||||
|
||||
class Stack extends RelationalEntity {
|
||||
protected $title;
|
||||
protected $boardId;
|
||||
@@ -50,4 +52,17 @@ class Stack extends RelationalEntity {
|
||||
}
|
||||
return $json;
|
||||
}
|
||||
|
||||
public function getCalendarObject(): VCalendar {
|
||||
$calendar = new VCalendar();
|
||||
$event = $calendar->createComponent('VTODO');
|
||||
$event->UID = 'deck-stack-' . $this->getId();
|
||||
$event->SUMMARY = 'List : ' . $this->getTitle();
|
||||
$calendar->add($event);
|
||||
return $calendar;
|
||||
}
|
||||
|
||||
public function getCalendarPrefix(): string {
|
||||
return 'stack';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ class StackMapper extends DeckMapper implements IPermissionMapper {
|
||||
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
|
||||
* @throws \OCP\AppFramework\Db\DoesNotExistException
|
||||
*/
|
||||
public function find($id) {
|
||||
public function find($id): Stack {
|
||||
$sql = 'SELECT * FROM `*PREFIX*deck_stacks` ' .
|
||||
'WHERE `id` = ?';
|
||||
return $this->findEntity($sql, [$id]);
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
namespace OCA\Deck\Middleware;
|
||||
|
||||
use OCA\Deck\Controller\PageController;
|
||||
use OCA\Deck\StatusException;
|
||||
use OCA\Deck\Exceptions\ConflictException;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
@@ -62,6 +63,10 @@ class ExceptionMiddleware extends Middleware {
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function afterException($controller, $methodName, \Exception $exception) {
|
||||
if (get_class($controller) === PageController::class) {
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
if ($exception instanceof ConflictException) {
|
||||
if ($this->config->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) {
|
||||
$this->logger->logException($exception);
|
||||
|
||||
41
lib/Search/BoardSearchResultEntry.php
Normal file
41
lib/Search/BoardSearchResultEntry.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @author Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace OCA\Deck\Search;
|
||||
|
||||
use OCA\Deck\Db\Board;
|
||||
use OCP\Search\SearchResultEntry;
|
||||
|
||||
class BoardSearchResultEntry extends SearchResultEntry {
|
||||
public function __construct(Board $board, $urlGenerator) {
|
||||
parent::__construct(
|
||||
'',
|
||||
$board->getTitle(),
|
||||
'',
|
||||
$urlGenerator->linkToRouteAbsolute('deck.page.index') . '#/board/' . $board->getId(),
|
||||
'icon-deck');
|
||||
}
|
||||
}
|
||||
38
lib/Search/CardSearchResultEntry.php
Normal file
38
lib/Search/CardSearchResultEntry.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @author Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace OCA\Deck\Search;
|
||||
|
||||
use OCA\Deck\Db\Board;
|
||||
use OCA\Deck\Db\Card;
|
||||
use OCA\Deck\Db\Stack;
|
||||
use OCP\Search\SearchResultEntry;
|
||||
|
||||
class CardSearchResultEntry extends SearchResultEntry {
|
||||
public function __construct(Board $board, Stack $stack, Card $card, $urlGenerator) {
|
||||
parent::__construct('', $card->getTitle(), $board->getTitle() . ' » ' . $stack->getTitle() , $urlGenerator->linkToRouteAbsolute('deck.page.index') . '#/board/' . $board->getId() . '/card/' . $card->getId(), 'icon-deck');
|
||||
}
|
||||
}
|
||||
115
lib/Search/DeckProvider.php
Normal file
115
lib/Search/DeckProvider.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @author Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace OCA\Deck\Search;
|
||||
|
||||
use OCA\Deck\Db\Board;
|
||||
use OCA\Deck\Db\Card;
|
||||
use OCA\Deck\Db\CardMapper;
|
||||
use OCA\Deck\Db\StackMapper;
|
||||
use OCA\Deck\Service\BoardService;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\IUser;
|
||||
use OCP\Search\IProvider;
|
||||
use OCP\Search\ISearchQuery;
|
||||
use OCP\Search\SearchResult;
|
||||
|
||||
class DeckProvider implements IProvider {
|
||||
|
||||
/**
|
||||
* @var BoardService
|
||||
*/
|
||||
private $boardService;
|
||||
/**
|
||||
* @var CardMapper
|
||||
*/
|
||||
private $cardMapper;
|
||||
/**
|
||||
* @var StackMapper
|
||||
*/
|
||||
private $stackMapper;
|
||||
/**
|
||||
* @var IURLGenerator
|
||||
*/
|
||||
private $urlGenerator;
|
||||
|
||||
public function __construct(
|
||||
BoardService $boardService,
|
||||
StackMapper $stackMapper,
|
||||
CardMapper $cardMapper,
|
||||
IURLGenerator $urlGenerator
|
||||
) {
|
||||
$this->boardService = $boardService;
|
||||
$this->stackMapper = $stackMapper;
|
||||
$this->cardMapper = $cardMapper;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
}
|
||||
|
||||
public function getId(): string {
|
||||
return 'deck';
|
||||
}
|
||||
|
||||
public function getName(): string {
|
||||
return 'Deck';
|
||||
}
|
||||
|
||||
public function search(IUser $user, ISearchQuery $query): SearchResult {
|
||||
$boards = $this->boardService->getUserBoards();
|
||||
|
||||
$matchedBoards = array_filter($this->boardService->getUserBoards(), static function (Board $board) use ($query) {
|
||||
return mb_stripos($board->getTitle(), $query->getTerm()) > -1;
|
||||
});
|
||||
|
||||
$matchedCards = $this->cardMapper->search(array_map(static function (Board $board) {
|
||||
return $board->getId();
|
||||
}, $boards), $query->getTerm(), $query->getLimit(), $query->getCursor());
|
||||
|
||||
$self = $this;
|
||||
$results = array_merge(
|
||||
array_map(function (Board $board) {
|
||||
return new BoardSearchResultEntry($board, $this->urlGenerator);
|
||||
}, $matchedBoards),
|
||||
|
||||
array_map(function (Card $card) use ($self) {
|
||||
$board = $self->boardService->find($self->cardMapper->findBoardId($card->getId()));
|
||||
$stack = $self->stackMapper->find($card->getStackId());
|
||||
return new CardSearchResultEntry($board, $stack, $card, $this->urlGenerator);
|
||||
}, $matchedCards)
|
||||
);
|
||||
|
||||
return SearchResult::complete(
|
||||
'Deck',
|
||||
$results
|
||||
);
|
||||
}
|
||||
|
||||
public function getOrder(string $route, array $routeParameters): int {
|
||||
if ($route === 'deck.page.index') {
|
||||
return -5;
|
||||
}
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
@@ -64,6 +64,8 @@ class BoardService {
|
||||
private $eventDispatcher;
|
||||
private $changeHelper;
|
||||
|
||||
private $boardsCache = null;
|
||||
|
||||
public function __construct(
|
||||
BoardMapper $boardMapper,
|
||||
StackMapper $stackMapper,
|
||||
@@ -105,42 +107,55 @@ class BoardService {
|
||||
$this->userId = $userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function findAll($since = -1, $details = null) {
|
||||
public function getUserBoards(int $since = -1): array {
|
||||
$userInfo = $this->getBoardPrerequisites();
|
||||
$userBoards = $this->boardMapper->findAllByUser($userInfo['user'], null, null, $since);
|
||||
$groupBoards = $this->boardMapper->findAllByGroups($userInfo['user'], $userInfo['groups'],null, null, $since);
|
||||
$circleBoards = $this->boardMapper->findAllByCircles($userInfo['user'], null, null, $since);
|
||||
$complete = array_merge($userBoards, $groupBoards, $circleBoards);
|
||||
$mergedBoards = array_merge($userBoards, $groupBoards, $circleBoards);
|
||||
$result = [];
|
||||
/** @var Board $item */
|
||||
foreach ($complete as &$item) {
|
||||
foreach ($mergedBoards as &$item) {
|
||||
if (!array_key_exists($item->getId(), $result)) {
|
||||
$this->boardMapper->mapOwner($item);
|
||||
if ($item->getAcl() !== null) {
|
||||
foreach ($item->getAcl() as &$acl) {
|
||||
$this->boardMapper->mapAcl($acl);
|
||||
}
|
||||
}
|
||||
if ($details !== null) {
|
||||
$this->enrichWithStacks($item);
|
||||
$this->enrichWithLabels($item);
|
||||
$this->enrichWithUsers($item);
|
||||
}
|
||||
$permissions = $this->permissionService->matchPermissions($item);
|
||||
$item->setPermissions([
|
||||
'PERMISSION_READ' => $permissions[Acl::PERMISSION_READ] ?? false,
|
||||
'PERMISSION_EDIT' => $permissions[Acl::PERMISSION_EDIT] ?? false,
|
||||
'PERMISSION_MANAGE' => $permissions[Acl::PERMISSION_MANAGE] ?? false,
|
||||
'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE] ?? false
|
||||
]);
|
||||
$result[$item->getId()] = $item;
|
||||
}
|
||||
}
|
||||
return array_values($result);
|
||||
}
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function findAll($since = -1, $details = null) {
|
||||
if ($this->boardsCache) {
|
||||
return $this->boardsCache;
|
||||
}
|
||||
$complete = $this->getUserBoards($since);
|
||||
$result = [];
|
||||
/** @var Board $item */
|
||||
foreach ($complete as &$item) {
|
||||
$this->boardMapper->mapOwner($item);
|
||||
if ($item->getAcl() !== null) {
|
||||
foreach ($item->getAcl() as &$acl) {
|
||||
$this->boardMapper->mapAcl($acl);
|
||||
}
|
||||
}
|
||||
if ($details !== null) {
|
||||
$this->enrichWithStacks($item);
|
||||
$this->enrichWithLabels($item);
|
||||
$this->enrichWithUsers($item);
|
||||
}
|
||||
$permissions = $this->permissionService->matchPermissions($item);
|
||||
$item->setPermissions([
|
||||
'PERMISSION_READ' => $permissions[Acl::PERMISSION_READ] ?? false,
|
||||
'PERMISSION_EDIT' => $permissions[Acl::PERMISSION_EDIT] ?? false,
|
||||
'PERMISSION_MANAGE' => $permissions[Acl::PERMISSION_MANAGE] ?? false,
|
||||
'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE] ?? false
|
||||
]);
|
||||
$result[$item->getId()] = $item;
|
||||
}
|
||||
$this->boardsCache = $result;
|
||||
return array_values($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $boardId
|
||||
@@ -151,6 +166,9 @@ class BoardService {
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function find($boardId) {
|
||||
if ($this->boardsCache && isset($this->boardsCache[$boardId])) {
|
||||
return $this->boardsCache[$boardId];
|
||||
}
|
||||
if (is_numeric($boardId) === false) {
|
||||
throw new BadRequestException('board id must be a number');
|
||||
}
|
||||
@@ -172,6 +190,7 @@ class BoardService {
|
||||
'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE] ?? false
|
||||
]);
|
||||
$this->enrichWithUsers($board);
|
||||
$this->boardsCache[$board->getId()] = $board;
|
||||
return $board;
|
||||
}
|
||||
|
||||
@@ -331,7 +350,7 @@ class BoardService {
|
||||
throw new BadRequestException('board id must be a number');
|
||||
}
|
||||
|
||||
$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_READ);
|
||||
$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_MANAGE);
|
||||
$board = $this->find($id);
|
||||
if ($board->getDeletedAt() > 0) {
|
||||
throw new BadRequestException('This board has already been deleted');
|
||||
@@ -360,7 +379,7 @@ class BoardService {
|
||||
throw new BadRequestException('board id must be a number');
|
||||
}
|
||||
|
||||
$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_READ);
|
||||
$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_MANAGE);
|
||||
$board = $this->find($id);
|
||||
$board->setDeletedAt(0);
|
||||
$board = $this->boardMapper->update($board);
|
||||
@@ -387,7 +406,7 @@ class BoardService {
|
||||
throw new BadRequestException('id must be a number');
|
||||
}
|
||||
|
||||
$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_READ);
|
||||
$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_MANAGE);
|
||||
$board = $this->find($id);
|
||||
$delete = $this->boardMapper->delete($board);
|
||||
|
||||
|
||||
@@ -116,6 +116,11 @@ class CardService {
|
||||
return $cards;
|
||||
}
|
||||
|
||||
public function search($boardIds, $term) {
|
||||
$cards = $this->cardMapper->search($boardIds, $term);
|
||||
return $cards;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cardId
|
||||
* @return \OCA\Deck\Db\RelationalEntity
|
||||
@@ -139,6 +144,15 @@ class CardService {
|
||||
return $card;
|
||||
}
|
||||
|
||||
public function findCalendarEntries($boardId) {
|
||||
$this->permissionService->checkPermission($this->boardMapper, $boardId, Acl::PERMISSION_READ);
|
||||
$cards = $this->cardMapper->findCalendarEntries($boardId);
|
||||
foreach ($cards as $card) {
|
||||
$this->enrich($card);
|
||||
}
|
||||
return $cards;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $title
|
||||
* @param $stackId
|
||||
|
||||
129
lib/Service/ConfigService.php
Normal file
129
lib/Service/ConfigService.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @author Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace OCA\Deck\Service;
|
||||
|
||||
use OCA\Deck\AppInfo\Application;
|
||||
use OCA\Deck\NoPermissionException;
|
||||
use OCP\IConfig;
|
||||
use OCP\IGroup;
|
||||
use OCP\IGroupManager;
|
||||
|
||||
class ConfigService {
|
||||
private $config;
|
||||
private $userId;
|
||||
private $groupManager;
|
||||
|
||||
public function __construct(
|
||||
IConfig $config,
|
||||
IGroupManager $groupManager,
|
||||
$userId
|
||||
) {
|
||||
$this->userId = $userId;
|
||||
$this->groupManager = $groupManager;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function getAll(): array {
|
||||
$data = [
|
||||
'calendar' => $this->get('calendar')
|
||||
];
|
||||
if ($this->groupManager->isAdmin($this->userId)) {
|
||||
$data = [
|
||||
'groupLimit' => $this->get('groupLimit'),
|
||||
];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function get($key) {
|
||||
$result = null;
|
||||
switch ($key) {
|
||||
case 'groupLimit':
|
||||
if (!$this->groupManager->isAdmin($this->userId)) {
|
||||
throw new NoPermissionException('You must be admin to get the group limit');
|
||||
}
|
||||
$result = $this->getGroupLimit();
|
||||
break;
|
||||
case 'calendar':
|
||||
$result = (bool)$this->config->getUserValue($this->userId, Application::APP_ID, 'calendar', true);
|
||||
break;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function set($key, $value) {
|
||||
$result = null;
|
||||
switch ($key) {
|
||||
case 'groupLimit':
|
||||
if (!$this->groupManager->isAdmin($this->userId)) {
|
||||
throw new NoPermissionException('You must be admin to set the group limit');
|
||||
}
|
||||
$result = $this->setGroupLimit($value);
|
||||
break;
|
||||
case 'calendar':
|
||||
$this->config->setUserValue($this->userId, Application::APP_ID, 'calendar', (int)$value);
|
||||
$result = $value;
|
||||
break;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function setGroupLimit($value) {
|
||||
$groups = [];
|
||||
foreach ($value as $group) {
|
||||
$groups[] = $group['id'];
|
||||
}
|
||||
$data = implode(',', $groups);
|
||||
$this->config->setAppValue(Application::APP_ID, 'groupLimit', $data);
|
||||
return $groups;
|
||||
}
|
||||
|
||||
private function getGroupLimitList() {
|
||||
$value = $this->config->getAppValue(Application::APP_ID, 'groupLimit', '');
|
||||
$groups = explode(',', $value);
|
||||
if ($value === '') {
|
||||
return [];
|
||||
}
|
||||
return $groups;
|
||||
}
|
||||
|
||||
private function getGroupLimit() {
|
||||
$groups = $this->getGroupLimitList();
|
||||
$groups = array_map(function ($groupId) {
|
||||
/** @var IGroup $groups */
|
||||
$group = $this->groupManager->get($groupId);
|
||||
if ($group === null) {
|
||||
return null;
|
||||
}
|
||||
return [
|
||||
'id' => $group->getGID(),
|
||||
'displayname' => $group->getDisplayName(),
|
||||
];
|
||||
}, $groups);
|
||||
return array_filter($groups);
|
||||
}
|
||||
}
|
||||
@@ -162,6 +162,11 @@ class StackService {
|
||||
return $stacks;
|
||||
}
|
||||
|
||||
public function findCalendarEntries($boardId) {
|
||||
$this->permissionService->checkPermission(null, $boardId, Acl::PERMISSION_READ);
|
||||
return $this->stackMapper->findAll($boardId);
|
||||
}
|
||||
|
||||
public function fetchDeleted($boardId) {
|
||||
$this->permissionService->checkPermission($this->boardMapper, $boardId, Acl::PERMISSION_READ);
|
||||
$stacks = $this->stackMapper->findDeleted($boardId);
|
||||
|
||||
Reference in New Issue
Block a user