Various fixes
This commit is contained in:
@@ -28,6 +28,11 @@ use JsonSerializable;
|
||||
|
||||
class Acl extends Entity implements JsonSerializable {
|
||||
|
||||
const PERMISSION_READ = 0;
|
||||
const PERMISSION_EDIT = 1;
|
||||
const PERMISSION_SHARE = 2;
|
||||
const PERMISSION_MANAGE = 3;
|
||||
|
||||
public $id;
|
||||
protected $participant;
|
||||
protected $type;
|
||||
@@ -46,6 +51,21 @@ class Acl extends Entity implements JsonSerializable {
|
||||
$this->addType('owner', 'boolean');
|
||||
$this->addRelation('owner');
|
||||
}
|
||||
|
||||
public function getPermission($permission) {
|
||||
switch ($permission) {
|
||||
case Acl::PERMISSION_READ:
|
||||
return true;
|
||||
case Acl::PERMISSION_EDIT:
|
||||
return $this->getPermissionWrite();
|
||||
case Acl::PERMISSION_SHARE:
|
||||
return $this->getPermissionInvite();
|
||||
case Acl::PERMISSION_MANAGE:
|
||||
return $this->getPermissionManage();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function jsonSerialize() {
|
||||
return [
|
||||
'id' => $this->id,
|
||||
|
||||
@@ -41,20 +41,6 @@ class AclMapper extends DeckMapper implements IPermissionMapper {
|
||||
return $this->findEntities($sql, [$boardId], $limit, $offset);
|
||||
}
|
||||
|
||||
public function findAllShared($boardId) {
|
||||
$sql = 'SELECT id, board_id, type, participant, permission_write, permission_invite, permission_manage FROM `*PREFIX*deck_board_acl` WHERE `board_id` = ? ';
|
||||
return $this->findEntities($sql, [$boardId]);
|
||||
}
|
||||
public function findAllForCard($cardId, $userId) {
|
||||
$findBoardId = "(SELECT board_id from oc_deck_stacks WHERE id IN (SELECT stack_id from oc_deck_cards WHERE id = 15))";
|
||||
$sql = "SELECT 0, id, 'user', owner, 1, 1, 1, 1 as owner FROM `oc_deck_boards` " .
|
||||
"WHERE `id` IN (SELECT board_id from oc_deck_stacks WHERE id IN (SELECT stack_id from oc_deck_cards WHERE id = 15))
|
||||
UNION
|
||||
SELECT id, board_id, type, participant, permission_write, permission_invite, permission_manage, 0 FROM oc_deck_board_acl
|
||||
WHERE participant = 'admin' AND board_id IN (SELECT board_id from oc_deck_stacks WHERE id IN (SELECT stack_id from oc_deck_cards WHERE id = 15));";
|
||||
|
||||
}
|
||||
|
||||
public function isOwner($userId, $aclId) {
|
||||
$sql = 'SELECT * FROM `*PREFIX*deck_boards` WHERE `id` IN (SELECT board_id FROM `*PREFIX*deck_board_acl` WHERE id = ?)';
|
||||
$stmt = $this->execute($sql, [$aclId]);
|
||||
|
||||
@@ -28,7 +28,7 @@ use OCP\AppFramework\Db\Mapper;
|
||||
use Symfony\Component\Config\Definition\Exception\Exception;
|
||||
|
||||
|
||||
class BoardMapper extends Mapper implements IPermissionMapper {
|
||||
class BoardMapper extends DeckMapper implements IPermissionMapper {
|
||||
|
||||
private $labelMapper;
|
||||
private $_relationMappers = array();
|
||||
|
||||
@@ -49,4 +49,11 @@ abstract class DeckMapper extends Mapper {
|
||||
|
||||
}
|
||||
|
||||
protected function execute($sql, array $params = [], $limit = null, $offset = null) {
|
||||
|
||||
\OCP\Util::writeLog('deck', "SQL: " . $sql, \OCP\Util::DEBUG);
|
||||
|
||||
return parent::execute($sql, $params, $limit, $offset); // TODO: Change the autogenerated stub
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,20 +21,27 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: jus
|
||||
* Date: 19.08.16
|
||||
* Time: 22:25
|
||||
*/
|
||||
|
||||
namespace OCA\Deck\Db;
|
||||
|
||||
|
||||
interface IPermissionMapper {
|
||||
|
||||
/**
|
||||
* Check if $userId is owner of Entity with $id
|
||||
*
|
||||
* @param $userId string userId
|
||||
* @param $id int|string unique entity identifier
|
||||
* @return boolean
|
||||
*/
|
||||
public function isOwner($userId, $id);
|
||||
|
||||
/**
|
||||
* Query boardId for Entity of given $id
|
||||
*
|
||||
* @param $id int|string unique entity identifier
|
||||
* @return int|null id of Board
|
||||
*/
|
||||
public function findBoardId($id);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user