Merge pull request #1629 from nextcloud/enh/assign-groups
Assign groups/circles to cards
This commit is contained in:
@@ -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'],
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -24,13 +24,15 @@
|
|||||||
namespace OCA\Deck\Db;
|
namespace OCA\Deck\Db;
|
||||||
|
|
||||||
|
|
||||||
|
use OCP\Share\IShare;
|
||||||
|
|
||||||
class Circle extends RelationalObject {
|
class Circle extends RelationalObject {
|
||||||
|
|
||||||
/** @var \OCA\Circles\Model\Circle */
|
/** @var \OCA\Circles\Model\Circle */
|
||||||
protected $object;
|
protected $object;
|
||||||
|
|
||||||
public function __construct(\OCA\Circles\Model\Circle $circle) {
|
public function __construct(\OCA\Circles\Model\Circle $circle) {
|
||||||
$primaryKey = $circle->getUniqueId();
|
$primaryKey = IShare::TYPE_CIRCLE . ':' . $circle->getUniqueId();
|
||||||
parent::__construct($primaryKey, $circle);
|
parent::__construct($primaryKey, $circle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,4 +44,4 @@ class Circle extends RelationalObject {
|
|||||||
'circleOwner' => $this->object->getOwner()
|
'circleOwner' => $this->object->getOwner()
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,11 +24,12 @@
|
|||||||
namespace OCA\Deck\Db;
|
namespace OCA\Deck\Db;
|
||||||
|
|
||||||
use OCP\IGroup;
|
use OCP\IGroup;
|
||||||
|
use OCP\Share\IShare;
|
||||||
|
|
||||||
class Group extends RelationalObject {
|
class Group extends RelationalObject {
|
||||||
|
|
||||||
public function __construct(IGroup $group) {
|
public function __construct(IGroup $group) {
|
||||||
$primaryKey = $group->getGID();
|
$primaryKey = IShare::TYPE_GROUP . ':' . $group->getGID();
|
||||||
parent::__construct($primaryKey, $group);
|
parent::__construct($primaryKey, $group);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,4 +39,4 @@ class Group extends RelationalObject {
|
|||||||
'displayname' => $this->object->getDisplayName()
|
'displayname' => $this->object->getDisplayName()
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,11 +24,12 @@
|
|||||||
namespace OCA\Deck\Db;
|
namespace OCA\Deck\Db;
|
||||||
|
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
|
use OCP\Share\IShare;
|
||||||
|
|
||||||
class User extends RelationalObject {
|
class User extends RelationalObject {
|
||||||
|
|
||||||
public function __construct(IUser $user) {
|
public function __construct(IUser $user) {
|
||||||
$primaryKey = $user->getUID();
|
$primaryKey = IShare::TYPE_USER . ':' . $user->getUID();
|
||||||
parent::__construct($primaryKey, $user);
|
parent::__construct($primaryKey, $user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,4 +47,4 @@ class User extends RelationalObject {
|
|||||||
public function getDisplayName() {
|
public function getDisplayName() {
|
||||||
return $this->object->getDisplayName();
|
return $this->object->getDisplayName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
55
lib/Event/FTSEvent.php
Normal file
55
lib/Event/FTSEvent.php
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<?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\Event;
|
||||||
|
|
||||||
|
|
||||||
|
use OCP\EventDispatcher\Event;
|
||||||
|
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a class to keep compatibility for currently used events in full text search integration
|
||||||
|
*/
|
||||||
|
class FTSEvent extends Event {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $arguments;
|
||||||
|
|
||||||
|
public function __construct($subject, $arguments = []) {
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->arguments = $arguments;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getArgument($key)
|
||||||
|
{
|
||||||
|
if ($this->hasArgument($key)) {
|
||||||
|
return $this->arguments[$key];
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new \InvalidArgumentException(sprintf('Argument "%s" not found.', $key));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
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) {
|
||||||
|
}
|
||||||
|
}
|
||||||
203
lib/Service/AssignmentService.php
Normal file
203
lib/Service/AssignmentService.php
Normal file
@@ -0,0 +1,203 @@
|
|||||||
|
<?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,
|
||||||
|
$userId
|
||||||
|
) {
|
||||||
|
$this->permissionService = $permissionService;
|
||||||
|
$this->cardMapper = $cardMapper;
|
||||||
|
$this->assignedUsersMapper = $assignedUsersMapper;
|
||||||
|
$this->aclMapper = $aclMapper;
|
||||||
|
$this->notificationHelper = $notificationHelper;
|
||||||
|
$this->changeHelper = $changeHelper;
|
||||||
|
$this->activityManager = $activityManager;
|
||||||
|
$this->eventDispatcher = $eventDispatcher;
|
||||||
|
$this->currentUser = $userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $cardId
|
||||||
|
* @param $userId
|
||||||
|
* @return bool|null|Entity
|
||||||
|
* @throws BadRequestException
|
||||||
|
* @throws NoPermissionException
|
||||||
|
* @throws MultipleObjectsReturnedException
|
||||||
|
* @throws DoesNotExistException
|
||||||
|
*/
|
||||||
|
public function assignUser($cardId, $userId, int $type = AssignedUsers::TYPE_USER) {
|
||||||
|
|
||||||
|
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 && $assignment->getType() === $type) {
|
||||||
|
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\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.');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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(
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
<li v-for="acl in board.acl" :key="acl.participant.uid">
|
<li v-for="acl in board.acl" :key="acl.participant.primaryKey">
|
||||||
<Avatar v-if="acl.type===0" :user="acl.participant.uid" />
|
<Avatar v-if="acl.type===0" :user="acl.participant.uid" />
|
||||||
<div v-if="acl.type===1" class="avatardiv icon icon-group" />
|
<div v-if="acl.type===1" class="avatardiv icon icon-group" />
|
||||||
<div v-if="acl.type===7" class="avatardiv icon icon-circles" />
|
<div v-if="acl.type===7" class="avatardiv icon icon-circles" />
|
||||||
@@ -33,10 +33,10 @@
|
|||||||
<span v-if="acl.type===7">{{ t('deck', '(Circle)') }}</span>
|
<span v-if="acl.type===7">{{ t('deck', '(Circle)') }}</span>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<ActionCheckbox v-if="!isCurrentUser(acl.participant.uid) && (canManage || (canEdit && canShare))" :checked="acl.permissionEdit" @change="clickEditAcl(acl)">
|
<ActionCheckbox v-if="!(isCurrentUser(acl.participant.uid) && acl.type === 0) && (canManage || (canEdit && canShare))" :checked="acl.permissionEdit" @change="clickEditAcl(acl)">
|
||||||
{{ t('deck', 'Can edit') }}
|
{{ t('deck', 'Can edit') }}
|
||||||
</ActionCheckbox>
|
</ActionCheckbox>
|
||||||
<Actions v-if="!isCurrentUser(acl.participant.uid)" :force-menu="true">
|
<Actions v-if="!(isCurrentUser(acl.participant.uid) && acl.type === 0)" :force-menu="true">
|
||||||
<ActionCheckbox v-if="canManage || canShare" :checked="acl.permissionShare" @change="clickShareAcl(acl)">
|
<ActionCheckbox v-if="canManage || canShare" :checked="acl.permissionShare" @change="clickShareAcl(acl)">
|
||||||
{{ t('deck', 'Can share') }}
|
{{ t('deck', 'Can share') }}
|
||||||
</ActionCheckbox>
|
</ActionCheckbox>
|
||||||
@@ -60,7 +60,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import { Avatar, Multiselect, Actions, ActionButton, ActionCheckbox } from '@nextcloud/vue'
|
import { Avatar, Multiselect, Actions, ActionButton, ActionCheckbox } from '@nextcloud/vue'
|
||||||
import { CollectionList } from 'nextcloud-vue-collections'
|
import { CollectionList } from 'nextcloud-vue-collections'
|
||||||
import { mapGetters } from 'vuex'
|
import { mapGetters, mapState } from 'vuex'
|
||||||
import { getCurrentUser } from '@nextcloud/auth'
|
import { getCurrentUser } from '@nextcloud/auth'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -87,8 +87,10 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapGetters([
|
...mapState([
|
||||||
'sharees',
|
'sharees',
|
||||||
|
]),
|
||||||
|
...mapGetters([
|
||||||
'canEdit',
|
'canEdit',
|
||||||
'canManage',
|
'canManage',
|
||||||
'canShare',
|
'canShare',
|
||||||
|
|||||||
@@ -61,23 +61,36 @@
|
|||||||
|
|
||||||
<div class="section-wrapper">
|
<div class="section-wrapper">
|
||||||
<div v-tooltip="t('deck', 'Assign to users')" class="section-label icon-group">
|
<div v-tooltip="t('deck', 'Assign to users')" class="section-label icon-group">
|
||||||
<span class="hidden-visually">{{ t('deck', 'Assign to users') }}</span>
|
<span class="hidden-visually">{{ t('deck', 'Assign to users/groups/circles') }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="section-details">
|
<div class="section-details">
|
||||||
<Multiselect v-model="assignedUsers"
|
<Multiselect v-if="canEdit"
|
||||||
:disabled="!canEdit"
|
v-model="assignedUsers"
|
||||||
:multiple="true"
|
:multiple="true"
|
||||||
:options="assignableUsers"
|
:options="formatedAssignables"
|
||||||
|
:user-select="true"
|
||||||
|
:auto-limit="false"
|
||||||
:placeholder="t('deck', 'Assign a user to this card…')"
|
:placeholder="t('deck', 'Assign a user to this card…')"
|
||||||
label="displayname"
|
label="displayname"
|
||||||
track-by="primaryKey"
|
track-by="primaryKey"
|
||||||
@select="assignUserToCard"
|
@select="assignUserToCard"
|
||||||
@remove="removeUserFromCard">
|
@remove="removeUserFromCard">
|
||||||
<template #option="scope">
|
<template #tag="scope">
|
||||||
<Avatar :user="scope.option.primaryKey" />
|
<div class="avatarlist--inline">
|
||||||
<span class="avatarLabel">{{ scope.option.displayname }} </span>
|
<Avatar :user="scope.option.uid"
|
||||||
|
:display-name="scope.option.displayname"
|
||||||
|
:size="24"
|
||||||
|
:disable-menu="true" />
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</Multiselect>
|
</Multiselect>
|
||||||
|
<div v-else class="avatar-list--readonly">
|
||||||
|
<Avatar v-for="option in currentCard.assignedUsers"
|
||||||
|
:key="option.primaryKey"
|
||||||
|
:user="option.participant.uid"
|
||||||
|
:display-name="option.participant.displayname"
|
||||||
|
:size="32" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -86,14 +99,11 @@
|
|||||||
<span class="hidden-visually">{{ t('deck', 'Due date') }}</span>
|
<span class="hidden-visually">{{ t('deck', 'Due date') }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="section-details">
|
<div class="section-details">
|
||||||
<DatetimePicker v-model="copiedCard.duedate"
|
<DatetimePicker v-model="duedate"
|
||||||
:placeholder="t('deck', 'Set a due date')"
|
:placeholder="t('deck', 'Set a due date')"
|
||||||
type="datetime"
|
type="datetime"
|
||||||
lang="en"
|
:disabled="saving || !canEdit"
|
||||||
:disabled="!canEdit"
|
confirm />
|
||||||
format="YYYY-MM-DD HH:mm"
|
|
||||||
confirm
|
|
||||||
@change="setDue()" />
|
|
||||||
<Actions v-if="canEdit">
|
<Actions v-if="canEdit">
|
||||||
<ActionButton v-if="copiedCard.duedate" icon="icon-delete" @click="removeDue()">
|
<ActionButton v-if="copiedCard.duedate" icon="icon-delete" @click="removeDue()">
|
||||||
{{ t('deck', 'Remove due date') }}
|
{{ t('deck', 'Remove due date') }}
|
||||||
@@ -189,11 +199,12 @@ export default {
|
|||||||
copiedCard: null,
|
copiedCard: null,
|
||||||
allLabels: null,
|
allLabels: null,
|
||||||
desc: null,
|
desc: null,
|
||||||
|
saving: false,
|
||||||
mdeConfig: {
|
mdeConfig: {
|
||||||
autoDownloadFontAwesome: false,
|
autoDownloadFontAwesome: false,
|
||||||
spellChecker: false,
|
spellChecker: false,
|
||||||
autofocus: true,
|
autofocus: true,
|
||||||
autosave: { enabled: true, uniqueId: 'unique' },
|
autosave: { enabled: false, uniqueId: 'unique' },
|
||||||
toolbar: false,
|
toolbar: false,
|
||||||
},
|
},
|
||||||
lastModifiedRelative: null,
|
lastModifiedRelative: null,
|
||||||
@@ -205,15 +216,49 @@ export default {
|
|||||||
computed: {
|
computed: {
|
||||||
...mapState({
|
...mapState({
|
||||||
currentBoard: state => state.currentBoard,
|
currentBoard: state => state.currentBoard,
|
||||||
assignableUsers: state => state.assignableUsers,
|
|
||||||
}),
|
}),
|
||||||
...mapGetters(['canEdit']),
|
...mapGetters(['canEdit', 'assignables']),
|
||||||
currentCard() {
|
currentCard() {
|
||||||
return this.$store.getters.cardById(this.id)
|
return this.$store.getters.cardById(this.id)
|
||||||
},
|
},
|
||||||
subtitle() {
|
subtitle() {
|
||||||
return t('deck', 'Modified') + ': ' + this.lastModifiedRelative + ' ' + t('deck', 'Created') + ': ' + this.lastCreatedRemative
|
return t('deck', 'Modified') + ': ' + this.lastModifiedRelative + ' ' + t('deck', 'Created') + ': ' + this.lastCreatedRemative
|
||||||
},
|
},
|
||||||
|
formatedAssignables() {
|
||||||
|
return this.assignables.map(item => {
|
||||||
|
const assignable = {
|
||||||
|
...item,
|
||||||
|
user: item.primaryKey,
|
||||||
|
displayName: item.displayname,
|
||||||
|
icon: 'icon-user',
|
||||||
|
isNoUser: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item.type === 1) {
|
||||||
|
assignable.icon = 'icon-group'
|
||||||
|
assignable.isNoUser = true
|
||||||
|
}
|
||||||
|
if (item.type === 7) {
|
||||||
|
assignable.icon = 'icon-circles'
|
||||||
|
assignable.isNoUser = true
|
||||||
|
}
|
||||||
|
|
||||||
|
return assignable
|
||||||
|
})
|
||||||
|
},
|
||||||
|
duedate: {
|
||||||
|
get() {
|
||||||
|
return this.currentCard.duedate ? new Date(this.currentCard.duedate) : null
|
||||||
|
},
|
||||||
|
async set(val) {
|
||||||
|
this.saving = true
|
||||||
|
await this.$store.dispatch('updateCardDue', {
|
||||||
|
...this.copiedCard,
|
||||||
|
duedate: val ? (new Date(val)).toISOString() : null,
|
||||||
|
})
|
||||||
|
this.saving = false
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
'currentCard': {
|
'currentCard': {
|
||||||
@@ -235,10 +280,6 @@ export default {
|
|||||||
this.updateRelativeTimestamps()
|
this.updateRelativeTimestamps()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
'copiedCard.description': function() {
|
|
||||||
this.saveDesc()
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
setInterval(this.updateRelativeTimestamps, 10000)
|
setInterval(this.updateRelativeTimestamps, 10000)
|
||||||
@@ -267,13 +308,23 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
assignUserToCard(user) {
|
assignUserToCard(user) {
|
||||||
this.copiedCard.newUserUid = user.uid
|
this.$store.dispatch('assignCardToUser', {
|
||||||
this.$store.dispatch('assignCardToUser', this.copiedCard)
|
card: this.copiedCard,
|
||||||
|
assignee: {
|
||||||
|
userId: user.uid,
|
||||||
|
type: user.type,
|
||||||
|
},
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
removeUserFromCard(user) {
|
removeUserFromCard(user) {
|
||||||
this.copiedCard.removeUserUid = user.uid
|
this.$store.dispatch('removeUserFromCard', {
|
||||||
this.$store.dispatch('removeUserFromCard', this.copiedCard)
|
card: this.copiedCard,
|
||||||
|
assignee: {
|
||||||
|
userId: user.uid,
|
||||||
|
type: user.type,
|
||||||
|
},
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
addLabelToCard(newLabel) {
|
addLabelToCard(newLabel) {
|
||||||
@@ -376,4 +427,28 @@ export default {
|
|||||||
padding: 6px
|
padding: 6px
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.section-details::v-deep .multiselect__tags-wrap {
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.avatar-list--readonly .avatardiv {
|
||||||
|
margin-right: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.avatarlist--inline {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
margin-right: 3px;
|
||||||
|
.avatarLabel {
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.multiselect::v-deep .multiselect__tags-wrap {
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.multiselect.multiselect--active::v-deep .multiselect__tags-wrap {
|
||||||
|
z-index: 0;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<div class="comment--header">
|
<div class="comment--header">
|
||||||
<Avatar :user="card.owner.uid" />
|
<Avatar :user="currentUser.uid" />
|
||||||
<span class="has-tooltip username">
|
<span class="has-tooltip username">
|
||||||
{{ card.owner.displayname }}
|
{{ currentUser.displayName }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -54,6 +54,7 @@ export default {
|
|||||||
return {
|
return {
|
||||||
newComment: '',
|
newComment: '',
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
|
currentUser: OC.getCurrentUser(),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
<At ref="at"
|
<At ref="at"
|
||||||
v-model="commentText"
|
v-model="commentText"
|
||||||
:members="members"
|
:members="members"
|
||||||
name-key="primaryKey"
|
name-key="uid"
|
||||||
:tab-select="true">
|
:tab-select="true">
|
||||||
<template v-slot:item="s">
|
<template v-slot:item="s">
|
||||||
<Avatar class="atwho-li--avatar" :user="s.item.uid" :size="24" />
|
<Avatar class="atwho-li--avatar" :user="s.item.uid" :size="24" />
|
||||||
@@ -34,9 +34,9 @@
|
|||||||
</template>
|
</template>
|
||||||
<template v-slot:embeddedItem="scope">
|
<template v-slot:embeddedItem="scope">
|
||||||
<span>
|
<span>
|
||||||
<UserBubble v-if="scope.current.primaryKey"
|
<UserBubble v-if="scope.current.uid"
|
||||||
:data-mention-id="scope.current.primaryKey"
|
:data-mention-id="scope.current.uid"
|
||||||
:user="scope.current.primaryKey"
|
:user="scope.current.uid"
|
||||||
:display-name="scope.current.displayname" />
|
:display-name="scope.current.displayname" />
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -22,13 +22,31 @@
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="avatars">
|
<div class="avatars">
|
||||||
<div class="avatar-list" @click.stop="popoverVisible=!popoverVisible">
|
<div class="avatar-list" @click.stop="togglePopover">
|
||||||
<div v-if="popover.length > 0" class="avatardiv icon-more" />
|
<div v-if="popover.length > 0">
|
||||||
<Avatar v-for="user in firstUsers"
|
<div class="avatardiv icon-more" />
|
||||||
:key="user.id"
|
</div>
|
||||||
:url="avatarUrl(user)"
|
<div v-for="user in firstUsers" :key="user.id">
|
||||||
:disable-tooltip="true"
|
<Avatar v-if="user.type === 0"
|
||||||
:size="32" />
|
:user="user.participant.uid"
|
||||||
|
:display-name="user.participant.displayname"
|
||||||
|
:disable-menu="true"
|
||||||
|
:size="32" />
|
||||||
|
<Avatar v-if="user.type === 1"
|
||||||
|
:user="user.participant.primaryKey"
|
||||||
|
:display-name="user.participant.displayname"
|
||||||
|
:tooltip-message="user.participant.displayname + ' ' + t('deck', '(group)')"
|
||||||
|
:is-no-user="true"
|
||||||
|
:disable-="true"
|
||||||
|
:size="32" />
|
||||||
|
<Avatar v-if="user.type === 7"
|
||||||
|
:user="user.participant.primaryKey"
|
||||||
|
:display-name="user.participant.displayname"
|
||||||
|
:tooltip-message="user.participant.displayname + ' ' + t('deck', '(circle)')"
|
||||||
|
:is-no-user="true"
|
||||||
|
:disable-="true"
|
||||||
|
:size="32" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-show="popoverVisible" class="popovermenu menu-right">
|
<div v-show="popoverVisible" class="popovermenu menu-right">
|
||||||
@@ -69,8 +87,11 @@ export default {
|
|||||||
return this.users.slice(0, 3)
|
return this.users.slice(0, 3)
|
||||||
},
|
},
|
||||||
avatarUrl() {
|
avatarUrl() {
|
||||||
return (session) => {
|
return (assignable) => {
|
||||||
const user = session.participant.displayname
|
if (assignable.type === 1) {
|
||||||
|
return 'icon-group'
|
||||||
|
}
|
||||||
|
const user = assignable.participant.uid
|
||||||
const size = 32
|
const size = 32
|
||||||
const avatarUrl = OC.generateUrl('/avatar/{user}/{size}',
|
const avatarUrl = OC.generateUrl('/avatar/{user}/{size}',
|
||||||
{
|
{
|
||||||
@@ -81,7 +102,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
popover() {
|
popover() {
|
||||||
if (!this.users || this.users.length < 0) {
|
if (!this.users || this.users.length === 0) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
return [
|
return [
|
||||||
@@ -89,19 +110,25 @@ export default {
|
|||||||
return {
|
return {
|
||||||
href: '#',
|
href: '#',
|
||||||
icon: this.avatarUrl(session),
|
icon: this.avatarUrl(session),
|
||||||
text: session.participant.displayname,
|
text: session.participant.displayname + (session.type === 1 ? ' ' + t('deck', '(group)') : ''),
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
togglePopover() {
|
||||||
|
if (this.popover.length > 0) {
|
||||||
|
this.popoverVisible = !this.popoverVisible
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
.avatars {
|
.avatars {
|
||||||
margin: 0;
|
margin-top: 5px;
|
||||||
position: relative;
|
position: relative;
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
/deep/ .popovermenu {
|
/deep/ .popovermenu {
|
||||||
@@ -118,14 +145,12 @@ export default {
|
|||||||
.avatar-list {
|
.avatar-list {
|
||||||
float: right;
|
float: right;
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
|
padding-right: 8px;
|
||||||
flex-direction: row-reverse;
|
flex-direction: row-reverse;
|
||||||
.avatardiv,
|
.avatardiv,
|
||||||
/deep/ .avatardiv {
|
/deep/ .avatardiv {
|
||||||
width: 36px;
|
width: 36px;
|
||||||
height: 36px;
|
height: 36px;
|
||||||
margin-right: -8px;
|
|
||||||
border: 2px solid var(--color-main-background);
|
|
||||||
background-color: var(--color-main-background) !important;
|
|
||||||
box-sizing: content-box !important;
|
box-sizing: content-box !important;
|
||||||
&.icon-more {
|
&.icon-more {
|
||||||
width: 32px;
|
width: 32px;
|
||||||
@@ -134,6 +159,13 @@ export default {
|
|||||||
background-color: var(--color-background-dark) !important;
|
background-color: var(--color-background-dark) !important;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
& {
|
||||||
|
margin-right: -12px;
|
||||||
|
transition: margin-right 0.2s ease-in-out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
&:hover div:nth-child(n+2) /deep/ .avatardiv {
|
||||||
|
margin-right: 1px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.popovermenu {
|
.popovermenu {
|
||||||
|
|||||||
@@ -97,19 +97,21 @@ export default {
|
|||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.badges {
|
.badges {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
|
|
||||||
.icon {
|
.icon {
|
||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
padding: 12px 14px;
|
padding: 12px 14px;
|
||||||
margin-right: 10px;
|
padding-right: 4px;
|
||||||
|
margin-right: 5px;
|
||||||
background-position: left;
|
background-position: left;
|
||||||
background-size: 16px;
|
background-size: 16px;
|
||||||
span {
|
span {
|
||||||
margin-left: 18px;
|
margin-left: 18px;
|
||||||
}
|
}
|
||||||
&.icon-filetype-text {
|
&.icon-edit {
|
||||||
opacity: 1;
|
opacity: 0.5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -124,6 +126,7 @@ export default {
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
opacity: .5;
|
opacity: .5;
|
||||||
|
flex-shrink: 1;
|
||||||
|
|
||||||
.icon {
|
.icon {
|
||||||
background-size: contain;
|
background-size: contain;
|
||||||
@@ -145,6 +148,9 @@ export default {
|
|||||||
|
|
||||||
span {
|
span {
|
||||||
margin-left: 20px;
|
margin-left: 20px;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -196,8 +196,13 @@ export default {
|
|||||||
},
|
},
|
||||||
assignCardToMe() {
|
assignCardToMe() {
|
||||||
this.copiedCard = Object.assign({}, this.card)
|
this.copiedCard = Object.assign({}, this.card)
|
||||||
this.copiedCard.newUserUid = this.card.owner.uid
|
this.$store.dispatch('assignCardToUser', {
|
||||||
this.$store.dispatch('assignCardToUser', this.copiedCard)
|
card: this.copiedCard,
|
||||||
|
assignee: {
|
||||||
|
userId: OC.getCurrentUser().uid,
|
||||||
|
type: 0,
|
||||||
|
},
|
||||||
|
})
|
||||||
},
|
},
|
||||||
async loadStacksFromBoard(board) {
|
async loadStacksFromBoard(board) {
|
||||||
try {
|
try {
|
||||||
@@ -234,6 +239,7 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.card {
|
.card {
|
||||||
|
transition: box-shadow 0.1s ease-in-out;
|
||||||
box-shadow: 0 0 2px 0 var(--color-box-shadow);
|
box-shadow: 0 0 2px 0 var(--color-box-shadow);
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
font-size: 100%;
|
font-size: 100%;
|
||||||
|
|||||||
@@ -105,8 +105,8 @@ export class CardApi {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
assignUser(card) {
|
assignUser(cardId, id, type) {
|
||||||
return axios.post(this.url(`/cards/${card.id}/assign`), { userId: card.newUserUid })
|
return axios.post(this.url(`/cards/${cardId}/assign`), { userId: id, type: type })
|
||||||
.then(
|
.then(
|
||||||
(response) => {
|
(response) => {
|
||||||
return Promise.resolve(response.data)
|
return Promise.resolve(response.data)
|
||||||
@@ -120,8 +120,8 @@ export class CardApi {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
removeUser(card) {
|
removeUser(cardId, id, type) {
|
||||||
return axios.delete(this.url(`/cards/${card.id}/assign/${card.removeUserUid}`))
|
return axios.put(this.url(`/cards/${cardId}/unassign`), { userId: id, type: type })
|
||||||
.then(
|
.then(
|
||||||
(response) => {
|
(response) => {
|
||||||
return Promise.resolve(response.data)
|
return Promise.resolve(response.data)
|
||||||
|
|||||||
@@ -198,12 +198,12 @@ export default {
|
|||||||
const updatedCard = await apiClient[call](card)
|
const updatedCard = await apiClient[call](card)
|
||||||
commit('deleteCard', updatedCard)
|
commit('deleteCard', updatedCard)
|
||||||
},
|
},
|
||||||
async assignCardToUser({ commit }, card) {
|
async assignCardToUser({ commit }, { card, assignee }) {
|
||||||
const user = await apiClient.assignUser(card)
|
const user = await apiClient.assignUser(card.id, assignee.userId, assignee.type)
|
||||||
commit('assignCardToUser', user)
|
commit('assignCardToUser', user)
|
||||||
},
|
},
|
||||||
async removeUserFromCard({ commit }, card) {
|
async removeUserFromCard({ commit }, { card, assignee }) {
|
||||||
const user = await apiClient.removeUser(card)
|
const user = await apiClient.removeUser(card.id, assignee.userId, assignee.type)
|
||||||
commit('removeUserFromCard', user)
|
commit('removeUserFromCard', user)
|
||||||
},
|
},
|
||||||
async addLabel({ commit }, data) {
|
async addLabel({ commit }, data) {
|
||||||
@@ -219,7 +219,7 @@ export default {
|
|||||||
commit('updateCardProperty', { property: 'description', card: updatedCard })
|
commit('updateCardProperty', { property: 'description', card: updatedCard })
|
||||||
},
|
},
|
||||||
async updateCardDue({ commit }, card) {
|
async updateCardDue({ commit }, card) {
|
||||||
const updatedCard = apiClient.updateCard(card)
|
const updatedCard = await apiClient.updateCard(card)
|
||||||
commit('updateCardProperty', { property: 'duedate', card: updatedCard })
|
commit('updateCardProperty', { property: 'duedate', card: updatedCard })
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -78,8 +78,12 @@ export default new Vuex.Store({
|
|||||||
boards: state => {
|
boards: state => {
|
||||||
return state.boards
|
return state.boards
|
||||||
},
|
},
|
||||||
sharees: state => {
|
assignables: state => {
|
||||||
return state.sharees
|
return [
|
||||||
|
...state.assignableUsers.map((user) => ({ ...user, type: 0 })),
|
||||||
|
...state.currentBoard.acl.filter((acl) => acl.type === 1 && typeof acl.participant === 'object').map((group) => ({ ...group.participant, type: 1 })),
|
||||||
|
...state.currentBoard.acl.filter((acl) => acl.type === 7 && typeof acl.participant === 'object').map((circle) => ({ ...circle.participant, type: 7 })),
|
||||||
|
]
|
||||||
},
|
},
|
||||||
noneArchivedBoards: state => {
|
noneArchivedBoards: state => {
|
||||||
return state.boards.filter(board => {
|
return state.boards.filter(board => {
|
||||||
|
|||||||
@@ -23,21 +23,22 @@
|
|||||||
|
|
||||||
namespace OCA\Deck\Db;
|
namespace OCA\Deck\Db;
|
||||||
|
|
||||||
|
use OCA\Deck\Service\AssignmentService;
|
||||||
use OCA\Deck\Service\BoardService;
|
use OCA\Deck\Service\BoardService;
|
||||||
use OCA\Deck\Service\StackService;
|
use OCA\Deck\Service\StackService;
|
||||||
use OCA\Deck\Service\CardService;
|
use OCA\Deck\Service\CardService;
|
||||||
use OCP\IDBConnection;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group DB
|
* @group DB
|
||||||
* @coversDefaultClass OCA\Deck\Db\AssignedUsersMapper
|
* @coversDefaultClass OCA\Deck\Db\AssignedUsersMapper
|
||||||
*/
|
*/
|
||||||
class AssignedUsersMapperTest extends \Test\TestCase {
|
class AssignedUsersMapperTest extends \Test\TestCase {
|
||||||
const TEST_USER1 = "test-share-user1";
|
|
||||||
const TEST_USER2 = "test-share-user2";
|
private const TEST_USER1 = 'test-share-user1';
|
||||||
const TEST_USER3 = "test-share-user3";
|
private const TEST_USER3 = 'test-share-user3';
|
||||||
const TEST_USER4 = "test-share-user4";
|
private const TEST_USER2 = 'test-share-user2';
|
||||||
const TEST_GROUP1 = "test-share-group1";
|
private const TEST_USER4 = 'test-share-user4';
|
||||||
|
private const TEST_GROUP1 = 'test-share-group1';
|
||||||
|
|
||||||
/** @var BoardService */
|
/** @var BoardService */
|
||||||
protected $boardService;
|
protected $boardService;
|
||||||
@@ -45,8 +46,10 @@ class AssignedUsersMapperTest extends \Test\TestCase {
|
|||||||
protected $cardService;
|
protected $cardService;
|
||||||
/** @var StackService */
|
/** @var StackService */
|
||||||
protected $stackService;
|
protected $stackService;
|
||||||
/** @var \OCA\Deck\Db\AssignedUsersMapper */
|
/** @var AssignedUsersMapper */
|
||||||
protected $assignedUsersMapper;
|
protected $assignedUsersMapper;
|
||||||
|
/** @var AssignmentService */
|
||||||
|
private $assignmentService;
|
||||||
|
|
||||||
public static function setUpBeforeClass(): void {
|
public static function setUpBeforeClass(): void {
|
||||||
parent::setUpBeforeClass();
|
parent::setUpBeforeClass();
|
||||||
@@ -78,10 +81,11 @@ class AssignedUsersMapperTest extends \Test\TestCase {
|
|||||||
public function setUp(): void {
|
public function setUp(): void {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
\OC::$server->getUserSession()->login(self::TEST_USER1, self::TEST_USER1);
|
\OC::$server->getUserSession()->login(self::TEST_USER1, self::TEST_USER1);
|
||||||
$this->boardService = \OC::$server->query("\OCA\Deck\Service\BoardService");
|
$this->boardService = \OC::$server->query(BoardService::class);
|
||||||
$this->stackService = \OC::$server->query("\OCA\Deck\Service\StackService");
|
$this->stackService = \OC::$server->query(StackService::class);
|
||||||
$this->cardService = \OC::$server->query("\OCA\Deck\Service\CardService");
|
$this->cardService = \OC::$server->query(CardService::class);
|
||||||
$this->assignedUsersMapper = \OC::$server->query(\OCA\Deck\Db\AssignedUsersMapper::class);
|
$this->assignmentService = \OC::$server->query(AssignmentService::class);
|
||||||
|
$this->assignedUsersMapper = \OC::$server->query(AssignedUsersMapper::class);
|
||||||
$this->createBoardWithExampleData();
|
$this->createBoardWithExampleData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,8 +111,8 @@ class AssignedUsersMapperTest extends \Test\TestCase {
|
|||||||
*/
|
*/
|
||||||
public function testFind() {
|
public function testFind() {
|
||||||
$uids = [];
|
$uids = [];
|
||||||
$this->cardService->assignUser($this->cards[0]->getId(), self::TEST_USER1);
|
$this->assignmentService->assignUser($this->cards[0]->getId(), self::TEST_USER1);
|
||||||
$this->cardService->assignUser($this->cards[0]->getId(), self::TEST_USER2);
|
$this->assignmentService->assignUser($this->cards[0]->getId(), self::TEST_USER2);
|
||||||
|
|
||||||
$assignedUsers = $this->assignedUsersMapper->find($this->cards[0]->getId());
|
$assignedUsers = $this->assignedUsersMapper->find($this->cards[0]->getId());
|
||||||
foreach ($assignedUsers as $user) {
|
foreach ($assignedUsers as $user) {
|
||||||
@@ -119,8 +123,8 @@ class AssignedUsersMapperTest extends \Test\TestCase {
|
|||||||
$this->assertArrayNotHasKey(self::TEST_USER3, $uids);
|
$this->assertArrayNotHasKey(self::TEST_USER3, $uids);
|
||||||
$this->assertArrayNotHasKey(self::TEST_USER4, $uids);
|
$this->assertArrayNotHasKey(self::TEST_USER4, $uids);
|
||||||
|
|
||||||
$this->cardService->unassignUser($this->cards[0]->getId(), self::TEST_USER1);
|
$this->assignmentService->unassignUser($this->cards[0]->getId(), self::TEST_USER1);
|
||||||
$this->cardService->unassignUser($this->cards[0]->getId(), self::TEST_USER2);
|
$this->assignmentService->unassignUser($this->cards[0]->getId(), self::TEST_USER2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -145,6 +149,7 @@ class AssignedUsersMapperTest extends \Test\TestCase {
|
|||||||
$assignment = new AssignedUsers();
|
$assignment = new AssignedUsers();
|
||||||
$assignment->setCardId($this->cards[1]->getId());
|
$assignment->setCardId($this->cards[1]->getId());
|
||||||
$assignment->setParticipant(self::TEST_USER4);
|
$assignment->setParticipant(self::TEST_USER4);
|
||||||
|
$assignment->setType(AssignedUsers::TYPE_USER);
|
||||||
$this->assignedUsersMapper->insert($assignment);
|
$this->assignedUsersMapper->insert($assignment);
|
||||||
|
|
||||||
$actual = $this->assignedUsersMapper->find($this->cards[1]->getId());
|
$actual = $this->assignedUsersMapper->find($this->cards[1]->getId());
|
||||||
@@ -160,6 +165,7 @@ class AssignedUsersMapperTest extends \Test\TestCase {
|
|||||||
$assignment = new AssignedUsers();
|
$assignment = new AssignedUsers();
|
||||||
$assignment->setCardId($this->cards[1]->getId());
|
$assignment->setCardId($this->cards[1]->getId());
|
||||||
$assignment->setParticipant('invalid-username');
|
$assignment->setParticipant('invalid-username');
|
||||||
|
$assignment->setType(AssignedUsers::TYPE_USER);
|
||||||
$actual = $this->assignedUsersMapper->insert($assignment);
|
$actual = $this->assignedUsersMapper->insert($assignment);
|
||||||
$this->assertNull($actual);
|
$this->assertNull($actual);
|
||||||
}
|
}
|
||||||
@@ -171,12 +177,14 @@ class AssignedUsersMapperTest extends \Test\TestCase {
|
|||||||
$assignment = new AssignedUsers();
|
$assignment = new AssignedUsers();
|
||||||
$assignment->setCardId($this->cards[1]->getId());
|
$assignment->setCardId($this->cards[1]->getId());
|
||||||
$assignment->setParticipant(self::TEST_USER4);
|
$assignment->setParticipant(self::TEST_USER4);
|
||||||
|
$assignment->setType(AssignedUsers::TYPE_USER);
|
||||||
$this->assignedUsersMapper->mapParticipant($assignment);
|
$this->assignedUsersMapper->mapParticipant($assignment);
|
||||||
$this->assertInstanceOf(User::class, $assignment->resolveParticipant());
|
$this->assertInstanceOf(User::class, $assignment->resolveParticipant());
|
||||||
|
|
||||||
$assignment = new AssignedUsers();
|
$assignment = new AssignedUsers();
|
||||||
$assignment->setCardId($this->cards[1]->getId());
|
$assignment->setCardId($this->cards[1]->getId());
|
||||||
$assignment->setParticipant('invalid-username');
|
$assignment->setParticipant('invalid-username');
|
||||||
|
$assignment->setType(AssignedUsers::TYPE_USER);
|
||||||
$this->assignedUsersMapper->mapParticipant($assignment);
|
$this->assignedUsersMapper->mapParticipant($assignment);
|
||||||
$this->assertEquals('invalid-username', $assignment->resolveParticipant());
|
$this->assertEquals('invalid-username', $assignment->resolveParticipant());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class GroupTest extends \Test\TestCase {
|
|||||||
$expected = [
|
$expected = [
|
||||||
'uid' => 'mygroup',
|
'uid' => 'mygroup',
|
||||||
'displayname' => 'My Group',
|
'displayname' => 'My Group',
|
||||||
'primaryKey' => 'mygroup'
|
'primaryKey' => '1:mygroup'
|
||||||
];
|
];
|
||||||
|
|
||||||
$actual = $groupRelationalObject->jsonSerialize();
|
$actual = $groupRelationalObject->jsonSerialize();
|
||||||
|
|||||||
@@ -57,8 +57,8 @@ class UserTest extends \Test\TestCase {
|
|||||||
$expected = [
|
$expected = [
|
||||||
'uid' => 'myuser',
|
'uid' => 'myuser',
|
||||||
'displayname' => 'myuser displayname',
|
'displayname' => 'myuser displayname',
|
||||||
'primaryKey' => 'myuser'
|
'primaryKey' => '0:myuser'
|
||||||
];
|
];
|
||||||
$this->assertEquals($expected, $userRelationalObject->jsonSerialize());
|
$this->assertEquals($expected, $userRelationalObject->jsonSerialize());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
236
tests/unit/Service/AssignmentServiceTest.php
Normal file
236
tests/unit/Service/AssignmentServiceTest.php
Normal file
@@ -0,0 +1,236 @@
|
|||||||
|
<?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\Service;
|
||||||
|
|
||||||
|
|
||||||
|
use OCA\Deck\Activity\ActivityManager;
|
||||||
|
use OCA\Deck\BadRequestException;
|
||||||
|
use OCA\Deck\Db\AclMapper;
|
||||||
|
use OCA\Deck\Db\AssignedUsers;
|
||||||
|
use OCA\Deck\Db\AssignedUsersMapper;
|
||||||
|
use OCA\Deck\Db\Card;
|
||||||
|
use OCA\Deck\Db\CardMapper;
|
||||||
|
use OCA\Deck\Db\ChangeHelper;
|
||||||
|
use OCA\Deck\Db\StackMapper;
|
||||||
|
use OCA\Deck\Db\BoardMapper;
|
||||||
|
use OCA\Deck\Db\LabelMapper;
|
||||||
|
use OCA\Deck\NotFoundException;
|
||||||
|
use OCA\Deck\Notification\NotificationHelper;
|
||||||
|
use OCA\Deck\StatusException;
|
||||||
|
use OCP\Activity\IEvent;
|
||||||
|
use OCP\Comments\ICommentsManager;
|
||||||
|
use OCP\EventDispatcher\ABroadcastedEvent;
|
||||||
|
use OCP\EventDispatcher\Event;
|
||||||
|
use OCP\EventDispatcher\IEventDispatcher;
|
||||||
|
use OCP\IUser;
|
||||||
|
use OCP\IUserManager;
|
||||||
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
|
use Test\TestCase;
|
||||||
|
|
||||||
|
class AssignmentServiceTest extends TestCase {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var MockObject|PermissionService
|
||||||
|
*/
|
||||||
|
private $permissionService;
|
||||||
|
/**
|
||||||
|
* @var MockObject|CardMapper
|
||||||
|
*/
|
||||||
|
private $cardMapper;
|
||||||
|
/**
|
||||||
|
* @var MockObject|AssignedUsersMapper
|
||||||
|
*/
|
||||||
|
private $assignedUsersMapper;
|
||||||
|
/**
|
||||||
|
* @var MockObject|AclMapper
|
||||||
|
*/
|
||||||
|
private $aclMapper;
|
||||||
|
/**
|
||||||
|
* @var MockObject|NotificationHelper
|
||||||
|
*/
|
||||||
|
private $notificationHelper;
|
||||||
|
/**
|
||||||
|
* @var MockObject|ChangeHelper
|
||||||
|
*/
|
||||||
|
private $changeHelper;
|
||||||
|
/**
|
||||||
|
* @var MockObject|ActivityManager
|
||||||
|
*/
|
||||||
|
private $activityManager;
|
||||||
|
/**
|
||||||
|
* @var MockObject|IEventDispatcher
|
||||||
|
*/
|
||||||
|
private $eventDispatcher;
|
||||||
|
/**
|
||||||
|
* @var AssignmentService
|
||||||
|
*/
|
||||||
|
private $assignmentService;
|
||||||
|
|
||||||
|
public function setUp(): void {
|
||||||
|
parent::setUp();
|
||||||
|
$this->aclMapper = $this->createMock(AclMapper::class);
|
||||||
|
$this->permissionService = $this->createMock(PermissionService::class);
|
||||||
|
$this->cardMapper = $this->createMock(CardMapper::class);
|
||||||
|
$this->notificationHelper = $this->createMock(NotificationHelper::class);
|
||||||
|
$this->assignedUsersMapper = $this->createMock(AssignedUsersMapper::class);
|
||||||
|
$this->activityManager = $this->createMock(ActivityManager::class);
|
||||||
|
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
|
||||||
|
$this->changeHelper = $this->createMock(ChangeHelper::class);
|
||||||
|
$this->assignmentService = new AssignmentService(
|
||||||
|
$this->permissionService,
|
||||||
|
$this->cardMapper,
|
||||||
|
$this->assignedUsersMapper,
|
||||||
|
$this->aclMapper,
|
||||||
|
$this->notificationHelper,
|
||||||
|
$this->activityManager,
|
||||||
|
$this->changeHelper,
|
||||||
|
$this->eventDispatcher,
|
||||||
|
'admin'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function mockActivity($type, $object, $subject) {
|
||||||
|
// ActivityManager::DECK_OBJECT_BOARD, $newAcl, ActivityManager::SUBJECT_BOARD_SHARE
|
||||||
|
$event = $this->createMock(IEvent::class);
|
||||||
|
$this->activityManager->expects($this->once())
|
||||||
|
->method('createEvent')
|
||||||
|
->with($type, $object, $subject)
|
||||||
|
->willReturn($event);
|
||||||
|
$this->activityManager->expects($this->once())
|
||||||
|
->method('sendToUsers')
|
||||||
|
->with($event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAssignUser() {
|
||||||
|
$assignments = [];
|
||||||
|
$this->assignedUsersMapper->expects($this->once())
|
||||||
|
->method('find')
|
||||||
|
->with(123)
|
||||||
|
->willReturn($assignments);
|
||||||
|
$assignment = new AssignedUsers();
|
||||||
|
$assignment->setCardId(123);
|
||||||
|
$assignment->setParticipant('admin');
|
||||||
|
$assignment->setType(AssignedUsers::TYPE_USER);
|
||||||
|
$this->cardMapper->expects($this->once())
|
||||||
|
->method('findBoardId')
|
||||||
|
->willReturn(1);
|
||||||
|
$this->permissionService->expects($this->once())
|
||||||
|
->method('findUsers')
|
||||||
|
->with(1)
|
||||||
|
->willReturn(['admin' => 'admin', 'user1' => 'user1']);
|
||||||
|
$this->aclMapper->expects($this->once())
|
||||||
|
->method('findAll')
|
||||||
|
->willReturn([]);
|
||||||
|
$this->assignedUsersMapper->expects($this->once())
|
||||||
|
->method('insert')
|
||||||
|
->with($assignment)
|
||||||
|
->willReturn($assignment);
|
||||||
|
$actual = $this->assignmentService->assignUser(123, 'admin');
|
||||||
|
$this->assertEquals($assignment, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAssignUserNoParticipant() {
|
||||||
|
$this->expectException(BadRequestException::class);
|
||||||
|
$this->expectExceptionMessage('The user is not part of the board');
|
||||||
|
$assignments = [];
|
||||||
|
$this->assignedUsersMapper->expects($this->once())
|
||||||
|
->method('find')
|
||||||
|
->with(123)
|
||||||
|
->willReturn($assignments);
|
||||||
|
$assignment = new AssignedUsers();
|
||||||
|
$assignment->setCardId(123);
|
||||||
|
$assignment->setParticipant('admin');
|
||||||
|
$assignment->setType(AssignedUsers::TYPE_USER);
|
||||||
|
$this->cardMapper->expects($this->once())
|
||||||
|
->method('findBoardId')
|
||||||
|
->willReturn(1);
|
||||||
|
$this->permissionService->expects($this->once())
|
||||||
|
->method('findUsers')
|
||||||
|
->with(1)
|
||||||
|
->willReturn(['user2' => 'user2', 'user1' => 'user1']);
|
||||||
|
$this->aclMapper->expects($this->once())
|
||||||
|
->method('findAll')
|
||||||
|
->willReturn([]);
|
||||||
|
$actual = $this->assignmentService->assignUser(123, 'admin');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAssignUserExisting() {
|
||||||
|
$this->expectException(BadRequestException::class);
|
||||||
|
$this->expectExceptionMessage('The user is already assigned to the card');
|
||||||
|
$assignment = new AssignedUsers();
|
||||||
|
$assignment->setCardId(123);
|
||||||
|
$assignment->setParticipant('admin');
|
||||||
|
$assignment->setType(AssignedUsers::TYPE_USER);
|
||||||
|
$assignments = [
|
||||||
|
$assignment
|
||||||
|
];
|
||||||
|
$this->assignedUsersMapper->expects($this->once())
|
||||||
|
->method('find')
|
||||||
|
->with(123)
|
||||||
|
->willReturn($assignments);
|
||||||
|
$actual = $this->assignmentService->assignUser(123, 'admin');
|
||||||
|
$this->assertFalse($actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUnassignUserExisting() {
|
||||||
|
$assignment = new AssignedUsers();
|
||||||
|
$assignment->setCardId(123);
|
||||||
|
$assignment->setParticipant('admin');
|
||||||
|
$assignment->setType(AssignedUsers::TYPE_USER);
|
||||||
|
$assignments = [
|
||||||
|
$assignment
|
||||||
|
];
|
||||||
|
$this->assignedUsersMapper->expects($this->once())
|
||||||
|
->method('find')
|
||||||
|
->with(123)
|
||||||
|
->willReturn($assignments);
|
||||||
|
$this->assignedUsersMapper->expects($this->once())
|
||||||
|
->method('delete')
|
||||||
|
->with($assignment)
|
||||||
|
->willReturn($assignment);
|
||||||
|
$actual = $this->assignmentService->unassignUser(123, 'admin');
|
||||||
|
$this->assertEquals($assignment, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUnassignUserNotExisting() {
|
||||||
|
$this->expectException(NotFoundException::class);
|
||||||
|
$assignment = new AssignedUsers();
|
||||||
|
$assignment->setCardId(123);
|
||||||
|
$assignment->setParticipant('admin');
|
||||||
|
$assignment->setType(AssignedUsers::TYPE_USER);
|
||||||
|
$assignments = [
|
||||||
|
$assignment
|
||||||
|
];
|
||||||
|
$this->assignedUsersMapper->expects($this->once())
|
||||||
|
->method('find')
|
||||||
|
->with(123)
|
||||||
|
->willReturn($assignments);
|
||||||
|
$this->expectException(NotFoundException::class);
|
||||||
|
$actual = $this->assignmentService->unassignUser(123, 'user');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -39,6 +39,9 @@ use OCA\Deck\Notification\NotificationHelper;
|
|||||||
use OCA\Deck\StatusException;
|
use OCA\Deck\StatusException;
|
||||||
use OCP\Activity\IEvent;
|
use OCP\Activity\IEvent;
|
||||||
use OCP\Comments\ICommentsManager;
|
use OCP\Comments\ICommentsManager;
|
||||||
|
use OCP\EventDispatcher\ABroadcastedEvent;
|
||||||
|
use OCP\EventDispatcher\Event;
|
||||||
|
use OCP\EventDispatcher\IEventDispatcher;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
@@ -91,7 +94,7 @@ class CardServiceTest extends TestCase {
|
|||||||
$this->activityManager = $this->createMock(ActivityManager::class);
|
$this->activityManager = $this->createMock(ActivityManager::class);
|
||||||
$this->commentsManager = $this->createMock(ICommentsManager::class);
|
$this->commentsManager = $this->createMock(ICommentsManager::class);
|
||||||
$this->userManager = $this->createMock(IUserManager::class);
|
$this->userManager = $this->createMock(IUserManager::class);
|
||||||
$this->eventDispatcher = $this->createMock(EventDispatcherInterface::class);
|
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
|
||||||
$this->changeHelper = $this->createMock(ChangeHelper::class);
|
$this->changeHelper = $this->createMock(ChangeHelper::class);
|
||||||
$this->cardService = new CardService(
|
$this->cardService = new CardService(
|
||||||
$this->cardMapper,
|
$this->cardMapper,
|
||||||
@@ -318,102 +321,4 @@ class CardServiceTest extends TestCase {
|
|||||||
$this->cardService->removeLabel(123, 999);
|
$this->cardService->removeLabel(123, 999);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAssignUser() {
|
|
||||||
$assignments = [];
|
|
||||||
$this->assignedUsersMapper->expects($this->once())
|
|
||||||
->method('find')
|
|
||||||
->with(123)
|
|
||||||
->willReturn($assignments);
|
|
||||||
$assignment = new AssignedUsers();
|
|
||||||
$assignment->setCardId(123);
|
|
||||||
$assignment->setParticipant('admin');
|
|
||||||
$this->cardMapper->expects($this->once())
|
|
||||||
->method('findBoardId')
|
|
||||||
->willReturn(1);
|
|
||||||
$this->permissionService->expects($this->once())
|
|
||||||
->method('findUsers')
|
|
||||||
->with(1)
|
|
||||||
->willReturn(['admin' => 'admin', 'user1' => 'user1']);
|
|
||||||
$this->assignedUsersMapper->expects($this->once())
|
|
||||||
->method('insert')
|
|
||||||
->with($assignment)
|
|
||||||
->willReturn($assignment);
|
|
||||||
$actual = $this->cardService->assignUser(123, 'admin');
|
|
||||||
$this->assertEquals($assignment, $actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testAssignUserNoParticipant() {
|
|
||||||
$this->expectException(BadRequestException::class);
|
|
||||||
$this->expectExceptionMessage('The user is not part of the board');
|
|
||||||
$assignments = [];
|
|
||||||
$this->assignedUsersMapper->expects($this->once())
|
|
||||||
->method('find')
|
|
||||||
->with(123)
|
|
||||||
->willReturn($assignments);
|
|
||||||
$assignment = new AssignedUsers();
|
|
||||||
$assignment->setCardId(123);
|
|
||||||
$assignment->setParticipant('admin');
|
|
||||||
$this->cardMapper->expects($this->once())
|
|
||||||
->method('findBoardId')
|
|
||||||
->willReturn(1);
|
|
||||||
$this->permissionService->expects($this->once())
|
|
||||||
->method('findUsers')
|
|
||||||
->with(1)
|
|
||||||
->willReturn(['user2' => 'user2', 'user1' => 'user1']);
|
|
||||||
$actual = $this->cardService->assignUser(123, 'admin');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testAssignUserExisting() {
|
|
||||||
$this->expectException(BadRequestException::class);
|
|
||||||
$this->expectExceptionMessage('The user is already assigned to the card');
|
|
||||||
$assignment = new AssignedUsers();
|
|
||||||
$assignment->setCardId(123);
|
|
||||||
$assignment->setParticipant('admin');
|
|
||||||
$assignments = [
|
|
||||||
$assignment
|
|
||||||
];
|
|
||||||
$this->assignedUsersMapper->expects($this->once())
|
|
||||||
->method('find')
|
|
||||||
->with(123)
|
|
||||||
->willReturn($assignments);
|
|
||||||
$actual = $this->cardService->assignUser(123, 'admin');
|
|
||||||
$this->assertFalse($actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testUnassignUserExisting() {
|
|
||||||
$assignment = new AssignedUsers();
|
|
||||||
$assignment->setCardId(123);
|
|
||||||
$assignment->setParticipant('admin');
|
|
||||||
$assignments = [
|
|
||||||
$assignment
|
|
||||||
];
|
|
||||||
$this->assignedUsersMapper->expects($this->once())
|
|
||||||
->method('find')
|
|
||||||
->with(123)
|
|
||||||
->willReturn($assignments);
|
|
||||||
$this->assignedUsersMapper->expects($this->once())
|
|
||||||
->method('delete')
|
|
||||||
->with($assignment)
|
|
||||||
->willReturn($assignment);
|
|
||||||
$actual = $this->cardService->unassignUser(123, 'admin');
|
|
||||||
$this->assertEquals($assignment, $actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testUnassignUserNotExisting() {
|
|
||||||
$this->expectException(NotFoundException::class);
|
|
||||||
$assignment = new AssignedUsers();
|
|
||||||
$assignment->setCardId(123);
|
|
||||||
$assignment->setParticipant('admin');
|
|
||||||
$assignments = [
|
|
||||||
$assignment
|
|
||||||
];
|
|
||||||
$this->assignedUsersMapper->expects($this->once())
|
|
||||||
->method('find')
|
|
||||||
->with(123)
|
|
||||||
->willReturn($assignments);
|
|
||||||
$this->expectException(NotFoundException::class);
|
|
||||||
$actual = $this->cardService->unassignUser(123, 'user');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
*/
|
*/
|
||||||
namespace OCA\Deck\Controller;
|
namespace OCA\Deck\Controller;
|
||||||
|
|
||||||
|
use OCA\Deck\Service\AssignmentService;
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
use OCP\AppFramework\Http\DataResponse;
|
use OCP\AppFramework\Http\DataResponse;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
@@ -37,12 +38,14 @@ class CardApiControllerTest extends \Test\TestCase {
|
|||||||
private $userId = 'admin';
|
private $userId = 'admin';
|
||||||
private $cardExample;
|
private $cardExample;
|
||||||
private $stackExample;
|
private $stackExample;
|
||||||
|
private $assignmentService;
|
||||||
|
|
||||||
public function setUp(): void {
|
public function setUp(): void {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->request = $this->createMock(IRequest::class);
|
$this->request = $this->createMock(IRequest::class);
|
||||||
$this->cardService = $this->createMock(CardService::class);
|
$this->cardService = $this->createMock(CardService::class);
|
||||||
|
$this->assignmentService = $this->createMock(AssignmentService::class);
|
||||||
|
|
||||||
$this->cardExample['id'] = 1;
|
$this->cardExample['id'] = 1;
|
||||||
$this->stackExample['id'] = 1;
|
$this->stackExample['id'] = 1;
|
||||||
@@ -51,6 +54,7 @@ class CardApiControllerTest extends \Test\TestCase {
|
|||||||
$appName = 'deck',
|
$appName = 'deck',
|
||||||
$this->request,
|
$this->request,
|
||||||
$this->cardService,
|
$this->cardService,
|
||||||
|
$this->assignmentService,
|
||||||
$this->userId
|
$this->userId
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,34 +23,35 @@
|
|||||||
|
|
||||||
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\AppFramework\Controller;
|
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
|
use Test\TestCase;
|
||||||
|
|
||||||
class CardControllerTest extends \Test\TestCase {
|
class CardControllerTest extends TestCase {
|
||||||
|
|
||||||
/** @var CardController|\PHPUnit\Framework\MockObject\MockObject */
|
/** @var CardController|MockObject */
|
||||||
private $controller;
|
private $controller;
|
||||||
/** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
|
/** @var IRequest|MockObject */
|
||||||
private $request;
|
private $request;
|
||||||
/** @var CardService|\PHPUnit\Framework\MockObject\MockObject */
|
/** @var CardService|MockObject */
|
||||||
private $cardService;
|
private $cardService;
|
||||||
|
/** @var AssignmentService|MockObject */
|
||||||
|
private $assignmentService;
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $userId = 'user';
|
private $userId = 'user';
|
||||||
|
|
||||||
|
|
||||||
public function setUp(): void {
|
public function setUp(): void {
|
||||||
$this->request = $this->getMockBuilder(
|
$this->request = $this->createMock(IRequest::class);
|
||||||
'\OCP\IRequest')
|
$this->cardService = $this->createMock(CardService::class);
|
||||||
->disableOriginalConstructor()
|
$this->assignmentService = $this->createMock(AssignmentService::class);
|
||||||
->getMock();
|
|
||||||
$this->cardService = $this->getMockBuilder(
|
|
||||||
'\OCA\Deck\Service\CardService')
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
$this->controller = new CardController(
|
$this->controller = new CardController(
|
||||||
'deck',
|
'deck',
|
||||||
$this->request,
|
$this->request,
|
||||||
$this->cardService,
|
$this->cardService,
|
||||||
|
$this->assignmentService,
|
||||||
$this->userId
|
$this->userId
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -115,12 +116,12 @@ class CardControllerTest extends \Test\TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testAssignUser() {
|
public function testAssignUser() {
|
||||||
$this->cardService->expects($this->once())->method('assignUser');
|
$this->assignmentService->expects($this->once())->method('assignUser');
|
||||||
$this->controller->assignUser(1, 'admin');
|
$this->controller->assignUser(1, 'admin');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUnssignUser() {
|
public function testUnssignUser() {
|
||||||
$this->cardService->expects($this->once())->method('unassignUser');
|
$this->assignmentService->expects($this->once())->method('unassignUser');
|
||||||
$this->controller->unassignUser(1, 'admin');
|
$this->controller->unassignUser(1, 'admin');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user