Add backend for assigning groups to cards
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
@@ -64,7 +64,7 @@ return [
|
||||
['name' => 'card#assignLabel', 'url' => '/cards/{cardId}/label/{labelId}', 'verb' => 'POST'],
|
||||
['name' => 'card#removeLabel', 'url' => '/cards/{cardId}/label/{labelId}', 'verb' => 'DELETE'],
|
||||
['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#create', 'url' => '/cards/{cardId}/attachment', 'verb' => 'POST'],
|
||||
|
||||
@@ -43,6 +43,8 @@ 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;
|
||||
@@ -217,34 +219,35 @@ class Application extends App {
|
||||
return;
|
||||
}
|
||||
|
||||
$eventDispatcher = $this->server->getEventDispatcher();
|
||||
/** @var IEventDispatcher $eventDispatcher */
|
||||
$eventDispatcher = $this->server->query(IEventDispatcher::class);
|
||||
$eventDispatcher->addListener(
|
||||
'\OCA\Deck\Card::onCreate', function(GenericEvent $e) {
|
||||
'\OCA\Deck\Card::onCreate', function(Event $e) {
|
||||
$this->fullTextSearchService->onCardCreated($e);
|
||||
}
|
||||
);
|
||||
$eventDispatcher->addListener(
|
||||
'\OCA\Deck\Card::onUpdate', function(GenericEvent $e) {
|
||||
'\OCA\Deck\Card::onUpdate', function(Event $e) {
|
||||
$this->fullTextSearchService->onCardUpdated($e);
|
||||
}
|
||||
);
|
||||
$eventDispatcher->addListener(
|
||||
'\OCA\Deck\Card::onDelete', function(GenericEvent $e) {
|
||||
'\OCA\Deck\Card::onDelete', function(Event $e) {
|
||||
$this->fullTextSearchService->onCardDeleted($e);
|
||||
}
|
||||
);
|
||||
$eventDispatcher->addListener(
|
||||
'\OCA\Deck\Board::onShareNew', function(GenericEvent $e) {
|
||||
'\OCA\Deck\Board::onShareNew', function(Event $e) {
|
||||
$this->fullTextSearchService->onBoardShares($e);
|
||||
}
|
||||
);
|
||||
$eventDispatcher->addListener(
|
||||
'\OCA\Deck\Board::onShareEdit', function(GenericEvent $e) {
|
||||
'\OCA\Deck\Board::onShareEdit', function(Event $e) {
|
||||
$this->fullTextSearchService->onBoardShares($e);
|
||||
}
|
||||
);
|
||||
$eventDispatcher->addListener(
|
||||
'\OCA\Deck\Board::onShareDelete', function(GenericEvent $e) {
|
||||
'\OCA\Deck\Board::onShareDelete', function(Event $e) {
|
||||
$this->fullTextSearchService->onBoardShares($e);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
namespace OCA\Deck\Controller;
|
||||
|
||||
use OCA\Deck\Service\AssignmentService;
|
||||
use OCP\AppFramework\ApiController;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
@@ -39,6 +40,7 @@
|
||||
class CardApiController extends ApiController {
|
||||
private $cardService;
|
||||
private $userId;
|
||||
private $assignmentService;
|
||||
|
||||
/**
|
||||
* @param string $appName
|
||||
@@ -46,10 +48,11 @@ class CardApiController extends ApiController {
|
||||
* @param CardService $cardService
|
||||
* @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);
|
||||
$this->cardService = $cardService;
|
||||
$this->userId = $userId;
|
||||
$this->assignmentService = $assignmentService;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,10 +138,10 @@ class CardApiController extends ApiController {
|
||||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* Unassign a user from a card
|
||||
* Assign a user to a card
|
||||
*/
|
||||
public function unassignUser($userId) {
|
||||
$card = $this->cardService->unassignUser($this->request->getParam('cardId'), $userId);
|
||||
public function assignUser($cardId, $userId, $type = 0) {
|
||||
$card = $this->assignmentService->assignUser($cardId, $userId, $type);
|
||||
return new DataResponse($card, HTTP::STATUS_OK);
|
||||
}
|
||||
|
||||
@@ -147,10 +150,10 @@ class CardApiController extends ApiController {
|
||||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* Assign a user to a card
|
||||
* Unassign a user from a card
|
||||
*/
|
||||
public function assignUser($userId) {
|
||||
$card = $this->cardService->assignUser($this->request->getParam('cardId'), $userId);;
|
||||
public function unassignUser($cardId, $userId, $type = 0) {
|
||||
$card = $this->assignmentService->unassignUser($cardId, $userId, $type);
|
||||
return new DataResponse($card, HTTP::STATUS_OK);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,24 +5,25 @@
|
||||
* @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\Controller;
|
||||
|
||||
use OCA\Deck\Service\AssignmentService;
|
||||
use OCA\Deck\Service\CardService;
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\Controller;
|
||||
@@ -31,11 +32,13 @@ class CardController extends Controller {
|
||||
|
||||
private $userId;
|
||||
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);
|
||||
$this->userId = $userId;
|
||||
$this->cardService = $cardService;
|
||||
$this->assignmentService = $assignmentService;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,15 +156,15 @@ class CardController extends Controller {
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function assignUser($cardId, $userId) {
|
||||
return $this->cardService->assignUser($cardId, $userId);
|
||||
public function assignUser($cardId, $userId, $type = 0) {
|
||||
return $this->assignmentService->assignUser($cardId, $userId, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function unassignUser($cardId, $userId) {
|
||||
return $this->cardService->unassignUser($cardId, $userId);
|
||||
public function unassignUser($cardId, $userId, $type = 0) {
|
||||
return $this->assignmentService->unassignUser($cardId, $userId, $type);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -30,10 +30,16 @@ class AssignedUsers extends RelationalEntity implements JsonSerializable {
|
||||
public $id;
|
||||
protected $participant;
|
||||
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() {
|
||||
$this->addType('id', 'integer');
|
||||
$this->addType('cardId', 'integer');
|
||||
$this->addType('type', 'integer');
|
||||
$this->addResolvable('participant');
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace OCA\Deck\Db;
|
||||
|
||||
use OCP\AppFramework\Db\Entity;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IUserManager;
|
||||
|
||||
|
||||
@@ -33,11 +34,16 @@ class AssignedUsersMapper extends DeckMapper implements IPermissionMapper {
|
||||
|
||||
private $cardMapper;
|
||||
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);
|
||||
$this->cardMapper = $cardMapper;
|
||||
$this->userManager = $userManager;
|
||||
$this->groupManager = $groupManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,8 +84,8 @@ class AssignedUsersMapper extends DeckMapper implements IPermissionMapper {
|
||||
* @return null|Entity
|
||||
*/
|
||||
public function insert(Entity $entity) {
|
||||
$user = $this->userManager->get($entity->getParticipant());
|
||||
if ($user !== null) {
|
||||
$origin = $this->getOrigin($entity);
|
||||
if ($origin !== null) {
|
||||
/** @var AssignedUsers $assignment */
|
||||
$assignment = parent::insert($entity);
|
||||
$this->mapParticipant($assignment);
|
||||
@@ -89,15 +95,26 @@ class AssignedUsersMapper extends DeckMapper implements IPermissionMapper {
|
||||
}
|
||||
|
||||
public function mapParticipant(AssignedUsers &$assignment) {
|
||||
$userManager = $this->userManager;
|
||||
$assignment->resolveRelation('participant', function() use (&$userManager, &$assignment) {
|
||||
$user = $userManager->get($assignment->getParticipant());
|
||||
if ($user !== null) {
|
||||
return new User($user);
|
||||
}
|
||||
return null;
|
||||
$self = $this;
|
||||
$assignment->resolveRelation('participant', function() use (&$self, &$assignment) {
|
||||
return $self->getOrigin($assignment);
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,7 +232,10 @@ class BoardMapper extends DeckMapper implements IPermissionMapper {
|
||||
\OC::$server->getLogger()->debug('Group ' . $acl->getId() . ' not found when mapping acl ' . $acl->getParticipant());
|
||||
return null;
|
||||
}
|
||||
if ($acl->getType() === Acl::PERMISSION_TYPE_CIRCLE && $this->circlesEnabled) {
|
||||
if ($acl->getType() === Acl::PERMISSION_TYPE_CIRCLE) {
|
||||
if (!$this->circlesEnabled) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
$circle = \OCA\Circles\Api\v1\Circles::detailsCircle($acl->getParticipant(), true);
|
||||
if ($circle) {
|
||||
|
||||
54
lib/Migration/Version1000Date20200308073933.php
Normal file
54
lib/Migration/Version1000Date20200308073933.php
Normal 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) {
|
||||
}
|
||||
}
|
||||
201
lib/Service/AssignmentService.php
Normal file
201
lib/Service/AssignmentService.php
Normal 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.');
|
||||
}
|
||||
}
|
||||
@@ -35,13 +35,17 @@ use OCA\Deck\Db\CardMapper;
|
||||
use OCA\Deck\Db\Acl;
|
||||
use OCA\Deck\Db\ChangeHelper;
|
||||
use OCA\Deck\Db\StackMapper;
|
||||
use OCA\Deck\Event\FTSEvent;
|
||||
use OCA\Deck\Notification\NotificationHelper;
|
||||
use OCA\Deck\Db\BoardMapper;
|
||||
use OCA\Deck\Db\LabelMapper;
|
||||
use OCA\Deck\NotFoundException;
|
||||
use OCA\Deck\StatusException;
|
||||
use OCA\Deck\BadRequestException;
|
||||
use OCP\Activity\IEvent;
|
||||
use OCP\Comments\ICommentsManager;
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\IUserManager;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||
@@ -61,7 +65,6 @@ class CardService {
|
||||
private $activityManager;
|
||||
private $commentsManager;
|
||||
private $changeHelper;
|
||||
/** @var EventDispatcherInterface */
|
||||
private $eventDispatcher;
|
||||
private $userManager;
|
||||
|
||||
@@ -79,7 +82,7 @@ class CardService {
|
||||
ICommentsManager $commentsManager,
|
||||
IUserManager $userManager,
|
||||
ChangeHelper $changeHelper,
|
||||
EventDispatcherInterface $eventDispatcher,
|
||||
IEventDispatcher $eventDispatcher,
|
||||
$userId
|
||||
) {
|
||||
$this->cardMapper = $cardMapper;
|
||||
@@ -197,7 +200,7 @@ class CardService {
|
||||
|
||||
$this->eventDispatcher->dispatch(
|
||||
'\OCA\Deck\Card::onCreate',
|
||||
new GenericEvent(
|
||||
new FTSEvent(
|
||||
null, ['id' => $card->getId(), 'card' => $card, 'userId' => $owner, 'stackId' => $stackId]
|
||||
)
|
||||
);
|
||||
@@ -231,7 +234,7 @@ class CardService {
|
||||
$this->changeHelper->cardChanged($card->getId(), false);
|
||||
|
||||
$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;
|
||||
@@ -327,7 +330,7 @@ class CardService {
|
||||
$this->changeHelper->cardChanged($card->getId(), true);
|
||||
|
||||
$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;
|
||||
@@ -366,7 +369,7 @@ class CardService {
|
||||
$update = $this->cardMapper->update($card);
|
||||
|
||||
$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;
|
||||
@@ -462,7 +465,7 @@ class CardService {
|
||||
$this->changeHelper->cardChanged($id, false);
|
||||
|
||||
$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;
|
||||
@@ -494,7 +497,7 @@ class CardService {
|
||||
$this->changeHelper->cardChanged($id, false);
|
||||
|
||||
$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;
|
||||
@@ -533,7 +536,7 @@ class CardService {
|
||||
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_LABEL_ASSIGN, ['label' => $label]);
|
||||
|
||||
$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->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.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ use OCA\Deck\Db\Card;
|
||||
use OCA\Deck\Db\CardMapper;
|
||||
use OCA\Deck\Db\Stack;
|
||||
use OCA\Deck\Db\StackMapper;
|
||||
use OCA\Deck\Event\FTSEvent;
|
||||
use OCA\Deck\Provider\DeckProvider;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
||||
@@ -45,7 +46,6 @@ use OCP\FullTextSearch\IFullTextSearchManager;
|
||||
use OCP\FullTextSearch\Model\IDocumentAccess;
|
||||
use OCP\FullTextSearch\Model\IIndex;
|
||||
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');
|
||||
$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');
|
||||
|
||||
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');
|
||||
|
||||
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');
|
||||
|
||||
$cards = array_map(
|
||||
|
||||
Reference in New Issue
Block a user