Fix Acl
This commit is contained in:
117
lib/Db/Acl.php
117
lib/Db/Acl.php
@@ -5,20 +5,20 @@
|
|||||||
* @author Julius Härtl <jus@bitgrid.net>
|
* @author Julius Härtl <jus@bitgrid.net>
|
||||||
*
|
*
|
||||||
* @license GNU AGPL version 3 or any later version
|
* @license GNU AGPL version 3 or any later version
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Affero General Public License as
|
* it under the terms of the GNU Affero General Public License as
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
* License, or (at your option) any later version.
|
* License, or (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Affero General Public License for more details.
|
* GNU Affero General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
* 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/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace OCA\Deck\Db;
|
namespace OCA\Deck\Db;
|
||||||
@@ -30,52 +30,77 @@ class Acl extends Entity implements \JsonSerializable {
|
|||||||
const PERMISSION_SHARE = 2;
|
const PERMISSION_SHARE = 2;
|
||||||
const PERMISSION_MANAGE = 3;
|
const PERMISSION_MANAGE = 3;
|
||||||
|
|
||||||
public $id;
|
const PERMISSION_TYPE_USER = 0;
|
||||||
protected $participant;
|
const PERMISSION_TYPE_GROUP = 1;
|
||||||
protected $type;
|
|
||||||
protected $boardId;
|
|
||||||
protected $permissionEdit;
|
|
||||||
protected $permissionShare;
|
|
||||||
protected $permissionManage;
|
|
||||||
protected $owner;
|
|
||||||
|
|
||||||
public function __construct() {
|
public $id;
|
||||||
$this->addType('id','integer');
|
protected $participant;
|
||||||
$this->addType('boardId','integer');
|
protected $type;
|
||||||
$this->addType('permissionEdit', 'boolean');
|
protected $boardId;
|
||||||
$this->addType('permissionShare', 'boolean');
|
protected $permissionEdit = false;
|
||||||
$this->addType('permissionManage', 'boolean');
|
protected $permissionShare = false;
|
||||||
$this->addType('owner', 'boolean');
|
protected $permissionManage = false;
|
||||||
$this->addRelation('owner');
|
protected $owner = false;
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$this->addType('id', 'integer');
|
||||||
|
$this->addType('boardId', 'integer');
|
||||||
|
$this->addType('permissionEdit', 'boolean');
|
||||||
|
$this->addType('permissionShare', 'boolean');
|
||||||
|
$this->addType('permissionManage', 'boolean');
|
||||||
|
$this->addType('owner', 'boolean');
|
||||||
|
$this->addType('type', 'integer');
|
||||||
|
$this->addRelation('owner');
|
||||||
$this->setPermissionEdit(false);
|
$this->setPermissionEdit(false);
|
||||||
$this->setPermissionShare(false);
|
$this->setPermissionShare(false);
|
||||||
$this->setPermissionManage(false);
|
$this->setPermissionManage(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPermission($permission) {
|
public function getPermission($permission) {
|
||||||
switch ($permission) {
|
switch ($permission) {
|
||||||
case Acl::PERMISSION_READ:
|
case Acl::PERMISSION_READ:
|
||||||
return true;
|
return true;
|
||||||
case Acl::PERMISSION_EDIT:
|
case Acl::PERMISSION_EDIT:
|
||||||
return $this->getPermissionEdit();
|
return $this->getPermissionEdit();
|
||||||
case Acl::PERMISSION_SHARE:
|
case Acl::PERMISSION_SHARE:
|
||||||
return $this->getPermissionShare();
|
return $this->getPermissionShare();
|
||||||
case Acl::PERMISSION_MANAGE:
|
case Acl::PERMISSION_MANAGE:
|
||||||
return $this->getPermissionManage();
|
return $this->getPermissionManage();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function jsonSerialize() {
|
public function jsonSerialize() {
|
||||||
return [
|
return [
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'participant' => $this->participant,
|
'participant' => $this->participant,
|
||||||
'type' => $this->type,
|
'type' => $this->getType(),
|
||||||
'boardId' => $this->boardId,
|
'boardId' => $this->boardId,
|
||||||
'permissionEdit' => $this->permissionEdit,
|
'permissionEdit' => $this->getPermissionEdit(),
|
||||||
'permissionShare' => $this->permissionShare,
|
'permissionShare' => $this->getPermissionShare(),
|
||||||
'permissionManage' => $this->permissionManage,
|
'permissionManage' => $this->getPermissionManage(),
|
||||||
'owner' => $this->owner
|
'owner' => $this->getOwner()
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* FIXME: migrate other code to const PERMISSION_TYPE_ instead of strings
|
||||||
|
* iirc js uses those strings as well
|
||||||
|
*/
|
||||||
|
public function getType() {
|
||||||
|
if ($this->type === Acl::PERMISSION_TYPE_GROUP) {
|
||||||
|
return 'group';
|
||||||
|
}
|
||||||
|
return 'user';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setType($type) {
|
||||||
|
if ($type === 'group') {
|
||||||
|
$typeInt = Acl::PERMISSION_TYPE_GROUP;
|
||||||
|
} else {
|
||||||
|
$typeInt = Acl::PERMISSION_TYPE_USER;
|
||||||
|
}
|
||||||
|
$this->markFieldUpdated('type');
|
||||||
|
$this->type = $typeInt;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -30,9 +30,9 @@ class AclTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$acl->setParticipant("admin");
|
$acl->setParticipant("admin");
|
||||||
$acl->setType("user");
|
$acl->setType("user");
|
||||||
$acl->setBoardId(1);
|
$acl->setBoardId(1);
|
||||||
$acl->setPermissionEdit(1);
|
$acl->setPermissionEdit(true);
|
||||||
$acl->setPermissionShare(1);
|
$acl->setPermissionShare(true);
|
||||||
$acl->setPermissionManage(1);
|
$acl->setPermissionManage(true);
|
||||||
return $acl;
|
return $acl;
|
||||||
}
|
}
|
||||||
private function createAclGroup() {
|
private function createAclGroup() {
|
||||||
@@ -41,9 +41,9 @@ class AclTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$acl->setParticipant("administrators");
|
$acl->setParticipant("administrators");
|
||||||
$acl->setType("group");
|
$acl->setType("group");
|
||||||
$acl->setBoardId(1);
|
$acl->setBoardId(1);
|
||||||
$acl->setPermissionEdit(1);
|
$acl->setPermissionEdit(true);
|
||||||
$acl->setPermissionShare(1);
|
$acl->setPermissionShare(true);
|
||||||
$acl->setPermissionManage(1);
|
$acl->setPermissionManage(true);
|
||||||
return $acl;
|
return $acl;
|
||||||
}
|
}
|
||||||
public function testJsonSerialize() {
|
public function testJsonSerialize() {
|
||||||
@@ -53,10 +53,10 @@ class AclTest extends \PHPUnit_Framework_TestCase {
|
|||||||
'participant' => 'admin',
|
'participant' => 'admin',
|
||||||
'type' => 'user',
|
'type' => 'user',
|
||||||
'boardId' => 1,
|
'boardId' => 1,
|
||||||
'permissionEdit' => 1,
|
'permissionEdit' => true,
|
||||||
'permissionShare' => 1,
|
'permissionShare' => true,
|
||||||
'permissionManage' => 1,
|
'permissionManage' => true,
|
||||||
'owner' => 0
|
'owner' => false
|
||||||
], $acl->jsonSerialize());
|
], $acl->jsonSerialize());
|
||||||
$acl = $this->createAclGroup();
|
$acl = $this->createAclGroup();
|
||||||
$this->assertEquals([
|
$this->assertEquals([
|
||||||
@@ -64,10 +64,10 @@ class AclTest extends \PHPUnit_Framework_TestCase {
|
|||||||
'participant' => 'administrators',
|
'participant' => 'administrators',
|
||||||
'type' => 'group',
|
'type' => 'group',
|
||||||
'boardId' => 1,
|
'boardId' => 1,
|
||||||
'permissionEdit' => 1,
|
'permissionEdit' => true,
|
||||||
'permissionShare' => 1,
|
'permissionShare' => true,
|
||||||
'permissionManage' => 1,
|
'permissionManage' => true,
|
||||||
'owner' => 0
|
'owner' => false
|
||||||
], $acl->jsonSerialize());
|
], $acl->jsonSerialize());
|
||||||
}
|
}
|
||||||
public function testSetOwner() {
|
public function testSetOwner() {
|
||||||
@@ -78,10 +78,10 @@ class AclTest extends \PHPUnit_Framework_TestCase {
|
|||||||
'participant' => 'admin',
|
'participant' => 'admin',
|
||||||
'type' => 'user',
|
'type' => 'user',
|
||||||
'boardId' => 1,
|
'boardId' => 1,
|
||||||
'permissionEdit' => 1,
|
'permissionEdit' => true,
|
||||||
'permissionShare' => 1,
|
'permissionShare' => true,
|
||||||
'permissionManage' => 1,
|
'permissionManage' => true,
|
||||||
'owner' => 1
|
'owner' => true
|
||||||
], $acl->jsonSerialize());
|
], $acl->jsonSerialize());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,9 +92,9 @@ class AclTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals(true, $acl->getPermission(Acl::PERMISSION_EDIT));
|
$this->assertEquals(true, $acl->getPermission(Acl::PERMISSION_EDIT));
|
||||||
$this->assertEquals(true, $acl->getPermission(Acl::PERMISSION_MANAGE));
|
$this->assertEquals(true, $acl->getPermission(Acl::PERMISSION_MANAGE));
|
||||||
$this->assertEquals(true, $acl->getPermission(Acl::PERMISSION_SHARE));
|
$this->assertEquals(true, $acl->getPermission(Acl::PERMISSION_SHARE));
|
||||||
$acl->setPermissionEdit(0);
|
$acl->setPermissionEdit(false);
|
||||||
$acl->setPermissionShare(0);
|
$acl->setPermissionShare(false);
|
||||||
$acl->setPermissionManage(0);
|
$acl->setPermissionManage(false);
|
||||||
$this->assertEquals(true, $acl->getPermission(Acl::PERMISSION_READ));
|
$this->assertEquals(true, $acl->getPermission(Acl::PERMISSION_READ));
|
||||||
$this->assertEquals(false, $acl->getPermission(Acl::PERMISSION_EDIT));
|
$this->assertEquals(false, $acl->getPermission(Acl::PERMISSION_EDIT));
|
||||||
$this->assertEquals(false, $acl->getPermission(Acl::PERMISSION_MANAGE));
|
$this->assertEquals(false, $acl->getPermission(Acl::PERMISSION_MANAGE));
|
||||||
|
|||||||
Reference in New Issue
Block a user