Start implementing board sharing
This commit is contained in:
@@ -13,6 +13,7 @@ class Acl extends Entity implements JsonSerializable {
|
||||
protected $permissionWrite;
|
||||
protected $permissionInvite;
|
||||
protected $permissionManage;
|
||||
protected $owner;
|
||||
|
||||
public function __construct() {
|
||||
$this->addType('id','integer');
|
||||
@@ -20,6 +21,8 @@ class Acl extends Entity implements JsonSerializable {
|
||||
$this->addType('permissionWrite', 'boolean');
|
||||
$this->addType('permissionInvite', 'boolean');
|
||||
$this->addType('permissionManage', 'boolean');
|
||||
$this->addType('owner', 'boolean');
|
||||
$this->addRelation('owner');
|
||||
}
|
||||
public function jsonSerialize() {
|
||||
return [
|
||||
@@ -30,6 +33,7 @@ class Acl extends Entity implements JsonSerializable {
|
||||
'permissionWrite' => $this->permissionWrite,
|
||||
'permissionInvite' => $this->permissionInvite,
|
||||
'permissionManage' => $this->permissionManage,
|
||||
'owner' => $this->owner
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -14,8 +14,8 @@ class AclMapper extends DeckMapper {
|
||||
}
|
||||
|
||||
public function findAll($boardId, $limit=null, $offset=null) {
|
||||
$sql = 'SELECT * FROM `*PREFIX*deck_board_acl` WHERE `board_id` = ?';
|
||||
return $this->findEntities($sql, [$boardId], $limit, $offset);
|
||||
$sql = 'SELECT id, board_id, type, participant, permission_write, permission_invite, permission_manage, 0 as owner FROM `*PREFIX*deck_board_acl` WHERE `board_id` = ? UNION SELECT 0, id, \'user\', owner, 1, 1, 1, 1 FROM `*PREFIX*deck_boards` WHERE `id` = ? ';
|
||||
return $this->findEntities($sql, [$boardId, $boardId], $limit, $offset);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
10
db/board.php
10
db/board.php
@@ -13,15 +13,19 @@ class Board extends \OCA\Deck\Db\Entity implements JsonSerializable {
|
||||
protected $archived;
|
||||
protected $labels;
|
||||
protected $acl;
|
||||
protected $shared;
|
||||
|
||||
public function __construct() {
|
||||
$this->addType('id','integer');
|
||||
$this->addType('shared','integer');
|
||||
$this->addRelation('labels');
|
||||
$this->addRelation('acl');
|
||||
$this->addRelation('shared');
|
||||
$this->shared = -1;
|
||||
}
|
||||
|
||||
public function jsonSerialize() {
|
||||
return [
|
||||
$result = [
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'owner' => $this->owner,
|
||||
@@ -29,6 +33,10 @@ class Board extends \OCA\Deck\Db\Entity implements JsonSerializable {
|
||||
'labels' => $this->labels,
|
||||
'acl' => $this->acl,
|
||||
];
|
||||
if($this->shared!==-1) {
|
||||
$result['shared'] = $this->shared;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function setLabels($labels) {
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace OCA\Deck\Db;
|
||||
|
||||
use OCP\IDb;
|
||||
use OCP\AppFramework\Db\Mapper;
|
||||
use Symfony\Component\Config\Definition\Exception\Exception;
|
||||
|
||||
|
||||
class BoardMapper extends Mapper {
|
||||
@@ -27,7 +28,7 @@ class BoardMapper extends Mapper {
|
||||
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
|
||||
*/
|
||||
public function find($id) {
|
||||
$sql = 'SELECT * FROM `*PREFIX*deck_boards` ' .
|
||||
$sql = 'SELECT id, title, owner, color, archived FROM `*PREFIX*deck_boards` ' .
|
||||
'WHERE `id` = ?';
|
||||
$board = $this->findEntity($sql, [$id]);
|
||||
|
||||
@@ -49,9 +50,39 @@ class BoardMapper extends Mapper {
|
||||
* @param null $offset
|
||||
* @return array
|
||||
*/
|
||||
public function findAll($userId, $limit=null, $offset=null) {
|
||||
$sql = 'SELECT * FROM `*PREFIX*deck_boards` WHERE `owner` = ? ORDER BY `title`';
|
||||
$entries = $this->findEntities($sql, [$userId], $limit, $offset);
|
||||
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);
|
||||
/* @var Board $entry */
|
||||
foreach ($entries as $entry) {
|
||||
$acl = $this->aclMapper->findAll($entry->id);
|
||||
$entry->setAcl($acl);
|
||||
}
|
||||
return $entries;
|
||||
}
|
||||
/**
|
||||
* Find all boards for a given user
|
||||
* @param $groups
|
||||
* @param null $limit
|
||||
* @param null $offset
|
||||
* @return array
|
||||
*/
|
||||
public function findAllByGroups($userId, $groups, $limit=null, $offset=null) {
|
||||
if(count($groups)<=0) {
|
||||
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 (';
|
||||
$countGroups = 0;
|
||||
foreach ($groups as $group) {
|
||||
$sql .= 'acl.participant = ? ';
|
||||
if(count($groups)>1 && $countGroups++<count($groups)-1)
|
||||
$sql .= ' OR ';
|
||||
}
|
||||
$sql .= ');';
|
||||
$entries = $this->findEntities($sql, array_merge([$userId], $groups), $limit, $offset);
|
||||
/* @var Board $entry */
|
||||
foreach ($entries as $entry) {
|
||||
$acl = $this->aclMapper->findAll($entry->id);
|
||||
@@ -65,4 +96,23 @@ class BoardMapper extends Mapper {
|
||||
return parent::delete($entity);
|
||||
}
|
||||
|
||||
public function userCanView($boardId, $userInfo) {
|
||||
$board = $this->find($boardId);
|
||||
if($board->getOwner()===$userInfo['user']) {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
$sql = 'SELECT acl.* 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.id = ? AND boards.owner != ?';
|
||||
$acl = $this->find($sql, [$userInfo['user'], $boardId, $userInfo['user']], $limit, $offset);
|
||||
return true;
|
||||
} catch (Exception $e) { }
|
||||
try {
|
||||
$acl = $this->find($sql, [$userInfo['user'], $boardId, $userInfo['user']], $limit, $offset);
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user