Add backend for assigning groups to cards

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2020-03-22 14:49:40 +01:00
parent 097e8df2ad
commit 3c6a177da9
11 changed files with 348 additions and 147 deletions

View File

@@ -64,7 +64,7 @@ return [
['name' => 'card#assignLabel', 'url' => '/cards/{cardId}/label/{labelId}', 'verb' => 'POST'], ['name' => 'card#assignLabel', 'url' => '/cards/{cardId}/label/{labelId}', 'verb' => 'POST'],
['name' => 'card#removeLabel', 'url' => '/cards/{cardId}/label/{labelId}', 'verb' => 'DELETE'], ['name' => 'card#removeLabel', 'url' => '/cards/{cardId}/label/{labelId}', 'verb' => 'DELETE'],
['name' => 'card#assignUser', 'url' => '/cards/{cardId}/assign', 'verb' => 'POST'], ['name' => 'card#assignUser', 'url' => '/cards/{cardId}/assign', 'verb' => 'POST'],
['name' => 'card#unassignUser', 'url' => '/cards/{cardId}/assign/{userId}', 'verb' => 'DELETE'], ['name' => 'card#unassignUser', 'url' => '/cards/{cardId}/unassign', 'verb' => 'PUT'],
['name' => 'attachment#getAll', 'url' => '/cards/{cardId}/attachments', 'verb' => 'GET'], ['name' => 'attachment#getAll', 'url' => '/cards/{cardId}/attachments', 'verb' => 'GET'],
['name' => 'attachment#create', 'url' => '/cards/{cardId}/attachment', 'verb' => 'POST'], ['name' => 'attachment#create', 'url' => '/cards/{cardId}/attachment', 'verb' => 'POST'],

View File

@@ -43,6 +43,8 @@ use OCP\AppFramework\App;
use OCP\Collaboration\Resources\IManager; use OCP\Collaboration\Resources\IManager;
use OCP\Collaboration\Resources\IProviderManager; use OCP\Collaboration\Resources\IProviderManager;
use OCP\Comments\CommentsEntityEvent; use OCP\Comments\CommentsEntityEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\FullTextSearch\IFullTextSearchManager; use OCP\FullTextSearch\IFullTextSearchManager;
use OCP\IGroup; use OCP\IGroup;
use OCP\IServerContainer; use OCP\IServerContainer;
@@ -217,34 +219,35 @@ class Application extends App {
return; return;
} }
$eventDispatcher = $this->server->getEventDispatcher(); /** @var IEventDispatcher $eventDispatcher */
$eventDispatcher = $this->server->query(IEventDispatcher::class);
$eventDispatcher->addListener( $eventDispatcher->addListener(
'\OCA\Deck\Card::onCreate', function(GenericEvent $e) { '\OCA\Deck\Card::onCreate', function(Event $e) {
$this->fullTextSearchService->onCardCreated($e); $this->fullTextSearchService->onCardCreated($e);
} }
); );
$eventDispatcher->addListener( $eventDispatcher->addListener(
'\OCA\Deck\Card::onUpdate', function(GenericEvent $e) { '\OCA\Deck\Card::onUpdate', function(Event $e) {
$this->fullTextSearchService->onCardUpdated($e); $this->fullTextSearchService->onCardUpdated($e);
} }
); );
$eventDispatcher->addListener( $eventDispatcher->addListener(
'\OCA\Deck\Card::onDelete', function(GenericEvent $e) { '\OCA\Deck\Card::onDelete', function(Event $e) {
$this->fullTextSearchService->onCardDeleted($e); $this->fullTextSearchService->onCardDeleted($e);
} }
); );
$eventDispatcher->addListener( $eventDispatcher->addListener(
'\OCA\Deck\Board::onShareNew', function(GenericEvent $e) { '\OCA\Deck\Board::onShareNew', function(Event $e) {
$this->fullTextSearchService->onBoardShares($e); $this->fullTextSearchService->onBoardShares($e);
} }
); );
$eventDispatcher->addListener( $eventDispatcher->addListener(
'\OCA\Deck\Board::onShareEdit', function(GenericEvent $e) { '\OCA\Deck\Board::onShareEdit', function(Event $e) {
$this->fullTextSearchService->onBoardShares($e); $this->fullTextSearchService->onBoardShares($e);
} }
); );
$eventDispatcher->addListener( $eventDispatcher->addListener(
'\OCA\Deck\Board::onShareDelete', function(GenericEvent $e) { '\OCA\Deck\Board::onShareDelete', function(Event $e) {
$this->fullTextSearchService->onBoardShares($e); $this->fullTextSearchService->onBoardShares($e);
} }
); );

