From dfe8bad832e83ae4b5ced6290f28c79f858ee3b5 Mon Sep 17 00:00:00 2001 From: Julius Haertl Date: Fri, 3 Feb 2017 18:35:41 +0100 Subject: [PATCH 1/3] Do not return string on Acl type getter --- lib/Db/Acl.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Db/Acl.php b/lib/Db/Acl.php index 04be2ac4d..d977f3f06 100644 --- a/lib/Db/Acl.php +++ b/lib/Db/Acl.php @@ -74,7 +74,7 @@ class Acl extends RelationalEntity implements \JsonSerializable { return [ 'id' => $this->id, 'participant' => $this->participant, - 'type' => $this->getType(), + 'type' => $this->getTypeString(), 'boardId' => $this->boardId, 'permissionEdit' => $this->getPermissionEdit(), 'permissionShare' => $this->getPermissionShare(), @@ -87,7 +87,7 @@ class Acl extends RelationalEntity implements \JsonSerializable { * FIXME: migrate other code to const PERMISSION_TYPE_ instead of strings * iirc js uses those strings as well */ - public function getType() { + public function getTypeString() { if ($this->type === Acl::PERMISSION_TYPE_GROUP) { return 'group'; } From 0333f31b9a242dfee9fc979750bbe02e6e1cca55 Mon Sep 17 00:00:00 2001 From: Julius Haertl Date: Fri, 3 Feb 2017 18:38:01 +0100 Subject: [PATCH 2/3] Move to int values for permission type checks --- lib/Db/Acl.php | 6 +----- lib/Service/PermissionService.php | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/Db/Acl.php b/lib/Db/Acl.php index d977f3f06..f4355ade8 100644 --- a/lib/Db/Acl.php +++ b/lib/Db/Acl.php @@ -82,11 +82,7 @@ class Acl extends RelationalEntity implements \JsonSerializable { 'owner' => $this->getOwner() ]; } - - /* - * FIXME: migrate other code to const PERMISSION_TYPE_ instead of strings - * iirc js uses those strings as well - */ + public function getTypeString() { if ($this->type === Acl::PERMISSION_TYPE_GROUP) { return 'group'; diff --git a/lib/Service/PermissionService.php b/lib/Service/PermissionService.php index ca1badae5..bd3985a51 100644 --- a/lib/Service/PermissionService.php +++ b/lib/Service/PermissionService.php @@ -127,14 +127,14 @@ class PermissionService { public function userCan(array $acls, $permission) { // check for users foreach ($acls as $acl) { - if ($acl->getType() === "user" && $acl->getParticipant() === $this->userId) { + if ($acl->getType() === Acl::PERMISSION_TYPE_USER && $acl->getParticipant() === $this->userId) { return $acl->getPermission($permission); } } // check for groups $hasGroupPermission = false; foreach ($acls as $acl) { - if (!$hasGroupPermission && $acl->getType() === "group" && $this->groupManager->isInGroup($this->userId, $acl->getParticipant())) { + if (!$hasGroupPermission && $acl->getType() === Acl::PERMISSION_TYPE_GROUP && $this->groupManager->isInGroup($this->userId, $acl->getParticipant())) { $hasGroupPermission = $acl->getPermission($permission); } } From f604f2f7799b028bbfa874afe818b374e0723a29 Mon Sep 17 00:00:00 2001 From: Julius Haertl Date: Sun, 5 Feb 2017 22:46:29 +0100 Subject: [PATCH 3/3] Remove another string representation --- lib/Db/BoardMapper.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Db/BoardMapper.php b/lib/Db/BoardMapper.php index e445c8255..02cabc2b3 100644 --- a/lib/Db/BoardMapper.php +++ b/lib/Db/BoardMapper.php @@ -77,8 +77,8 @@ class BoardMapper extends DeckMapper implements IPermissionMapper { public function findAllByUser($userId, $limit = null, $offset = null) { $sql = 'SELECT id, title, owner, color, archived, 0 as shared FROM oc_deck_boards WHERE owner = ? UNION ' . 'SELECT boards.id, title, owner, color, archived, 1 as shared FROM oc_deck_boards as boards ' . - 'JOIN oc_deck_board_acl as acl ON boards.id=acl.board_id WHERE acl.participant=? AND acl.type=\'user\' AND boards.owner != ?'; - $entries = $this->findEntities($sql, [$userId, $userId, $userId], $limit, $offset); + 'JOIN oc_deck_board_acl as acl ON boards.id=acl.board_id WHERE acl.participant=? AND acl.type=? AND boards.owner != ?'; + $entries = $this->findEntities($sql, [$userId, $userId, Acl::PERMISSION_TYPE_USER, $userId], $limit, $offset); /* @var Board $entry */ foreach ($entries as $entry) { $acl = $this->aclMapper->findAll($entry->id); @@ -101,7 +101,7 @@ class BoardMapper extends DeckMapper implements IPermissionMapper { return []; } $sql = 'SELECT boards.id, title, owner, color, archived, 2 as shared FROM oc_deck_boards as boards ' . - 'INNER JOIN oc_deck_board_acl as acl ON boards.id=acl.board_id WHERE owner != ? AND type=\'group\' AND ('; + 'INNER JOIN oc_deck_board_acl as acl ON boards.id=acl.board_id WHERE owner != ? AND type=? AND ('; for ($i = 0; $i < count($groups); $i++) { $sql .= 'acl.participant = ? '; if (count($groups) > 1 && $i < count($groups) - 1) { @@ -109,7 +109,7 @@ class BoardMapper extends DeckMapper implements IPermissionMapper { } } $sql .= ');'; - $entries = $this->findEntities($sql, array_merge([$userId], $groups), $limit, $offset); + $entries = $this->findEntities($sql, array_merge([$userId, Acl::PERMISSION_TYPE_GROUP], $groups), $limit, $offset); /* @var Board $entry */ foreach ($entries as $entry) { $acl = $this->aclMapper->findAll($entry->id);