Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
['name' => 'card#assignLabel', 'url' => '/cards/{cardId}/label/{labelId}', 'verb' => 'POST'],
['name' => 'card#removeLabel', 'url' => '/cards/{cardId}/label/{labelId}', 'verb' => 'DELETE'],
['name' => 'card#assignUser', 'url' => '/cards/{cardId}/assign', 'verb' => 'POST'],
['name' => 'card#unassignUser', 'url' => '/cards/{cardId}/assign/{userId}', 'verb' => 'DELETE'],
['name' => 'card#unassignUser', 'url' => '/cards/{cardId}/unassign', 'verb' => 'PUT'],

['name' => 'attachment#getAll', 'url' => '/cards/{cardId}/attachments', 'verb' => 'GET'],
['name' => 'attachment#create', 'url' => '/cards/{cardId}/attachment', 'verb' => 'POST'],
Expand Down
17 changes: 10 additions & 7 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
use OCP\Collaboration\Resources\IManager;
use OCP\Collaboration\Resources\IProviderManager;
use OCP\Comments\CommentsEntityEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\FullTextSearch\IFullTextSearchManager;
use OCP\IGroup;
use OCP\IServerContainer;
Expand Down Expand Up @@ -217,34 +219,35 @@ public function registerFullTextSearch(): void {
return;
}