View File

@@ -25,6 +25,7 @@
namespace OCA\Deck\Controller; namespace OCA\Deck\Controller;
use OCA\Deck\Service\AssignmentService;
use OCP\AppFramework\ApiController; use OCP\AppFramework\ApiController;
use OCP\AppFramework\Http; use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\DataResponse;
@@ -39,6 +40,7 @@
class CardApiController extends ApiController { class CardApiController extends ApiController {
private $cardService; private $cardService;
private $userId; private $userId;
private $assignmentService;
/** /**
* @param string $appName * @param string $appName
@@ -46,10 +48,11 @@ class CardApiController extends ApiController {
* @param CardService $cardService * @param CardService $cardService
* @param $userId * @param $userId
*/ */
public function __construct($appName, IRequest $request, CardService $cardService, $userId) { public function __construct($appName, IRequest $request, CardService $cardService, AssignmentService $assignmentService, $userId) {
parent::__construct($appName, $request); parent::__construct($appName, $request);
$this->cardService = $cardService; $this->cardService = $cardService;
$this->userId = $userId; $this->userId = $userId;
$this->assignmentService = $assignmentService;
} }
/** /**
@@ -135,10 +138,10 @@ class CardApiController extends ApiController {
* @CORS * @CORS
* @NoCSRFRequired * @NoCSRFRequired
* *
* Unassign a user from a card * Assign a user to a card
*/ */
public function unassignUser($userId) { public function assignUser($cardId, $userId, $type = 0) {
$card = $this->cardService->unassignUser($this->request->getParam('cardId'), $userId); $card = $this->assignmentService->assignUser($cardId, $userId, $type);
return new DataResponse($card, HTTP::STATUS_OK); return new DataResponse($card, HTTP::STATUS_OK);
} }
@@ -147,10 +150,10 @@ class CardApiController extends ApiController {
* @CORS * @CORS
* @NoCSRFRequired * @NoCSRFRequired
* *
* Assign a user to a card * Unassign a user from a card
*/ */
public function assignUser($userId) { public function unassignUser($cardId, $userId, $type = 0) {
$card = $this->cardService->assignUser($this->request->getParam('cardId'), $userId);; $card = $this->assignmentService->unassignUser($cardId, $userId, $type);
return new DataResponse($card, HTTP::STATUS_OK); return new DataResponse($card, HTTP::STATUS_OK);
} }

View File

@@ -5,24 +5,25 @@
* @author Julius Härtl <jus@bitgrid.net> * @author Julius Härtl <jus@bitgrid.net>
* *
* @license GNU AGPL version 3 or any later version * @license GNU AGPL version 3 or any later version
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the * published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version. * License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * 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/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
namespace OCA\Deck\Controller; namespace OCA\Deck\Controller;
use OCA\Deck\Service\AssignmentService;
use OCA\Deck\Service\CardService; use OCA\Deck\Service\CardService;
use OCP\IRequest; use OCP\IRequest;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
@@ -31,11 +32,13 @@ class CardController extends Controller {
private $userId; private $userId;
private $cardService; private $cardService;
private $assignmentService;
public function __construct($appName, IRequest $request, CardService $cardService, $userId) { public function __construct($appName, IRequest $request, CardService $cardService, AssignmentService $assignmentService, $userId) {
parent::__construct($appName, $request); parent::__construct($appName, $request);
$this->userId = $userId; $this->userId = $userId;
$this->cardService = $cardService; $this->cardService = $cardService;
$this->assignmentService = $assignmentService;
} }
/** /**
@@ -153,15 +156,15 @@ class CardController extends Controller {
/** /**
* @NoAdminRequired * @NoAdminRequired
*/ */
public function assignUser($cardId, $userId) { public function assignUser($cardId, $userId, $type = 0) {
return $this->cardService->assignUser($cardId, $userId); return $this->assignmentService->assignUser($cardId, $userId, $type);
} }
/** /**
* @NoAdminRequired * @NoAdminRequired
*/ */
public function unassignUser($cardId, $userId) { public function unassignUser($cardId, $userId, $type = 0) {
return $this->cardService->unassignUser($cardId, $userId); return $this->assignmentService->unassignUser($cardId, $userId, $type);
} }

View File

@@ -30,10 +30,16 @@ class AssignedUsers extends RelationalEntity implements JsonSerializable {
public $id; public $id;
protected $participant; protected $participant;
protected $cardId; protected $cardId;
protected $type;
public const TYPE_USER = Acl::PERMISSION_TYPE_USER;
public const TYPE_GROUP = Acl::PERMISSION_TYPE_GROUP;
public const TYPE_CIRCLE = Acl::PERMISSION_TYPE_CIRCLE;
public function __construct() { public function __construct() {
$this->addType('id', 'integer'); $this->addType('id', 'integer');
$this->addType('cardId', 'integer'); $this->addType('cardId', 'integer');
$this->addType('type', 'integer');
$this->addResolvable('participant'); $this->addResolvable('participant');
} }

View File

@@ -26,6 +26,7 @@ namespace OCA\Deck\Db;
use OCP\AppFramework\Db\Entity; use OCP\AppFramework\Db\Entity;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IGroupManager;
use OCP\IUserManager; use OCP\IUserManager;
@@ -33,11 +34,16 @@ class AssignedUsersMapper extends DeckMapper implements IPermissionMapper {
private $cardMapper; private $cardMapper;
private $userManager; private $userManager;
/**
* @var IGroupManager
*/
private $groupManager;
public function __construct(IDBConnection $db, CardMapper $cardMapper, IUserManager $userManager) { public function __construct(IDBConnection $db, CardMapper $cardMapper, IUserManager $userManager, IGroupManager $groupManager) {
parent::__construct($db, 'deck_assigned_users', AssignedUsers::class); parent::__construct($db, 'deck_assigned_users', AssignedUsers::class);
$this->cardMapper = $cardMapper; $this->cardMapper = $cardMapper;
$this->userManager = $userManager; $this->userManager = $userManager;
$this->groupManager = $groupManager;
} }
/** /**
@@ -78,8 +84,8 @@ class AssignedUsersMapper extends DeckMapper implements IPermissionMapper {
* @return null|Entity * @return null|Entity
*/ */
public function insert(Entity $entity) { public function insert(Entity $entity) {
$user = $this->userManager->get($entity->getParticipant()); $origin = $this->getOrigin($entity);
if ($user !== null) { if ($origin !== null) {
/** @var AssignedUsers $assignment */ /** @var AssignedUsers $assignment */
$assignment = parent::insert($entity); $assignment = parent::insert($entity);
$this->mapParticipant($assignment); $this->mapParticipant($assignment);
@@ -89,15 +95,26 @@ class AssignedUsersMapper extends DeckMapper implements IPermissionMapper {
} }
public function mapParticipant(AssignedUsers &$assignment) { public function mapParticipant(AssignedUsers &$assignment) {
$userManager = $this->userManager; $self = $this;
$assignment->resolveRelation('participant', function() use (&$userManager, &$assignment) { $assignment->resolveRelation('participant', function() use (&$self, &$assignment) {
$user = $userManager->get($assignment->getParticipant()); return $self->getOrigin($assignment);
if ($user !== null) {
return new User($user);
}
return null;
}); });
} }
private function getOrigin(AssignedUsers $assignment) {
if ($assignment->getType() === AssignedUsers::TYPE_USER) {
$origin = $this->userManager->get($assignment->getParticipant());
return $origin ? new User($origin) : null;
}
if ($assignment->getType() === AssignedUsers::TYPE_GROUP) {
$origin = $this->groupManager->get($assignment->getParticipant());
return $origin ? new Group($origin) : null;
}
if ($assignment->getType() === AssignedUsers::TYPE_CIRCLE) {
$origin = $this->groupManager->get($assignment->getParticipant());
return $origin ? new Circle($origin) : null;
}
return null;
}
} }

View File

@@ -232,7 +232,10 @@ class BoardMapper extends DeckMapper implements IPermissionMapper {
\OC::$server->getLogger()->debug('Group ' . $acl->getId() . ' not found when mapping acl ' . $acl->getParticipant()); \OC::$server->getLogger()->debug('Group ' . $acl->getId() . ' not found when mapping acl ' . $acl->getParticipant());
return null; return null;
} }
if ($acl->getType() === Acl::PERMISSION_TYPE_CIRCLE && $this->circlesEnabled) { if ($acl->getType() === Acl::PERMISSION_TYPE_CIRCLE) {
if (!$this->circlesEnabled) {
return null;
}
try { try {
$circle = \OCA\Circles\Api\v1\Circles::detailsCircle($acl->getParticipant(), true); $circle = \OCA\Circles\Api\v1\Circles::detailsCircle($acl->getParticipant(), true);
if ($circle) { if ($circle) {

View File

@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
namespace OCA\Deck\Migration;
use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
/**
* Auto-generated migration step: Please modify to your needs!
*/
class Version1000Date20200308073933 extends SimpleMigrationStep {
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*/
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
}
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
$table = $schema->getTable('deck_assigned_users');
// Defaults to TYPE_USER = 0
$table->addColumn('type', 'integer', [
'notnull' => true,
'default' => 0
]);
$table->addIndex(['participant'], 'deck_assigned_users_idx_t');
return $schema;
}
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
}
}

View File

@@ -0,0 +1,201 @@
<?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/>.
*
*/
namespace OCA\Deck\Service;
use OCA\Deck\Activity\ActivityManager;
use OCA\Deck\BadRequestException;
use OCA\Deck\Db\Acl;
use OCA\Deck\Db\AclMapper;
use OCA\Deck\Db\AssignedUsers;
use OCA\Deck\Db\AssignedUsersMapper;
use OCA\Deck\Db\CardMapper;
use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\Event\FTSEvent;
use OCA\Deck\NoPermissionException;
use OCA\Deck\NotFoundException;
use OCA\Deck\Notification\NotificationHelper;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\EventDispatcher\IEventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
class AssignmentService {
/**
* @var PermissionService
*/
private $permissionService;
/**
* @var CardMapper
*/
private $cardMapper;
/**
* @var AssignedUsersMapper
*/
private $assignedUsersMapper;
/**
* @var AclMapper
*/
private $aclMapper;
/**
* @var NotificationHelper
*/
private $notificationHelper;
/**
* @var ChangeHelper
*/
private $changeHelper;
/**
* @var ActivityManager
*/
private $activityManager;
/**
* @var IEventDispatcher
*/
private $eventDispatcher;
public function __construct(
PermissionService $permissionService,
CardMapper $cardMapper,
AssignedUsersMapper $assignedUsersMapper,
AclMapper $aclMapper,
NotificationHelper $notificationHelper,
ActivityManager $activityManager,
ChangeHelper $changeHelper,
IEventDispatcher $eventDispatcher
) {
$this->permissionService = $permissionService;
$this->cardMapper = $cardMapper;
$this->assignedUsersMapper = $assignedUsersMapper;
$this->aclMapper = $aclMapper;
$this->notificationHelper = $notificationHelper;
$this->changeHelper = $changeHelper;
$this->activityManager = $activityManager;
$this->eventDispatcher = $eventDispatcher;
}
/**
* @param $cardId
* @param $userId
* @return bool|null|Entity
* @throws BadRequestException
* @throws NoPermissionException
* @throws MultipleObjectsReturnedException
* @throws DoesNotExistException
*/
public function assignUser($cardId, $userId, int $type = 0) {
if (is_numeric($cardId) === false) {
throw new BadRequestException('card id must be a number');
}
if ($userId === false || $userId === null) {
throw new BadRequestException('user id must be provided');
}
if ($type !== AssignedUsers::TYPE_USER && $type !== AssignedUsers::TYPE_GROUP) {
throw new BadRequestException('Invalid type provided for assignemnt');
}
$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT);
$assignments = $this->assignedUsersMapper->find($cardId);
foreach ($assignments as $assignment) {
if ($assignment->getParticipant() === $userId) {
throw new BadRequestException('The user is already assigned to the card');
}
}
$card = $this->cardMapper->find($cardId);
$boardId = $this->cardMapper->findBoardId($cardId);
$boardUsers = array_keys($this->permissionService->findUsers($boardId, true));
$groups = array_filter($this->aclMapper->findAll($boardId), function (Acl $acl) use ($userId) {
return $acl->getType() === Acl::PERMISSION_TYPE_GROUP && $acl->getParticipant() === $userId;
});
if (!in_array($userId, $boardUsers) && count($groups) !== 1) {
throw new BadRequestException('The user is not part of the board');
}
if ($userId !== $this->currentUser) {
/* Notifyuser about the card assignment */
$this->notificationHelper->sendCardAssigned($card, $userId);
}
$assignment = new AssignedUsers();
$assignment->setCardId($cardId);
$assignment->setParticipant($userId);
$assignment->setType($type);
$assignment = $this->assignedUsersMapper->insert($assignment);
$this->changeHelper->cardChanged($cardId, false);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_USER_ASSIGN, ['assigneduser' => $userId]);
$this->eventDispatcher->dispatch(
'\OCA\Deck\Card::onUpdate', new FTSEvent(null, ['id' => $cardId, 'card' => $card])
);
return $assignment;
}
/**
* @param $cardId
* @param $userId
* @return Entity
* @throws BadRequestException
* @throws NotFoundException
* @throws NoPermissionException
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
*/
public function unassignUser($cardId, $userId, $type = 0) {
$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT);
if (is_numeric($cardId) === false) {
throw new BadRequestException('card id must be a number');
}
if ($userId === false || $userId === null) {
throw new BadRequestException('user must be provided');
}
$assignments = $this->assignedUsersMapper->find($cardId);
foreach ($assignments as $assignment) {
if ($assignment->getParticipant() === $userId && $assignment->getType() === $type) {
$assignment = $this->assignedUsersMapper->delete($assignment);
$card = $this->cardMapper->find($cardId);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_USER_UNASSIGN, ['assigneduser' => $userId]);
$this->changeHelper->cardChanged($cardId, false);
$this->eventDispatcher->dispatch(
'\OCA\Deck\Card::onUpdate', new FTSEvent(null, ['id' => $cardId, 'card' => $card])
);
return $assignment;
}
}
throw new NotFoundException('No assignment for ' . $userId . 'found.');
}
}

View File

@@ -35,13 +35,17 @@ use OCA\Deck\Db\CardMapper;
use OCA\Deck\Db\Acl; use OCA\Deck\Db\Acl;
use OCA\Deck\Db\ChangeHelper; use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\Db\StackMapper; use OCA\Deck\Db\StackMapper;
use OCA\Deck\Event\FTSEvent;
use OCA\Deck\Notification\NotificationHelper; use OCA\Deck\Notification\NotificationHelper;
use OCA\Deck\Db\BoardMapper; use OCA\Deck\Db\BoardMapper;
use OCA\Deck\Db\LabelMapper; use OCA\Deck\Db\LabelMapper;
use OCA\Deck\NotFoundException; use OCA\Deck\NotFoundException;
use OCA\Deck\StatusException; use OCA\Deck\StatusException;
use OCA\Deck\BadRequestException; use OCA\Deck\BadRequestException;
use OCP\Activity\IEvent;
use OCP\Comments\ICommentsManager; use OCP\Comments\ICommentsManager;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IUserManager; use OCP\IUserManager;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent; use Symfony\Component\EventDispatcher\GenericEvent;
@@ -61,7 +65,6 @@ class CardService {
private $activityManager; private $activityManager;
private $commentsManager; private $commentsManager;
private $changeHelper; private $changeHelper;
/** @var EventDispatcherInterface */
private $eventDispatcher; private $eventDispatcher;
private $userManager; private $userManager;
@@ -79,7 +82,7 @@ class CardService {
ICommentsManager $commentsManager, ICommentsManager $commentsManager,
IUserManager $userManager, IUserManager $userManager,
ChangeHelper $changeHelper, ChangeHelper $changeHelper,
EventDispatcherInterface $eventDispatcher, IEventDispatcher $eventDispatcher,
$userId $userId
) { ) {
$this->cardMapper = $cardMapper; $this->cardMapper = $cardMapper;
@@ -197,7 +200,7 @@ class CardService {
$this->eventDispatcher->dispatch( $this->eventDispatcher->dispatch(
'\OCA\Deck\Card::onCreate', '\OCA\Deck\Card::onCreate',
new GenericEvent( new FTSEvent(
null, ['id' => $card->getId(), 'card' => $card, 'userId' => $owner, 'stackId' => $stackId] null, ['id' => $card->getId(), 'card' => $card, 'userId' => $owner, 'stackId' => $stackId]
) )
); );
@@ -231,7 +234,7 @@ class CardService {
$this->changeHelper->cardChanged($card->getId(), false); $this->changeHelper->cardChanged($card->getId(), false);
$this->eventDispatcher->dispatch( $this->eventDispatcher->dispatch(
'\OCA\Deck\Card::onDelete', new GenericEvent(null, ['id' => $id, 'card' => $card]) '\OCA\Deck\Card::onDelete', new FTSEvent(null, ['id' => $id, 'card' => $card])
); );
return $card; return $card;
@@ -327,7 +330,7 @@ class CardService {
$this->changeHelper->cardChanged($card->getId(), true); $this->changeHelper->cardChanged($card->getId(), true);
$this->eventDispatcher->dispatch( $this->eventDispatcher->dispatch(
'\OCA\Deck\Card::onUpdate', new GenericEvent(null, ['id' => $id, 'card' => $card]) '\OCA\Deck\Card::onUpdate', new FTSEvent(null, ['id' => $id, 'card' => $card])
); );
return $card; return $card;
@@ -366,7 +369,7 @@ class CardService {
$update = $this->cardMapper->update($card); $update = $this->cardMapper->update($card);
$this->eventDispatcher->dispatch( $this->eventDispatcher->dispatch(
'\OCA\Deck\Card::onUpdate', new GenericEvent(null, ['id' => $id, 'card' => $card]) '\OCA\Deck\Card::onUpdate', new FTSEvent(null, ['id' => $id, 'card' => $card])
); );
return $update; return $update;
@@ -462,7 +465,7 @@ class CardService {
$this->changeHelper->cardChanged($id, false); $this->changeHelper->cardChanged($id, false);
$this->eventDispatcher->dispatch( $this->eventDispatcher->dispatch(
'\OCA\Deck\Card::onUpdate', new GenericEvent(null, ['id' => $id, 'card' => $card]) '\OCA\Deck\Card::onUpdate', new FTSEvent(null, ['id' => $id, 'card' => $card])
); );
return $newCard; return $newCard;
@@ -494,7 +497,7 @@ class CardService {
$this->changeHelper->cardChanged($id, false); $this->changeHelper->cardChanged($id, false);
$this->eventDispatcher->dispatch( $this->eventDispatcher->dispatch(
'\OCA\Deck\Card::onUpdate', new GenericEvent(null, ['id' => $id, 'card' => $card]) '\OCA\Deck\Card::onUpdate', new FTSEvent(null, ['id' => $id, 'card' => $card])
); );
return $newCard; return $newCard;
@@ -533,7 +536,7 @@ class CardService {
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_LABEL_ASSIGN, ['label' => $label]); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_LABEL_ASSIGN, ['label' => $label]);
$this->eventDispatcher->dispatch( $this->eventDispatcher->dispatch(
'\OCA\Deck\Card::onUpdate', new GenericEvent(null, ['id' => $cardId, 'card' => $card]) '\OCA\Deck\Card::onUpdate', new FTSEvent(null, ['id' => $cardId, 'card' => $card])
); );
} }
@@ -570,100 +573,8 @@ class CardService {
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_LABEL_UNASSING, ['label' => $label]); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_LABEL_UNASSING, ['label' => $label]);
$this->eventDispatcher->dispatch( $this->eventDispatcher->dispatch(
'\OCA\Deck\Card::onUpdate', new GenericEvent(null, ['id' => $cardId, 'card' => $card]) '\OCA\Deck\Card::onUpdate', new FTSEvent(null, ['id' => $cardId, 'card' => $card])
); );
} }
/**
* @param $cardId
* @param $userId
* @return bool|null|\OCP\AppFramework\Db\Entity
* @throws BadRequestException
* @throws \OCA\Deck\NoPermissionException
* @throws \OCP\AppFramework\Db\DoesNotExistException
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
*/
public function assignUser($cardId, $userId) {
if (is_numeric($cardId) === false) {
throw new BadRequestException('card id must be a number');
}
if ($userId === false || $userId === null) {
throw new BadRequestException('user id must be provided');
}
$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT);
$assignments = $this->assignedUsersMapper->find($cardId);
foreach ($assignments as $assignment) {
if ($assignment->getParticipant() === $userId) {
throw new BadRequestException('The user is already assigned to the card');
}
}
$card = $this->cardMapper->find($cardId);
$boardId = $this->cardMapper->findBoardId($cardId);
$boardUsers = array_keys($this->permissionService->findUsers($boardId, true));
if (!in_array($userId, $boardUsers)) {
throw new BadRequestException('The user is not part of the board');
}
if ($userId !== $this->currentUser) {
/* Notifyuser about the card assignment */
$this->notificationHelper->sendCardAssigned($card, $userId);
}
$assignment = new AssignedUsers();
$assignment->setCardId($cardId);
$assignment->setParticipant($userId);
$assignment = $this->assignedUsersMapper->insert($assignment);
$this->changeHelper->cardChanged($cardId, false);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_USER_ASSIGN, ['assigneduser' => $userId]);
$this->eventDispatcher->dispatch(
'\OCA\Deck\Card::onUpdate', new GenericEvent(null, ['id' => $cardId, 'card' => $card])
);
return $assignment;
}
/**
* @param $cardId
* @param $userId
* @return \OCP\AppFramework\Db\Entity
* @throws BadRequestException
* @throws NotFoundException
* @throws \OCA\Deck\NoPermissionException
* @throws \OCP\AppFramework\Db\DoesNotExistException
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
*/
public function unassignUser($cardId, $userId) {
$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT);
if (is_numeric($cardId) === false) {
throw new BadRequestException('card id must be a number');
}
if ($userId === false || $userId === null) {
throw new BadRequestException('user must be provided');
}
$assignments = $this->assignedUsersMapper->find($cardId);
foreach ($assignments as $assignment) {
if ($assignment->getParticipant() === $userId) {
$assignment = $this->assignedUsersMapper->delete($assignment);
$card = $this->cardMapper->find($cardId);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_USER_UNASSIGN, ['assigneduser' => $userId]);
$this->changeHelper->cardChanged($cardId, false);
$this->eventDispatcher->dispatch(
'\OCA\Deck\Card::onUpdate', new GenericEvent(null, ['id' => $cardId, 'card' => $card])
);
return $assignment;
}
}
throw new NotFoundException('No assignment for ' . $userId . 'found.');
}
} }

View File

@@ -37,6 +37,7 @@ use OCA\Deck\Db\Card;
use OCA\Deck\Db\CardMapper; use OCA\Deck\Db\CardMapper;
use OCA\Deck\Db\Stack; use OCA\Deck\Db\Stack;
use OCA\Deck\Db\StackMapper; use OCA\Deck\Db\StackMapper;
use OCA\Deck\Event\FTSEvent;
use OCA\Deck\Provider\DeckProvider; use OCA\Deck\Provider\DeckProvider;
use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException; use OCP\AppFramework\Db\MultipleObjectsReturnedException;
@@ -45,7 +46,6 @@ use OCP\FullTextSearch\IFullTextSearchManager;
use OCP\FullTextSearch\Model\IDocumentAccess; use OCP\FullTextSearch\Model\IDocumentAccess;
use OCP\FullTextSearch\Model\IIndex; use OCP\FullTextSearch\Model\IIndex;
use OCP\FullTextSearch\Model\IIndexDocument; use OCP\FullTextSearch\Model\IIndexDocument;
use Symfony\Component\EventDispatcher\GenericEvent;
/** /**
@@ -90,9 +90,9 @@ class FullTextSearchService {
/** /**
* @param GenericEvent $e * @param FTSEvent $e
*/ */
public function onCardCreated(GenericEvent $e) { public function onCardCreated(FTSEvent $e) {
$cardId = $e->getArgument('id'); $cardId = $e->getArgument('id');
$userId = $e->getArgument('userId'); $userId = $e->getArgument('userId');
@@ -106,9 +106,9 @@ class FullTextSearchService {
/** /**
* @param GenericEvent $e * @param FTSEvent $e
*/ */
public function onCardUpdated(GenericEvent $e) { public function onCardUpdated(FTSEvent $e) {
$cardId = $e->getArgument('id'); $cardId = $e->getArgument('id');
try { try {
@@ -121,9 +121,9 @@ class FullTextSearchService {
/** /**
* @param GenericEvent $e * @param FTSEvent $e
*/ */
public function onCardDeleted(GenericEvent $e) { public function onCardDeleted(FTSEvent $e) {
$cardId = $e->getArgument('id'); $cardId = $e->getArgument('id');
try { try {
@@ -136,9 +136,9 @@ class FullTextSearchService {
/** /**
* @param GenericEvent $e * @param FTSEvent $e
*/ */
public function onBoardShares(GenericEvent $e) { public function onBoardShares(FTSEvent $e) {
$boardId = (int)$e->getArgument('boardId'); $boardId = (int)$e->getArgument('boardId');
$cards = array_map( $cards = array_map(