Merge pull request #58 from nextcloud/displaynames
Implement relational mapping for users and groups to show displaynames
This commit is contained in:
@@ -55,26 +55,19 @@ app.factory('BoardService', function(ApiService, $http, $q){
|
|||||||
|
|
||||||
// filter out everyone who is already in the share list
|
// filter out everyone who is already in the share list
|
||||||
angular.forEach(users, function (item) {
|
angular.forEach(users, function (item) {
|
||||||
|
var acl = self.generateAcl('user', item);
|
||||||
var exists = false;
|
var exists = false;
|
||||||
angular.forEach(self.getCurrent().acl, function (acl) {
|
angular.forEach(self.getCurrent().acl, function (acl) {
|
||||||
if (acl.participant.primaryKey === item.value.shareWith || OC.getCurrentUser() === item.value.shareWith) {
|
if (acl.participant.primaryKey === item.value.shareWith) {
|
||||||
exists = true;
|
exists = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!exists) {
|
if (!exists && OC.getCurrentUser().uid !== item.value.shareWith) {
|
||||||
self.sharees.push({
|
self.sharees.push(acl);
|
||||||
boardId: null,
|
|
||||||
id: null,
|
|
||||||
owner: false,
|
|
||||||
participant: item.value.shareWith,
|
|
||||||
permissionEdit: true,
|
|
||||||
permissionManage: true,
|
|
||||||
permissionShare: true,
|
|
||||||
type: 'user'
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
angular.forEach(groups, function (item) {
|
angular.forEach(groups, function (item) {
|
||||||
|
var acl = self.generateAcl('group', item);
|
||||||
var exists = false;
|
var exists = false;
|
||||||
angular.forEach(self.getCurrent().acl, function (acl) {
|
angular.forEach(self.getCurrent().acl, function (acl) {
|
||||||
if (acl.participant.primaryKey === item.value.shareWith) {
|
if (acl.participant.primaryKey === item.value.shareWith) {
|
||||||
@@ -82,16 +75,7 @@ app.factory('BoardService', function(ApiService, $http, $q){
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
self.sharees.push({
|
self.sharees.push(acl);
|
||||||
boardId: null,
|
|
||||||
id: null,
|
|
||||||
owner: false,
|
|
||||||
participant: item.value.shareWith,
|
|
||||||
permissionEdit: true,
|
|
||||||
permissionManage: true,
|
|
||||||
permissionShare: true,
|
|
||||||
type: 'group'
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -103,13 +87,30 @@ app.factory('BoardService', function(ApiService, $http, $q){
|
|||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
BoardService.prototype.addAcl = function(acl) {
|
BoardService.prototype.generateAcl = function(type, ocsItem) {
|
||||||
|
return {
|
||||||
|
boardId: null,
|
||||||
|
id: null,
|
||||||
|
owner: false,
|
||||||
|
participant: {
|
||||||
|
primaryKey: ocsItem.value.shareWith,
|
||||||
|
uid: ocsItem.value.shareWith,
|
||||||
|
displayname: ocsItem.label
|
||||||
|
},
|
||||||
|
permissionEdit: true,
|
||||||
|
permissionManage: true,
|
||||||
|
permissionShare: true,
|
||||||
|
type: type
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
BoardService.prototype.addAcl = function (acl) {
|
||||||
var board = this.getCurrent();
|
var board = this.getCurrent();
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
var self = this;
|
var self = this;
|
||||||
var _acl = acl;
|
var _acl = acl;
|
||||||
$http.post(this.baseUrl + '/' + acl.boardId + '/acl', _acl).then(function (response) {
|
$http.post(this.baseUrl + '/' + acl.boardId + '/acl', _acl).then(function (response) {
|
||||||
if(!board.acl) {
|
if (!board.acl || board.acl.length === 0) {
|
||||||
board.acl = {};
|
board.acl = {};
|
||||||
}
|
}
|
||||||
board.acl[response.data.id] = response.data;
|
board.acl[response.data.id] = response.data;
|
||||||
@@ -155,7 +156,6 @@ app.factory('BoardService', function(ApiService, $http, $q){
|
|||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
$http.get(this.baseUrl + '/' + board.id + '/permissions').then(function (response) {
|
$http.get(this.baseUrl + '/' + board.id + '/permissions').then(function (response) {
|
||||||
board.permissions = response.data;
|
board.permissions = response.data;
|
||||||
console.log(board.permissions);
|
|
||||||
deferred.resolve(response.data);
|
deferred.resolve(response.data);
|
||||||
}, function (error) {
|
}, function (error) {
|
||||||
deferred.reject('Error fetching board permissions ' + board);
|
deferred.reject('Error fetching board permissions ' + board);
|
||||||
|
|||||||
@@ -48,12 +48,10 @@ class Acl extends RelationalEntity implements \JsonSerializable {
|
|||||||
$this->addType('permissionEdit', 'boolean');
|
$this->addType('permissionEdit', 'boolean');
|
||||||
$this->addType('permissionShare', 'boolean');
|
$this->addType('permissionShare', 'boolean');
|
||||||
$this->addType('permissionManage', 'boolean');
|
$this->addType('permissionManage', 'boolean');
|
||||||
$this->addType('owner', 'boolean');
|
|
||||||
$this->addType('type', 'integer');
|
$this->addType('type', 'integer');
|
||||||
|
$this->addType('owner', 'boolean');
|
||||||
$this->addRelation('owner');
|
$this->addRelation('owner');
|
||||||
$this->setPermissionEdit(false);
|
$this->addResolvable('participant');
|
||||||
$this->setPermissionShare(false);
|
|
||||||
$this->setPermissionManage(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPermission($permission) {
|
public function getPermission($permission) {
|
||||||
@@ -93,4 +91,5 @@ class Acl extends RelationalEntity implements \JsonSerializable {
|
|||||||
$this->markFieldUpdated('type');
|
$this->markFieldUpdated('type');
|
||||||
$this->type = $typeInt;
|
$this->type = $typeInt;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -25,7 +25,6 @@ namespace OCA\Deck\Db;
|
|||||||
|
|
||||||
use OCP\IDBConnection;
|
use OCP\IDBConnection;
|
||||||
|
|
||||||
|
|
||||||
class AclMapper extends DeckMapper implements IPermissionMapper {
|
class AclMapper extends DeckMapper implements IPermissionMapper {
|
||||||
|
|
||||||
public function __construct(IDBConnection $db) {
|
public function __construct(IDBConnection $db) {
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ class Board extends RelationalEntity implements JsonSerializable {
|
|||||||
protected $owner;
|
protected $owner;
|
||||||
protected $color;
|
protected $color;
|
||||||
protected $archived = false;
|
protected $archived = false;
|
||||||
protected $labels;
|
protected $labels = [];
|
||||||
protected $acl;
|
protected $acl = [];
|
||||||
protected $shared;
|
protected $shared;
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
@@ -43,6 +43,7 @@ class Board extends RelationalEntity implements JsonSerializable {
|
|||||||
$this->addRelation('labels');
|
$this->addRelation('labels');
|
||||||
$this->addRelation('acl');
|
$this->addRelation('acl');
|
||||||
$this->addRelation('shared');
|
$this->addRelation('shared');
|
||||||
|
$this->addResolvable('owner');
|
||||||
$this->shared = -1;
|
$this->shared = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,6 +52,7 @@ class Board extends RelationalEntity implements JsonSerializable {
|
|||||||
if ($this->shared === -1) {
|
if ($this->shared === -1) {
|
||||||
unset($json['shared']);
|
unset($json['shared']);
|
||||||
}
|
}
|
||||||
|
$json['owner'] = $this->resolveOwner();
|
||||||
return $json;
|
return $json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,19 +24,31 @@
|
|||||||
namespace OCA\Deck\Db;
|
namespace OCA\Deck\Db;
|
||||||
|
|
||||||
use OCP\IDBConnection;
|
use OCP\IDBConnection;
|
||||||
|
use OCP\IUserManager;
|
||||||
|
use OCP\IGroupManager;
|
||||||
|
|
||||||
class BoardMapper extends DeckMapper implements IPermissionMapper {
|
class BoardMapper extends DeckMapper implements IPermissionMapper {
|
||||||
|
|
||||||
private $labelMapper;
|
private $labelMapper;
|
||||||
private $aclMapper;
|
private $aclMapper;
|
||||||
private $stackMapper;
|
private $stackMapper;
|
||||||
|
private $userManager;
|
||||||
|
private $groupManager;
|
||||||
|
|
||||||
public function __construct(IDBConnection $db, LabelMapper $labelMapper, AclMapper $aclMapper, StackMapper $stackMapper) {
|
public function __construct(
|
||||||
|
IDBConnection $db,
|
||||||
|
LabelMapper $labelMapper,
|
||||||
|
AclMapper $aclMapper,
|
||||||
|
StackMapper $stackMapper,
|
||||||
|
IUserManager $userManager,
|
||||||
|
IGroupManager $groupManager
|
||||||
|
) {
|
||||||
parent::__construct($db, 'deck_boards', '\OCA\Deck\Db\Board');
|
parent::__construct($db, 'deck_boards', '\OCA\Deck\Db\Board');
|
||||||
$this->labelMapper = $labelMapper;
|
$this->labelMapper = $labelMapper;
|
||||||
$this->aclMapper = $aclMapper;
|
$this->aclMapper = $aclMapper;
|
||||||
$this->stackMapper = $stackMapper;
|
$this->stackMapper = $stackMapper;
|
||||||
|
$this->userManager = $userManager;
|
||||||
|
$this->groupManager = $groupManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -149,5 +161,29 @@ class BoardMapper extends DeckMapper implements IPermissionMapper {
|
|||||||
return $id;
|
return $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function mapAcl(Acl &$acl) {
|
||||||
|
$userManager = $this->userManager;
|
||||||
|
$groupManager = $this->groupManager;
|
||||||
|
$acl->resolveRelation('participant', function($participant) use (&$acl, &$userManager, &$groupManager) {
|
||||||
|
if($acl->getType() === Acl::PERMISSION_TYPE_USER) {
|
||||||
|
return new User($userManager->get($acl->getParticipant($participant)));
|
||||||
|
}
|
||||||
|
if($acl->getType() === Acl::PERMISSION_TYPE_GROUP) {
|
||||||
|
return new Group($groupManager->get($acl->getParticipant($participant)));
|
||||||
|
}
|
||||||
|
throw new \Exception('Unknown permission type for mapping Acl');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Board $board
|
||||||
|
*/
|
||||||
|
public function mapOwner(Board &$board) {
|
||||||
|
$userManager = $this->userManager;
|
||||||
|
$board->resolveRelation('owner', function($owner) use (&$userManager) {
|
||||||
|
return new User($userManager->get($owner));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -48,6 +48,7 @@ class Card extends RelationalEntity implements JsonSerializable {
|
|||||||
$this->addType('createdAt', 'integer');
|
$this->addType('createdAt', 'integer');
|
||||||
$this->addType('archived', 'boolean');
|
$this->addType('archived', 'boolean');
|
||||||
$this->addRelation('labels');
|
$this->addRelation('labels');
|
||||||
|
$this->addResolvable('owner');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,15 +25,17 @@ namespace OCA\Deck\Db;
|
|||||||
|
|
||||||
use OCP\AppFramework\Db\Entity;
|
use OCP\AppFramework\Db\Entity;
|
||||||
use OCP\IDBConnection;
|
use OCP\IDBConnection;
|
||||||
|
use OCP\IUserManager;
|
||||||
|
|
||||||
|
|
||||||
class CardMapper extends DeckMapper implements IPermissionMapper {
|
class CardMapper extends DeckMapper implements IPermissionMapper {
|
||||||
|
|
||||||
private $labelMapper;
|
private $labelMapper;
|
||||||
|
|
||||||
public function __construct(IDBConnection $db, LabelMapper $labelMapper) {
|
public function __construct(IDBConnection $db, LabelMapper $labelMapper, IUserManager $userManager) {
|
||||||
parent::__construct($db, 'deck_cards', '\OCA\Deck\Db\Card');
|
parent::__construct($db, 'deck_cards', '\OCA\Deck\Db\Card');
|
||||||
$this->labelMapper = $labelMapper;
|
$this->labelMapper = $labelMapper;
|
||||||
|
$this->userManager = $userManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function insert(Entity $entity) {
|
public function insert(Entity $entity) {
|
||||||
@@ -57,6 +59,7 @@ class CardMapper extends DeckMapper implements IPermissionMapper {
|
|||||||
$card = $this->findEntity($sql, [$id]);
|
$card = $this->findEntity($sql, [$id]);
|
||||||
$labels = $this->labelMapper->findAssignedLabelsForCard($card->id);
|
$labels = $this->labelMapper->findAssignedLabelsForCard($card->id);
|
||||||
$card->setLabels($labels);
|
$card->setLabels($labels);
|
||||||
|
$this->mapOwner($card);
|
||||||
return $card;
|
return $card;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,5 +128,12 @@ class CardMapper extends DeckMapper implements IPermissionMapper {
|
|||||||
return $row['id'];
|
return $row['id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function mapOwner(Card &$card) {
|
||||||
|
$userManager = $this->userManager;
|
||||||
|
$card->resolveRelation('owner', function($owner) use (&$userManager) {
|
||||||
|
return new User($userManager->get($owner));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
41
lib/Db/Group.php
Normal file
41
lib/Db/Group.php
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @copyright Copyright (c) 2017 Julius Härtl <jus@bitgrid.net>
|
||||||
|
*
|
||||||
|
* @author Julius Härtl <jus@bitgrid.net>
|
||||||
|
*
|
||||||
|
* @license GNU AGPL version 3 or any later version
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace OCA\Deck\Db;
|
||||||
|
|
||||||
|
use OCP\IGroup;
|
||||||
|
|
||||||
|
class Group extends RelationalObject {
|
||||||
|
|
||||||
|
public function __construct(IGroup $group) {
|
||||||
|
$primaryKey = $group->getGID();
|
||||||
|
parent::__construct($primaryKey, $group);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getObjectSerialization() {
|
||||||
|
return [
|
||||||
|
'uid' => $this->object->getGID(),
|
||||||
|
'displayname' => $this->object->getDisplayName()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
|
* @copyright Copyright (c) 2017 Julius Härtl <jus@bitgrid.net>
|
||||||
*
|
*
|
||||||
* @author Julius Härtl <jus@bitgrid.net>
|
* @author Julius Härtl <jus@bitgrid.net>
|
||||||
*
|
*
|
||||||
@@ -23,20 +23,31 @@
|
|||||||
|
|
||||||
namespace OCA\Deck\Db;
|
namespace OCA\Deck\Db;
|
||||||
|
|
||||||
|
use OCP\AppFramework\Db\Entity;
|
||||||
|
|
||||||
class RelationalEntity extends \OCP\AppFramework\Db\Entity implements \JsonSerializable {
|
class RelationalEntity extends Entity implements \JsonSerializable {
|
||||||
|
|
||||||
private $_relations = array();
|
private $_relations = array();
|
||||||
|
private $_resolvedProperties = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark a property as relation so it will not get updated using Mapper::update
|
* Mark a property as relation so it will not get updated using Mapper::update
|
||||||
* @param string $property Name of the property
|
* @param $property string Name of the property
|
||||||
*/
|
*/
|
||||||
public function addRelation($property) {
|
public function addRelation($property) {
|
||||||
if (!in_array($property, $this->_relations)) {
|
if (!in_array($property, $this->_relations)) {
|
||||||
$this->_relations[] = $property;
|
$this->_relations[] = $property;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mark a property as resolvable via resolveRelation()
|
||||||
|
* @param $property string Name of the property
|
||||||
|
*/
|
||||||
|
public function addResolvable($property) {
|
||||||
|
$this->_resolvedProperties[$property] = null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark am attribute as updated
|
* Mark am attribute as updated
|
||||||
* overwritten from \OCP\AppFramework\Db\Entity to avoid writing relational attributes
|
* overwritten from \OCP\AppFramework\Db\Entity to avoid writing relational attributes
|
||||||
@@ -56,14 +67,75 @@ class RelationalEntity extends \OCP\AppFramework\Db\Entity implements \JsonSeria
|
|||||||
$properties = get_object_vars($this);
|
$properties = get_object_vars($this);
|
||||||
$reflection = new \ReflectionClass($this);
|
$reflection = new \ReflectionClass($this);
|
||||||
$json = [];
|
$json = [];
|
||||||
foreach($properties as $property=>$value) {
|
foreach ($properties as $property => $value) {
|
||||||
if(substr($property, 0, 1) !== '_' && $reflection->hasProperty($property)) {
|
if (substr($property, 0, 1) !== '_' && $reflection->hasProperty($property)) {
|
||||||
$propertyReflection = $reflection->getProperty($property);
|
$propertyReflection = $reflection->getProperty($property);
|
||||||
if(!$propertyReflection->isPrivate()) {
|
if (!$propertyReflection->isPrivate()) {
|
||||||
$json[$property] = $this->getter($property);
|
$json[$property] = $this->getter($property);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
foreach ($this->_resolvedProperties as $property => $value) {
|
||||||
|
if($value !== null) {
|
||||||
|
$json[$property] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
return $json;
|
return $json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Resolve relational data from external methods
|
||||||
|
*
|
||||||
|
* example usage:
|
||||||
|
*
|
||||||
|
* in Board::__construct()
|
||||||
|
* $this->addResolvable('owner')
|
||||||
|
*
|
||||||
|
* in BoardMapper
|
||||||
|
* $board->resolveRelation('owner', function($owner) use (&$userManager) {
|
||||||
|
* return new \OCA\Deck\Db\User($userManager->get($owner));
|
||||||
|
* });
|
||||||
|
*
|
||||||
|
* resolved values can be obtained by calling resolveProperty
|
||||||
|
* e.g. $board->resolveOwner()
|
||||||
|
*
|
||||||
|
* @param string $property name of the property
|
||||||
|
* @param callable $resolver anonymous function to resolve relational
|
||||||
|
* data defined by $property as unique identifier
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function resolveRelation($property, $resolver) {
|
||||||
|
$result = null;
|
||||||
|
if($property !== null && $this->$property !== null) {
|
||||||
|
$result = $resolver($this->$property);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($result instanceof RelationalObject || $result === null) {
|
||||||
|
$this->_resolvedProperties[$property] = $result;
|
||||||
|
} else {
|
||||||
|
throw new \Exception('resolver must return an instance of RelationalObject');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __call($methodName, $args){
|
||||||
|
$attr = lcfirst( substr($methodName, 7) );
|
||||||
|
if(strpos($methodName, 'resolve') === 0 && array_key_exists($attr, $this->_resolvedProperties)) {
|
||||||
|
if($this->_resolvedProperties[$attr] !== null) {
|
||||||
|
return $this->_resolvedProperties[$attr];
|
||||||
|
} else {
|
||||||
|
return $this->getter($attr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$attr = lcfirst( substr($methodName, 3) );
|
||||||
|
if(strpos($methodName, 'set') === 0 && array_key_exists($attr, $this->_resolvedProperties)) {
|
||||||
|
if(!is_scalar($args[0])) {
|
||||||
|
$args[0] = $args[0]['primaryKey'];
|
||||||
|
}
|
||||||
|
parent::setter($attr, $args);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return parent::__call($methodName, $args);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
59
lib/Db/RelationalObject.php
Normal file
59
lib/Db/RelationalObject.php
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @copyright Copyright (c) 2017 Julius Härtl <jus@bitgrid.net>
|
||||||
|
*
|
||||||
|
* @author Julius Härtl <jus@bitgrid.net>
|
||||||
|
*
|
||||||
|
* @license GNU AGPL version 3 or any later version
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace OCA\Deck\Db;
|
||||||
|
|
||||||
|
class RelationalObject implements \JsonSerializable {
|
||||||
|
|
||||||
|
private $primaryKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RelationalObject constructor.
|
||||||
|
*
|
||||||
|
* @param $primaryKey string
|
||||||
|
* @param $object
|
||||||
|
*/
|
||||||
|
public function __construct($primaryKey, $object) {
|
||||||
|
$this->primaryKey = $primaryKey;
|
||||||
|
$this->object = $object;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function jsonSerialize() {
|
||||||
|
return array_merge(
|
||||||
|
['primaryKey' => $this->primaryKey],
|
||||||
|
$this->getObjectSerialization()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method should be overwritten if object doesn't implement \JsonSerializable
|
||||||
|
*/
|
||||||
|
public function getObjectSerialization() {
|
||||||
|
if($this->object instanceof \JsonSerializable) {
|
||||||
|
$this->object->jsonSerialize();
|
||||||
|
} else {
|
||||||
|
throw new \Exception('jsonSerialize is not implemented on ' . get_class($this));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
41
lib/Db/User.php
Normal file
41
lib/Db/User.php
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @copyright Copyright (c) 2017 Julius Härtl <jus@bitgrid.net>
|
||||||
|
*
|
||||||
|
* @author Julius Härtl <jus@bitgrid.net>
|
||||||
|
*
|
||||||
|
* @license GNU AGPL version 3 or any later version
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace OCA\Deck\Db;
|
||||||
|
|
||||||
|
use OCP\IUser;
|
||||||
|
|
||||||
|
class User extends RelationalObject {
|
||||||
|
|
||||||
|
public function __construct(IUser $user) {
|
||||||
|
$primaryKey = $user->getUID();
|
||||||
|
parent::__construct($primaryKey, $user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getObjectSerialization() {
|
||||||
|
return [
|
||||||
|
'uid' => $this->object->getUID(),
|
||||||
|
'displayname' => $this->object->getDisplayName()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,10 +26,7 @@ namespace OCA\Deck\Service;
|
|||||||
use OCA\Deck\Db\Acl;
|
use OCA\Deck\Db\Acl;
|
||||||
use OCA\Deck\Db\AclMapper;
|
use OCA\Deck\Db\AclMapper;
|
||||||
use OCA\Deck\Db\Label;
|
use OCA\Deck\Db\Label;
|
||||||
|
|
||||||
|
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
|
|
||||||
use OCA\Deck\Db\Board;
|
use OCA\Deck\Db\Board;
|
||||||
use OCA\Deck\Db\BoardMapper;
|
use OCA\Deck\Db\BoardMapper;
|
||||||
use OCA\Deck\Db\LabelMapper;
|
use OCA\Deck\Db\LabelMapper;
|
||||||
@@ -55,13 +52,35 @@ class BoardService {
|
|||||||
$userBoards = $this->boardMapper->findAllByUser($userInfo['user']);
|
$userBoards = $this->boardMapper->findAllByUser($userInfo['user']);
|
||||||
$groupBoards = $this->boardMapper->findAllByGroups($userInfo['user'], $userInfo['groups']);
|
$groupBoards = $this->boardMapper->findAllByGroups($userInfo['user'], $userInfo['groups']);
|
||||||
$complete = array_merge($userBoards, $groupBoards);
|
$complete = array_merge($userBoards, $groupBoards);
|
||||||
return array_map("unserialize", array_unique(array_map("serialize", $complete)));
|
$result = [];
|
||||||
|
foreach($complete as &$item) {
|
||||||
|
if(!array_key_exists($item->getId(), $result)) {
|
||||||
|
$this->boardMapper->mapOwner($item);
|
||||||
|
if($item->getAcl() !== null) {
|
||||||
|
foreach ($item->getAcl() as &$acl) {
|
||||||
|
$this->boardMapper->mapAcl($acl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$result[$item->getId()] = $item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return array_values($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function find($boardId) {
|
public function find($boardId) {
|
||||||
$this->permissionService->checkPermission($this->boardMapper, $boardId, Acl::PERMISSION_READ);
|
$this->permissionService->checkPermission($this->boardMapper, $boardId, Acl::PERMISSION_READ);
|
||||||
return $this->boardMapper->find($boardId, true, true);
|
/** @var Board $board */
|
||||||
|
$board = $this->boardMapper->find($boardId, true, true);
|
||||||
|
$this->boardMapper->mapOwner($board);
|
||||||
|
foreach ($board->getAcl() as &$acl) {
|
||||||
|
if($acl !== null) {
|
||||||
|
$this->boardMapper->mapAcl($acl);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return $board;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function create($title, $userId, $color) {
|
public function create($title, $userId, $color) {
|
||||||
$board = new Board();
|
$board = new Board();
|
||||||
@@ -86,6 +105,7 @@ class BoardService {
|
|||||||
$labels[] = $this->labelMapper->insert($label);
|
$labels[] = $this->labelMapper->insert($label);
|
||||||
}
|
}
|
||||||
$new_board->setLabels($labels);
|
$new_board->setLabels($labels);
|
||||||
|
$this->boardMapper->mapOwner($new_board);
|
||||||
return $new_board;
|
return $new_board;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -100,6 +120,7 @@ class BoardService {
|
|||||||
$board = $this->find($id);
|
$board = $this->find($id);
|
||||||
$board->setTitle($title);
|
$board->setTitle($title);
|
||||||
$board->setColor($color);
|
$board->setColor($color);
|
||||||
|
$this->boardMapper->mapOwner($board);
|
||||||
return $this->boardMapper->update($board);
|
return $this->boardMapper->update($board);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,21 +134,27 @@ class BoardService {
|
|||||||
$acl->setPermissionEdit($edit);
|
$acl->setPermissionEdit($edit);
|
||||||
$acl->setPermissionShare($share);
|
$acl->setPermissionShare($share);
|
||||||
$acl->setPermissionManage($manage);
|
$acl->setPermissionManage($manage);
|
||||||
return $this->aclMapper->insert($acl);
|
$newAcl = $this->aclMapper->insert($acl);
|
||||||
|
$this->boardMapper->mapAcl($newAcl);
|
||||||
|
return $newAcl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateAcl($id, $edit, $share, $manage) {
|
public function updateAcl($id, $edit, $share, $manage) {
|
||||||
$this->permissionService->checkPermission($this->aclMapper, $id, Acl::PERMISSION_SHARE);
|
$this->permissionService->checkPermission($this->aclMapper, $id, Acl::PERMISSION_SHARE);
|
||||||
|
/** @var Acl $acl */
|
||||||
$acl = $this->aclMapper->find($id);
|
$acl = $this->aclMapper->find($id);
|
||||||
$acl->setPermissionEdit($edit);
|
$acl->setPermissionEdit($edit);
|
||||||
$acl->setPermissionShare($share);
|
$acl->setPermissionShare($share);
|
||||||
$acl->setPermissionManage($manage);
|
$acl->setPermissionManage($manage);
|
||||||
|
$this->boardMapper->mapAcl($acl);
|
||||||
return $this->aclMapper->update($acl);
|
return $this->aclMapper->update($acl);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteAcl($id) {
|
public function deleteAcl($id) {
|
||||||
$this->permissionService->checkPermission($this->aclMapper, $id, Acl::PERMISSION_SHARE);
|
$this->permissionService->checkPermission($this->aclMapper, $id, Acl::PERMISSION_SHARE);
|
||||||
|
/** @var Acl $acl */
|
||||||
$acl = $this->aclMapper->find($id);
|
$acl = $this->aclMapper->find($id);
|
||||||
|
$this->boardMapper->mapAcl($acl);
|
||||||
return $this->aclMapper->delete($acl);
|
return $this->aclMapper->delete($acl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ class CardService {
|
|||||||
|
|
||||||
public function find($cardId) {
|
public function find($cardId) {
|
||||||
$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_READ);
|
$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_READ);
|
||||||
return $this->cardMapper->find($cardId);
|
$card = $this->cardMapper->find($cardId);
|
||||||
|
return $card;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -19,10 +19,10 @@
|
|||||||
|
|
||||||
<ui-select ng-if="boardservice.canShare()" ng-model="status.addSharee" theme="select2" style="width:100%;" title="Choose a user to assign" placeholder="Assign users ..." on-select="aclAdd(status.addSharee)" search-enabled="true">
|
<ui-select ng-if="boardservice.canShare()" ng-model="status.addSharee" theme="select2" style="width:100%;" title="Choose a user to assign" placeholder="Assign users ..." on-select="aclAdd(status.addSharee)" search-enabled="true">
|
||||||
<ui-select-match placeholder="<?php p($l->t('Select users or groups to share with')); ?>">
|
<ui-select-match placeholder="<?php p($l->t('Select users or groups to share with')); ?>">
|
||||||
<span><i class="icon icon-{{$item.type}}"></i> {{ $item.participant }}</span>
|
<span><i class="icon icon-{{$item.type}}"></i> {{ $item.participant.displayname }}</span>
|
||||||
</ui-select-match>
|
</ui-select-match>
|
||||||
<ui-select-choices refresh="searchForUser($select.search)" refresh-delay="0" repeat="sharee in boardservice.sharees">
|
<ui-select-choices refresh="searchForUser($select.search)" refresh-delay="0" repeat="sharee in boardservice.sharees">
|
||||||
<span><i class="icon icon-{{sharee.type}}"></i> {{ sharee.participant }}</span>
|
<span><i class="icon icon-{{sharee.type}}"></i> {{ sharee.participant.displayname }}</span>
|
||||||
</ui-select-choices>
|
</ui-select-choices>
|
||||||
<ui-select-no-choice>
|
<ui-select-no-choice>
|
||||||
<?php p($l->t('No matching user or group found.')); ?>
|
<?php p($l->t('No matching user or group found.')); ?>
|
||||||
@@ -32,18 +32,18 @@
|
|||||||
<ul id="shareWithList" class="shareWithList">
|
<ul id="shareWithList" class="shareWithList">
|
||||||
<li>
|
<li>
|
||||||
<span class="icon-loading-small" style="display:none;"></span>
|
<span class="icon-loading-small" style="display:none;"></span>
|
||||||
<div class="avatardiv" avatar ng-attr-displayname="{{ boardservice.getCurrent().owner }}" ng-if="boardservice.id"></div>
|
<div class="avatardiv" avatar ng-attr-displayname="{{ boardservice.getCurrent().owner.uid }}" ng-if="boardservice.id"></div>
|
||||||
<span class="has-tooltip username">
|
<span class="has-tooltip username">
|
||||||
{{ boardservice.getCurrent().owner }}
|
{{ boardservice.getCurrent().owner.displayname }}
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
<li ng-repeat="acl in boardservice.getCurrent().acl track by $index">
|
<li ng-repeat="acl in boardservice.getCurrent().acl track by $index">
|
||||||
<span class="icon-loading-small" style="display:none;"></span>
|
<span class="icon-loading-small" style="display:none;"></span>
|
||||||
<div class="avatardiv" avatar displayname="{{ acl.participant }}" ng-if="acl.type=='user'"></div>
|
<div class="avatardiv" avatar displayname="{{ acl.participant.uid }}" ng-if="acl.type=='user'"></div>
|
||||||
<div class="avatardiv" ng-if="acl.type=='group'"><i class="icon icon-{{acl.type}}"></i></div>
|
<div class="avatardiv" ng-if="acl.type=='group'"><i class="icon icon-{{acl.type}}"></i></div>
|
||||||
|
|
||||||
<span class="has-tooltip username">
|
<span class="has-tooltip username">
|
||||||
{{ acl.participant }}
|
{{ acl.participant.displayname }}
|
||||||
</span>
|
</span>
|
||||||
<span class="sharingOptionsGroup">
|
<span class="sharingOptionsGroup">
|
||||||
<span class="shareOption" ng-if="boardservice.canManage()">
|
<span class="shareOption" ng-if="boardservice.canManage()">
|
||||||
|
|||||||
@@ -17,11 +17,8 @@
|
|||||||
<td><a href="#/board/{{b.id}}">{{ b.title }}</a></td>
|
<td><a href="#/board/{{b.id}}">{{ b.title }}</a></td>
|
||||||
<td>
|
<td>
|
||||||
<div id="assigned-users">
|
<div id="assigned-users">
|
||||||
<div class="avatardiv" avatar
|
<div class="avatardiv" avatar displayname="{{ b.owner.uid }}" title="{{ b.owner.displayname }}"></div>
|
||||||
displayname="{{ b.owner }}"></div>
|
<div class="avatardiv" avatar displayname="{{ acl.participant.uid }}" title="{{ acl.participant.uid }}" ng-repeat="acl in b.acl | limitTo: 7"></div>
|
||||||
<div class="avatardiv" avatar
|
|
||||||
displayname="{{ acl.participant }}"
|
|
||||||
ng-repeat="acl in b.acl | limitTo: 7"></div>
|
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
<?php p($l->t('Modified:')); ?> <span class="live-relative-timestamp" data-timestamp="{{cardservice.getCurrent().lastModified*1000}}">{{ cardservice.getCurrent().lastModified|relativeDateFilter }}</span>
|
<?php p($l->t('Modified:')); ?> <span class="live-relative-timestamp" data-timestamp="{{cardservice.getCurrent().lastModified*1000}}">{{ cardservice.getCurrent().lastModified|relativeDateFilter }}</span>
|
||||||
<?php p($l->t('Created:')); ?> <span class="live-relative-timestamp" data-timestamp="{{cardservice.getCurrent().createdAt*1000}}">{{ cardservice.getCurrent().createdAt|relativeDateFilter }}</span>
|
<?php p($l->t('Created:')); ?> <span class="live-relative-timestamp" data-timestamp="{{cardservice.getCurrent().createdAt*1000}}">{{ cardservice.getCurrent().createdAt|relativeDateFilter }}</span>
|
||||||
<?php p($l->t('by')); ?>
|
<?php p($l->t('by')); ?>
|
||||||
<span>{{ cardservice.getCurrent().owner }}</span>
|
<span>{{ cardservice.getCurrent().owner.displayname }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="labels">
|
<div id="labels">
|
||||||
|
|||||||
@@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
namespace OCA\Deck\Db;
|
namespace OCA\Deck\Db;
|
||||||
|
|
||||||
|
use OCP\IGroupManager;
|
||||||
|
use OCP\IUserManager;
|
||||||
use Test\AppFramework\Db\MapperTestUtility;
|
use Test\AppFramework\Db\MapperTestUtility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -33,6 +35,8 @@ class AclMapperTest extends MapperTestUtility {
|
|||||||
private $dbConnection;
|
private $dbConnection;
|
||||||
private $aclMapper;
|
private $aclMapper;
|
||||||
private $boardMapper;
|
private $boardMapper;
|
||||||
|
private $userManager;
|
||||||
|
private $groupManager;
|
||||||
|
|
||||||
// Data
|
// Data
|
||||||
private $acls;
|
private $acls;
|
||||||
@@ -43,11 +47,16 @@ class AclMapperTest extends MapperTestUtility {
|
|||||||
|
|
||||||
$this->dbConnection = \OC::$server->getDatabaseConnection();
|
$this->dbConnection = \OC::$server->getDatabaseConnection();
|
||||||
$this->aclMapper = new AclMapper($this->dbConnection);
|
$this->aclMapper = new AclMapper($this->dbConnection);
|
||||||
|
$this->userManager = $this->createMock(IUserManager::class);
|
||||||
|
$this->groupManager = $this->createMock(IGroupManager::class);
|
||||||
$this->boardMapper = new BoardMapper(
|
$this->boardMapper = new BoardMapper(
|
||||||
$this->dbConnection,
|
$this->dbConnection,
|
||||||
\OC::$server->query(LabelMapper::class),
|
\OC::$server->query(LabelMapper::class),
|
||||||
$this->aclMapper,
|
$this->aclMapper,
|
||||||
\OC::$server->query(StackMapper::class));
|
\OC::$server->query(StackMapper::class),
|
||||||
|
$this->userManager,
|
||||||
|
$this->groupManager
|
||||||
|
);
|
||||||
|
|
||||||
$this->boards = [
|
$this->boards = [
|
||||||
$this->boardMapper->insert($this->getBoard('MyBoard 1', 'user1')),
|
$this->boardMapper->insert($this->getBoard('MyBoard 1', 'user1')),
|
||||||
|
|||||||
@@ -23,7 +23,8 @@
|
|||||||
|
|
||||||
namespace OCA\Deck\Db;
|
namespace OCA\Deck\Db;
|
||||||
|
|
||||||
class AclTest extends \PHPUnit_Framework_TestCase {
|
class AclTest extends \Test\TestCase {
|
||||||
|
|
||||||
private function createAclUser() {
|
private function createAclUser() {
|
||||||
$acl = new Acl();
|
$acl = new Acl();
|
||||||
$acl->setId(1);
|
$acl->setId(1);
|
||||||
@@ -35,6 +36,7 @@ class AclTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$acl->setPermissionManage(true);
|
$acl->setPermissionManage(true);
|
||||||
return $acl;
|
return $acl;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createAclGroup() {
|
private function createAclGroup() {
|
||||||
$acl = new Acl();
|
$acl = new Acl();
|
||||||
$acl->setId(1);
|
$acl->setId(1);
|
||||||
@@ -46,6 +48,7 @@ class AclTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$acl->setPermissionManage(true);
|
$acl->setPermissionManage(true);
|
||||||
return $acl;
|
return $acl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testJsonSerialize() {
|
public function testJsonSerialize() {
|
||||||
$acl = $this->createAclUser();
|
$acl = $this->createAclUser();
|
||||||
$this->assertEquals([
|
$this->assertEquals([
|
||||||
@@ -70,6 +73,7 @@ class AclTest extends \PHPUnit_Framework_TestCase {
|
|||||||
'owner' => false
|
'owner' => false
|
||||||
], $acl->jsonSerialize());
|
], $acl->jsonSerialize());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetOwner() {
|
public function testSetOwner() {
|
||||||
$acl = $this->createAclUser();
|
$acl = $this->createAclUser();
|
||||||
$acl->setOwner(1);
|
$acl->setOwner(1);
|
||||||
|
|||||||
@@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
namespace OCA\Deck\Db;
|
namespace OCA\Deck\Db;
|
||||||
|
|
||||||
|
use OCP\IGroupManager;
|
||||||
|
use OCP\IUserManager;
|
||||||
use Test\AppFramework\Db\MapperTestUtility;
|
use Test\AppFramework\Db\MapperTestUtility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -33,6 +35,8 @@ class BoardMapperTest extends MapperTestUtility {
|
|||||||
private $dbConnection;
|
private $dbConnection;
|
||||||
private $aclMapper;
|
private $aclMapper;
|
||||||
private $boardMapper;
|
private $boardMapper;
|
||||||
|
private $userManager;
|
||||||
|
private $groupManager;
|
||||||
|
|
||||||
// Data
|
// Data
|
||||||
private $acls;
|
private $acls;
|
||||||
@@ -41,12 +45,17 @@ class BoardMapperTest extends MapperTestUtility {
|
|||||||
public function setup(){
|
public function setup(){
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->userManager = $this->createMock(IUserManager::class);
|
||||||
|
$this->groupManager = $this->createMock(IGroupManager::class);
|
||||||
|
|
||||||
$this->dbConnection = \OC::$server->getDatabaseConnection();
|
$this->dbConnection = \OC::$server->getDatabaseConnection();
|
||||||
$this->boardMapper = new BoardMapper(
|
$this->boardMapper = new BoardMapper(
|
||||||
$this->dbConnection,
|
$this->dbConnection,
|
||||||
\OC::$server->query(LabelMapper::class),
|
\OC::$server->query(LabelMapper::class),
|
||||||
\OC::$server->query(AclMapper::class),
|
\OC::$server->query(AclMapper::class),
|
||||||
\OC::$server->query(StackMapper::class)
|
\OC::$server->query(StackMapper::class),
|
||||||
|
$this->userManager,
|
||||||
|
$this->groupManager
|
||||||
);
|
);
|
||||||
$this->aclMapper = \OC::$server->query(AclMapper::class);
|
$this->aclMapper = \OC::$server->query(AclMapper::class);
|
||||||
$this->labelMapper = \OC::$server->query(LabelMapper::class);
|
$this->labelMapper = \OC::$server->query(LabelMapper::class);
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ class BoardTest extends \PHPUnit_Framework_TestCase {
|
|||||||
'title' => "My Board",
|
'title' => "My Board",
|
||||||
'owner' => "admin",
|
'owner' => "admin",
|
||||||
'color' => "000000",
|
'color' => "000000",
|
||||||
'labels' => null,
|
'labels' => array(),
|
||||||
'acl' => null,
|
'acl' => array(),
|
||||||
'archived' => false
|
'archived' => false
|
||||||
], $board->jsonSerialize());
|
], $board->jsonSerialize());
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ class BoardTest extends \PHPUnit_Framework_TestCase {
|
|||||||
'owner' => "admin",
|
'owner' => "admin",
|
||||||
'color' => "000000",
|
'color' => "000000",
|
||||||
'labels' => array("foo", "bar"),
|
'labels' => array("foo", "bar"),
|
||||||
'acl' => null,
|
'acl' => array(),
|
||||||
'archived' => false
|
'archived' => false
|
||||||
], $board->jsonSerialize());
|
], $board->jsonSerialize());
|
||||||
}
|
}
|
||||||
@@ -55,8 +55,8 @@ class BoardTest extends \PHPUnit_Framework_TestCase {
|
|||||||
'title' => "My Board",
|
'title' => "My Board",
|
||||||
'owner' => "admin",
|
'owner' => "admin",
|
||||||
'color' => "000000",
|
'color' => "000000",
|
||||||
'labels' => null,
|
'labels' => array(),
|
||||||
'acl' => null,
|
'acl' => array(),
|
||||||
'archived' => false,
|
'archived' => false,
|
||||||
'shared' => 1,
|
'shared' => 1,
|
||||||
], $board->jsonSerialize());
|
], $board->jsonSerialize());
|
||||||
|
|||||||
@@ -29,34 +29,35 @@ use OCA\Deck\Db\AclMapper;
|
|||||||
use OCA\Deck\Db\Board;
|
use OCA\Deck\Db\Board;
|
||||||
use OCA\Deck\Db\BoardMapper;
|
use OCA\Deck\Db\BoardMapper;
|
||||||
use OCA\Deck\Db\LabelMapper;
|
use OCA\Deck\Db\LabelMapper;
|
||||||
|
use OCA\Deck\Db\User;
|
||||||
use OCP\IGroupManager;
|
use OCP\IGroupManager;
|
||||||
use OCP\ILogger;
|
use OCP\ILogger;
|
||||||
|
use OCP\IUser;
|
||||||
|
use OCP\IUserManager;
|
||||||
|
|
||||||
class BoardServiceTest extends \PHPUnit_Framework_TestCase {
|
class BoardServiceTest extends \Test\TestCase {
|
||||||
|
|
||||||
|
/** @var BoardService */
|
||||||
private $service;
|
private $service;
|
||||||
private $logger;
|
/** @var L10N */
|
||||||
private $l10n;
|
private $l10n;
|
||||||
|
/** @var LabelMapper */
|
||||||
private $labelMapper;
|
private $labelMapper;
|
||||||
|
/** @var AclMapper */
|
||||||
private $aclMapper;
|
private $aclMapper;
|
||||||
|
/** @var BoardMapper */
|
||||||
private $boardMapper;
|
private $boardMapper;
|
||||||
private $groupManager;
|
/** @var PermissionService */
|
||||||
private $permissionService;
|
private $permissionService;
|
||||||
|
|
||||||
private $userId = 'admin';
|
private $userId = 'admin';
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
$this->l10n = $this->getMockBuilder(L10N::class)
|
$this->l10n = $this->createMock(L10N::class);
|
||||||
->disableOriginalConstructor()
|
$this->aclMapper = $this->createMock(AclMapper::class);
|
||||||
->getMock();
|
$this->boardMapper = $this->createMock(BoardMapper::class);
|
||||||
$this->aclMapper = $this->getMockBuilder(AclMapper::class)
|
$this->labelMapper = $this->createMock(LabelMapper::class);
|
||||||
->disableOriginalConstructor()->getMock();
|
$this->permissionService = $this->createMock(PermissionService::class);
|
||||||
$this->boardMapper = $this->getMockBuilder(BoardMapper::class)
|
|
||||||
->disableOriginalConstructor()->getMock();
|
|
||||||
$this->labelMapper = $this->getMockBuilder(LabelMapper::class)
|
|
||||||
->disableOriginalConstructor()->getMock();
|
|
||||||
$this->permissionService = $this->getMockBuilder(PermissionService::class)
|
|
||||||
->disableOriginalConstructor()->getMock();
|
|
||||||
|
|
||||||
$this->service = new BoardService(
|
$this->service = new BoardService(
|
||||||
$this->boardMapper,
|
$this->boardMapper,
|
||||||
@@ -65,32 +66,43 @@ class BoardServiceTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$this->aclMapper,
|
$this->aclMapper,
|
||||||
$this->permissionService
|
$this->permissionService
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$user = $this->createMock(IUser::class);
|
||||||
|
$user->method('getUID')->willReturn('admin');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFindAll() {
|
public function testFindAll() {
|
||||||
|
$b1 = new Board();
|
||||||
|
$b1->setId(1);
|
||||||
|
$b2 = new Board();
|
||||||
|
$b2->setId(2);
|
||||||
|
$b3 = new Board();
|
||||||
|
$b3->setId(3);
|
||||||
$this->boardMapper->expects($this->once())
|
$this->boardMapper->expects($this->once())
|
||||||
->method('findAllByUser')
|
->method('findAllByUser')
|
||||||
->with('admin')
|
->with('admin')
|
||||||
->willReturn([1,2,3,6,7]);
|
->willReturn([$b1, $b2]);
|
||||||
$this->boardMapper->expects($this->once())
|
$this->boardMapper->expects($this->once())
|
||||||
->method('findAllByGroups')
|
->method('findAllByGroups')
|
||||||
->with('admin', ['a', 'b', 'c'])
|
->with('admin', ['a', 'b', 'c'])
|
||||||
->willReturn([4,5,6,7,8]);
|
->willReturn([$b2, $b3]);
|
||||||
$userinfo = [
|
$userinfo = [
|
||||||
'user' => 'admin',
|
'user' => 'admin',
|
||||||
'groups' => ['a', 'b', 'c']
|
'groups' => ['a', 'b', 'c']
|
||||||
];
|
];
|
||||||
$result = $this->service->findAll($userinfo);
|
$result = $this->service->findAll($userinfo);
|
||||||
sort($result);
|
sort($result);
|
||||||
$this->assertEquals([1,2,3,4,5,6,7,8], $result);
|
$this->assertEquals([$b1, $b2, $b3], $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFind() {
|
public function testFind() {
|
||||||
|
$b1 = new Board();
|
||||||
|
$b1->setId(1);
|
||||||
$this->boardMapper->expects($this->once())
|
$this->boardMapper->expects($this->once())
|
||||||
->method('find')
|
->method('find')
|
||||||
->with(123)
|
->with(1)
|
||||||
->willReturn(1);
|
->willReturn($b1);
|
||||||
$this->assertEquals(1, $this->service->find(123));
|
$this->assertEquals($b1, $this->service->find(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreate() {
|
public function testCreate() {
|
||||||
@@ -130,9 +142,11 @@ class BoardServiceTest extends \PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testDelete() {
|
public function testDelete() {
|
||||||
|
$board = new Board();
|
||||||
|
$board->setOwner('admin');
|
||||||
$this->boardMapper->expects($this->once())
|
$this->boardMapper->expects($this->once())
|
||||||
->method('find')
|
->method('find')
|
||||||
->willReturn(new Board());
|
->willReturn($board);
|
||||||
$this->boardMapper->expects($this->once())
|
$this->boardMapper->expects($this->once())
|
||||||
->method('delete')
|
->method('delete')
|
||||||
->willReturn(1);
|
->willReturn(1);
|
||||||
@@ -140,6 +154,8 @@ class BoardServiceTest extends \PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testAddAcl() {
|
public function testAddAcl() {
|
||||||
|
$user = $this->createMock(IUser::class);
|
||||||
|
$user->method('getUID')->willReturn('admin');
|
||||||
$acl = new Acl();
|
$acl = new Acl();
|
||||||
$acl->setBoardId(123);
|
$acl->setBoardId(123);
|
||||||
$acl->setType('user');
|
$acl->setType('user');
|
||||||
@@ -147,6 +163,9 @@ class BoardServiceTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$acl->setPermissionEdit(true);
|
$acl->setPermissionEdit(true);
|
||||||
$acl->setPermissionShare(true);
|
$acl->setPermissionShare(true);
|
||||||
$acl->setPermissionManage(true);
|
$acl->setPermissionManage(true);
|
||||||
|
$acl->resolveRelation('participant', function($participant) use (&$user) {
|
||||||
|
return null;
|
||||||
|
});
|
||||||
$this->aclMapper->expects($this->once())
|
$this->aclMapper->expects($this->once())
|
||||||
->method('insert')
|
->method('insert')
|
||||||
->with($acl)
|
->with($acl)
|
||||||
|
|||||||
Reference in New Issue
Block a user