$eventDispatcher = $this->server->getEventDispatcher();
/** @var IEventDispatcher $eventDispatcher */
$eventDispatcher = $this->server->query(IEventDispatcher::class);
$eventDispatcher->addListener(
'\OCA\Deck\Card::onCreate', function(GenericEvent $e) {
'\OCA\Deck\Card::onCreate', function(Event $e) {
$this->fullTextSearchService->onCardCreated($e);
}
);
$eventDispatcher->addListener(
'\OCA\Deck\Card::onUpdate', function(GenericEvent $e) {
'\OCA\Deck\Card::onUpdate', function(Event $e) {
$this->fullTextSearchService->onCardUpdated($e);
}
);
$eventDispatcher->addListener(
'\OCA\Deck\Card::onDelete', function(GenericEvent $e) {
'\OCA\Deck\Card::onDelete', function(Event $e) {
$this->fullTextSearchService->onCardDeleted($e);
}
);
$eventDispatcher->addListener(
'\OCA\Deck\Board::onShareNew', function(GenericEvent $e) {
'\OCA\Deck\Board::onShareNew', function(Event $e) {
$this->fullTextSearchService->onBoardShares($e);
}
);
$eventDispatcher->addListener(
'\OCA\Deck\Board::onShareEdit', function(GenericEvent $e) {
'\OCA\Deck\Board::onShareEdit', function(Event $e) {
$this->fullTextSearchService->onBoardShares($e);
}
);
$eventDispatcher->addListener(
'\OCA\Deck\Board::onShareDelete', function(GenericEvent $e) {
'\OCA\Deck\Board::onShareDelete', function(Event $e) {
$this->fullTextSearchService->onBoardShares($e);
}
);
Expand Down
17 changes: 10 additions & 7 deletions lib/Controller/CardApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

namespace OCA\Deck\Controller;

use OCA\Deck\Service\AssignmentService;
use OCP\AppFramework\ApiController;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
Expand All @@ -39,17 +40,19 @@
class CardApiController extends ApiController {
private $cardService;
private $userId;
private $assignmentService;

/**
* @param string $appName
* @param IRequest $request
* @param CardService $cardService
* @param $userId
*/
public function __construct($appName, IRequest $request, CardService $cardService, $userId) {
public function __construct($appName, IRequest $request, CardService $cardService, AssignmentService $assignmentService, $userId) {
parent::__construct($appName, $request);
$this->cardService = $cardService;
$this->userId = $userId;
$this->assignmentService = $assignmentService;
}

/**
Expand Down Expand Up @@ -135,10 +138,10 @@ public function removeLabel($labelId) {
* @CORS
* @NoCSRFRequired
*
* Unassign a user from a card
* Assign a user to a card
*/
public function unassignUser($userId) {
$card = $this->cardService->unassignUser($this->request->getParam('cardId'), $userId);
public function assignUser($cardId, $userId, $type = 0) {
$card = $this->assignmentService->assignUser($cardId, $userId, $type);
return new DataResponse($card, HTTP::STATUS_OK);
}

Expand All @@ -147,10 +150,10 @@ public function unassignUser($userId) {
* @CORS
* @NoCSRFRequired
*
* Assign a user to a card
* Unassign a user from a card
*/
public function assignUser($userId) {
$card = $this->cardService->assignUser($this->request->getParam('cardId'), $userId);;
public function unassignUser($cardId, $userId, $type = 0) {
$card = $this->assignmentService->unassignUser($cardId, $userId, $type);
return new DataResponse($card, HTTP::STATUS_OK);
}

Expand Down
21 changes: 12 additions & 9 deletions lib/Controller/CardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,25 @@
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/

namespace OCA\Deck\Controller;

use OCA\Deck\Service\AssignmentService;
use OCA\Deck\Service\CardService;
use OCP\IRequest;
use OCP\AppFramework\Controller;
Expand All @@ -31,11 +32,13 @@ class CardController extends Controller {

private $userId;
private $cardService;
private $assignmentService;

public function __construct($appName, IRequest $request, CardService $cardService, $userId) {
public function __construct($appName, IRequest $request, CardService $cardService, AssignmentService $assignmentService, $userId) {
parent::__construct($appName, $request);
$this->userId = $userId;
$this->cardService = $cardService;
$this->assignmentService = $assignmentService;
}

/**
Expand Down Expand Up @@ -153,15 +156,15 @@ public function removeLabel($cardId, $labelId) {
/**
* @NoAdminRequired
*/
public function assignUser($cardId, $userId) {
return $this->cardService->assignUser($cardId, $userId);
public function assignUser($cardId, $userId, $type = 0) {
return $this->assignmentService->assignUser($cardId, $userId, $type);
}

/**
* @NoAdminRequired
*/
public function unassignUser($cardId, $userId) {
return $this->cardService->unassignUser($cardId, $userId);
public function unassignUser($cardId, $userId, $type = 0) {
return $this->assignmentService->unassignUser($cardId, $userId, $type);
}


Expand Down
6 changes: 6 additions & 0 deletions lib/Db/AssignedUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@ class AssignedUsers extends RelationalEntity implements JsonSerializable {
public $id;
protected $participant;
protected $cardId;
protected $type;

public const TYPE_USER = Acl::PERMISSION_TYPE_USER;
public const TYPE_GROUP = Acl::PERMISSION_TYPE_GROUP;
public const TYPE_CIRCLE = Acl::PERMISSION_TYPE_CIRCLE;

public function __construct() {
$this->addType('id', 'integer');
$this->addType('cardId', 'integer');
$this->addType('type', 'integer');
$this->addResolvable('participant');
}

Expand Down
39 changes: 28 additions & 11 deletions lib/Db/AssignedUsersMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,24 @@

use OCP\AppFramework\Db\Entity;
use OCP\IDBConnection;
use OCP\IGroupManager;
use OCP\IUserManager;


class AssignedUsersMapper extends DeckMapper implements IPermissionMapper {

private $cardMapper;
private $userManager;
/**
* @var IGroupManager
*/
private $groupManager;

public function __construct(IDBConnection $db, CardMapper $cardMapper, IUserManager $userManager) {
public function __construct(IDBConnection $db, CardMapper $cardMapper, IUserManager $userManager, IGroupManager $groupManager) {
parent::__construct($db, 'deck_assigned_users', AssignedUsers::class);
$this->cardMapper = $cardMapper;
$this->userManager = $userManager;
$this->groupManager = $groupManager;
}

/**
Expand Down Expand Up @@ -78,8 +84,8 @@ public function findBoardId($cardId) {
* @return null|Entity
*/
public function insert(Entity $entity) {
$user = $this->userManager->get($entity->getParticipant());
if ($user !== null) {
$origin = $this->getOrigin($entity);
if ($origin !== null) {
/** @var AssignedUsers $assignment */
$assignment = parent::insert($entity);
$this->mapParticipant($assignment);
Expand All @@ -89,15 +95,26 @@ public function insert(Entity $entity) {
}

public function mapParticipant(AssignedUsers &$assignment) {
$userManager = $this->userManager;
$assignment->resolveRelation('participant', function() use (&$userManager, &$assignment) {
$user = $userManager->get($assignment->getParticipant());
if ($user !== null) {
return new User($user);
}
return null;
$self = $this;
$assignment->resolveRelation('participant', function() use (&$self, &$assignment) {
return $self->getOrigin($assignment);
});
}

private function getOrigin(AssignedUsers $assignment) {
if ($assignment->getType() === AssignedUsers::TYPE_USER) {
$origin = $this->userManager->get($assignment->getParticipant());
return $origin ? new User($origin) : null;
}
if ($assignment->getType() === AssignedUsers::TYPE_GROUP) {
$origin = $this->groupManager->get($assignment->getParticipant());
return $origin ? new Group($origin) : null;
}
if ($assignment->getType() === AssignedUsers::TYPE_CIRCLE) {
$origin = $this->groupManager->get($assignment->getParticipant());
return $origin ? new Circle($origin) : null;
}
return null;
}

}
}
5 changes: 4 additions & 1 deletion lib/Db/BoardMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,10 @@ public function mapAcl(Acl &$acl) {
\OC::$server->getLogger()->debug('Group ' . $acl->getId() . ' not found when mapping acl ' . $acl->getParticipant());
return null;
}
if ($acl->getType() === Acl::PERMISSION_TYPE_CIRCLE && $this->circlesEnabled) {
if ($acl->getType() === Acl::PERMISSION_TYPE_CIRCLE) {
if (!$this->circlesEnabled) {
return null;
}
try {
$circle = \OCA\Circles\Api\v1\Circles::detailsCircle($acl->getParticipant(), true);
if ($circle) {
Expand Down
6 changes: 4 additions & 2 deletions lib/Db/Circle.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@
namespace OCA\Deck\Db;


use OCP\Share\IShare;

class Circle extends RelationalObject {

/** @var \OCA\Circles\Model\Circle */
protected $object;

public function __construct(\OCA\Circles\Model\Circle $circle) {
$primaryKey = $circle->getUniqueId();
$primaryKey = IShare::TYPE_CIRCLE . ':' . $circle->getUniqueId();
parent::__construct($primaryKey, $circle);
}

Expand All @@ -42,4 +44,4 @@ public function getObjectSerialization() {
'circleOwner' => $this->object->getOwner()
];
}
}
}
5 changes: 3 additions & 2 deletions lib/Db/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
namespace OCA\Deck\Db;

use OCP\IGroup;
use OCP\Share\IShare;

class Group extends RelationalObject {

public function __construct(IGroup $group) {
$primaryKey = $group->getGID();
$primaryKey = IShare::TYPE_GROUP . ':' . $group->getGID();
parent::__construct($primaryKey, $group);
}

Expand All @@ -38,4 +39,4 @@ public function getObjectSerialization() {
'displayname' => $this->object->getDisplayName()
];
}
}
}
5 changes: 3 additions & 2 deletions lib/Db/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
namespace OCA\Deck\Db;

use OCP\IUser;
use OCP\Share\IShare;

class User extends RelationalObject {

public function __construct(IUser $user) {
$primaryKey = $user->getUID();
$primaryKey = IShare::TYPE_USER . ':' . $user->getUID();
parent::__construct($primaryKey, $user);
}

Expand All @@ -46,4 +47,4 @@ public function getUID() {
public function getDisplayName() {
return $this->object->getDisplayName();
}
}
}
Loading