Implement collections integration
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
@@ -25,6 +25,7 @@ namespace OCA\Deck\Service;
|
||||
|
||||
use OCA\Deck\Activity\ActivityManager;
|
||||
use OCA\Deck\Activity\ChangeSet;
|
||||
use OCA\Deck\Collaboration\Resources\ResourceProvider;
|
||||
use OCA\Deck\Db\Acl;
|
||||
use OCA\Deck\Db\AclMapper;
|
||||
use OCA\Deck\Db\AssignedUsersMapper;
|
||||
@@ -59,6 +60,7 @@ class BoardService {
|
||||
private $userId;
|
||||
private $activityManager;
|
||||
private $changeHelper;
|
||||
private $resourceProvider;
|
||||
|
||||
public function __construct(
|
||||
BoardMapper $boardMapper,
|
||||
@@ -73,6 +75,7 @@ class BoardService {
|
||||
IGroupManager $groupManager,
|
||||
ActivityManager $activityManager,
|
||||
ChangeHelper $changeHelper,
|
||||
ResourceProvider $resourceProvider,
|
||||
$userId
|
||||
) {
|
||||
$this->boardMapper = $boardMapper;
|
||||
@@ -87,6 +90,7 @@ class BoardService {
|
||||
$this->groupManager = $groupManager;
|
||||
$this->activityManager = $activityManager;
|
||||
$this->changeHelper = $changeHelper;
|
||||
$this->resourceProvider = $resourceProvider;
|
||||
$this->userId = $userId;
|
||||
}
|
||||
|
||||
@@ -459,6 +463,7 @@ class BoardService {
|
||||
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $newAcl, ActivityManager::SUBJECT_BOARD_SHARE);
|
||||
$this->boardMapper->mapAcl($newAcl);
|
||||
$this->changeHelper->boardChanged($boardId);
|
||||
$this->resourceProvider->invalidateAccessCache($boardId);
|
||||
return $newAcl;
|
||||
}
|
||||
|
||||
@@ -529,6 +534,7 @@ class BoardService {
|
||||
}
|
||||
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $acl, ActivityManager::SUBJECT_BOARD_UNSHARE);
|
||||
$this->changeHelper->boardChanged($acl->getBoardId());
|
||||
$this->resourceProvider->invalidateAccessCache($acl->getBoardId());
|
||||
return $this->aclMapper->delete($acl);
|
||||
}
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ class PermissionService {
|
||||
* @return bool
|
||||
* @throws NoPermissionException
|
||||
*/
|
||||
public function checkPermission($mapper, $id, $permission) {
|
||||
public function checkPermission($mapper, $id, $permission, $userId = null) {
|
||||
$boardId = $id;
|
||||
if ($mapper instanceof IPermissionMapper) {
|
||||
$boardId = $mapper->findBoardId($id);
|
||||
@@ -141,12 +141,12 @@ class PermissionService {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->userIsBoardOwner($boardId)) {
|
||||
if ($this->userIsBoardOwner($boardId, $userId)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$acls = $this->aclMapper->findAll($boardId);
|
||||
$result = $this->userCan($acls, $permission);
|
||||
$result = $this->userCan($acls, $permission, $userId);
|
||||
if ($result) {
|
||||
return true;
|
||||
}
|
||||
@@ -159,10 +159,13 @@ class PermissionService {
|
||||
* @param $boardId
|
||||
* @return bool
|
||||
*/
|
||||
public function userIsBoardOwner($boardId) {
|
||||
public function userIsBoardOwner($boardId, $userId = null) {
|
||||
if ($userId === null) {
|
||||
$userId = $this->userId;
|
||||
}
|
||||
try {
|
||||
$board = $this->boardMapper->find($boardId);
|
||||
return $board && $this->userId === $board->getOwner();
|
||||
return $board && $userId === $board->getOwner();
|
||||
} catch (DoesNotExistException $e) {
|
||||
} catch (MultipleObjectsReturnedException $e) {
|
||||
return false;
|
||||
@@ -176,17 +179,20 @@ class PermissionService {
|
||||
* @param $permission
|
||||
* @return bool
|
||||
*/
|
||||
public function userCan(array $acls, $permission) {
|
||||
public function userCan(array $acls, $permission, $userId = null) {
|
||||
if ($userId === null) {
|
||||
$userId = $this->userId;
|
||||
}
|
||||
// check for users
|
||||
foreach ($acls as $acl) {
|
||||
if ($acl->getType() === Acl::PERMISSION_TYPE_USER && $acl->getParticipant() === $this->userId) {
|
||||
if ($acl->getType() === Acl::PERMISSION_TYPE_USER && $acl->getParticipant() === $userId) {
|
||||
return $acl->getPermission($permission);
|
||||
}
|
||||
}
|
||||
// check for groups
|
||||
$hasGroupPermission = false;
|
||||
foreach ($acls as $acl) {
|
||||
if (!$hasGroupPermission && $acl->getType() === Acl::PERMISSION_TYPE_GROUP && $this->groupManager->isInGroup($this->userId, $acl->getParticipant())) {
|
||||
if (!$hasGroupPermission && $acl->getType() === Acl::PERMISSION_TYPE_GROUP && $this->groupManager->isInGroup($userId, $acl->getParticipant())) {
|
||||
$hasGroupPermission = $acl->getPermission($permission);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user