Start implementing board sharing

This commit is contained in:
Julius Haertl 2016-08-16 10:29:37 +02:00
Родитель 135d9c9cbc
Коммит 6a040f1470
10 изменённых файлов: 140 добавлений и 25 удалений

Просмотреть файл

@ -8,18 +8,34 @@ use OCP\IRequest;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\IUserManager;
use OCP\IGroupManager;
class BoardController extends Controller {
private $userId;
private $boardService;
protected $userManager;
protected $groupManager;
public function __construct($appName,
IRequest $request,
IUserManager $userManager,
IGroupManager $groupManager,
BoardService $cardService,
$userId) {
parent::__construct($appName, $request);
$this->userId = $userId;
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->boardService = $cardService;
$this->userInfo = $this->getBoardPrequisites();
}
private function getBoardPrequisites() {
$groups = $this->groupManager->getUserGroupIds($this->userManager->get($this->userId));
return [
'user' => $this->userId,
'groups' => $groups
];
}
/**
@ -27,7 +43,7 @@ class BoardController extends Controller {
*/
public function index() {
return $this->boardService->findAll($this->userId);
return $this->boardService->findAll($this->userInfo);
}
/**

Просмотреть файл

@ -12,14 +12,17 @@ class ShareController extends Controller {
protected $userManager;
protected $groupManager;
private $userId;
public function __construct($appName,
IRequest $request,
IUserManager $userManager,
IGroupManager $groupManager
IGroupManager $groupManager,
$userId
){
parent::__construct($appName, $request);
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->userId = $userId;
}
/**
@ -41,9 +44,11 @@ class ShareController extends Controller {
$result[] = $acl;
}
foreach ($this->userManager->searchDisplayName($search, $limit, $offset) as $idx => $user) {
if($user->getUID() === $this->userId)
continue;
$acl = new Acl();
$acl->setType('user');
$acl->setParticipant($user->getDisplayName());
$acl->setParticipant($user->getUID());
$acl->setPermissionWrite(true);
$acl->setPermissionInvite(true);
$acl->setPermissionManage(true);

Просмотреть файл

@ -6,6 +6,14 @@
.app-navigation-entry-utils-menu-button {
display: block !important;
}
.app-navigation-entry-utils-menu-share {
display: block !important;
text-align:right;
padding-top:3px;
padding-right:5px;
opacity:0.4;
}
#app-navigation .app-navigation-entry-edit {
height: auto;
}

Просмотреть файл

@ -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);
}
}

Просмотреть файл

@ -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) {
}
}
}

Просмотреть файл

@ -0,0 +1,32 @@
<?php
namespace OCA\Deck\Middleware;
use \OCP\AppFramework\Middleware;
use OCP\IDBConnection;
use OCP\IGroupManager;
use OCP\IUserManager;
class SharingMiddleware extends Middleware {
public function __construct(
IUserManager $userManager,
IGroupManager $groupManager,
IDBConnection $db,
$userId
) {
$this->userId = $userId;
$this->db = $db;
$this->userManager = $userManager;
$this->groupManager = $groupManager;
}
public function beforeController($controller, $methodName) {
\OCP\Util::writeLog('deck', "", \OCP\Util::ERROR);
//$userBoards = $this->boardMapper->findAllByUser($userInfo['user']);
//$groupBoards = $this->boardMapper->findAllByGroups($userInfo['user'], $userInfo['groups']);
}
}

Просмотреть файл

@ -1,11 +0,0 @@
<?php
/**
* Created by PhpStorm.
* User: jus
* Date: 15.08.16
* Time: 16:36
*/
class SharingMiddleware {
}

Просмотреть файл

@ -24,7 +24,8 @@ class BoardService {
private $l10n;
private $timeFactory;
public function __construct(BoardMapper $boardMapper, ILogger $logger,
public function __construct(BoardMapper $boardMapper,
ILogger $logger,
IL10N $l10n,
ITimeFactory $timeFactory,
LabelMapper $labelMapper,
@ -36,8 +37,10 @@ class BoardService {
$this->l10n = $l10n;
}
public function findAll($userId) {
return $this->boardMapper->findAll($userId);
public function findAll($userInfo) {
$userBoards = $this->boardMapper->findAllByUser($userInfo['user']);
$groupBoards = $this->boardMapper->findAllByGroups($userInfo['user'], $userInfo['groups']);
return array_merge($userBoards, $groupBoards);
}
public function find($userId, $boardId) {