-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement group entity and group entity mapper (+ new table migration…
… and unit tests)
- Loading branch information
Showing
8 changed files
with
563 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
namespace OC\Migrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use OCP\Migration\ISchemaMigration; | ||
use Doctrine\DBAL\Types\Type; | ||
|
||
class Version20170927145820 implements ISchemaMigration { | ||
|
||
public function changeSchema(Schema $schema, array $options) { | ||
$prefix = $options['tablePrefix']; | ||
|
||
// Backend Groups Table | ||
$table = $schema->createTable("{$prefix}backend_groups"); | ||
$table->addColumn('id', Type::INTEGER, [ | ||
'autoincrement' => true, | ||
'unsigned' => true, | ||
'notnull' => true, | ||
]); | ||
$table->addColumn('group_id', Type::STRING, [ | ||
'notnull' => true, | ||
'length' => 255, | ||
]); | ||
$table->addColumn('display_name', Type::STRING, [ | ||
'notnull' => false, | ||
'length' => 255, | ||
]); | ||
$table->addColumn('backend', Type::STRING, [ | ||
'notnull' => true, | ||
'length' => 64, | ||
]); | ||
$table->setPrimaryKey(['id']); | ||
|
||
// Group Memberships Table | ||
$table = $schema->createTable("{$prefix}memberships"); | ||
$table->addColumn('backend_group_id', Type::INTEGER, [ | ||
'notnull' => true, | ||
'unsigned' => true, | ||
]); | ||
$table->addColumn('account_id', Type::BIGINT, [ | ||
'notnull' => true, | ||
'unsigned' => true, | ||
]); | ||
$table->addColumn('membership_type', Type::SMALLINT, [ | ||
'notnull' => true, | ||
'comment' => '0: GroupUser, 1: GroupAdmin' | ||
]); | ||
|
||
// This set of values has to be unique | ||
$table->addUniqueIndex(['backend_group_id', 'account_id', 'membership_type'], 'group_account_membership_index'); | ||
|
||
//TODO: Do it later since it requires changes here for Oracle https://github.com/owncloud/core/blob/master/lib/private/DB/OracleMigrator.php#L158-L160 | ||
// Add foreign keys on backend_group and accounts tables | ||
//$table->addForeignKeyConstraint("{$prefix}backend_groups",array('backend_group_id'), array('id')); | ||
//$table->addForeignKeyConstraint("{$prefix}accounts", array('account_id'), array('id')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
/** | ||
* @author Piotr Mrowczynski <piotr@owncloud.com> | ||
* | ||
* @copyright Copyright (c) 2017, ownCloud GmbH | ||
* @license AGPL-3.0 | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* 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, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OC\Group; | ||
|
||
use OCP\AppFramework\Db\Entity; | ||
use OCP\GroupInterface; | ||
|
||
/** | ||
* Class BackendGroup | ||
* | ||
* @method int getGroupId() | ||
* @method string getDisplayName() | ||
* @method void setDisplayName(string $displayName) | ||
* @method string getBackend() | ||
* @method void setBackend(string $backEnd) | ||
* | ||
* @package OC\Group | ||
*/ | ||
class BackendGroup extends Entity { | ||
|
||
protected $groupId; | ||
protected $displayName; | ||
protected $backend; | ||
|
||
public function __construct() { } | ||
|
||
public function setGroupId($gid) { | ||
parent::setter('groupId', [$gid]); | ||
} | ||
|
||
/** | ||
* @return GroupInterface | ||
*/ | ||
public function getBackendInstance() { | ||
$backendClass = $this->getBackend(); | ||
if (empty($backendClass)) { | ||
return null; | ||
} | ||
|
||
return \OC::$server->getGroupManager()->getBackend($backendClass); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
/** | ||
* @author Piotr Mrowczynski <piotr@owncloud.com> | ||
* | ||
* @copyright Copyright (c) 2017, ownCloud GmbH | ||
* @license AGPL-3.0 | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* 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, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OC\Group; | ||
|
||
use OC\Group\BackendGroup; | ||
use OCP\AppFramework\Db\Mapper; | ||
use OCP\AppFramework\Db\Entity; | ||
use OCP\IConfig; | ||
use OCP\IDBConnection; | ||
|
||
class GroupMapper extends Mapper { | ||
|
||
public function __construct(IDBConnection $db) { | ||
parent::__construct($db, 'backend_groups', BackendGroup::class); | ||
} | ||
|
||
/** | ||
* @param BackendGroup $entity | ||
* @return Entity the saved entity with the set id | ||
*/ | ||
public function insert(Entity $entity) { | ||
// run the normal entity insert operation to get an id | ||
return parent::insert($entity); | ||
} | ||
|
||
/** | ||
* @param string $uid | ||
* @return BackendGroup | ||
*/ | ||
public function getGroup($gid) { | ||
$qb = $this->db->getQueryBuilder(); | ||
$qb->select('*') | ||
->from($this->getTableName()) | ||
->where($qb->expr()->eq('group_id', $qb->createNamedParameter($gid))); | ||
|
||
return $this->findEntity($qb->getSQL(), $qb->getParameters()); | ||
} | ||
|
||
/** | ||
* @param string $fieldName | ||
* @param string $pattern | ||
* @param integer $limit | ||
* @param integer $offset | ||
* @return BackendGroup[] | ||
*/ | ||
public function search($fieldName, $pattern, $limit, $offset) { | ||
$qb = $this->db->getQueryBuilder(); | ||
$qb->select('*') | ||
->from($this->getTableName()) | ||
->where($qb->expr()->iLike($fieldName, $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($pattern) . '%'))) | ||
->orderBy($fieldName); | ||
|
||
return $this->findEntities($qb->getSQL(), $qb->getParameters(), $limit, $offset); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.