Use display name for users and groups

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Haertl
2017-02-13 22:05:50 +01:00
committed by Julius Härtl
parent 000e447801
commit 3e304a9ff2
12 changed files with 288 additions and 61 deletions

View File

@@ -48,12 +48,10 @@ class Acl extends RelationalEntity implements \JsonSerializable {
$this->addType('permissionEdit', 'boolean');
$this->addType('permissionShare', 'boolean');
$this->addType('permissionManage', 'boolean');
$this->addType('owner', 'boolean');
$this->addType('type', 'integer');
$this->addType('owner', 'boolean');
$this->addRelation('owner');
$this->setPermissionEdit(false);
$this->setPermissionShare(false);
$this->setPermissionManage(false);
$this->addResolvable('participant');
}
public function getPermission($permission) {
@@ -93,4 +91,5 @@ class Acl extends RelationalEntity implements \JsonSerializable {
$this->markFieldUpdated('type');
$this->type = $typeInt;
}
}

View File

@@ -25,7 +25,6 @@ namespace OCA\Deck\Db;
use OCP\IDBConnection;
class AclMapper extends DeckMapper implements IPermissionMapper {
public function __construct(IDBConnection $db) {

View File

@@ -32,8 +32,8 @@ class Board extends RelationalEntity implements JsonSerializable {
protected $owner;
protected $color;
protected $archived = false;
protected $labels;
protected $acl;
protected $labels = [];
protected $acl = [];
protected $shared;
public function __construct() {
@@ -43,6 +43,7 @@ class Board extends RelationalEntity implements JsonSerializable {
$this->addRelation('labels');
$this->addRelation('acl');
$this->addRelation('shared');
$this->addResolvable('owner');
$this->shared = -1;
}

View File

@@ -26,7 +26,9 @@ namespace OCA\Deck\Db;
class RelationalEntity extends \OCP\AppFramework\Db\Entity implements \JsonSerializable {
private $primaryKey;
private $_relations = array();
private $_resolvedProperties = [];
/**
* Mark a property as relation so it will not get updated using Mapper::update
@@ -37,6 +39,11 @@ class RelationalEntity extends \OCP\AppFramework\Db\Entity implements \JsonSeria
$this->_relations[] = $property;
}
}
public function addResolvable($property) {
$this->_resolvedProperties[$property] = null;
}
/**
* Mark am attribute as updated
* overwritten from \OCP\AppFramework\Db\Entity to avoid writing relational attributes
@@ -65,5 +72,40 @@ class RelationalEntity extends \OCP\AppFramework\Db\Entity implements \JsonSeria
}
}
return $json;
public function resolveRelation($property, $resolver) {
if($property !== null && $this->$property !== null) {
$result = $resolver($this->$property);
} else {
$result = null;
}
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, $args);
}
}
$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);
}
parent::setter($attr, $args);
}
return parent::__call($methodName, $args);
}
}

View File

@@ -0,0 +1,61 @@
<?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/>.
*
*/
/**
* Created by PhpStorm.
* User: jus
* Date: 27.02.17
* Time: 14:05
*/
namespace OCA\Deck\Db;
abstract class RelationalObject implements \JsonSerializable {
/**
* 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()
);
}
public function getObjectSerialization() {
$this->object->jsonSerialize();
}
public function getPrimaryKey() {
return $this->getPrimaryKey();
}
}

42
lib/Db/User.php Normal file
View File

@@ -0,0 +1,42 @@
<?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;
use OCP\IUser;
class User extends RelationalObject {
public function __construct(IUser $user = null) {
$primaryKey = $user->getUID();
parent::__construct($primaryKey, $user);
}
public function getObjectSerialization() {
return [
'uid' => $this->object->getUID(),
'displayname' => $this->object->getDisplayName()
];
}
}