From 4b79a8d54264183a490a6ada87c2c5c8dacb6e2f Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Fri, 21 Jun 2019 16:08:32 -0100 Subject: [PATCH] Entities Manager Signed-off-by: Maxence Lange some more Signed-off-by: Maxence Lange fixing stuff, better details Signed-off-by: Maxence Lange still working on details Signed-off-by: Maxence Lange details on members Signed-off-by: Maxence Lange --short option Signed-off-by: Maxence Lange create entities from command line Signed-off-by: Maxence Lange cleaner way to check for owner Signed-off-by: Maxence Lange search within accounts Signed-off-by: Maxence Lange import displayName during migration Signed-off-by: Maxence Lange display result in table Signed-off-by: Maxence Lange admin right, some cleaning and sql logging Signed-off-by: Maxence Lange add comments to sql log Signed-off-by: Maxence Lange log exception from sql execution Signed-off-by: Maxence Lange fixing and cleaning ! Signed-off-by: Maxence Lange fixing Signed-off-by: Maxence Lange generate viewer and caching data Signed-off-by: Maxence Lange cleaning Signed-off-by: Maxence Lange limit visibility Signed-off-by: Maxence Lange fixing default visibility on local user entity Signed-off-by: Maxence Lange options and visibility level for admin Signed-off-by: Maxence Lange better way to test EM Signed-off-by: Maxence Lange new Session command Signed-off-by: Maxence Lange nc-small-php-tools Signed-off-by: Maxence Lange fix creation+deleteOn Signed-off-by: Maxence Lange --- 3rdparty | 2 +- .../Version17000Date20190417091242.php | 276 ++++++ core/register_command.php | 18 + lib/composer/composer/autoload_classmap.php | 70 ++ lib/composer/composer/autoload_static.php | 70 ++ .../Entities/Classes/Entities/Account.php | 62 ++ .../Entities/Classes/Entities/AdminGroup.php | 64 ++ .../Entities/Classes/Entities/GlobalGroup.php | 53 ++ .../Entities/Classes/Entities/Group.php | 60 ++ .../Entities/Classes/Entities/User.php | 80 ++ .../Classes/EntitiesAccounts/LocalAdmin.php | 50 + .../Classes/EntitiesAccounts/LocalUser.php | 95 ++ .../Classes/EntitiesAccounts/MailAddress.php | 68 ++ lib/private/Entities/Command/Create.php | 369 ++++++++ lib/private/Entities/Command/Delete.php | 103 +++ lib/private/Entities/Command/Details.php | 214 +++++ lib/private/Entities/Command/ExtendedBase.php | 243 +++++ lib/private/Entities/Command/Install.php | 87 ++ lib/private/Entities/Command/Migration.php | 98 ++ lib/private/Entities/Command/Modify.php | 103 +++ lib/private/Entities/Command/Search.php | 275 ++++++ lib/private/Entities/Command/Session.php | 707 +++++++++++++++ .../Entities/Db/CoreRequestBuilder.php | 162 ++++ .../Entities/Db/EntitiesAccountsRequest.php | 241 +++++ .../Db/EntitiesAccountsRequestBuilder.php | 128 +++ .../Entities/Db/EntitiesMembersRequest.php | 207 +++++ .../Db/EntitiesMembersRequestBuilder.php | 136 +++ .../Entities/Db/EntitiesQueryBuilder.php | 360 ++++++++ lib/private/Entities/Db/EntitiesRequest.php | 261 ++++++ .../Entities/Db/EntitiesRequestBuilder.php | 136 +++ .../Entities/Db/EntitiesTypesRequest.php | 86 ++ .../Db/EntitiesTypesRequestBuilder.php | 128 +++ lib/private/Entities/EntitiesManager.php | 854 ++++++++++++++++++ .../EntityAccountAlreadyExistsException.php | 40 + .../EntityAccountCreationException.php | 40 + .../EntityAccountNotFoundException.php | 40 + .../EntityAlreadyExistsException.php | 40 + .../Exceptions/EntityCreationException.php | 40 + .../EntityMemberAlreadyExistsException.php | 40 + .../EntityMemberCreationException.php | 40 + .../Exceptions/EntityMemberLevelException.php | 40 + .../EntityMemberNotFoundException.php | 40 + .../Exceptions/EntityNotFoundException.php | 40 + .../EntityTypeNotFoundException.php | 40 + .../ImplementationNotFoundException.php | 40 + .../Exceptions/ViewerNotSetException.php | 40 + lib/private/Entities/FullMockup.php | 43 + .../Entities/Helper/EntitiesHelper.php | 288 ++++++ .../Helper/EntitiesMigrationHelper.php | 265 ++++++ lib/private/Entities/Model/Entity.php | 429 +++++++++ lib/private/Entities/Model/EntityAccount.php | 262 ++++++ lib/private/Entities/Model/EntityMember.php | 347 +++++++ lib/private/Entities/Model/EntityType.php | 209 +++++ lib/private/Server.php | 37 +- .../Entities/Helper/IEntitiesHelper.php | 115 +++ .../Helper/IEntitiesMigrationHelper.php | 56 ++ lib/public/Entities/IEntitiesManager.php | 253 ++++++ lib/public/Entities/IEntitiesQueryBuilder.php | 63 ++ .../Interface/IEntities/IEntities.php | 48 + .../IEntities/IEntitiesAdminCreation.php | 42 + .../IEntities/IEntitiesAdminRights.php | 53 ++ .../IEntities/IEntitiesConfirmCreation.php | 49 + .../IEntities/IEntitiesOwnerFree.php | 42 + .../IEntities/IEntitiesOwnerIsNotMember.php | 46 + .../IEntities/IEntitiesSearchDuplicate.php | 43 + .../IEntities/IEntitiesSearchEntities.php | 55 ++ .../IEntitiesAccounts/IEntitiesAccounts.php | 44 + .../IEntitiesAccountsHasAdminRights.php | 42 + .../IEntitiesAccountsSearchAccounts.php | 54 ++ .../IEntitiesAccountsSearchDuplicate.php | 48 + .../IEntitiesAccountsSearchEntities.php | 54 ++ lib/public/Entities/Model/IEntity.php | 128 +++ lib/public/Entities/Model/IEntityAccount.php | 69 ++ lib/public/Entities/Model/IEntityMember.php | 99 ++ lib/public/Entities/Model/IEntityType.php | 58 ++ version.php | 2 +- 76 files changed, 9726 insertions(+), 3 deletions(-) create mode 100644 core/Migrations/Version17000Date20190417091242.php create mode 100644 lib/private/Entities/Classes/Entities/Account.php create mode 100644 lib/private/Entities/Classes/Entities/AdminGroup.php create mode 100644 lib/private/Entities/Classes/Entities/GlobalGroup.php create mode 100644 lib/private/Entities/Classes/Entities/Group.php create mode 100644 lib/private/Entities/Classes/Entities/User.php create mode 100644 lib/private/Entities/Classes/EntitiesAccounts/LocalAdmin.php create mode 100644 lib/private/Entities/Classes/EntitiesAccounts/LocalUser.php create mode 100644 lib/private/Entities/Classes/EntitiesAccounts/MailAddress.php create mode 100644 lib/private/Entities/Command/Create.php create mode 100644 lib/private/Entities/Command/Delete.php create mode 100644 lib/private/Entities/Command/Details.php create mode 100644 lib/private/Entities/Command/ExtendedBase.php create mode 100644 lib/private/Entities/Command/Install.php create mode 100644 lib/private/Entities/Command/Migration.php create mode 100644 lib/private/Entities/Command/Modify.php create mode 100644 lib/private/Entities/Command/Search.php create mode 100644 lib/private/Entities/Command/Session.php create mode 100644 lib/private/Entities/Db/CoreRequestBuilder.php create mode 100644 lib/private/Entities/Db/EntitiesAccountsRequest.php create mode 100644 lib/private/Entities/Db/EntitiesAccountsRequestBuilder.php create mode 100644 lib/private/Entities/Db/EntitiesMembersRequest.php create mode 100644 lib/private/Entities/Db/EntitiesMembersRequestBuilder.php create mode 100644 lib/private/Entities/Db/EntitiesQueryBuilder.php create mode 100644 lib/private/Entities/Db/EntitiesRequest.php create mode 100644 lib/private/Entities/Db/EntitiesRequestBuilder.php create mode 100644 lib/private/Entities/Db/EntitiesTypesRequest.php create mode 100644 lib/private/Entities/Db/EntitiesTypesRequestBuilder.php create mode 100644 lib/private/Entities/EntitiesManager.php create mode 100644 lib/private/Entities/Exceptions/EntityAccountAlreadyExistsException.php create mode 100644 lib/private/Entities/Exceptions/EntityAccountCreationException.php create mode 100644 lib/private/Entities/Exceptions/EntityAccountNotFoundException.php create mode 100644 lib/private/Entities/Exceptions/EntityAlreadyExistsException.php create mode 100644 lib/private/Entities/Exceptions/EntityCreationException.php create mode 100644 lib/private/Entities/Exceptions/EntityMemberAlreadyExistsException.php create mode 100644 lib/private/Entities/Exceptions/EntityMemberCreationException.php create mode 100644 lib/private/Entities/Exceptions/EntityMemberLevelException.php create mode 100644 lib/private/Entities/Exceptions/EntityMemberNotFoundException.php create mode 100644 lib/private/Entities/Exceptions/EntityNotFoundException.php create mode 100644 lib/private/Entities/Exceptions/EntityTypeNotFoundException.php create mode 100644 lib/private/Entities/Exceptions/ImplementationNotFoundException.php create mode 100644 lib/private/Entities/Exceptions/ViewerNotSetException.php create mode 100644 lib/private/Entities/FullMockup.php create mode 100644 lib/private/Entities/Helper/EntitiesHelper.php create mode 100644 lib/private/Entities/Helper/EntitiesMigrationHelper.php create mode 100644 lib/private/Entities/Model/Entity.php create mode 100644 lib/private/Entities/Model/EntityAccount.php create mode 100644 lib/private/Entities/Model/EntityMember.php create mode 100644 lib/private/Entities/Model/EntityType.php create mode 100644 lib/public/Entities/Helper/IEntitiesHelper.php create mode 100644 lib/public/Entities/Helper/IEntitiesMigrationHelper.php create mode 100644 lib/public/Entities/IEntitiesManager.php create mode 100644 lib/public/Entities/IEntitiesQueryBuilder.php create mode 100644 lib/public/Entities/Interface/IEntities/IEntities.php create mode 100644 lib/public/Entities/Interface/IEntities/IEntitiesAdminCreation.php create mode 100644 lib/public/Entities/Interface/IEntities/IEntitiesAdminRights.php create mode 100644 lib/public/Entities/Interface/IEntities/IEntitiesConfirmCreation.php create mode 100644 lib/public/Entities/Interface/IEntities/IEntitiesOwnerFree.php create mode 100644 lib/public/Entities/Interface/IEntities/IEntitiesOwnerIsNotMember.php create mode 100644 lib/public/Entities/Interface/IEntities/IEntitiesSearchDuplicate.php create mode 100644 lib/public/Entities/Interface/IEntities/IEntitiesSearchEntities.php create mode 100644 lib/public/Entities/Interface/IEntitiesAccounts/IEntitiesAccounts.php create mode 100644 lib/public/Entities/Interface/IEntitiesAccounts/IEntitiesAccountsHasAdminRights.php create mode 100644 lib/public/Entities/Interface/IEntitiesAccounts/IEntitiesAccountsSearchAccounts.php create mode 100644 lib/public/Entities/Interface/IEntitiesAccounts/IEntitiesAccountsSearchDuplicate.php create mode 100644 lib/public/Entities/Interface/IEntitiesAccounts/IEntitiesAccountsSearchEntities.php create mode 100644 lib/public/Entities/Model/IEntity.php create mode 100644 lib/public/Entities/Model/IEntityAccount.php create mode 100644 lib/public/Entities/Model/IEntityMember.php create mode 100644 lib/public/Entities/Model/IEntityType.php diff --git a/3rdparty b/3rdparty index ef289bc27eae0..f0a425a1e35d4 160000 --- a/3rdparty +++ b/3rdparty @@ -1 +1 @@ -Subproject commit ef289bc27eae0cdfc3f74f419ace8dda8dd84ef0 +Subproject commit f0a425a1e35d4dc35476b84bb4c72649bf49e32d diff --git a/core/Migrations/Version17000Date20190417091242.php b/core/Migrations/Version17000Date20190417091242.php new file mode 100644 index 0000000000000..e54a97023e61f --- /dev/null +++ b/core/Migrations/Version17000Date20190417091242.php @@ -0,0 +1,276 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Core\Migrations; + + +use Closure; +use Doctrine\DBAL\Types\Type; +use OCP\DB\ISchemaWrapper; +use OCP\Migration\IOutput; +use OCP\Migration\SimpleMigrationStep; + + +/** + * + */ +class Version17000Date20190417091242 extends SimpleMigrationStep { + + + /** + * @param IOutput $output + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` + * @param array $options + * + * @return null|ISchemaWrapper + */ + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options + ): ISchemaWrapper { + + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + + /** + * entities + * + * - id string - a unique uuid to ident the entity + * - type string - type of the entity: no_member, unique, group, admin_group + * - owner_id string - id from 'entitied_accounts' for the owner + * - visibility small int - visible to all, visible to owner only, visible to members + * - access small int - free, invite only, request needed + * - name string - name of the entity + * - creation datetime + */ + $table = $schema->createTable('entities'); + $table->addColumn( + 'id', Type::STRING, + [ + 'notnull' => true, + 'length' => 11, + ] + ); + $table->addColumn( + 'type', Type::STRING, + [ + 'notnull' => true, + 'length' => 15 + ] + ); + $table->addColumn( + 'owner_id', Type::STRING, + [ + 'notnull' => true, + 'length' => 11, + ] + ); + $table->addColumn( + 'visibility', Type::SMALLINT, + [ + 'notnull' => true, + 'length' => 1, + ] + ); + $table->addColumn( + 'access', Type::SMALLINT, + [ + 'notnull' => true, + 'length' => 1, + ] + ); + $table->addColumn( + 'name', Type::STRING, + [ + 'notnull' => true, + 'length' => 63 + ] + ); + $table->addColumn( + 'creation', Type::DATETIME, + [ + 'notnull' => true + ] + ); + $table->setPrimaryKey(['id']); + + + /** + * entities_accounts + * + * - id string - a unique uuid to ident the account + * - type string - local_user, mail_address, guest_user + * - account string - account/user_id + * - creation datetime + */ + $table = $schema->createTable('entities_accounts'); + $table->addColumn( + 'id', Type::STRING, + [ + 'notnull' => true, + 'length' => 11, + ] + ); + $table->addColumn( + 'type', Type::STRING, + [ + 'notnull' => true, + 'length' => 15 + ] + ); + $table->addColumn( + 'account', Type::STRING, + [ + 'notnull' => true, + 'length' => 127 + ] + ); + $table->addColumn( + 'delete_on', Type::INTEGER, + [ + 'notnull' => true, + 'length' => 12 + ] + ); + $table->addColumn( + 'creation', Type::DATETIME, + [ + 'notnull' => true + ] + ); + $table->setPrimaryKey(['id']); + + + /** + * entities_members + * + * - id string - a unique uuid + * - entity_id string - id from 'entities' + * - account_id string - id from 'entities_accounts' + * - slave_entity_id string - id from 'entities' + * - status string - invited, requesting, member + * - level small int - 1=member, 4=moderator, 8=admin + * - creation datetime + */ + $table = $schema->createTable('entities_members'); + $table->addColumn( + 'id', Type::STRING, + [ + 'notnull' => true, + 'length' => 11, + ] + ); + $table->addColumn( + 'entity_id', Type::STRING, + [ + 'notnull' => true, + 'length' => 11 + ] + ); + $table->addColumn( + 'account_id', Type::STRING, + [ + 'notnull' => false, + 'length' => 11 + ] + ); + $table->addColumn( + 'slave_entity_id', Type::STRING, + [ + 'notnull' => false, + 'length' => 11 + ] + ); + $table->addColumn( + 'status', Type::STRING, + [ + 'notnull' => true, + 'length' => 15 + ] + ); + $table->addColumn( + 'level', Type::SMALLINT, + [ + 'notnull' => true, + 'length' => 1, + 'unsigned' => true + ] + ); + $table->addColumn( + 'creation', Type::DATETIME, + [ + 'notnull' => true + ] + ); + $table->setPrimaryKey(['id']); + + + /** + * entities_types + * + * - id int - incremented and primary key, nothing more + * - type string - string that define the type + * - interface string - type of the type(sic) + * - class string - class to be called to manage the service + */ + $table = $schema->createTable('entities_types'); + $table->addColumn( + 'id', Type::INTEGER, + [ + 'autoincrement' => true, + 'notnull' => true, + 'length' => 3, + 'unsigned' => true, + ] + ); + $table->addColumn( + 'type', Type::STRING, + [ + 'notnull' => true, + 'length' => 15 + ] + ); + $table->addColumn( + 'interface', Type::STRING, + [ + 'notnull' => true, + 'length' => 31 + ] + ); + $table->addColumn( + 'class', Type::STRING, + [ + 'notnull' => true, + 'length' => 127 + ] + ); + $table->setPrimaryKey(['id']); + + + return $schema; + } +} diff --git a/core/register_command.php b/core/register_command.php index 8690e1d1cba4c..14073b64b8a76 100644 --- a/core/register_command.php +++ b/core/register_command.php @@ -36,6 +36,10 @@ * */ + +use OCP\AppFramework\QueryException; + + /** @var $application Symfony\Component\Console\Application */ $application->add(new \Stecman\Component\Symfony\Console\BashCompletion\CompletionCommand()); $application->add(new OC\Core\Command\Status); @@ -166,6 +170,20 @@ $application->add(new OC\Core\Command\Security\ListCertificates(\OC::$server->getCertificateManager(null), \OC::$server->getL10N('core'))); $application->add(new OC\Core\Command\Security\ImportCertificate(\OC::$server->getCertificateManager(null))); $application->add(new OC\Core\Command\Security\RemoveCertificate(\OC::$server->getCertificateManager(null))); + + try { + $application->add(new OC\Entities\Command\Create(OC::$server->getEntitiesManager(), OC::$server->getEntitiesHelper())); + $application->add(new OC\Entities\Command\Delete(OC::$server->getEntitiesManager(), OC::$server->getEntitiesHelper())); + $application->add(new OC\Entities\Command\Details(OC::$server->getEntitiesManager())); + $application->add(new OC\Entities\Command\Install(OC::$server->getEntitiesHelper())); + $application->add(new OC\Entities\Command\Migration(OC::$server->getEntitiesManager(), OC::$server->getEntitiesMigrationHelper())); + $application->add(new OC\Entities\Command\Modify(OC::$server->getEntitiesManager(), OC::$server->getEntitiesHelper())); + $application->add(new OC\Entities\Command\Search(OC::$server->getEntitiesHelper(), OC::$server->getEntitiesManager())); + $application->add(new OC\Entities\Command\Session(OC::$server->getEntitiesManager(), OC::$server->getEntitiesHelper())); + } catch (QueryException $e) { + OC::$server->getLogger()->log(3, 'QueryException while loading Entities/Commands: ' . $e->getMessage()); + } + } else { $application->add(new OC\Core\Command\Maintenance\Install(\OC::$server->getSystemConfig())); } diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index f49865ae6edc3..f667602a7cf7b 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -169,6 +169,27 @@ 'OCP\\Encryption\\IFile' => $baseDir . '/lib/public/Encryption/IFile.php', 'OCP\\Encryption\\IManager' => $baseDir . '/lib/public/Encryption/IManager.php', 'OCP\\Encryption\\Keys\\IStorage' => $baseDir . '/lib/public/Encryption/Keys/IStorage.php', + 'OCP\\Entities\\Helper\\IEntitiesHelper' => $baseDir . '/lib/public/Entities/Helper/IEntitiesHelper.php', + 'OCP\\Entities\\Helper\\IEntitiesMigrationHelper' => $baseDir . '/lib/public/Entities/Helper/IEntitiesMigrationHelper.php', + 'OCP\\Entities\\IEntitiesManager' => $baseDir . '/lib/public/Entities/IEntitiesManager.php', + 'OCP\\Entities\\IEntitiesQueryBuilder' => $baseDir . '/lib/public/Entities/IEntitiesQueryBuilder.php', + 'OCP\\Entities\\Implementation\\IEntitiesAccounts\\IEntitiesAccounts' => $baseDir . '/lib/public/Entities/Interface/IEntitiesAccounts/IEntitiesAccounts.php', + 'OCP\\Entities\\Implementation\\IEntitiesAccounts\\IEntitiesAccountsHasAdminRights' => $baseDir . '/lib/public/Entities/Interface/IEntitiesAccounts/IEntitiesAccountsHasAdminRights.php', + 'OCP\\Entities\\Implementation\\IEntitiesAccounts\\IEntitiesAccountsSearchAccounts' => $baseDir . '/lib/public/Entities/Interface/IEntitiesAccounts/IEntitiesAccountsSearchAccounts.php', + 'OCP\\Entities\\Implementation\\IEntitiesAccounts\\IEntitiesAccountsSearchDuplicate' => $baseDir . '/lib/public/Entities/Interface/IEntitiesAccounts/IEntitiesAccountsSearchDuplicate.php', + 'OCP\\Entities\\Implementation\\IEntitiesAccounts\\IEntitiesAccountsSearchEntities' => $baseDir . '/lib/public/Entities/Interface/IEntitiesAccounts/IEntitiesAccountsSearchEntities.php', + 'OCP\\Entities\\Implementation\\IEntities\\IEntities' => $baseDir . '/lib/public/Entities/Interface/IEntities/IEntities.php', + 'OCP\\Entities\\Implementation\\IEntities\\IEntitiesAdminCreation' => $baseDir . '/lib/public/Entities/Interface/IEntities/IEntitiesAdminCreation.php', + 'OCP\\Entities\\Implementation\\IEntities\\IEntitiesAdminRights' => $baseDir . '/lib/public/Entities/Interface/IEntities/IEntitiesAdminRights.php', + 'OCP\\Entities\\Implementation\\IEntities\\IEntitiesConfirmCreation' => $baseDir . '/lib/public/Entities/Interface/IEntities/IEntitiesConfirmCreation.php', + 'OCP\\Entities\\Implementation\\IEntities\\IEntitiesOwnerFree' => $baseDir . '/lib/public/Entities/Interface/IEntities/IEntitiesOwnerFree.php', + 'OCP\\Entities\\Implementation\\IEntities\\IEntitiesOwnerIsNotMember' => $baseDir . '/lib/public/Entities/Interface/IEntities/IEntitiesOwnerIsNotMember.php', + 'OCP\\Entities\\Implementation\\IEntities\\IEntitiesSearchDuplicate' => $baseDir . '/lib/public/Entities/Interface/IEntities/IEntitiesSearchDuplicate.php', + 'OCP\\Entities\\Implementation\\IEntities\\IEntitiesSearchEntities' => $baseDir . '/lib/public/Entities/Interface/IEntities/IEntitiesSearchEntities.php', + 'OCP\\Entities\\Model\\IEntity' => $baseDir . '/lib/public/Entities/Model/IEntity.php', + 'OCP\\Entities\\Model\\IEntityAccount' => $baseDir . '/lib/public/Entities/Model/IEntityAccount.php', + 'OCP\\Entities\\Model\\IEntityMember' => $baseDir . '/lib/public/Entities/Model/IEntityMember.php', + 'OCP\\Entities\\Model\\IEntityType' => $baseDir . '/lib/public/Entities/Model/IEntityType.php', 'OCP\\Federation\\Exceptions\\ActionNotSupportedException' => $baseDir . '/lib/public/Federation/Exceptions/ActionNotSupportedException.php', 'OCP\\Federation\\Exceptions\\AuthenticationFailedException' => $baseDir . '/lib/public/Federation/Exceptions/AuthenticationFailedException.php', 'OCP\\Federation\\Exceptions\\BadRequestException' => $baseDir . '/lib/public/Federation/Exceptions/BadRequestException.php', @@ -743,6 +764,7 @@ 'OC\\Core\\Migrations\\Version16000Date20190212081545' => $baseDir . '/core/Migrations/Version16000Date20190212081545.php', 'OC\\Core\\Migrations\\Version16000Date20190427105638' => $baseDir . '/core/Migrations/Version16000Date20190427105638.php', 'OC\\Core\\Migrations\\Version16000Date20190428150708' => $baseDir . '/core/Migrations/Version16000Date20190428150708.php', + 'OC\\Core\\Migrations\\Version17000Date20190417091242' => $baseDir . '/core/Migrations/Version17000Date20190417091242.php', 'OC\\Core\\Notification\\RemoveLinkSharesNotifier' => $baseDir . '/core/Notification/RemoveLinkSharesNotifier.php', 'OC\\Core\\Service\\LoginFlowV2Service' => $baseDir . '/core/Service/LoginFlowV2Service.php', 'OC\\DB\\Adapter' => $baseDir . '/lib/private/DB/Adapter.php', @@ -810,6 +832,54 @@ 'OC\\Encryption\\Manager' => $baseDir . '/lib/private/Encryption/Manager.php', 'OC\\Encryption\\Update' => $baseDir . '/lib/private/Encryption/Update.php', 'OC\\Encryption\\Util' => $baseDir . '/lib/private/Encryption/Util.php', + 'OC\\Entities\\Classes\\IEntitiesAccounts\\LocalAdmin' => $baseDir . '/lib/private/Entities/Classes/EntitiesAccounts/LocalAdmin.php', + 'OC\\Entities\\Classes\\IEntitiesAccounts\\LocalUser' => $baseDir . '/lib/private/Entities/Classes/EntitiesAccounts/LocalUser.php', + 'OC\\Entities\\Classes\\IEntitiesAccounts\\MailAddress' => $baseDir . '/lib/private/Entities/Classes/EntitiesAccounts/MailAddress.php', + 'OC\\Entities\\Classes\\IEntities\\Account' => $baseDir . '/lib/private/Entities/Classes/Entities/Account.php', + 'OC\\Entities\\Classes\\IEntities\\AdminGroup' => $baseDir . '/lib/private/Entities/Classes/Entities/AdminGroup.php', + 'OC\\Entities\\Classes\\IEntities\\GlobalGroup' => $baseDir . '/lib/private/Entities/Classes/Entities/GlobalGroup.php', + 'OC\\Entities\\Classes\\IEntities\\Group' => $baseDir . '/lib/private/Entities/Classes/Entities/Group.php', + 'OC\\Entities\\Classes\\IEntities\\User' => $baseDir . '/lib/private/Entities/Classes/Entities/User.php', + 'OC\\Entities\\Command\\Create' => $baseDir . '/lib/private/Entities/Command/Create.php', + 'OC\\Entities\\Command\\Delete' => $baseDir . '/lib/private/Entities/Command/Delete.php', + 'OC\\Entities\\Command\\Details' => $baseDir . '/lib/private/Entities/Command/Details.php', + 'OC\\Entities\\Command\\ExtendedBase' => $baseDir . '/lib/private/Entities/Command/ExtendedBase.php', + 'OC\\Entities\\Command\\Install' => $baseDir . '/lib/private/Entities/Command/Install.php', + 'OC\\Entities\\Command\\Migration' => $baseDir . '/lib/private/Entities/Command/Migration.php', + 'OC\\Entities\\Command\\Modify' => $baseDir . '/lib/private/Entities/Command/Modify.php', + 'OC\\Entities\\Command\\Search' => $baseDir . '/lib/private/Entities/Command/Search.php', + 'OC\\Entities\\Command\\Session' => $baseDir . '/lib/private/Entities/Command/Session.php', + 'OC\\Entities\\Db\\CoreRequestBuilder' => $baseDir . '/lib/private/Entities/Db/CoreRequestBuilder.php', + 'OC\\Entities\\Db\\EntitiesAccountsRequest' => $baseDir . '/lib/private/Entities/Db/EntitiesAccountsRequest.php', + 'OC\\Entities\\Db\\EntitiesAccountsRequestBuilder' => $baseDir . '/lib/private/Entities/Db/EntitiesAccountsRequestBuilder.php', + 'OC\\Entities\\Db\\EntitiesMembersRequest' => $baseDir . '/lib/private/Entities/Db/EntitiesMembersRequest.php', + 'OC\\Entities\\Db\\EntitiesMembersRequestBuilder' => $baseDir . '/lib/private/Entities/Db/EntitiesMembersRequestBuilder.php', + 'OC\\Entities\\Db\\EntitiesQueryBuilder' => $baseDir . '/lib/private/Entities/Db/EntitiesQueryBuilder.php', + 'OC\\Entities\\Db\\EntitiesRequest' => $baseDir . '/lib/private/Entities/Db/EntitiesRequest.php', + 'OC\\Entities\\Db\\EntitiesRequestBuilder' => $baseDir . '/lib/private/Entities/Db/EntitiesRequestBuilder.php', + 'OC\\Entities\\Db\\EntitiesTypesRequest' => $baseDir . '/lib/private/Entities/Db/EntitiesTypesRequest.php', + 'OC\\Entities\\Db\\EntitiesTypesRequestBuilder' => $baseDir . '/lib/private/Entities/Db/EntitiesTypesRequestBuilder.php', + 'OC\\Entities\\EntitiesManager' => $baseDir . '/lib/private/Entities/EntitiesManager.php', + 'OC\\Entities\\Exceptions\\EntityAccountAlreadyExistsException' => $baseDir . '/lib/private/Entities/Exceptions/EntityAccountAlreadyExistsException.php', + 'OC\\Entities\\Exceptions\\EntityAccountCreationException' => $baseDir . '/lib/private/Entities/Exceptions/EntityAccountCreationException.php', + 'OC\\Entities\\Exceptions\\EntityAccountNotFoundException' => $baseDir . '/lib/private/Entities/Exceptions/EntityAccountNotFoundException.php', + 'OC\\Entities\\Exceptions\\EntityAlreadyExistsException' => $baseDir . '/lib/private/Entities/Exceptions/EntityAlreadyExistsException.php', + 'OC\\Entities\\Exceptions\\EntityCreationException' => $baseDir . '/lib/private/Entities/Exceptions/EntityCreationException.php', + 'OC\\Entities\\Exceptions\\EntityMemberAlreadyExistsException' => $baseDir . '/lib/private/Entities/Exceptions/EntityMemberAlreadyExistsException.php', + 'OC\\Entities\\Exceptions\\EntityMemberCreationException' => $baseDir . '/lib/private/Entities/Exceptions/EntityMemberCreationException.php', + 'OC\\Entities\\Exceptions\\EntityMemberLevelException' => $baseDir . '/lib/private/Entities/Exceptions/EntityMemberLevelException.php', + 'OC\\Entities\\Exceptions\\EntityMemberNotFoundException' => $baseDir . '/lib/private/Entities/Exceptions/EntityMemberNotFoundException.php', + 'OC\\Entities\\Exceptions\\EntityNotFoundException' => $baseDir . '/lib/private/Entities/Exceptions/EntityNotFoundException.php', + 'OC\\Entities\\Exceptions\\EntityTypeNotFoundException' => $baseDir . '/lib/private/Entities/Exceptions/EntityTypeNotFoundException.php', + 'OC\\Entities\\Exceptions\\ImplementationNotFoundException' => $baseDir . '/lib/private/Entities/Exceptions/ImplementationNotFoundException.php', + 'OC\\Entities\\Exceptions\\ViewerNotSetException' => $baseDir . '/lib/private/Entities/Exceptions/ViewerNotSetException.php', + 'OC\\Entities\\FullMockup' => $baseDir . '/lib/private/Entities/FullMockup.php', + 'OC\\Entities\\Helper\\EntitiesHelper' => $baseDir . '/lib/private/Entities/Helper/EntitiesHelper.php', + 'OC\\Entities\\Helper\\EntitiesMigrationHelper' => $baseDir . '/lib/private/Entities/Helper/EntitiesMigrationHelper.php', + 'OC\\Entities\\Model\\Entity' => $baseDir . '/lib/private/Entities/Model/Entity.php', + 'OC\\Entities\\Model\\EntityAccount' => $baseDir . '/lib/private/Entities/Model/EntityAccount.php', + 'OC\\Entities\\Model\\EntityMember' => $baseDir . '/lib/private/Entities/Model/EntityMember.php', + 'OC\\Entities\\Model\\EntityType' => $baseDir . '/lib/private/Entities/Model/EntityType.php', 'OC\\Federation\\CloudFederationFactory' => $baseDir . '/lib/private/Federation/CloudFederationFactory.php', 'OC\\Federation\\CloudFederationNotification' => $baseDir . '/lib/private/Federation/CloudFederationNotification.php', 'OC\\Federation\\CloudFederationProviderManager' => $baseDir . '/lib/private/Federation/CloudFederationProviderManager.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 5f204e4e23eb1..f632043e15762 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -203,6 +203,27 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OCP\\Encryption\\IFile' => __DIR__ . '/../../..' . '/lib/public/Encryption/IFile.php', 'OCP\\Encryption\\IManager' => __DIR__ . '/../../..' . '/lib/public/Encryption/IManager.php', 'OCP\\Encryption\\Keys\\IStorage' => __DIR__ . '/../../..' . '/lib/public/Encryption/Keys/IStorage.php', + 'OCP\\Entities\\Helper\\IEntitiesHelper' => __DIR__ . '/../../..' . '/lib/public/Entities/Helper/IEntitiesHelper.php', + 'OCP\\Entities\\Helper\\IEntitiesMigrationHelper' => __DIR__ . '/../../..' . '/lib/public/Entities/Helper/IEntitiesMigrationHelper.php', + 'OCP\\Entities\\IEntitiesManager' => __DIR__ . '/../../..' . '/lib/public/Entities/IEntitiesManager.php', + 'OCP\\Entities\\IEntitiesQueryBuilder' => __DIR__ . '/../../..' . '/lib/public/Entities/IEntitiesQueryBuilder.php', + 'OCP\\Entities\\Implementation\\IEntitiesAccounts\\IEntitiesAccounts' => __DIR__ . '/../../..' . '/lib/public/Entities/Interface/IEntitiesAccounts/IEntitiesAccounts.php', + 'OCP\\Entities\\Implementation\\IEntitiesAccounts\\IEntitiesAccountsHasAdminRights' => __DIR__ . '/../../..' . '/lib/public/Entities/Interface/IEntitiesAccounts/IEntitiesAccountsHasAdminRights.php', + 'OCP\\Entities\\Implementation\\IEntitiesAccounts\\IEntitiesAccountsSearchAccounts' => __DIR__ . '/../../..' . '/lib/public/Entities/Interface/IEntitiesAccounts/IEntitiesAccountsSearchAccounts.php', + 'OCP\\Entities\\Implementation\\IEntitiesAccounts\\IEntitiesAccountsSearchDuplicate' => __DIR__ . '/../../..' . '/lib/public/Entities/Interface/IEntitiesAccounts/IEntitiesAccountsSearchDuplicate.php', + 'OCP\\Entities\\Implementation\\IEntitiesAccounts\\IEntitiesAccountsSearchEntities' => __DIR__ . '/../../..' . '/lib/public/Entities/Interface/IEntitiesAccounts/IEntitiesAccountsSearchEntities.php', + 'OCP\\Entities\\Implementation\\IEntities\\IEntities' => __DIR__ . '/../../..' . '/lib/public/Entities/Interface/IEntities/IEntities.php', + 'OCP\\Entities\\Implementation\\IEntities\\IEntitiesAdminCreation' => __DIR__ . '/../../..' . '/lib/public/Entities/Interface/IEntities/IEntitiesAdminCreation.php', + 'OCP\\Entities\\Implementation\\IEntities\\IEntitiesAdminRights' => __DIR__ . '/../../..' . '/lib/public/Entities/Interface/IEntities/IEntitiesAdminRights.php', + 'OCP\\Entities\\Implementation\\IEntities\\IEntitiesConfirmCreation' => __DIR__ . '/../../..' . '/lib/public/Entities/Interface/IEntities/IEntitiesConfirmCreation.php', + 'OCP\\Entities\\Implementation\\IEntities\\IEntitiesOwnerFree' => __DIR__ . '/../../..' . '/lib/public/Entities/Interface/IEntities/IEntitiesOwnerFree.php', + 'OCP\\Entities\\Implementation\\IEntities\\IEntitiesOwnerIsNotMember' => __DIR__ . '/../../..' . '/lib/public/Entities/Interface/IEntities/IEntitiesOwnerIsNotMember.php', + 'OCP\\Entities\\Implementation\\IEntities\\IEntitiesSearchDuplicate' => __DIR__ . '/../../..' . '/lib/public/Entities/Interface/IEntities/IEntitiesSearchDuplicate.php', + 'OCP\\Entities\\Implementation\\IEntities\\IEntitiesSearchEntities' => __DIR__ . '/../../..' . '/lib/public/Entities/Interface/IEntities/IEntitiesSearchEntities.php', + 'OCP\\Entities\\Model\\IEntity' => __DIR__ . '/../../..' . '/lib/public/Entities/Model/IEntity.php', + 'OCP\\Entities\\Model\\IEntityAccount' => __DIR__ . '/../../..' . '/lib/public/Entities/Model/IEntityAccount.php', + 'OCP\\Entities\\Model\\IEntityMember' => __DIR__ . '/../../..' . '/lib/public/Entities/Model/IEntityMember.php', + 'OCP\\Entities\\Model\\IEntityType' => __DIR__ . '/../../..' . '/lib/public/Entities/Model/IEntityType.php', 'OCP\\Federation\\Exceptions\\ActionNotSupportedException' => __DIR__ . '/../../..' . '/lib/public/Federation/Exceptions/ActionNotSupportedException.php', 'OCP\\Federation\\Exceptions\\AuthenticationFailedException' => __DIR__ . '/../../..' . '/lib/public/Federation/Exceptions/AuthenticationFailedException.php', 'OCP\\Federation\\Exceptions\\BadRequestException' => __DIR__ . '/../../..' . '/lib/public/Federation/Exceptions/BadRequestException.php', @@ -777,6 +798,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Core\\Migrations\\Version16000Date20190212081545' => __DIR__ . '/../../..' . '/core/Migrations/Version16000Date20190212081545.php', 'OC\\Core\\Migrations\\Version16000Date20190427105638' => __DIR__ . '/../../..' . '/core/Migrations/Version16000Date20190427105638.php', 'OC\\Core\\Migrations\\Version16000Date20190428150708' => __DIR__ . '/../../..' . '/core/Migrations/Version16000Date20190428150708.php', + 'OC\\Core\\Migrations\\Version17000Date20190417091242' => __DIR__ . '/../../..' . '/core/Migrations/Version17000Date20190417091242.php', 'OC\\Core\\Notification\\RemoveLinkSharesNotifier' => __DIR__ . '/../../..' . '/core/Notification/RemoveLinkSharesNotifier.php', 'OC\\Core\\Service\\LoginFlowV2Service' => __DIR__ . '/../../..' . '/core/Service/LoginFlowV2Service.php', 'OC\\DB\\Adapter' => __DIR__ . '/../../..' . '/lib/private/DB/Adapter.php', @@ -844,6 +866,54 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Encryption\\Manager' => __DIR__ . '/../../..' . '/lib/private/Encryption/Manager.php', 'OC\\Encryption\\Update' => __DIR__ . '/../../..' . '/lib/private/Encryption/Update.php', 'OC\\Encryption\\Util' => __DIR__ . '/../../..' . '/lib/private/Encryption/Util.php', + 'OC\\Entities\\Classes\\IEntitiesAccounts\\LocalAdmin' => __DIR__ . '/../../..' . '/lib/private/Entities/Classes/EntitiesAccounts/LocalAdmin.php', + 'OC\\Entities\\Classes\\IEntitiesAccounts\\LocalUser' => __DIR__ . '/../../..' . '/lib/private/Entities/Classes/EntitiesAccounts/LocalUser.php', + 'OC\\Entities\\Classes\\IEntitiesAccounts\\MailAddress' => __DIR__ . '/../../..' . '/lib/private/Entities/Classes/EntitiesAccounts/MailAddress.php', + 'OC\\Entities\\Classes\\IEntities\\Account' => __DIR__ . '/../../..' . '/lib/private/Entities/Classes/Entities/Account.php', + 'OC\\Entities\\Classes\\IEntities\\AdminGroup' => __DIR__ . '/../../..' . '/lib/private/Entities/Classes/Entities/AdminGroup.php', + 'OC\\Entities\\Classes\\IEntities\\GlobalGroup' => __DIR__ . '/../../..' . '/lib/private/Entities/Classes/Entities/GlobalGroup.php', + 'OC\\Entities\\Classes\\IEntities\\Group' => __DIR__ . '/../../..' . '/lib/private/Entities/Classes/Entities/Group.php', + 'OC\\Entities\\Classes\\IEntities\\User' => __DIR__ . '/../../..' . '/lib/private/Entities/Classes/Entities/User.php', + 'OC\\Entities\\Command\\Create' => __DIR__ . '/../../..' . '/lib/private/Entities/Command/Create.php', + 'OC\\Entities\\Command\\Delete' => __DIR__ . '/../../..' . '/lib/private/Entities/Command/Delete.php', + 'OC\\Entities\\Command\\Details' => __DIR__ . '/../../..' . '/lib/private/Entities/Command/Details.php', + 'OC\\Entities\\Command\\ExtendedBase' => __DIR__ . '/../../..' . '/lib/private/Entities/Command/ExtendedBase.php', + 'OC\\Entities\\Command\\Install' => __DIR__ . '/../../..' . '/lib/private/Entities/Command/Install.php', + 'OC\\Entities\\Command\\Migration' => __DIR__ . '/../../..' . '/lib/private/Entities/Command/Migration.php', + 'OC\\Entities\\Command\\Modify' => __DIR__ . '/../../..' . '/lib/private/Entities/Command/Modify.php', + 'OC\\Entities\\Command\\Search' => __DIR__ . '/../../..' . '/lib/private/Entities/Command/Search.php', + 'OC\\Entities\\Command\\Session' => __DIR__ . '/../../..' . '/lib/private/Entities/Command/Session.php', + 'OC\\Entities\\Db\\CoreRequestBuilder' => __DIR__ . '/../../..' . '/lib/private/Entities/Db/CoreRequestBuilder.php', + 'OC\\Entities\\Db\\EntitiesAccountsRequest' => __DIR__ . '/../../..' . '/lib/private/Entities/Db/EntitiesAccountsRequest.php', + 'OC\\Entities\\Db\\EntitiesAccountsRequestBuilder' => __DIR__ . '/../../..' . '/lib/private/Entities/Db/EntitiesAccountsRequestBuilder.php', + 'OC\\Entities\\Db\\EntitiesMembersRequest' => __DIR__ . '/../../..' . '/lib/private/Entities/Db/EntitiesMembersRequest.php', + 'OC\\Entities\\Db\\EntitiesMembersRequestBuilder' => __DIR__ . '/../../..' . '/lib/private/Entities/Db/EntitiesMembersRequestBuilder.php', + 'OC\\Entities\\Db\\EntitiesQueryBuilder' => __DIR__ . '/../../..' . '/lib/private/Entities/Db/EntitiesQueryBuilder.php', + 'OC\\Entities\\Db\\EntitiesRequest' => __DIR__ . '/../../..' . '/lib/private/Entities/Db/EntitiesRequest.php', + 'OC\\Entities\\Db\\EntitiesRequestBuilder' => __DIR__ . '/../../..' . '/lib/private/Entities/Db/EntitiesRequestBuilder.php', + 'OC\\Entities\\Db\\EntitiesTypesRequest' => __DIR__ . '/../../..' . '/lib/private/Entities/Db/EntitiesTypesRequest.php', + 'OC\\Entities\\Db\\EntitiesTypesRequestBuilder' => __DIR__ . '/../../..' . '/lib/private/Entities/Db/EntitiesTypesRequestBuilder.php', + 'OC\\Entities\\EntitiesManager' => __DIR__ . '/../../..' . '/lib/private/Entities/EntitiesManager.php', + 'OC\\Entities\\Exceptions\\EntityAccountAlreadyExistsException' => __DIR__ . '/../../..' . '/lib/private/Entities/Exceptions/EntityAccountAlreadyExistsException.php', + 'OC\\Entities\\Exceptions\\EntityAccountCreationException' => __DIR__ . '/../../..' . '/lib/private/Entities/Exceptions/EntityAccountCreationException.php', + 'OC\\Entities\\Exceptions\\EntityAccountNotFoundException' => __DIR__ . '/../../..' . '/lib/private/Entities/Exceptions/EntityAccountNotFoundException.php', + 'OC\\Entities\\Exceptions\\EntityAlreadyExistsException' => __DIR__ . '/../../..' . '/lib/private/Entities/Exceptions/EntityAlreadyExistsException.php', + 'OC\\Entities\\Exceptions\\EntityCreationException' => __DIR__ . '/../../..' . '/lib/private/Entities/Exceptions/EntityCreationException.php', + 'OC\\Entities\\Exceptions\\EntityMemberAlreadyExistsException' => __DIR__ . '/../../..' . '/lib/private/Entities/Exceptions/EntityMemberAlreadyExistsException.php', + 'OC\\Entities\\Exceptions\\EntityMemberCreationException' => __DIR__ . '/../../..' . '/lib/private/Entities/Exceptions/EntityMemberCreationException.php', + 'OC\\Entities\\Exceptions\\EntityMemberLevelException' => __DIR__ . '/../../..' . '/lib/private/Entities/Exceptions/EntityMemberLevelException.php', + 'OC\\Entities\\Exceptions\\EntityMemberNotFoundException' => __DIR__ . '/../../..' . '/lib/private/Entities/Exceptions/EntityMemberNotFoundException.php', + 'OC\\Entities\\Exceptions\\EntityNotFoundException' => __DIR__ . '/../../..' . '/lib/private/Entities/Exceptions/EntityNotFoundException.php', + 'OC\\Entities\\Exceptions\\EntityTypeNotFoundException' => __DIR__ . '/../../..' . '/lib/private/Entities/Exceptions/EntityTypeNotFoundException.php', + 'OC\\Entities\\Exceptions\\ImplementationNotFoundException' => __DIR__ . '/../../..' . '/lib/private/Entities/Exceptions/ImplementationNotFoundException.php', + 'OC\\Entities\\Exceptions\\ViewerNotSetException' => __DIR__ . '/../../..' . '/lib/private/Entities/Exceptions/ViewerNotSetException.php', + 'OC\\Entities\\FullMockup' => __DIR__ . '/../../..' . '/lib/private/Entities/FullMockup.php', + 'OC\\Entities\\Helper\\EntitiesHelper' => __DIR__ . '/../../..' . '/lib/private/Entities/Helper/EntitiesHelper.php', + 'OC\\Entities\\Helper\\EntitiesMigrationHelper' => __DIR__ . '/../../..' . '/lib/private/Entities/Helper/EntitiesMigrationHelper.php', + 'OC\\Entities\\Model\\Entity' => __DIR__ . '/../../..' . '/lib/private/Entities/Model/Entity.php', + 'OC\\Entities\\Model\\EntityAccount' => __DIR__ . '/../../..' . '/lib/private/Entities/Model/EntityAccount.php', + 'OC\\Entities\\Model\\EntityMember' => __DIR__ . '/../../..' . '/lib/private/Entities/Model/EntityMember.php', + 'OC\\Entities\\Model\\EntityType' => __DIR__ . '/../../..' . '/lib/private/Entities/Model/EntityType.php', 'OC\\Federation\\CloudFederationFactory' => __DIR__ . '/../../..' . '/lib/private/Federation/CloudFederationFactory.php', 'OC\\Federation\\CloudFederationNotification' => __DIR__ . '/../../..' . '/lib/private/Federation/CloudFederationNotification.php', 'OC\\Federation\\CloudFederationProviderManager' => __DIR__ . '/../../..' . '/lib/private/Federation/CloudFederationProviderManager.php', diff --git a/lib/private/Entities/Classes/Entities/Account.php b/lib/private/Entities/Classes/Entities/Account.php new file mode 100644 index 0000000000000..f308ea53b82ae --- /dev/null +++ b/lib/private/Entities/Classes/Entities/Account.php @@ -0,0 +1,62 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Classes\IEntities; + + +use OC; +use OCP\Entities\IEntitiesQueryBuilder; +use OCP\Entities\Implementation\IEntities\IEntities; +use OCP\Entities\Implementation\IEntities\IEntitiesOwnerIsNotMember; +use OCP\Entities\Implementation\IEntities\IEntitiesSearchDuplicate; +use OCP\Entities\Model\IEntity; + + +class Account implements + IEntities, + IEntitiesOwnerIsNotMember, + IEntitiesSearchDuplicate { + + + const TYPE = 'account'; + + + /** + * @param IEntitiesQueryBuilder $qb + * @param IEntity $entity + */ + public function buildSearchDuplicate(IEntitiesQueryBuilder $qb, IEntity $entity) { + $qb->limitToType($entity->getType()); + $qb->limitToOwnerId($entity->getOwnerId()); + $qb->limitToName($entity->getName()); + } + +} + diff --git a/lib/private/Entities/Classes/Entities/AdminGroup.php b/lib/private/Entities/Classes/Entities/AdminGroup.php new file mode 100644 index 0000000000000..787f963b0d920 --- /dev/null +++ b/lib/private/Entities/Classes/Entities/AdminGroup.php @@ -0,0 +1,64 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Classes\IEntities; + + +use OC; +use OCP\Entities\Implementation\IEntities\IEntitiesAdminRights; +use OCP\Entities\Implementation\IEntities\IEntitiesOwnerFree; +use OCP\Entities\Model\IEntity; + + +/** + * Class AdminGroup + * + * @package OC\Entities\Classes\IEntities + */ +class AdminGroup extends Group implements + IEntitiesOwnerFree, + IEntitiesAdminRights { + + + const TYPE = 'admin_group'; + + + /** + * @param IEntity $entity + * + * @return bool + */ + public function hasAdminRights(IEntity $entity): bool { + return true; + } + + +} + diff --git a/lib/private/Entities/Classes/Entities/GlobalGroup.php b/lib/private/Entities/Classes/Entities/GlobalGroup.php new file mode 100644 index 0000000000000..38a93e2041544 --- /dev/null +++ b/lib/private/Entities/Classes/Entities/GlobalGroup.php @@ -0,0 +1,53 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Classes\IEntities; + + +use OC; +use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\Entities\IEntitiesQueryBuilder; +use OCP\Entities\Implementation\IEntities\IEntities; +use OCP\Entities\Implementation\IEntities\IEntitiesAdminCreation; +use OCP\Entities\Implementation\IEntities\IEntitiesOwnerFree; +use OCP\Entities\Implementation\IEntities\IEntitiesSearchDuplicate; +use OCP\Entities\Model\IEntity; + + +class GlobalGroup extends Group implements + IEntitiesOwnerFree, + IEntitiesAdminCreation { + + + const TYPE = 'global_group'; + + +} + diff --git a/lib/private/Entities/Classes/Entities/Group.php b/lib/private/Entities/Classes/Entities/Group.php new file mode 100644 index 0000000000000..66b4351dfd454 --- /dev/null +++ b/lib/private/Entities/Classes/Entities/Group.php @@ -0,0 +1,60 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Classes\IEntities; + + +use OC; +use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\Entities\IEntitiesQueryBuilder; +use OCP\Entities\Implementation\IEntities\IEntities; +use OCP\Entities\Implementation\IEntities\IEntitiesSearchDuplicate; +use OCP\Entities\Model\IEntity; + + +class Group implements + IEntities, + IEntitiesSearchDuplicate { + + + const TYPE = 'group'; + + + /** + * @param IEntitiesQueryBuilder $qb + * @param IEntity $entity + */ + public function buildSearchDuplicate(IEntitiesQueryBuilder $qb, IEntity $entity) { + $qb->limitToDBFieldArray('type', [self::TYPE, AdminGroup::TYPE, GlobalGroup::TYPE]); + $qb->limitToName($entity->getName()); + } + +} + diff --git a/lib/private/Entities/Classes/Entities/User.php b/lib/private/Entities/Classes/Entities/User.php new file mode 100644 index 0000000000000..2eabf2b3fd7b8 --- /dev/null +++ b/lib/private/Entities/Classes/Entities/User.php @@ -0,0 +1,80 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Classes\IEntities; + + +use OC; +use OC\Entities\Classes\IEntitiesAccounts\LocalUser; +use OC\Entities\Exceptions\EntityCreationException; +use OCP\Entities\IEntitiesQueryBuilder; +use OCP\Entities\Implementation\IEntities\IEntities; +use OCP\Entities\Implementation\IEntities\IEntitiesConfirmCreation; +use OCP\Entities\Implementation\IEntities\IEntitiesSearchDuplicate; +use OCP\Entities\Model\IEntity; + + +class User implements + IEntities, + IEntitiesConfirmCreation, + IEntitiesSearchDuplicate { + + + const TYPE = 'user'; + + + /** + * @param IEntity $entity + * + * @throws EntityCreationException + */ + public function confirmCreationStatus(IEntity $entity): void { + if (!$entity->hasOwner()) { + throw new EntityCreationException('Owner is needed but not defined'); + } + + $owner = $entity->getOwner(); + if ($owner->getType() !== LocalUser::TYPE) { + throw new EntityCreationException('Owner must be a LocalUser'); + } + } + + + /** + * @param IEntitiesQueryBuilder $qb + * @param IEntity $entity + */ + public function buildSearchDuplicate(IEntitiesQueryBuilder $qb, IEntity $entity) { + $qb->limitToType($entity->getType()); + $qb->limitToOwnerId($entity->getOwnerId()); + } + +} + diff --git a/lib/private/Entities/Classes/EntitiesAccounts/LocalAdmin.php b/lib/private/Entities/Classes/EntitiesAccounts/LocalAdmin.php new file mode 100644 index 0000000000000..feb23a90d5be9 --- /dev/null +++ b/lib/private/Entities/Classes/EntitiesAccounts/LocalAdmin.php @@ -0,0 +1,50 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Classes\IEntitiesAccounts; + + +use OC; +use OCP\Entities\Implementation\IEntitiesAccounts\IEntitiesAccountsHasAdminRights; + + +/** + * Class LocalUser + * + * @package OC\Entities\Classes\IEntitiesAccounts + */ +class LocalAdmin extends LocalUser implements IEntitiesAccountsHasAdminRights { + + + const TYPE = 'local_admin'; + + +} + diff --git a/lib/private/Entities/Classes/EntitiesAccounts/LocalUser.php b/lib/private/Entities/Classes/EntitiesAccounts/LocalUser.php new file mode 100644 index 0000000000000..7ad4ba4bd51a3 --- /dev/null +++ b/lib/private/Entities/Classes/EntitiesAccounts/LocalUser.php @@ -0,0 +1,95 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Classes\IEntitiesAccounts; + + +use OC; +use OC\Entities\Db\CoreRequestBuilder; +use OCP\DB\QueryBuilder\ICompositeExpression; +use OCP\Entities\IEntitiesQueryBuilder; +use OCP\Entities\Implementation\IEntitiesAccounts\IEntitiesAccounts; +use OCP\Entities\Implementation\IEntitiesAccounts\IEntitiesAccountsSearchDuplicate; +use OCP\Entities\Implementation\IEntitiesAccounts\IEntitiesAccountsSearchEntities; +use OCP\Entities\Model\IEntityAccount; + + +/** + * Class LocalUser + * + * @package OC\Entities\Classes\IEntitiesAccounts + */ +class LocalUser implements + IEntitiesAccounts, + IEntitiesAccountsSearchEntities, + IEntitiesAccountsSearchDuplicate { + + + const TYPE = 'local_user'; + + + /** + * @param IEntitiesQueryBuilder $qb + * @param string $needle + * + * @return ICompositeExpression + */ + public function exprSearchEntities(IEntitiesQueryBuilder $qb, string $needle + ): ICompositeExpression { + $qb->from(CoreRequestBuilder::TABLE_ENTITIES_ACCOUNTS, 'ea'); + + $expr = $qb->expr(); + $dbConn = $qb->getConnection(); + + $andX = $expr->andX(); + $andX->add($expr->eq('ea.id', 'e.owner_id')); + $andX->add($expr->eq('ea.type', $qb->createNamedParameter(self::TYPE))); + $andX->add( + $expr->iLike( + 'ea.account', + $qb->createNamedParameter('%' . $dbConn->escapeLikeParameter($needle) . '%') + ) + ); + + return $andX; + } + + + /** + * @param IEntitiesQueryBuilder $qb + * @param IEntityAccount $account + */ + public function buildSearchDuplicate(IEntitiesQueryBuilder $qb, IEntityAccount $account) { + $qb->limitToType($account->getType()); + $qb->limitToAccount($account->getAccount()); + } + +} + diff --git a/lib/private/Entities/Classes/EntitiesAccounts/MailAddress.php b/lib/private/Entities/Classes/EntitiesAccounts/MailAddress.php new file mode 100644 index 0000000000000..9a1c8862ae48c --- /dev/null +++ b/lib/private/Entities/Classes/EntitiesAccounts/MailAddress.php @@ -0,0 +1,68 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Classes\IEntitiesAccounts; + + +use OC; +use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\Entities\IEntitiesQueryBuilder; +use OCP\Entities\Implementation\IEntitiesAccounts\IEntitiesAccounts; +use OCP\Entities\Implementation\IEntitiesAccounts\IEntitiesAccountsSearchDuplicate; +use OCP\Entities\Model\IEntity; +use OCP\Entities\Model\IEntityAccount; + + +/** + * Class MailAddress + * + * @package OC\Entities\Classes\IEntitiesAccounts + */ +class MailAddress implements + IEntitiesAccounts, + IEntitiesAccountsSearchDuplicate { + + + const TYPE = 'mail_address'; + + + /** + * @param IEntitiesQueryBuilder $qb + * @param IEntityAccount $account + */ + public function buildSearchDuplicate(IEntitiesQueryBuilder $qb, IEntityAccount $account) { + + $qb->limitToType($account->getType()); + $qb->limitToAccount($account->getAccount()); + + } + +} + diff --git a/lib/private/Entities/Command/Create.php b/lib/private/Entities/Command/Create.php new file mode 100644 index 0000000000000..1c5ea195065ac --- /dev/null +++ b/lib/private/Entities/Command/Create.php @@ -0,0 +1,369 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Command; + + +use Exception; +use OC\Entities\Exceptions\EntityAccountNotFoundException; +use OC\Entities\Exceptions\EntityMemberAlreadyExistsException; +use OC\Entities\Exceptions\EntityNotFoundException; +use OC\Entities\Model\Entity; +use OC\Entities\Model\EntityAccount; +use OC\Entities\Model\EntityMember; +use OCP\Entities\Helper\IEntitiesHelper; +use OCP\Entities\IEntitiesManager; +use OCP\Entities\Implementation\IEntities\IEntities; +use OCP\Entities\Implementation\IEntitiesAccounts\IEntitiesAccounts; +use OCP\Entities\Model\IEntity; +use OCP\Entities\Model\IEntityMember; +use OCP\Entities\Model\IEntityType; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Question\ConfirmationQuestion; + + +/** + * Class Create + * + * @package OC\Entities\Command + */ +class Create extends ExtendedBase { + + + /** @var IEntitiesManager */ + private $entitiesManager; + + /** @var IEntitiesHelper */ + private $entitiesHelper; + + + /** + * Create constructor. + * + * @param IEntitiesManager $entitiesManager + * @param IEntitiesHelper $entitiesHelper + */ + public function __construct(IEntitiesManager $entitiesManager, IEntitiesHelper $entitiesHelper + ) { + parent::__construct(); + + $this->entitiesManager = $entitiesManager; + $this->entitiesHelper = $entitiesHelper; + } + + + /** + * + */ + protected function configure() { + parent::configure(); + $this->setName('entities:manage:create') + ->addArgument( + 'item', InputArgument::REQUIRED, 'item to create (entity, account, member)' + ) + ->addArgument('type', InputArgument::OPTIONAL, 'type/status of the item', '') + ->addOption('name', '', InputOption::VALUE_REQUIRED, 'name', '') + ->addOption('access', 'x', InputOption::VALUE_REQUIRED, 'access level', '') + ->addOption('visibility', 'b', InputOption::VALUE_REQUIRED, 'visibility level', '') + ->addOption('entity', 'm', InputOption::VALUE_REQUIRED, 'entity Id (master)', '') + ->addOption('slave', 's', InputOption::VALUE_REQUIRED, 'entity Id (slave)', '') + ->addOption('account', 'c', InputOption::VALUE_REQUIRED, 'account Id', '') + ->addOption('level', 'l', InputOption::VALUE_REQUIRED, 'level', '') + ->addOption('owner', 'o', InputOption::VALUE_REQUIRED, 'account id of owner', '') + ->setDescription('Create a new entity/account/member'); + } + + + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @throws Exception + */ + protected function execute(InputInterface $input, OutputInterface $output) { + $this->output = $output; + $this->input = $input; + + $item = $input->getArgument('item'); + $type = $input->getArgument('type'); + + $this->verifyType($item, $type); + + switch ($item) { + case 'entity': + $this->createEntity( + $type, + $input->getOption('name'), + $input->getOption('access'), + $input->getOption('visibility'), + $input->getOption('owner') + ); + break; + + case 'account': + $this->createAccount( + $type, + $input->getOption('account') + ); + break; + + case 'member': + $this->createMember( + $type, + $input->getOption('entity'), + $input->getOption('account'), + $input->getOption('slave'), + $input->getOption('level') + ); + break; + + default: + throw new Exception('Unknown item'); + } + + +// switch ($action) { +// +// case 'create': +// $this->actionCreate($item, $type, $data); +// break; +// +// default: +// throw new Exception('unknown action'); +// +// } + } + + + /** + * @param string $type + * @param string $name + * @param string $access + * @param string $visibility + * + * @param string $ownerId + * + * @throws Exception + */ + private function createEntity( + string $type, string $name, string $access, string $visibility, string $ownerId + ): void { + if ($name === '') { + throw new Exception('must specify a name (--name)'); + } + + $listAccess = array_values(IEntity::CONVERT_ACCESS); + if (!in_array($access, $listAccess)) { + throw new Exception( + 'must specify an Access Level (--access): ' . implode(', ', $listAccess) + ); + } + + $listVisibility = array_values(IEntity::CONVERT_VISIBILITY); + if (!in_array($visibility, $listVisibility)) { + throw new Exception( + 'must specify an Visibility Level (--visibility): ' . implode(', ', $listVisibility) + ); + } + + $owner = null; + if ($ownerId !== '') { + $owner = $this->entitiesManager->getAccount($ownerId); + } + + $entity = new Entity(); + $entity->setType($type); + $entity->setName($name); + $entity->setAccess(array_search($access, IEntity::CONVERT_ACCESS)); + $entity->setVisibility(array_search($visibility, IEntity::CONVERT_VISIBILITY)); + $this->outputEntity($entity); + + if ($owner !== null) { + $this->outputAccount($owner); + } + + $this->output->writeln(''); + $helper = $this->getHelper('question'); + $question = new ConfirmationQuestion( + 'Create this Entity? (Y/n) ', true, '/^(y|Y)/i' + ); + if (!$helper->ask($this->input, $this->output, $question)) { + return; + } + + $this->entitiesManager->saveEntity($entity, $ownerId); + $this->output->writeln('Entity created'); + } + + + /** + * @param string $type + * @param string $accountName + * + * @throws Exception + */ + private function createAccount(string $type, string $accountName): void { + if ($accountName === '') { + throw new Exception('must specify an account name (--account)'); + } + + $account = new EntityAccount(); + $account->setType($type); + $account->setAccount($accountName); + $this->outputAccount($account); + + $this->output->writeln(''); + $helper = $this->getHelper('question'); + $question = new ConfirmationQuestion( + 'Create this EntityAccount? (Y/n) ', true, '/^(y|Y)/i' + ); + if (!$helper->ask($this->input, $this->output, $question)) { + return; + } + + $this->entitiesManager->saveAccount($account); + $this->output->writeln('EntityAccount created'); + } + + + /** + * @param string $status + * @param string $entityId + * @param string $slaveId + * @param string $accountId + * @param string $level + * + * @throws Exception + */ + private function createMember( + string $status, string $entityId, string $accountId, string $slaveId, string $level + ): void { + $listLevel = array_values(IEntityMember::CONVERT_LEVEL); + if (!in_array($level, $listLevel)) { + throw new Exception( + 'must specify a level (--level): ' . implode(', ', $listLevel) + ); + } + + try { + $entity = $this->entitiesManager->getEntity($entityId); + } catch (EntityNotFoundException $e) { + throw new Exception('must specify a valid EntityId (--entity)'); + } + + $account = null; + $slave = null; + try { + $account = $this->entitiesManager->getAccount($accountId); + } catch (EntityAccountNotFoundException $e) { + try { + $slave = $this->entitiesManager->getEntity($slaveId); + } catch (EntityNotFoundException $e) { + throw new Exception( + 'must specify a valid AccountId (--account) or SlaveEntityId (--slave)' + ); + } + } + + $member = new EntityMember(); + $member->setStatus($status); + $member->setLevel(array_search($level, IEntityMember::CONVERT_LEVEL)); + $member->setEntity($entity); + if ($slave !== null) { + $member->setSlaveEntityId($slave->getId()); + } + if ($account !== null) { + $member->setAccount($account); + } + + $this->outputMember($member); +// $this->outputEntity($entity); + +// if ($account !== null) { +// $this->outputAccount($account); +// } +// if ($slave !== null) { +// $this->outputEntity($slave); +// } + + $this->output->writeln(''); + $helper = $this->getHelper('question'); + $question = new ConfirmationQuestion( + 'Create this EntityMember? (Y/n) ', true, '/^(y|Y)/i' + ); + if (!$helper->ask($this->input, $this->output, $question)) { + return; + } + + $this->entitiesManager->saveMember($member); + $this->output->writeln('EntityMember created'); + } + + + /** + * @param string $item + * @param string $type + * + * @throws Exception + */ + private function verifyType(string $item, string $type) { + switch ($item) { + case 'entity': + $interface = IEntities::INTERFACE; + break; + + case 'account': + $interface = IEntitiesAccounts::INTERFACE; + break; + + case 'member': + return; + + default: + throw new Exception('unknown item'); + } + + $entityTypes = $this->entitiesHelper->getEntityTypes($interface); + $types = array_map( + function(IEntityType $item) { + return $item->getType(); + }, $entityTypes + ); + + if (!in_array($type, $types)) { + throw new Exception('Please specify a type: ' . implode(', ', $types)); + } + } + +} + diff --git a/lib/private/Entities/Command/Delete.php b/lib/private/Entities/Command/Delete.php new file mode 100644 index 0000000000000..afe4f68972806 --- /dev/null +++ b/lib/private/Entities/Command/Delete.php @@ -0,0 +1,103 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Command; + + +use Exception; +use OC\Core\Command\Base; +use OCP\Entities\Helper\IEntitiesHelper; +use OCP\Entities\IEntitiesManager; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; + + +class Delete extends Base { + + + /** @var IEntitiesManager */ + private $entitiesManager; + + /** @var IEntitiesHelper */ + private $entitiesHelper; + + + public function __construct(IEntitiesManager $entitiesManager, IEntitiesHelper $entitiesHelper + ) { + parent::__construct(); + + $this->entitiesManager = $entitiesManager; + $this->entitiesHelper = $entitiesHelper; + } + + + + /** + * + */ + protected function configure() { + parent::configure(); + $this->setName('entities:manage:delete') + ->addArgument( + 'item_id', InputArgument::REQUIRED, 'itemId to delete' + ) + ->setDescription('Delete an entity/account/member'); + } + + + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @throws Exception + */ + protected function execute(InputInterface $input, OutputInterface $output) { + $item = $input->getArgument('item'); + $type = $input->getOption('type'); +// switch ($action) { +// +// case 'create': +// $this->actionCreate($item, $type, $data); +// break; +// +// default: +// throw new Exception('unknown action'); +// +// } + } + + + private function actionCreate(InputInterface $input) { + + } +} + diff --git a/lib/private/Entities/Command/Details.php b/lib/private/Entities/Command/Details.php new file mode 100644 index 0000000000000..04acf97bde799 --- /dev/null +++ b/lib/private/Entities/Command/Details.php @@ -0,0 +1,214 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Command; + + +use daita\NcSmallPhpTools\Traits\TArrayTools; +use Exception; +use OC\Entities\Exceptions\EntityAccountNotFoundException; +use OC\Entities\Exceptions\EntityMemberNotFoundException; +use OC\Entities\Exceptions\EntityNotFoundException; +use OCP\Entities\IEntitiesManager; +use OCP\Entities\Model\IEntity; +use OCP\Entities\Model\IEntityAccount; +use OCP\Entities\Model\IEntityMember; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; + + +/** + * Class Details + * + * @package OC\Entities\Command + */ +class Details extends ExtendedBase { + + + use TArrayTools; + + + /** @var IEntitiesManager */ + private $entitiesManager; + + + /** + * Details constructor. + * + * @param IEntitiesManager $entitiesManager + */ + public function __construct(IEntitiesManager $entitiesManager) { + parent::__construct(); + + $this->entitiesManager = $entitiesManager; + } + + + /** + * + */ + protected function configure() { + parent::configure(); + $this->setName('entities:details') + ->addArgument('entityId', InputArgument::REQUIRED, 'entity Id') + ->addOption('short', 's', InputOption::VALUE_NONE, 'short result') + ->setDescription('Details about an entity'); + } + + + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @throws Exception + */ + protected function execute(InputInterface $input, OutputInterface $output) { + + $this->output = $output; + $this->input = $input; + + $this->short = $input->getOption('short'); + + if (!$this->search()) { + throw new Exception('no item were found with this id, please use entities:search'); + } + } + + + /** + * @return bool + */ + private function search(): bool { + $itemId = $this->input->getArgument('entityId'); + + try { + $this->searchForEntity($itemId); + + return true; + } catch (EntityNotFoundException $e) { + } + + try { + $this->searchForEntityAccount($itemId); + + return true; + } catch (EntityAccountNotFoundException $e) { + } + + try { + $this->searchForEntityMember($itemId); + + return true; + } catch (EntityMemberNotFoundException $e) { + } + + return false; + } + + + /** + * @param string $itemId + * + * @return IEntity + * @throws EntityNotFoundException + */ + private function searchForEntity(string $itemId): IEntity { + + $entity = $this->entitiesManager->getEntity($itemId); + $this->outputEntity($entity); + + if (!$this->short) { + $this->output('- Owner'); + if ($entity->getOwnerId() === '') { + $this->output(' (no owner)'); + } else { + $this->outputAccount($entity->getOwner(), ' '); + } + } + + $members = $entity->getMembers(); + $this->output('- getMembers (' . count($members) . ')'); + foreach ($members as $member) { + $this->outputMember( + $member, ' ', + [ + 'entity' => ($member->getEntityId() !== $entity->getId()), + 'account' => ($member->getAccountId() !== $entity->getOwnerId()), + ] + ); + } + + return $entity; + } + + + /** + * @param string $itemId + * + * @return IEntityAccount + * @throws EntityAccountNotFoundException + */ + private function searchForEntityAccount(string $itemId): IEntityAccount { + + $account = $this->entitiesManager->getAccount($itemId); + $this->outputAccount($account); + + $belongsTo = $account->belongsTo(); + $this->output('- belongsTo (' . count($belongsTo) . ')'); + foreach ($belongsTo as $member) { + $this->outputMember( + $member, ' ', [ + 'account' => ($member->getAccountId() !== $account->getId()) + ] + ); + } + + return $account; + } + + + /** + * @param string $itemId + * + * @return IEntityMember + * @throws EntityMemberNotFoundException + */ + private function searchForEntityMember(string $itemId): IEntityMember { + + $member = $this->entitiesManager->getMember($itemId); + $this->outputMember($member); + + return $member; + } + +} + diff --git a/lib/private/Entities/Command/ExtendedBase.php b/lib/private/Entities/Command/ExtendedBase.php new file mode 100644 index 0000000000000..b2e64c9a76c85 --- /dev/null +++ b/lib/private/Entities/Command/ExtendedBase.php @@ -0,0 +1,243 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Command; + + +use daita\NcSmallPhpTools\Traits\TArrayTools; +use OC\Core\Command\Base; +use OCP\Entities\Model\IEntity; +use OCP\Entities\Model\IEntityAccount; +use OCP\Entities\Model\IEntityMember; +use Symfony\Component\Console\Helper\Table; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + + +/** + * Class Details + * + * @package OC\Entities\Command + */ +class ExtendedBase extends Base { + + + use TArrayTools; + + + /** @var InputInterface */ + protected $input; + + /** @var OutputInterface */ + protected $output; + + /** @var bool */ + protected $short = false; + + + /** + * @param IEntity $entity + * @param string $prefix + */ + protected function outputEntity(IEntity $entity, $prefix = ''): void { + $this->output($prefix . '- Entity Id: ' . $entity->getId() . ''); + $this->output($prefix . ' - Type: ' . $entity->getType() . ''); + $this->output($prefix . ' - Name: ' . $entity->getName() . ''); + $this->output( + $prefix . ' - Access: ' . $entity->getAccess() . ' (' + . $entity->getAccessString() . ')', true + ); + $this->output( + $prefix . ' - Visibility: ' . $entity->getVisibility() . ' (' + . $entity->getVisibilityString() . ')', true + ); + + if ($entity->getCreation() > 0) { + $this->output( + $prefix . ' - Creation: ' . date('Y-m-d H:i:s', $entity->getCreation()) . '', true + ); + } + } + + + /** + * @param IEntity[] $entities + */ + protected function outputEntities(array $entities): void { + $table = new Table($this->output); + $table->setHeaders( + [ + 'Entity Id', 'Type', 'Name', 'Owner Id', 'Owner Account', 'Owner Type', 'Admin', + 'Viewer Status', 'Viewer Level' + ] + ); + $table->render(); + $this->output->writeln(''); + foreach ($entities as $entity) { + $ownerId = ''; + $ownerName = ''; + $ownerType = ''; + if ($entity->hasOwner()) { + $owner = $entity->getOwner(); + $ownerId = '' . $owner->getId() . ''; + $ownerName = $owner->getAccount(); + $ownerType = '' . $owner->getType() . ''; + } + + $viewerStatus = ''; + $viewerLevel = ''; + if ($entity->hasViewer()) { + $viewer = $entity->getViewer(); + $viewerStatus = + ($viewer->getStatus() !== IEntityMember::STATUS_MEMBER) ? $viewer->getStatus( + ) : '' . $viewer->getStatus() . ''; + $viewerLevel = ($viewer->getLevel() > 0) ? '' . $viewer->getLevelString() + . '' : $viewer->getLevelString(); + } + + $table->appendRow( + [ + '' . $entity->getId() . '', + '' . $entity->getType() . '', + $entity->getName(), + $ownerId, + $ownerName, + $ownerType, + $entity->hasAdminRights() ? 'yes' : 'no', + $viewerStatus, + $viewerLevel + ] + ); + } + } + + + /** + * @param IEntityAccount $account + * @param string $prefix + */ + protected function outputAccount(IEntityAccount $account, $prefix = ''): void { + $this->output($prefix . '- Account Id: ' . $account->getId() . ''); + $this->output($prefix . ' - Type: ' . $account->getType() . ''); + $this->output( + $prefix . ' - Account: ' . $account->getAccount() . '' + ); + $this->output( + $prefix . ' - Admin: ' . ($account->hasAdminRights() ? 'yes' : 'no') + ); + + if ($account->getCreation() > 0) { + $this->output( + $prefix . ' - Creation: ' . date('Y-m-d H:i:s', $account->getCreation()) . '', true + ); + } + + if ($account->getDeleteOn() > 0) { + $this->output( + $prefix . ' - Deadline: ' . date('Y-m-d H:i:s', $account->getDeleteOn()) . '', true + ); + } + } + + + /** + * @param IEntityAccount[] $accounts + */ + protected function outputAccounts(array $accounts): void { + $table = new Table($this->output); + $table->setHeaders(['Account Id', 'Type', 'Account', 'Admin']); + $table->render(); + $this->output->writeln(''); + foreach ($accounts as $account) { + $table->appendRow( + [ + '' . $account->getId() . '', + '' . $account->getType() . '', + $account->getAccount(), + $account->hasAdminRights() ? 'yes' : 'no' + ] + ); + } + } + + + /** + * @param IEntityMember $member + * @param string $prefix + * @param array $details + */ + protected function outputMember(IEntityMember $member, string $prefix = '', array $details = [] + ) { + $this->output($prefix . '- Member Id: ' . $member->getId() . ''); + + if ($this->getBool('entity', $details, true)) { + $this->outputEntity($member->getEntity(), $prefix . ' '); + } else { + $this->output( + $prefix . ' - Entity Id: ' . $member->getEntityId() . '', true + ); + } + + if ($this->getBool('account', $details, true)) { + $this->outputAccount($member->getAccount(), $prefix . ' '); + } else { + $this->output( + $prefix . ' - Account Id: ' . $member->getAccountId() . '', true + ); + + } + + $this->output( + $prefix . ' - Slave Entity Id: ' . $member->getSlaveEntityId() . '' + ); + $this->output($prefix . ' - Status: ' . $member->getStatus() . '', true); + $this->output($prefix . ' - Level: ' . $member->getLevel() . '', true); + + if ($member->getCreation() > 0) { + $this->output( + $prefix . ' - Creation: ' . date('Y-m-d H:i:s', $member->getCreation()) . '', true + ); + } + } + + + /** + * @param string $line + * @param bool $optional + */ + protected function output(string $line, bool $optional = false) { + if ($optional && $this->short) { + return; + } + $this->output->writeln($line); + } + +} + diff --git a/lib/private/Entities/Command/Install.php b/lib/private/Entities/Command/Install.php new file mode 100644 index 0000000000000..0960c153526d6 --- /dev/null +++ b/lib/private/Entities/Command/Install.php @@ -0,0 +1,87 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Command; + + +use Exception; +use OC\Core\Command\Base; +use OCP\Entities\Helper\IEntitiesHelper; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + + +/** + * Class Install + * + * @package OC\Entities\Command + */ +class Install extends Base { + + + /** @var IEntitiesHelper */ + private $entitiesHelper; + + + /** + * Migration constructor. + * + * @param IEntitiesHelper $entitiesHelper + */ + public function __construct(IEntitiesHelper $entitiesHelper) { + parent::__construct(); + + $this->entitiesHelper = $entitiesHelper; + } + + + /** + * + */ + protected function configure() { + parent::configure(); + $this->setName('entities:install') + ->setDescription('Fresh install'); + } + + + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @throws Exception + */ + protected function execute(InputInterface $input, OutputInterface $output) { + $this->entitiesHelper->refreshInstall(); + } + + +} + diff --git a/lib/private/Entities/Command/Migration.php b/lib/private/Entities/Command/Migration.php new file mode 100644 index 0000000000000..8cc7d1aeff0f4 --- /dev/null +++ b/lib/private/Entities/Command/Migration.php @@ -0,0 +1,98 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Command; + + +use Exception; +use OC\Core\Command\Base; +use OCP\Entities\Helper\IEntitiesMigrationHelper; +use OCP\Entities\IEntitiesManager; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + + +/** + * Class Migration + * + * @package OC\Entities\Command + */ +class Migration extends Base { + + + /** @var IEntitiesManager */ + private $entitiesManager; + + /** @var IEntitiesMigrationHelper */ + private $entitiesMigrationHelper; + + + /** + * Migration constructor. + * + * @param IEntitiesManager $entitiesManager + * @param IEntitiesMigrationHelper $entitiesMigrationHelper + */ + public function __construct( + IEntitiesManager $entitiesManager, IEntitiesMigrationHelper $entitiesMigrationHelper + ) { + parent::__construct(); + + $this->entitiesManager = $entitiesManager; + $this->entitiesMigrationHelper = $entitiesMigrationHelper; + } + + + /** + * + */ + protected function configure() { + parent::configure(); + $this->setName('entities:migration') + ->setDescription('Migrate current users/groups/circles to Entities'); + } + + + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @throws Exception + */ + protected function execute(InputInterface $input, OutputInterface $output) { + + $this->entitiesMigrationHelper->migrateUsers(); + $this->entitiesMigrationHelper->migrateGroups(); + + } + + +} + diff --git a/lib/private/Entities/Command/Modify.php b/lib/private/Entities/Command/Modify.php new file mode 100644 index 0000000000000..5d4b6394b4ae1 --- /dev/null +++ b/lib/private/Entities/Command/Modify.php @@ -0,0 +1,103 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Command; + + +use Exception; +use OC\Core\Command\Base; +use OCP\Entities\Helper\IEntitiesHelper; +use OCP\Entities\IEntitiesManager; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; + + +class Modify extends Base { + + + /** @var IEntitiesManager */ + private $entitiesManager; + + /** @var IEntitiesHelper */ + private $entitiesHelper; + + + public function __construct(IEntitiesManager $entitiesManager, IEntitiesHelper $entitiesHelper + ) { + parent::__construct(); + + $this->entitiesManager = $entitiesManager; + $this->entitiesHelper = $entitiesHelper; + } + + + /** + * + */ + protected function configure() { + parent::configure(); + $this->setName('entities:manage:modify') + ->addArgument( + 'item_id', InputArgument::REQUIRED, 'item to create (entity, account, member)' + ) + ->setDescription('modify an entity/account/member'); + } + + + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @throws Exception + */ + protected function execute(InputInterface $input, OutputInterface $output) { + $item = $input->getArgument('item'); + $type = $input->getOption('type'); +// switch ($action) { +// +// case 'create': +// $this->actionCreate($item, $type, $data); +// break; +// +// default: +// throw new Exception('unknown action'); +// +// } + } + + + private function actionCreate(InputInterface $input) { + + } + +} + diff --git a/lib/private/Entities/Command/Search.php b/lib/private/Entities/Command/Search.php new file mode 100644 index 0000000000000..c01c05bf362fb --- /dev/null +++ b/lib/private/Entities/Command/Search.php @@ -0,0 +1,275 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Command; + + +use Exception; +use OCP\Entities\Helper\IEntitiesHelper; +use OCP\Entities\IEntitiesManager; +use OCP\Entities\Implementation\IEntities\IEntities; +use OCP\Entities\Implementation\IEntitiesAccounts\IEntitiesAccounts; +use OCP\Entities\Model\IEntityAccount; +use OCP\Entities\Model\IEntityMember; +use OCP\Entities\Model\IEntityType; +use Symfony\Component\Console\Helper\Table; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\ConsoleOutput; +use Symfony\Component\Console\Output\OutputInterface; + + +class Search extends ExtendedBase { + + + /** @var IEntitiesManager */ + private $entitiesManager; + + /** @var IEntitiesHelper */ + private $entitiesHelper; + + + public function __construct(IEntitiesHelper $entitiesHelper, IEntitiesManager $entitiesManager + ) { + parent::__construct(); + + $this->entitiesHelper = $entitiesHelper; + $this->entitiesManager = $entitiesManager; + } + + + /** + * + */ + protected function configure() { + parent::configure(); + $this->setName('entities:search') + ->addArgument('needle', InputArgument::OPTIONAL, 'needle', '') + ->addOption('accounts', '', InputOption::VALUE_NONE, 'search for accounts') + ->addOption( + 'viewer', '', InputOption::VALUE_REQUIRED, 'search from a user\'s point of view', + '' + ) + ->addOption( + 'visibility', '', InputOption::VALUE_REQUIRED, 'level of visibility (as admin)', + 'none' + ) + ->addOption( + 'non-admin-viewer', '', InputOption::VALUE_NONE, + 'create a non-admin temporary viewer' + ) + ->addOption('type', '', InputOption::VALUE_REQUIRED, 'limit to a type', '') + ->setDescription('Search for entities'); + } + + + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @throws Exception + */ + protected function execute(InputInterface $input, OutputInterface $output) { + $output = new ConsoleOutput(); + $this->output = $output->section(); + + $needle = $input->getArgument('needle'); + $viewerName = $input->getOption('viewer'); + $type = $input->getOption('type'); + $level = $input->getOption('visibility'); + + if ($input->getOption('accounts')) { + $this->searchAccounts($needle, $type); + } else { + + if ($viewerName === '') { + $viewer = + $this->entitiesHelper->temporaryLocalAccount( + !$input->getOption('non-admin-viewer') + ); + } else { + $viewer = $this->entitiesHelper->getLocalAccount($viewerName); + } + + + $listLevel = array_values(IEntityMember::CONVERT_LEVEL); + if (!in_array($level, $listLevel)) { + throw new Exception( + 'must specify an Visibility Level (--visibility): ' . implode(', ', $listLevel) + ); + } + + $viewer->getOptions() + ->setOptionInt( + 'viewer.visibility', array_search($level, IEntityMember::CONVERT_LEVEL) + ); + + + $this->searchEntities($needle, $viewer, $type); + } + + $this->output->writeln(''); + } + + + /** + * @param string $needle + * @param string $type + * + * @throws Exception + */ + private function searchAccounts(string $needle, $type = ''): void { + + if ($type !== '') { + $this->verifyType(IEntitiesAccounts::INTERFACE, $type); + } + + if ($needle === '') { + $accounts = $this->entitiesManager->getAllAccounts($type); + } else { + $accounts = $this->entitiesManager->searchAccounts($needle, $type); + } + + $table = new Table($this->output); + $table->setHeaders(['Account Id', 'Type', 'Account', 'Admin']); + $table->render(); + $this->output->writeln(''); + foreach ($accounts as $account) { + $table->appendRow( + [ + '' . $account->getId() . '', + '' . $account->getType() . '', + $account->getAccount(), + $account->hasAdminRights() ? 'yes' : 'no' + ] + ); + } + + } + + + /** + * @param string $needle + * @param IEntityAccount $viewer + * @param string $type + * + * @throws Exception + */ + private function searchEntities(string $needle, IEntityAccount $viewer, $type = ''): void { + + $this->output->writeln('Viewer: ' . $viewer->getAccount() . ''); + $this->output->writeln(''); + $this->outputAccount($viewer); + $this->entitiesManager->setViewer($viewer); + + $this->output->writeln(''); + + if ($type !== '') { + $this->verifyType(IEntities::INTERFACE, $type); + } + + if ($needle === '') { + $entities = $this->entitiesManager->getAllEntities($type); + } else { + $entities = $this->entitiesManager->searchEntities($needle, $type); + } + + $table = new Table($this->output); + $table->setHeaders( + [ + 'Entity Id', 'Type', 'Name', 'Owner Id', 'Owner Account', 'Owner Type', 'Admin', + 'Viewer Status', 'Viewer Level' + ] + ); + $table->render(); + $this->output->writeln(''); + foreach ($entities as $entity) { + $ownerId = ''; + $ownerName = ''; + $ownerType = ''; + if ($entity->hasOwner()) { + $owner = $entity->getOwner(); + $ownerId = '' . $owner->getId() . ''; + $ownerName = $owner->getAccount(); + $ownerType = '' . $owner->getType() . ''; + } + + $viewerStatus = ''; + $viewerLevel = ''; + if ($entity->hasViewer()) { + $viewer = $entity->getViewer(); + $viewerStatus = + ($viewer->getStatus() !== IEntityMember::STATUS_MEMBER) ? $viewer->getStatus( + ) : '' . $viewer->getStatus() . ''; + $viewerLevel = ($viewer->getLevel() > 0) ? '' . $viewer->getLevelString() + . '' : $viewer->getLevelString(); + } + + $table->appendRow( + [ + '' . $entity->getId() . '', + '' . $entity->getType() . '', + $entity->getName(), + $ownerId, + $ownerName, + $ownerType, + $entity->hasAdminRights() ? 'yes' : 'no', + $viewerStatus, + $viewerLevel + ] + ); + } + } + + + /** + * @param string $interface + * @param string $type + * + * @throws Exception + */ + private function verifyType(string $interface, string $type) { + + $entityTypes = $this->entitiesHelper->getEntityTypes($interface); + $types = array_map( + function(IEntityType $item) { + return $item->getType(); + }, $entityTypes + ); + + if (!in_array($type, $types)) { + throw new Exception('Please specify a type: ' . implode(', ', $types)); + } + + } + +} + diff --git a/lib/private/Entities/Command/Session.php b/lib/private/Entities/Command/Session.php new file mode 100644 index 0000000000000..5f64bc18ca411 --- /dev/null +++ b/lib/private/Entities/Command/Session.php @@ -0,0 +1,707 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Command; + + +use daita\NcSmallPhpTools\Exceptions\ShellMissingCommandException; +use daita\NcSmallPhpTools\Exceptions\ShellMissingItemException; +use daita\NcSmallPhpTools\Exceptions\ShellUnknownCommandException; +use daita\NcSmallPhpTools\Exceptions\ShellUnknownItemException; +use daita\NcSmallPhpTools\IInteractiveShellClient; +use daita\NcSmallPhpTools\Service\InteractiveShell; +use daita\NcSmallPhpTools\Traits\TStringTools; +use Exception; +use OC\Entities\Exceptions\EntityAccountNotFoundException; +use OC\Entities\Exceptions\EntityMemberNotFoundException; +use OC\Entities\Exceptions\EntityNotFoundException; +use OC\Entities\Exceptions\EntityTypeNotFoundException; +use OC\Entities\Model\Entity; +use OC\Entities\Model\EntityAccount; +use OCP\Entities\Helper\IEntitiesHelper; +use OCP\Entities\IEntitiesManager; +use OCP\Entities\Implementation\IEntities\IEntities; +use OCP\Entities\Implementation\IEntitiesAccounts\IEntitiesAccounts; +use OCP\Entities\Model\IEntity; +use OCP\Entities\Model\IEntityAccount; +use OCP\Entities\Model\IEntityMember; +use OCP\Entities\Model\IEntityType; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\ConsoleOutput; +use Symfony\Component\Console\Output\OutputInterface; + + +/** + * Class Session + * + * @package OC\Entities\Command + */ +class Session extends ExtendedBase implements IInteractiveShellClient { + + + use TStringTools; + + + /** @var IEntitiesManager */ + private $entitiesManager; + + /** @var IEntitiesHelper */ + private $entitiesHelper; + + + /** @var IEntityAccount */ + private $viewer; + + /** @var InteractiveShell */ + private $interactiveShell; + + + /** + * Session constructor. + * + * @param IEntitiesManager $entitiesManager + * @param IEntitiesHelper $entitiesHelper + */ + public function __construct(IEntitiesManager $entitiesManager, IEntitiesHelper $entitiesHelper + ) { + parent::__construct(); + + $this->entitiesManager = $entitiesManager; + $this->entitiesHelper = $entitiesHelper; + } + + + /** + * + */ + protected function configure(): void { + parent::configure(); + $this->setName('entities:session') + ->addArgument( + 'viewer', InputArgument::OPTIONAL, 'session from a user\'s point of view', + '' + ) + ->addOption( + 'visibility', '', InputOption::VALUE_REQUIRED, 'level of visibility (as admin)', + 'none' + ) + ->addOption( + 'as-non-admin', '', InputOption::VALUE_NONE, + 'create a non-admin temporary viewer' + ) + ->setDescription('Start session as a temporary (or local) user'); + } + + + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @throws Exception + */ + protected function execute(InputInterface $input, OutputInterface $output): void { + + $output = new ConsoleOutput(); + $this->output = $output->section(); + $this->input = $input; + + $this->generateViewer(); + $this->entitiesManager->setViewer($this->viewer); + + $this->output->writeln('* Identity used during this session:'); + $this->outputAccount($this->viewer); + $this->output->writeln(''); + + $this->interactiveShell = new InteractiveShell($this, $input, $output, $this); + + $commands = [ + 'create.entity.?type_IEntities', + 'create.account.?type_IEntitiesAccounts', + 'list.entities.?type_IEntities', + 'list.accounts.?type_IEntitiesAccounts', + 'search.accounts', + 'details.?entity_id', + 'invite.?entity_id.?account_id', + 'join.?entity_id', + 'notifications' + ]; + + $tag = '$'; + if ($this->viewer->hasAdminRights()) { + $tag = '#'; + $commands = array_merge( + $commands, + [ + 'create.member.?entity_id.?account_id', + ] + ); + } + + sort($commands); + $this->interactiveShell->setCommands($commands); + + $this->interactiveShell->run( + 'EntitiesManager [' . $this->viewer->getAccount() + . ']:%PATH%' . $tag + ); + + } + + + /** + * @param string $source + * @param string $needle + * + * @return string[] + */ + public function fillCommandList(string $source, string $needle): array { + + switch ($source) { + case 'type': + $entries = $this->entitiesHelper->getEntityTypes($needle); + + return array_map( + function(IEntityType $entry) { + return $entry->getType(); + }, $entries + ); + + case 'entity': + $entries = $this->entitiesManager->getAllEntities(); + + return array_map( + function(IEntity $entry) { + return $entry->getId(); + }, $entries + ); + + case 'account': + $accounts = $this->entitiesManager->getAllAccounts(); + + return array_map( + function(IEntityAccount $entry) { + return $entry->getId(); + }, $accounts + ); + } + + return []; + } + + + /** + * @param string $command + * + * @throws ShellMissingCommandException + * @throws ShellMissingItemException + * @throws ShellUnknownCommandException + * @throws ShellUnknownItemException + */ + public function manageCommand(string $command): void { + $args = explode(' ', $command); + $cmd = array_shift($args); + switch ($cmd) { + + case 'create': + $this->manageCommandCreate($args); + break; + + case 'list': + $this->manageCommandList($args); + break; + + case 'search': + $this->manageCommandSearch($args); + break; + + case 'details': + $this->manageCommandDetails($args); + break; + + case 'invite': + $this->manageCommandInvite($args); + break; + + case 'join': + $this->manageCommandJoin($args); + break; + + case 'notifications': + $this->manageCommandNotifications($args); + break; + + default: + throw new ShellUnknownCommandException(); + } + } + + + /** + * @param array $args + * + * @throws ShellMissingCommandException + * @throws ShellUnknownCommandException + * @throws ShellUnknownItemException + */ + private function manageCommandCreate(array $args): void { + $item = array_shift($args); + switch ($item) { + case 'entity': + $this->manageCommandCreateEntity($args); + break; + + case 'account': + $this->manageCommandCreateAccount($args); + break; + + case 'member': + $this->manageCommandCreateMember($args); + break; + + case '': + throw new ShellMissingCommandException(); + + default: + throw new ShellUnknownCommandException(); + } + } + + + /** + * @param array $args + * + * @throws ShellUnknownItemException + * @throws ShellMissingCommandException + */ + private function manageCommandCreateEntity(array $args): void { + $type = array_shift($args); + if (!is_string($type)) { + throw new ShellMissingCommandException(); + } + + try { + $this->verifyEntityType($type); + } catch (EntityTypeNotFoundException $e) { + throw new ShellUnknownItemException(); + } + + $entity = new Entity(); + $entity->setType($type); + + $listVisibility = array_values(IEntity::CONVERT_VISIBILITY); + $visibility = $this->interactiveShell->asking('Visibility', '', $listVisibility); + $entity->setVisibility(array_search($visibility, IEntity::CONVERT_VISIBILITY)); + + $listAccess = array_values(IEntity::CONVERT_ACCESS); + $access = $this->interactiveShell->asking('Access', '', $listAccess); + $entity->setAccess(array_search($access, IEntity::CONVERT_ACCESS)); + + $entity->setName($this->interactiveShell->asking('Name', '')); + + + $this->outputEntity($entity); + try { + $this->interactiveShell->confirming('Save this Entity?'); + $this->entitiesManager->saveEntity($entity); + $this->output->writeln('Entity saved'); + } catch (Exception $e) { + $this->output->writeln('Entity NOT saved'); + } + + } + + + /** + * @param array $args + * + * @throws ShellMissingCommandException + * @throws ShellUnknownItemException + */ + private function manageCommandCreateAccount(array $args): void { + $type = array_shift($args); + if (!is_string($type)) { + throw new ShellMissingCommandException(); + } + + try { + $this->verifyAccountType($type); + } catch (EntityTypeNotFoundException $e) { + throw new ShellUnknownItemException(); + } + + $account = new EntityAccount(); + $account->setType($type); + $account->setAccount($this->interactiveShell->asking('Account', '')); + + $this->outputAccount($account); + try { + $this->interactiveShell->confirming('Save this EntityAccount?'); + $this->entitiesManager->saveAccount($account); + $this->output->writeln('Account saved'); + } catch (Exception $e) { + $this->output->writeln('Account NOT saved'); + } + } + + + /** + * @param array $args + * + * @throws ShellMissingCommandException + * @throws ShellUnknownCommandException + * @throws ShellUnknownItemException + */ + private function manageCommandCreateMember(array $args): void { + if (!$this->viewer->hasAdminRights()) { + throw new ShellUnknownCommandException(); + } + } + + + /** + * @param array $args + * + * @throws ShellMissingCommandException + * @throws ShellUnknownCommandException + * @throws ShellUnknownItemException + */ + private function manageCommandList(array $args): void { + $item = array_shift($args); + switch ($item) { + case 'entities': + $this->manageCommandListEntities($args); + break; + + case 'accounts': + $this->manageCommandListAccounts($args); + break; + + case '': + throw new ShellMissingCommandException(); + + default: + throw new ShellUnknownCommandException(); + } + } + + + /** + * @param array $args + * + * @throws ShellUnknownItemException + */ + private function manageCommandListEntities(array $args): void { + $type = array_shift($args); + if (is_string($type)) { + try { + $this->verifyEntityType($type); + } catch (EntityTypeNotFoundException $e) { + throw new ShellUnknownItemException(); + } + } else { + $type = ''; + } + + $entities = $this->entitiesManager->getAllEntities($type); + $this->outputEntities($entities); + } + + + /** + * @param array $args + * + * @throws ShellUnknownItemException + */ + private function manageCommandListAccounts(array $args): void { + $type = array_shift($args); + if (is_string($type)) { + try { + $this->verifyAccountType($type); + } catch (EntityTypeNotFoundException $e) { + throw new ShellUnknownItemException(); + } + } else { + $type = ''; + } + + $accounts = $this->entitiesManager->getAllAccounts($type); + $this->outputAccounts($accounts); + } + + + /** + * @param array $args + * + * @throws ShellMissingItemException + */ + private function manageCommandSearch(array $args): void { + $item = array_shift($args); + if (!is_string($item)) { + throw new ShellMissingItemException(); + } + + switch ($item) { + case 'accounts': + $item = array_shift($args); + if (!is_string($item)) { + throw new ShellMissingItemException(); + } + + $this->manageCommandSearchAccounts($item); + break; + + default: + $this->manageCommandSearchEntities($item); + } + } + + + /** + * @param string $needle + */ + private function manageCommandSearchEntities(string $needle): void { + $entities = $this->entitiesManager->searchEntities($needle); + $this->outputEntities($entities); + } + + + /** + * @param string $needle + */ + private function manageCommandSearchAccounts(string $needle): void { + $accounts = $this->entitiesManager->searchAccounts($needle); + $this->outputAccounts($accounts); + } + + + /** + * @param array $args + * + * @throws ShellUnknownItemException + * @throws ShellMissingItemException + */ + private function manageCommandDetails(array $args): void { + $itemId = array_shift($args); + if (!is_string($itemId)) { + throw new ShellMissingItemException(); + } + + try { + $this->detailsOnEntity($itemId); + + return; + } catch (EntityNotFoundException $e) { + } + + try { + $this->detailsOnAccount($itemId); + + return; + } catch (EntityAccountNotFoundException $e) { + } + + try { + $this->detailsOnMember($itemId); + + return; + } catch (EntityMemberNotFoundException $e) { + } + + throw new ShellUnknownItemException(); + } + + + /** + * @param string $itemId + * + * @throws EntityNotFoundException + */ + private function detailsOnEntity(string $itemId): void { + + $entity = $this->entitiesManager->getEntity($itemId); + $this->outputEntity($entity); + + if (!$this->short) { + $this->output('- Owner'); + if ($entity->getOwnerId() === '') { + $this->output(' (no owner)'); + } else { + $this->outputAccount($entity->getOwner(), ' '); + } + } + + $members = $entity->getMembers(); + $this->output('- getMembers (' . count($members) . ')'); + foreach ($members as $member) { + $this->outputMember( + $member, ' ', + [ + 'entity' => ($member->getEntityId() !== $entity->getId()), + 'account' => ($member->getAccountId() !== $entity->getOwnerId()), + ] + ); + } + } + + + /** + * @param string $itemId + * + * @throws EntityAccountNotFoundException + */ + private function detailsOnAccount(string $itemId): void { + $account = $this->entitiesManager->getAccount($itemId); + $this->outputAccount($account); + + $belongsTo = $account->belongsTo(); + $this->output('- belongsTo (' . count($belongsTo) . ')'); + foreach ($belongsTo as $member) { + $this->outputMember( + $member, ' ', [ + 'account' => ($member->getAccountId() !== $account->getId()) + ] + ); + } + } + + + /** + * @param string $itemId + * + * @throws EntityMemberNotFoundException + */ + private function detailsOnMember(string $itemId): void { + $member = $this->entitiesManager->getMember($itemId); + $this->outputMember($member); + } + + + /** + * @param array $args + * + * @throws ShellMissingItemException + * @throws ShellUnknownItemException + */ + private function manageCommandInvite(array $args): void { + list($entityId, $accountId) = $args; + + if ($entityId === null || $accountId === null) { + throw new ShellMissingItemException('syntax: invite entityId accountId'); + } + + try { + $entity = $this->entitiesManager->getEntity($entityId); + } catch (EntityNotFoundException $e) { + throw new ShellUnknownItemException($entityId); + } + + try { + $account = $this->entitiesManager->getAccount($accountId); + } catch (EntityAccountNotFoundException $e) { + throw new ShellUnknownItemException($accountId); + } + + $account->inviteTo($entity->getId()); + } + + private function manageCommandJoin(array $args): void { + } + + private function manageCommandNotifications(array $args): void { + } + + + /** + * @throws EntityAccountNotFoundException + * @throws Exception + */ + private function generateViewer(): void { + $viewerName = $this->input->getArgument('viewer'); + $level = $this->input->getOption('visibility'); + + if ($viewerName === '') { + $asAdmin = !$this->input->getOption('as-non-admin'); + $this->viewer = $this->entitiesHelper->temporaryLocalAccount($asAdmin); + } else { + $this->viewer = $this->entitiesHelper->getLocalAccount($viewerName); + } + + $listLevel = array_values(IEntityMember::CONVERT_LEVEL); + if (!in_array($level, $listLevel)) { + throw new Exception( + 'must specify an Visibility Level (--visibility): ' . implode(', ', $listLevel) + ); + } + + $this->viewer->getOptions() + ->setOptionInt( + 'viewer.visibility', array_search($level, IEntityMember::CONVERT_LEVEL) + ); + } + + + /** + * @param string $type + * + * @throws EntityTypeNotFoundException + */ + private function verifyEntityType(string $type): void { + $all = $this->entitiesHelper->getEntityTypes(IEntities::INTERFACE); + foreach ($all as $entityType) { + if ($entityType->getType() === $type) { + return; + } + } + + throw new EntityTypeNotFoundException(); + } + + + /** + * @param string $type + * + * @throws EntityTypeNotFoundException + */ + private function verifyAccountType(string $type): void { + $all = $this->entitiesHelper->getEntityTypes(IEntitiesAccounts::INTERFACE); + foreach ($all as $entityType) { + if ($entityType->getType() === $type) { + return; + } + } + + throw new EntityTypeNotFoundException(); + } + + +} + diff --git a/lib/private/Entities/Db/CoreRequestBuilder.php b/lib/private/Entities/Db/CoreRequestBuilder.php new file mode 100644 index 0000000000000..d4983b0d4f8f2 --- /dev/null +++ b/lib/private/Entities/Db/CoreRequestBuilder.php @@ -0,0 +1,162 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Db; + + +use OC; +use OC\Entities\Model\Entity; +use OC\Entities\Model\EntityAccount; +use OC\Entities\Model\EntityMember; +use OCP\Entities\Model\IEntity; +use OCP\Entities\Model\IEntityAccount; +use OCP\Entities\Model\IEntityMember; +use OCP\IConfig; +use OCP\IDBConnection; + + +/** + * Class CoreRequestBuilder + * + * @package OC\Entities\Db + */ +class CoreRequestBuilder { + + + const TABLE_ENTITIES = 'entities'; + const TABLE_ENTITIES_ACCOUNTS = 'entities_accounts'; + const TABLE_ENTITIES_MEMBERS = 'entities_members'; + const TABLE_ENTITIES_TYPES = 'entities_types'; + + const LEFT_JOIN_PREFIX_ENTITIES = 'entity_'; + const LEFT_JOIN_PREFIX_ENTITIES_ACCOUNT = 'entityaccount_'; + const LEFT_JOIN_PREFIX_ENTITIES_MEMBER = 'entitymember_'; + + + /** @var IConfig */ + private $config; + + /** @var IDBConnection */ + protected $dbConnection; + + + /** + * CoreRequestBuilder constructor. + * + * @param IConfig $config + * @param IDBConnection $connection + */ + public function __construct(IConfig $config, IDBConnection $connection) { + $this->config = $config; + $this->dbConnection = $connection; + } + + + /** + * @param string $comment + * + * @return EntitiesQueryBuilder + */ + public function getQueryBuilder(string $comment = ''): EntitiesQueryBuilder { + $qb = new EntitiesQueryBuilder( + $this->dbConnection, + OC::$server->getSystemConfig(), + OC::$server->getLogger() + ); + + $logSql = $this->config->getSystemValue('entities.log.sql', '0'); + $qb->setLogSql($logSql === '1' || $logSql === '2'); + $qb->setComment($comment); + + return $qb; + } + + + /** + * @param array $data + * + * @return IEntity + */ + public function parseLeftJoinEntity(array $data): IEntity { + $new = []; + foreach ($data as $k => $v) { + if (strpos($k, self::LEFT_JOIN_PREFIX_ENTITIES) === 0) { + $new[substr($k, strlen(self::LEFT_JOIN_PREFIX_ENTITIES))] = $v; + } + } + + $entity = new Entity(); + $entity->importFromDatabase($new); + + return $entity; + } + + + /** + * @param array $data + * + * @return IEntityAccount + */ + public function parseLeftJoinAccount(array $data): IEntityAccount { + $new = []; + foreach ($data as $k => $v) { + if (strpos($k, self::LEFT_JOIN_PREFIX_ENTITIES_ACCOUNT) === 0) { + $new[substr($k, strlen(self::LEFT_JOIN_PREFIX_ENTITIES_ACCOUNT))] = $v; + } + } + + $account = new EntityAccount(); + $account->importFromDatabase($new); + + return $account; + } + + + /** + * @param array $data + * + * @return IEntityMember + */ + public function parseLeftJoinMember(array $data): IEntityMember { + $new = []; + foreach ($data as $k => $v) { + if (strpos($k, self::LEFT_JOIN_PREFIX_ENTITIES_MEMBER) === 0) { + $new[substr($k, strlen(self::LEFT_JOIN_PREFIX_ENTITIES_MEMBER))] = $v; + } + } + + $member = new EntityMember(); + $member->importFromDatabase($new); + + return $member; + } + +} + diff --git a/lib/private/Entities/Db/EntitiesAccountsRequest.php b/lib/private/Entities/Db/EntitiesAccountsRequest.php new file mode 100644 index 0000000000000..c5b265b6fadd4 --- /dev/null +++ b/lib/private/Entities/Db/EntitiesAccountsRequest.php @@ -0,0 +1,241 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Db; + + +use DateTime; +use Exception; +use OC\Entities\Exceptions\EntityAccountNotFoundException; +use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\Entities\Implementation\IEntitiesAccounts\IEntitiesAccountsSearchAccounts; +use OCP\Entities\Model\IEntityAccount; +use stdClass; + +/** + * Class EntitiesRequest + * + * @package OC\Entities\Db + */ +class EntitiesAccountsRequest extends EntitiesAccountsRequestBuilder { + + + /** + * @param IEntityAccount $account + * + * @throws Exception + */ + public function create(IEntityAccount $account) { + $now = new DateTime('now'); + + $qb = + $this->getEntitiesAccountsInsertSql( + 'create a new EntityAccount: ' . json_encode($account) + ); + $qb->setValue('id', $qb->createNamedParameter($account->getId())) + ->setValue('type', $qb->createNamedParameter($account->getType())) + ->setValue('account', $qb->createNamedParameter($account->getAccount())) + ->setValue('delete_on', $qb->createNamedParameter($account->getDeleteOn())) + ->setValue('creation', $qb->createNamedParameter($now, IQueryBuilder::PARAM_DATE)); + + $qb->execute(); + + $account->setCreation($now->getTimestamp()); + } + + + /** + * @param string $accountId + * + * @return IEntityAccount + * @throws EntityAccountNotFoundException + */ + public function getFromId(string $accountId): IEntityAccount { + $qb = $this->getEntitiesAccountsSelectSql( + 'get EntityAccount from Id - Id: ' . $accountId + ); + $qb->limitToIdString($accountId); + + return $this->getItemFromRequest($qb); + } + + + /** + * @param string $account + * @param string $type + * + * @return IEntityAccount + * @throws EntityAccountNotFoundException + */ + public function getFromAccount(string $account, string $type = ''): IEntityAccount { + $qb = $this->getEntitiesAccountsSelectSql( + 'get EntityAccount from Account - account: ' . $account . ' - type: ' . $type + ); + $qb->limitToAccount($account); + + if ($type !== '') { + $qb->limitToType($type); + } + + return $this->getItemFromRequest($qb); + } + + + /** + * @param string $type + * + * @return IEntityAccount[] + */ + public function getAll(string $type = ''): array { + $qb = $this->getEntitiesAccountsSelectSql('get all EntityAccounts - type: ' . $type); + if ($type !== '') { + $qb->limitToType($type); + } + + $qb->orderBy('type', 'asc'); + + return $this->getListFromRequest($qb); + } + +// +// /** +// * @param string $userId +// * +// * @return IEntityAccount +// * @throws EntityAccountNotFoundException +// */ +// public function getFromLocalUserId(string $userId) { +// $qb = +// $this->getEntitiesAccountsSelectSql('get EntityAccount from LocalUserId - ' . $userId); +// +// $qb->limitToType(LocalUser::TYPE); +// $qb->limitToAccount($userId); +// +// return $this->getItemFromRequest($qb); +// } + + + /** + * @param string $needle + * @param string $type + * @param stdClass[] $classes + * + * @return IEntityAccount[] + */ + public function search(string $needle, string $type = '', array $classes = []): array { + $qb = $this->getEntitiesAccountsSelectSql( + 'search EntityAccounts - needle: ' . $needle . ' - type: ' . $type . ' - classes: ' + . json_encode($classes) + ); + if ($type !== '') { + $qb->limitToType($type); + } + + $qb->orderBy('type', 'asc'); + + $needle = $this->dbConnection->escapeLikeParameter($needle); + $qb->searchInAccount('%' . $needle . '%'); + + if (sizeof($classes) > 0) { + $orX = $qb->expr() + ->orX(); + foreach ($classes as $class) { + /** @var IEntitiesAccountsSearchAccounts $class */ + $orX->add($class->exprSearchAccounts($qb, $needle)); + } + + $qb->orWhere($orX); + } + + return $this->getListFromRequest($qb); + } + + + /** + * @param string $accountId + * + * @throws Exception + */ + public function delete(string $accountId) { + $qb = $this->getEntitiesAccountsDeleteSql('delete EntityAccount - id: ' . $accountId); + $qb->limitToIdString($accountId); + + $qb->execute(); + } + + + /** + * @param IQueryBuilder $qb + * + * @return IEntityAccount + * @throws EntityAccountNotFoundException + */ + public function getItemFromRequest(IQueryBuilder $qb): IEntityAccount { + $cursor = $qb->execute(); + $data = $cursor->fetch(); + $cursor->closeCursor(); + + if ($data === false) { + throw new EntityAccountNotFoundException('EntityAccount not found'); + } + + return $this->parseEntitiesAccountsSelectSql($data); + } + + + /** + * @param IQueryBuilder $qb + * + * @return IEntityAccount[] + */ + public function getListFromRequest(IQueryBuilder $qb): array { + $accounts = []; + $cursor = $qb->execute(); + while ($data = $cursor->fetch()) { + $accounts[] = $this->parseEntitiesAccountsSelectSql($data); + } + $cursor->closeCursor(); + + return $accounts; + } + + + /** + * + * @throws Exception + */ + public function clearAll(): void { + $qb = $this->getEntitiesAccountsDeleteSql('clear all EntityAccounts'); + + $qb->execute(); + } + +} + diff --git a/lib/private/Entities/Db/EntitiesAccountsRequestBuilder.php b/lib/private/Entities/Db/EntitiesAccountsRequestBuilder.php new file mode 100644 index 0000000000000..596dac0ca2382 --- /dev/null +++ b/lib/private/Entities/Db/EntitiesAccountsRequestBuilder.php @@ -0,0 +1,128 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Db; + + +use daita\NcSmallPhpTools\Traits\TArrayTools; +use OC\Entities\Model\EntityAccount; +use OCP\Entities\Model\IEntityAccount; + + +/** + * Class EntitiesRequestBuilder + * + * @package OC\Entities\Db + */ +class EntitiesAccountsRequestBuilder extends CoreRequestBuilder { + + + use TArrayTools; + + + /** + * Base of the Sql Insert request + * + * @param string $comment + * + * @return EntitiesQueryBuilder + */ + protected function getEntitiesAccountsInsertSql(string $comment = ''): EntitiesQueryBuilder { + $qb = $this->getQueryBuilder($comment); + $qb->insert(self::TABLE_ENTITIES_ACCOUNTS); + + return $qb; + } + + + /** + * Base of the Sql Update request + * + * @param string $comment + * + * @return EntitiesQueryBuilder + */ + protected function getEntitiesAccountsUpdateSql(string $comment = ''): EntitiesQueryBuilder { + $qb = $this->getQueryBuilder($comment); + $qb->update(self::TABLE_ENTITIES_ACCOUNTS); + + return $qb; + } + + + /** + * Base of the Sql Select request for Entities Accounts + * + * @param string $comment + * + * @return EntitiesQueryBuilder + */ + public function getEntitiesAccountsSelectSql(string $comment = ''): EntitiesQueryBuilder { + $qb = $this->getQueryBuilder($comment); + + /** @noinspection PhpMethodParametersCountMismatchInspection */ + $qb->select('ea.id', 'ea.type', 'ea.account', 'ea.delete_on', 'ea.creation') + ->from(self::TABLE_ENTITIES_ACCOUNTS, 'ea'); + + $qb->setDefaultSelectAlias('ea'); + + return $qb; + } + + + /** + * Base of the Sql Delete request + * + * @param string $comment + * + * @return EntitiesQueryBuilder + */ + protected function getEntitiesAccountsDeleteSql(string $comment = ''): EntitiesQueryBuilder { + $qb = $this->getQueryBuilder($comment); + $qb->delete(self::TABLE_ENTITIES_ACCOUNTS); + + return $qb; + } + + + /** + * @param array $data + * + * @return EntityAccount + */ + protected function parseEntitiesAccountsSelectSql(array $data): IEntityAccount { + $entityAccount = new EntityAccount(); + $entityAccount->importFromDatabase($data); + + return $entityAccount; + } + +} + diff --git a/lib/private/Entities/Db/EntitiesMembersRequest.php b/lib/private/Entities/Db/EntitiesMembersRequest.php new file mode 100644 index 0000000000000..acf6606b7828d --- /dev/null +++ b/lib/private/Entities/Db/EntitiesMembersRequest.php @@ -0,0 +1,207 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Db; + + +use DateTime; +use Exception; +use OC\Entities\Exceptions\EntityMemberNotFoundException; +use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\Entities\Model\IEntity; +use OCP\Entities\Model\IEntityAccount; +use OCP\Entities\Model\IEntityMember; + + +/** + * Class EntitiesMembersRequest + * + * @package OC\Entities\Db + */ +class EntitiesMembersRequest extends EntitiesMembersRequestBuilder { + + + public function create(IEntityMember $member) { + $now = new DateTime('now'); + + $qb = $this->getEntitiesMembersInsertSql( + 'create a new EntityMember: ' . json_encode($member) + ); + $qb->setValue('id', $qb->createNamedParameter($member->getId())) + ->setValue('entity_id', $qb->createNamedParameter($member->getEntityId())) + ->setValue('account_id', $qb->createNamedParameter($member->getAccountId())) + ->setValue('status', $qb->createNamedParameter($member->getStatus())) + ->setValue('level', $qb->createNamedParameter($member->getLevel())) + ->setValue('creation', $qb->createNamedParameter($now, IQueryBuilder::PARAM_DATE)); + + $qb->execute(); + + $member->setCreation($now->getTimestamp()); + } + + + /** + * @param string $accountId + * @param string $entityId + * + * @return IEntityMember + * @throws EntityMemberNotFoundException + */ + public function getMember(string $accountId, string $entityId): IEntityMember { + $qb = $this->getEntitiesMembersSelectSql( + 'get EntityMember by Account+Entity Ids - accountId: ' . $accountId . ' - entityId: ' + . $entityId + ); + $qb->limitToEntityId($entityId); + $qb->limitToAccountId($accountId); + + return $this->getItemFromRequest($qb); + } + + + /** + * @param string $memberId + * + * @return IEntityMember + * @throws EntityMemberNotFoundException + */ + public function getFromId(string $memberId) { + $qb = + $this->getEntitiesMembersSelectSql('get EntityMember from Id - memberId: ' . $memberId); + $qb->leftJoinEntity(); + $qb->leftJoinEntityAccount(); + $qb->limitToIdString($memberId); + + return $this->getItemFromRequest($qb); + } + + + /** + * @param IEntity $entity + * + * @return IEntityMember[] + */ + public function getMembers(IEntity $entity): array { + $qb = $this->getEntitiesMembersSelectSql( + ' get all EntityMembers from an Entity: ' . json_encode($entity) + ); + $qb->leftJoinEntityAccount(); + + $qb->limitToEntityId($entity->getId()); + + return $this->getListFromRequest($qb); + } + + + /** + * @param IEntityAccount $account + * + * @return IEntityMember[] + */ + public function getMembership(IEntityAccount $account): array { + $qb = $this->getEntitiesMembersSelectSql( + 'get EntityMembers from an account: ' . json_encode($account) + ); + $qb->leftJoinEntity(); + $qb->leftJoinEntityAccount(); + + $qb->limitToAccountId($account->getId()); + + return $this->getListFromRequest($qb); + } + + + + + /** + * @param string $memberId + * + * @throws Exception + */ + public function delete(string $memberId) { + $qb = $this->getEntitiesMembersDeleteSql('delete EntityMember - id: ' . $memberId); + $qb->limitToIdString($memberId); + + $qb->execute(); + } + + + + + + /** + * @param IQueryBuilder $qb + * + * @return IEntityMember + * @throws EntityMemberNotFoundException + */ + public function getItemFromRequest(IQueryBuilder $qb): IEntityMember { + $cursor = $qb->execute(); + $data = $cursor->fetch(); + $cursor->closeCursor(); + + if ($data === false) { + throw new EntityMemberNotFoundException(); + } + + return $this->parseEntitiesMembersSelectSql($data); + } + + + /** + * @param IQueryBuilder $qb + * + * @return IEntityMember[] + */ + public function getListFromRequest(IQueryBuilder $qb): array { + $members = []; + $cursor = $qb->execute(); + while ($data = $cursor->fetch()) { + $members[] = $this->parseEntitiesMembersSelectSql($data); + } + $cursor->closeCursor(); + + return $members; + } + + + /** + * + * @throws Exception + */ + public function clearAll(): void { + $qb = $this->getEntitiesMembersDeleteSql('clear all EntityMembers'); + + $qb->execute(); + } + + +} + diff --git a/lib/private/Entities/Db/EntitiesMembersRequestBuilder.php b/lib/private/Entities/Db/EntitiesMembersRequestBuilder.php new file mode 100644 index 0000000000000..78d94511c816a --- /dev/null +++ b/lib/private/Entities/Db/EntitiesMembersRequestBuilder.php @@ -0,0 +1,136 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Db; + + +use daita\NcSmallPhpTools\Traits\TArrayTools; +use OC\Entities\Model\EntityMember; + + +/** + * Class EntitiesMembersRequestBuilder + * + * @package OC\Entities\Db + */ +class EntitiesMembersRequestBuilder extends CoreRequestBuilder { + + + use TArrayTools; + + + /** + * Base of the Sql Insert request + * + * @param string $comment + * + * @return EntitiesQueryBuilder + */ + protected function getEntitiesMembersInsertSql(string $comment = ''): EntitiesQueryBuilder { + $qb = $this->getQueryBuilder($comment); + $qb->insert(self::TABLE_ENTITIES_MEMBERS); + + return $qb; + } + + + /** + * Base of the Sql Update request + * + * @param string $comment + * + * @return EntitiesQueryBuilder + */ + protected function getEntitiesMembersUpdateSql(string $comment = ''): EntitiesQueryBuilder { + $qb = $this->getQueryBuilder($comment); + $qb->update(self::TABLE_ENTITIES_MEMBERS); + + return $qb; + } + + + /** + * Base of the Sql Select request for Entities Accounts + * + * @param string $comment + * + * @return EntitiesQueryBuilder + */ + protected function getEntitiesMembersSelectSql(string $comment = ''): EntitiesQueryBuilder { + $qb = $this->getQueryBuilder($comment); + + /** @noinspection PhpMethodParametersCountMismatchInspection */ + $qb->select( + 'em.id', 'em.entity_id', 'em.account_id', 'em.slave_entity_id', 'em.status', 'em.level', + 'em.creation' + ) + ->from(self::TABLE_ENTITIES_MEMBERS, 'em'); + + $qb->setDefaultSelectAlias('em'); + + return $qb; + } + + + /** + * Base of the Sql Delete request + * + * @param string $comment + * + * @return EntitiesQueryBuilder + */ + protected function getEntitiesMembersDeleteSql(string $comment = ''): EntitiesQueryBuilder { + $qb = $this->getQueryBuilder($comment); + $qb->delete(self::TABLE_ENTITIES_MEMBERS); + + return $qb; + } + + + /** + * @param array $data + * + * @return EntityMember + */ + protected function parseEntitiesMembersSelectSql(array $data): EntityMember { + $member = new EntityMember(); + $member->importFromDatabase($data); + + $entity = $this->parseLeftJoinEntity($data); + $member->setEntity($entity); + + $account = $this->parseLeftJoinAccount($data); + $member->setAccount($account); + + return $member; + } + +} + diff --git a/lib/private/Entities/Db/EntitiesQueryBuilder.php b/lib/private/Entities/Db/EntitiesQueryBuilder.php new file mode 100644 index 0000000000000..da50992410ec4 --- /dev/null +++ b/lib/private/Entities/Db/EntitiesQueryBuilder.php @@ -0,0 +1,360 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Db; + + +use daita\NcSmallPhpTools\Db\ExtendedQueryBuilder; +use Doctrine\DBAL\Driver\Statement; +use Doctrine\DBAL\Query\QueryBuilder; +use Exception; +use OC; +use OC\SystemConfig; +use OCP\Entities\IEntitiesQueryBuilder; +use OCP\Entities\Model\IEntity; +use OCP\Entities\Model\IEntityAccount; +use OCP\IDBConnection; +use OCP\ILogger; + + +class EntitiesQueryBuilder extends ExtendedQueryBuilder implements IEntitiesQueryBuilder { + + + /** @var array */ + private $comment = []; + + /** @var CoreRequestBuilder */ + private $isLogSql = false; + + + /** + * EntitiesQueryBuilder constructor. + * + * @param IDBConnection $connection + * @param SystemConfig $config + * @param ILogger $logger + */ + public function __construct(IDBConnection $connection, SystemConfig $config, ILogger $logger) { + parent::__construct($connection, $config, $logger); + } + + + /** + * @param bool $logSql + */ + public function setLogSql(bool $logSql): void { + $this->isLogSql = $logSql; + } + + + /** + * @param string $comment + */ + public function setComment(string $comment = ''): void { + $this->comment = []; + $this->addComment($comment); + } + + /** + * @param string $comment + */ + public function addComment(string $comment): void { + $this->comment[] = $comment; + } + + /** + * @return string[] + */ + public function getComment(): array { + return $this->comment; + } + + + /** + * @return Statement|int + * @throws Exception + */ + public function execute() { + if ($this->isLogSql) { + $time1 = microtime(true); + } + + $exception = null; + try { + $result = parent::execute(); + } catch (Exception $e) { + $exception = $e; + } + + if ($this->isLogSql) { + $time2 = microtime(true); + OC::$server->getEntitiesManager() + ->logSql($this, ($time2 - $time1), $exception); + } + + if ($exception !== null) { + throw $exception; + } + + return $result; + } + + /** + * Limit the request to the Interface + * + * @param string $interface + * + * @return IEntitiesQueryBuilder + */ + public function limitToInterface(string $interface): IEntitiesQueryBuilder { + $this->limitToDBField('interface', $interface, false); + + return $this; + } + + + /** + * Limit the request to the Type + * + * @param string $type + * + * @return IEntitiesQueryBuilder + */ + public function limitToType(string $type): IEntitiesQueryBuilder { + $this->limitToDBField('type', $type, false); + + return $this; + } + + + /** + * Limit the request to the OwnerId + * + * @param string $ownerId + * + * @return IEntitiesQueryBuilder + */ + public function limitToOwnerId(string $ownerId): IEntitiesQueryBuilder { + $this->limitToDBField('owner_id', $ownerId, false); + + return $this; + } + + + /** + * Limit the request to the Name + * + * @param string $name + * + * @return IEntitiesQueryBuilder + */ + public function limitToName(string $name): IEntitiesQueryBuilder { + $this->limitToDBField('name', $name, false); + + return $this; + } + + + /** + * @param string $like + * + * @return IEntitiesQueryBuilder + */ + public function searchInName(string $like): IEntitiesQueryBuilder { + $this->searchInDBField('name', $like); + + return $this; + } + + + /** + * @param string $account + * + * @return IEntitiesQueryBuilder + */ + public function limitToAccount(string $account): IEntitiesQueryBuilder { + $this->limitToDBField('account', $account, false); + + return $this; + } + + + /** + * @param string $like + * + * @return IEntitiesQueryBuilder + */ + public function searchInAccount(string $like): IEntitiesQueryBuilder { + $this->searchInDBField('account', $like); + + return $this; + } + + + /** + * @param string $accountId + * + * @return IEntitiesQueryBuilder + */ + public function limitToAccountId(string $accountId): IEntitiesQueryBuilder { + $this->limitToDBField('account_id', $accountId, false); + + return $this; + } + + + /** + * @param string $entityId + * + * @return IEntitiesQueryBuilder + */ + public function limitToEntityId(string $entityId): IEntitiesQueryBuilder { + $this->limitToDBField('entity_id', $entityId, false); + + return $this; + } + + + /** + * @param IEntityAccount $viewer + * + * @return IEntitiesQueryBuilder + */ + public function limitToViewer(IEntityAccount $viewer): IEntitiesQueryBuilder { + $this->leftJoinEntityMember($viewer->getId(), 'id'); + + $visibility = IEntity::VISIBILITY_ALL; + if ($viewer->hasAdminRights()) { + $visibility = $viewer->getOptions()->getOptionInt('viewer.visibility'); + } + + $expr = $this->expr(); + $orX = $expr->orX(); + $orX->add($expr->lte('e.visibility', $this->createNamedParameter($visibility))); + $orX->add($expr->lte('e.visibility', 'lj_em.level')); + + $this->andWhere($orX); + + return $this; + } + + + /** + * @param string $fieldEntityId + * + * @return IEntitiesQueryBuilder + */ + public function leftJoinEntity(string $fieldEntityId = 'entity_id'): IEntitiesQueryBuilder { + if ($this->getType() !== QueryBuilder::SELECT) { + return $this; + } + + $pf = CoreRequestBuilder::LEFT_JOIN_PREFIX_ENTITIES; + $expr = $this->expr(); + $this->selectAlias('lj_e.id', $pf . 'id') + ->selectAlias('lj_e.type', $pf . 'type') + ->selectAlias('lj_e.owner_id', $pf . 'owner_id') + ->selectAlias('lj_e.visibility', $pf . 'visibility') + ->selectAlias('lj_e.access', $pf . 'access') + ->selectAlias('lj_e.name', $pf . 'name') + ->selectAlias('lj_e.creation', $pf . 'creation') + ->leftJoin( + $this->getDefaultSelectAlias(), CoreRequestBuilder::TABLE_ENTITIES, 'lj_e', + $expr->eq($this->getDefaultSelectAlias() . '.' . $fieldEntityId, 'lj_e.id') + ); + + return $this; + } + + + /** + * @param string $fieldOwnerId + * + * @return IEntitiesQueryBuilder + */ + public function leftJoinEntityAccount(string $fieldOwnerId = 'account_id' + ): IEntitiesQueryBuilder { + if ($this->getType() !== QueryBuilder::SELECT) { + return $this; + } + + $pf = CoreRequestBuilder::LEFT_JOIN_PREFIX_ENTITIES_ACCOUNT; + $expr = $this->expr(); + $this->selectAlias('lj_ea.id', $pf . 'id') + ->selectAlias('lj_ea.type', $pf . 'type') + ->selectAlias('lj_ea.account', $pf . 'account') + ->selectAlias('lj_ea.creation', $pf . 'creation') + ->leftJoin( + $this->getDefaultSelectAlias(), CoreRequestBuilder::TABLE_ENTITIES_ACCOUNTS, + 'lj_ea', + $expr->eq($this->getDefaultSelectAlias() . '.' . $fieldOwnerId, 'lj_ea.id') + ); + + return $this; + } + + + /** + * @param string $accountId + * @param string $fieldEntityId + * + * @return IEntitiesQueryBuilder + */ + public function leftJoinEntityMember(string $accountId, string $fieldEntityId = 'entity_id' + ): IEntitiesQueryBuilder { + if ($this->getType() !== QueryBuilder::SELECT) { + return $this; + } + + $pf = CoreRequestBuilder::LEFT_JOIN_PREFIX_ENTITIES_MEMBER; + $expr = $this->expr(); + $andX = $expr->andX(); + $andX->add( + $expr->eq($this->getDefaultSelectAlias() . '.' . $fieldEntityId, 'lj_em.entity_id') + ); + $andX->add($expr->eq('lj_em.account_id', $this->createNamedParameter($accountId))); + + $this->selectAlias('lj_em.id', $pf . 'id') + ->selectAlias('lj_em.entity_id', $pf . 'entity_id') + ->selectAlias('lj_em.account_id', $pf . 'account_id') + ->selectAlias('lj_em.status', $pf . 'status') + ->selectAlias('lj_em.level', $pf . 'level') + ->selectAlias('lj_em.creation', $pf . 'creation') + ->leftJoin( + $this->getDefaultSelectAlias(), CoreRequestBuilder::TABLE_ENTITIES_MEMBERS, + 'lj_em', + $andX + ); + + return $this; + } + +} + diff --git a/lib/private/Entities/Db/EntitiesRequest.php b/lib/private/Entities/Db/EntitiesRequest.php new file mode 100644 index 0000000000000..8f92fbe80e662 --- /dev/null +++ b/lib/private/Entities/Db/EntitiesRequest.php @@ -0,0 +1,261 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Db; + + +use DateTime; +use Exception; +use OC\Entities\Exceptions\EntityNotFoundException; +use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\Entities\Implementation\IEntities\IEntitiesSearchEntities; +use OCP\Entities\Implementation\IEntitiesAccounts\IEntitiesAccountsSearchEntities; +use OCP\Entities\Model\IEntity; +use OCP\Entities\Model\IEntityAccount; +use stdClass; + +/** + * Class EntitiesRequest + * + * @package OC\Entities\Db + */ +class EntitiesRequest extends EntitiesRequestBuilder { + + + /** + * @param IEntity $entity + * + * @throws Exception + */ + public function create(IEntity $entity) { + $now = new DateTime('now'); + + $qb = $this->getEntitiesInsertSql('create a new Entity: ' . json_encode($entity)); + $qb->setValue('id', $qb->createNamedParameter($entity->getId())) + ->setValue('type', $qb->createNamedParameter($entity->getType())) + ->setValue('owner_id', $qb->createNamedParameter($entity->getOwnerId())) + ->setValue('visibility', $qb->createNamedParameter($entity->getVisibility())) + ->setValue('access', $qb->createNamedParameter($entity->getAccess())) + ->setValue('name', $qb->createNamedParameter($entity->getName())) + ->setValue('creation', $qb->createNamedParameter($now, IQueryBuilder::PARAM_DATE)); + $qb->execute(); + + $entity->setCreation($now->getTimestamp()); + } + + + /** + * @param string $entityId + * @param IEntityAccount $viewer + * + * @return IEntity + * @throws EntityNotFoundException + */ + public function getFromId(string $entityId): IEntity { + $qb = $this->buildGetFromId($entityId); + + return $this->getItemFromRequest($qb); + } + + + /** + * @param IEntityAccount $viewer + * @param string $entityId + * + * @return IEntity + * @throws EntityNotFoundException + */ + public function viewerGetFromId(IEntityAccount $viewer, string $entityId): IEntity { + $qb = $this->buildGetFromId($entityId); + $qb->addComment('Viewer: ' . json_encode($viewer)); + $qb->limitToViewer($viewer); + + return $this->getItemFromRequest($qb); + + } + + + /** + * @param string $type + * + * @return IEntity[] + */ + public function getAll(string $type = ''): array { + $qb = $this->buildGetAll($type); + + return $this->getListFromRequest($qb); + } + + /** + * @param IEntityAccount $viewer + * @param string $type + * + * @return array + */ + public function viewerGetAll(IEntityAccount $viewer, string $type = ''): array { + $qb = $this->buildGetAll($type); + $qb->addComment('Viewer: ' . json_encode($viewer)); + $qb->limitToViewer($viewer); + + return $this->getListFromRequest($qb); + } + + + /** + * @param string $needle + * @param string $type + * @param stdClass[] $classes + * + * @return IEntity[] + */ + public function search(string $needle, string $type = '', array $classes = []): array { + $qb = $this->getEntitiesSelectSql( + 'search Entities - needle: ' . $needle . ' - type: ' . $type . ' - classes: ' + . json_encode($classes) + ); + if ($type !== '') { + $qb->limitToType($type); + } + + $qb->orderBy('type', 'asc'); + $qb->leftJoinEntityAccount('owner_id'); + + $needle = $this->dbConnection->escapeLikeParameter($needle); + $qb->searchInName('%' . $needle . '%'); + + if (sizeof($classes) > 0) { + $orX = $qb->expr() + ->orX(); + foreach ($classes as $class) { + /** @var IEntitiesAccountsSearchEntities|IEntitiesSearchEntities $class */ + $orX->add($class->exprSearchEntities($qb, $needle)); + } + + $qb->orWhere($orX); + } + + return $this->getListFromRequest($qb); + } + + + /** + * @param string $entityId + * + * @throws Exception + */ + public function delete(string $entityId) { + $qb = $this->getEntitiesDeleteSql('delete Entity - id: ' . $entityId); + $qb->limitToIdString($entityId); + + $qb->execute(); + } + + + /** + * + * @throws Exception + */ + public function clearAll(): void { + $qb = $this->getEntitiesDeleteSql('clear all Entities'); + + $qb->execute(); + } + + + /** + * @param IQueryBuilder $qb + * + * @return IEntity + * @throws EntityNotFoundException + */ + public function getItemFromRequest(IQueryBuilder $qb): IEntity { + $cursor = $qb->execute(); + $data = $cursor->fetch(); + $cursor->closeCursor(); + + if ($data === false) { + throw new EntityNotFoundException(); + } + + return $this->parseEntitiesSelectSql($data); + } + + + /** + * @param IQueryBuilder $qb + * + * @return IEntity[] + */ + public function getListFromRequest(IQueryBuilder $qb): array { + $entities = []; + $cursor = $qb->execute(); + while ($data = $cursor->fetch()) { + $entities[] = $this->parseEntitiesSelectSql($data); + } + $cursor->closeCursor(); + + return $entities; + } + + + /** + * @param string $entityId + * + * @return EntitiesQueryBuilder + */ + private function buildGetFromId(string $entityId): EntitiesQueryBuilder { + $qb = $this->getEntitiesSelectSql('get Entity from Id - entityId: ' . $entityId); + $qb->leftJoinEntityAccount('owner_id'); + $qb->limitToIdString($entityId); + + return $qb; + } + + + /** + * @param string $type + * + * @return EntitiesQueryBuilder + */ + private function buildGetAll(string $type = ''): EntitiesQueryBuilder { + $qb = $this->getEntitiesSelectSql('get all Entities - type: ' . $type); + if ($type !== '') { + $qb->limitToType($type); + } + + $qb->orderBy('type', 'asc'); + $qb->leftJoinEntityAccount('owner_id'); + + return $qb; + } + + +} + diff --git a/lib/private/Entities/Db/EntitiesRequestBuilder.php b/lib/private/Entities/Db/EntitiesRequestBuilder.php new file mode 100644 index 0000000000000..a2bb3abd3afda --- /dev/null +++ b/lib/private/Entities/Db/EntitiesRequestBuilder.php @@ -0,0 +1,136 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Db; + + +use daita\NcSmallPhpTools\Traits\TArrayTools; +use OC\Entities\Model\Entity; + + +/** + * Class EntitiesRequestBuilder + * + * @package OC\Entities\Db + */ +class EntitiesRequestBuilder extends CoreRequestBuilder { + + + use TArrayTools; + + + /** + * Base of the Sql Insert request + * + * @param string $comment + * + * @return EntitiesQueryBuilder + */ + protected function getEntitiesInsertSql(string $comment = ''): EntitiesQueryBuilder { + $qb = $this->getQueryBuilder($comment); + $qb->insert(self::TABLE_ENTITIES); + + return $qb; + } + + + /** + * Base of the Sql Update request + * + * @param string $comment + * + * @return EntitiesQueryBuilder + */ + protected function getEntitiesUpdateSql(string $comment = ''): EntitiesQueryBuilder { + $qb = $this->getQueryBuilder($comment); + $qb->update(self::TABLE_ENTITIES); + + return $qb; + } + + + /** + * Base of the Sql Select request for Entities + * + * @param string $comment + * + * @return EntitiesQueryBuilder + */ + public function getEntitiesSelectSql(string $comment = ''): EntitiesQueryBuilder { + $qb = $this->getQueryBuilder($comment); + + /** @noinspection PhpMethodParametersCountMismatchInspection */ + $qb->select( + 'e.id', 'e.type', 'e.owner_id', 'e.visibility', 'e.access', 'e.name', 'e.creation' + ) + ->from(self::TABLE_ENTITIES, 'e') + ->groupBy('e.id'); + + $qb->setDefaultSelectAlias('e'); + + return $qb; + } + + + /** + * Base of the Sql Delete request + * + * @param string $comment + * + * @return EntitiesQueryBuilder + */ + protected function getEntitiesDeleteSql(string $comment = ''): EntitiesQueryBuilder { + $qb = $this->getQueryBuilder($comment); + $qb->delete(self::TABLE_ENTITIES); + + return $qb; + } + + + /** + * @param array $data + * + * @return Entity + */ + protected function parseEntitiesSelectSql(array $data): Entity { + $entity = new Entity(); + $entity->importFromDatabase($data); + + $owner = $this->parseLeftJoinAccount($data); + $entity->setOwner($owner); + + $viewer = $this->parseLeftJoinMember($data); + $entity->setViewer($viewer); + + return $entity; + } + +} + diff --git a/lib/private/Entities/Db/EntitiesTypesRequest.php b/lib/private/Entities/Db/EntitiesTypesRequest.php new file mode 100644 index 0000000000000..c9cbdcffde512 --- /dev/null +++ b/lib/private/Entities/Db/EntitiesTypesRequest.php @@ -0,0 +1,86 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Db; + + +use OCP\Entities\Model\IEntityType; + +/** + * Class EntitiesRequest + * + * @package OC\Entities\Db + */ +class EntitiesTypesRequest extends EntitiesTypesRequestBuilder { + + + /** + * @param IEntityType $entityType + */ + public function create(IEntityType $entityType) { + $qb = $this->getEntitiesTypesInsertSql('create a new EntityType: ' . json_encode($entityType)); + $qb->setValue('type', $qb->createNamedParameter($entityType->getType())) + ->setValue('interface', $qb->createNamedParameter($entityType->getInterface())) + ->setValue('class', $qb->createNamedParameter($entityType->getClassName())); + + $qb->execute(); + } + + + /** + * @param string $interface + * + * @return IEntityType[] + */ + public function getClasses(string $interface = ''): array { + $qb = $this->getEntitiesTypesSelectSql('get all EntityTypes - interface: ' . $interface); + if ($interface !== '') { + $qb->limitToInterface($interface); + } + + $entities = []; + $cursor = $qb->execute(); + while ($data = $cursor->fetch()) { + $entities[] = $this->parseEntitiesTypesSelectSql($data); + } + $cursor->closeCursor(); + + return $entities; + } + + + public function clearAll(): void { + $qb = $this->getEntitiesTypesDeleteSql('clear all EntityTypes'); + + $qb->execute(); + } + +} + diff --git a/lib/private/Entities/Db/EntitiesTypesRequestBuilder.php b/lib/private/Entities/Db/EntitiesTypesRequestBuilder.php new file mode 100644 index 0000000000000..a9cb75fbb3210 --- /dev/null +++ b/lib/private/Entities/Db/EntitiesTypesRequestBuilder.php @@ -0,0 +1,128 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Db; + + +use daita\NcSmallPhpTools\Traits\TArrayTools; +use OC\Entities\Model\EntityType; +use OCP\Entities\Model\IEntityType; + + +/** + * Class EntitiesTypesRequestBuilder + * + * @package OC\Entities\Db + */ +class EntitiesTypesRequestBuilder extends CoreRequestBuilder { + + + use TArrayTools; + + + /** + * Base of the Sql Insert request + * + * @param string $comment + * + * @return EntitiesQueryBuilder + */ + protected function getEntitiesTypesInsertSql(string $comment = ''): EntitiesQueryBuilder { + $qb = $this->getQueryBuilder($comment); + $qb->insert(self::TABLE_ENTITIES_TYPES); + + return $qb; + } + + + /** + * Base of the Sql Update request + * + * @param string $comment + * + * @return EntitiesQueryBuilder + */ + protected function getEntitiesTypesUpdateSql(string $comment = ''): EntitiesQueryBuilder { + $qb = $this->getQueryBuilder($comment); + $qb->update(self::TABLE_ENTITIES_TYPES); + + return $qb; + } + + + /** + * Base of the Sql Select request for Entities Accounts + * + * @param string $comment + * + * @return EntitiesQueryBuilder + */ + protected function getEntitiesTypesSelectSql(string $comment = ''): EntitiesQueryBuilder { + $qb = $this->getQueryBuilder($comment); + + /** @noinspection PhpMethodParametersCountMismatchInspection */ + $qb->select('et.id', 'et.type', 'et.interface', 'et.class') + ->from(self::TABLE_ENTITIES_TYPES, 'et'); + + $qb->setDefaultSelectAlias('et'); + + return $qb; + } + + + /** + * Base of the Sql Delete request + * + * @param string $comment + * + * @return EntitiesQueryBuilder + */ + protected function getEntitiesTypesDeleteSql(string $comment = ''): EntitiesQueryBuilder { + $qb = $this->getQueryBuilder($comment); + $qb->delete(self::TABLE_ENTITIES_TYPES); + + return $qb; + } + + + /** + * @param array $data + * + * @return IEntityType + */ + protected function parseEntitiesTypesSelectSql(array $data): IEntityType { + $entityType = new EntityType(); + $entityType->importFromDatabase($data); + + return $entityType; + } + +} + diff --git a/lib/private/Entities/EntitiesManager.php b/lib/private/Entities/EntitiesManager.php new file mode 100644 index 0000000000000..411fbd38898d4 --- /dev/null +++ b/lib/private/Entities/EntitiesManager.php @@ -0,0 +1,854 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities; + + +use daita\NcSmallPhpTools\Exceptions\NotCachedException; +use daita\NcSmallPhpTools\Traits\TCacheResult; +use Exception; +use OC; +use OC\Entities\Db\EntitiesAccountsRequest; +use OC\Entities\Db\EntitiesMembersRequest; +use OC\Entities\Db\EntitiesRequest; +use OC\Entities\Db\EntitiesTypesRequest; +use OC\Entities\Exceptions\EntityAccountAlreadyExistsException; +use OC\Entities\Exceptions\EntityAccountCreationException; +use OC\Entities\Exceptions\EntityAccountNotFoundException; +use OC\Entities\Exceptions\EntityAlreadyExistsException; +use OC\Entities\Exceptions\EntityCreationException; +use OC\Entities\Exceptions\EntityMemberAlreadyExistsException; +use OC\Entities\Exceptions\EntityMemberLevelException; +use OC\Entities\Exceptions\EntityMemberNotFoundException; +use OC\Entities\Exceptions\EntityNotFoundException; +use OC\Entities\Exceptions\EntityTypeNotFoundException; +use OC\Entities\Exceptions\ImplementationNotFoundException; +use OC\Entities\Exceptions\ViewerNotSetException; +use OC\Entities\Model\EntityMember; +use OCP\AppFramework\QueryException; +use OCP\Entities\IEntitiesManager; +use OCP\Entities\IEntitiesQueryBuilder; +use OCP\Entities\Implementation\IEntities\IEntitiesAdminCreation; +use OCP\Entities\Implementation\IEntities\IEntitiesAdminRights; +use OCP\Entities\Implementation\IEntities\IEntitiesConfirmCreation; +use OCP\Entities\Implementation\IEntities\IEntitiesOwnerFree; +use OCP\Entities\Implementation\IEntities\IEntitiesOwnerIsNotMember; +use OCP\Entities\Implementation\IEntities\IEntitiesSearchDuplicate; +use OCP\Entities\Implementation\IEntities\IEntitiesSearchEntities; +use OCP\Entities\Implementation\IEntitiesAccounts\IEntitiesAccountsHasAdminRights; +use OCP\Entities\Implementation\IEntitiesAccounts\IEntitiesAccountsSearchAccounts; +use OCP\Entities\Implementation\IEntitiesAccounts\IEntitiesAccountsSearchDuplicate; +use OCP\Entities\Implementation\IEntitiesAccounts\IEntitiesAccountsSearchEntities; +use OCP\Entities\Model\IEntity; +use OCP\Entities\Model\IEntityAccount; +use OCP\Entities\Model\IEntityMember; +use OCP\Entities\Model\IEntityType; +use OCP\IConfig; +use OCP\ILogger; +use stdClass; + + +/** + * Class EntitiesManager + * + * @package OCP\Entities + */ +class EntitiesManager implements IEntitiesManager { + + + use TCacheResult; + + + const INTERFACE_ENTITIES = 'IEntities'; + const INTERFACE_ENTITIES_ACCOUNTS = 'IEntitiesAccounts'; + const INTERFACE_ENTITIES_MEMBERS = 'IEntitiesMembers'; + const INTERFACE_ENTITIES_TYPES = 'IEntitiesTypes'; + + + /** @var ILogger */ + private $logger; + + /** @var IConfig */ + private $config; + + /** @var EntitiesRequest */ + private $entitiesRequest; + + /** @var EntitiesAccountsRequest */ + private $entitiesAccountsRequest; + + /** @var EntitiesMembersRequest */ + private $entitiesMembersRequest; + + /** @var EntitiesTypesRequest */ + private $entitiesTypesRequest; + + /** @var IEntityType[] */ + private $classes = []; + + /** @var string[] */ + private $logSql = []; + + + /** @var IEntityAccount */ + private $viewer; + + + /** + * @param ILogger $logger + * @param IConfig $config + * @param EntitiesRequest $entitiesRequest + * @param EntitiesAccountsRequest $entitiesAccountsRequest + * @param EntitiesMembersRequest $entitiesMembersRequest + * @param EntitiesTypesRequest $entitiesTypesRequest + */ + public function __construct( + ILogger $logger, IConfig $config, EntitiesRequest $entitiesRequest, + EntitiesAccountsRequest $entitiesAccountsRequest, + EntitiesMembersRequest $entitiesMembersRequest, + EntitiesTypesRequest $entitiesTypesRequest + ) { + $this->logger = $logger; + $this->config = $config; + $this->entitiesRequest = $entitiesRequest; + $this->entitiesAccountsRequest = $entitiesAccountsRequest; + $this->entitiesMembersRequest = $entitiesMembersRequest; + $this->entitiesTypesRequest = $entitiesTypesRequest; + } + + + /** + * @param IEntity $entity + * @param string $ownerId + * + * @throws EntityAccountNotFoundException + * @throws EntityAlreadyExistsException + * @throws EntityCreationException + * @throws EntityMemberAlreadyExistsException + * @throws EntityTypeNotFoundException + * @throws ImplementationNotFoundException + * @throws ViewerNotSetException + */ + public function saveEntity(IEntity $entity, string $ownerId = ''): void { + + try { + $this->getClass( + self::INTERFACE_ENTITIES, $entity->getType(), IEntitiesAdminCreation::class + ); + + $viewer = $this->getViewer(); + if (!$viewer->hasAdminRights()) { + throw new EntityCreationException('must be admin'); + } + } catch (ImplementationNotFoundException $e) { + } + + if ($ownerId !== '') { + $owner = $this->getAccount($ownerId); + $entity->setOwner($owner); + + $member = new EntityMember(); + $member->setEntityId($entity->getId()); + $member->setAccountId($owner->getId()); + $member->setStatus(IEntityMember::STATUS_MEMBER); + $member->setLevel(IEntityMember::LEVEL_OWNER); + + try { + $this->getClass( + self::INTERFACE_ENTITIES, $entity->getType(), IEntitiesOwnerIsNotMember::class + ); + } catch (ImplementationNotFoundException $e) { + $this->saveMember($member); + } + } else { + $this->getClass( + self::INTERFACE_ENTITIES, $entity->getType(), IEntitiesOwnerFree::class + ); + } + + try { + $this->confirmCreationStatus($entity); + $knownEntity = $this->searchDuplicateEntity($entity); + + $this->logger->log( + 2, + 'Entity Creation Exception: duplicate entry ' . json_encode($entity) + . ' known as ' . json_encode($knownEntity) + ); + + $entity->setId($knownEntity->getId()); + throw new EntityAlreadyExistsException( + 'Entity already exists (' . $knownEntity->getId() . ')' + ); + } catch (EntityTypeNotFoundException $e) { + $this->logger->log( + 2, + 'Entity Creation Exception: Type not found ' . json_encode($entity) + ); + throw new EntityCreationException('Unknown Entity Type'); + } catch (EntityNotFoundException $e) { + $this->entitiesRequest->create($entity); + } + } + + + /** + * @param string $entityId + * + * @throws Exception + */ + public function deleteEntity(string $entityId): void { + $this->entitiesRequest->delete($entityId); + } + + + /** + * @param IEntityAccount $account + * + * @throws EntityAccountCreationException + * @throws EntityAccountAlreadyExistsException + */ + public function saveAccount(IEntityAccount $account): void { + + try { + $knownAccount = $this->searchDuplicateEntityAccount($account); + + $this->logger->log( + 2, + 'EntityAccount Creation Exception: duplicate entry ' . json_encode($account) + . ' known as ' . json_encode($knownAccount) + ); + + throw new EntityAccountAlreadyExistsException( + 'EntityAccount already exists (' . $knownAccount->getId() . ')' + ); + + } catch (EntityTypeNotFoundException $e) { + $this->logger->log( + 2, + 'EntityAccount Creation Exception: Type not found ' . json_encode($account) + ); + throw new EntityAccountCreationException('Unknown EntityAccount Type'); + + } catch (EntityAccountNotFoundException $e) { + $this->entitiesAccountsRequest->create($account); + } + + } + + + /** + * @param string $accountId + * + * @throws Exception + */ + public function deleteAccount(string $accountId): void { + $this->entitiesAccountsRequest->delete($accountId); + } + + + /** + * @param IEntityMember $member + * + * @throws EntityMemberAlreadyExistsException + */ + public function saveMember(IEntityMember $member): void { + try { + $knownMember = $this->entitiesMembersRequest->getMember( + $member->getAccountId(), $member->getEntityId() + ); + + throw new EntityMemberAlreadyExistsException( + 'EntityMember already exists (' . $knownMember->getId() . ')' + ); + } catch (EntityMemberNotFoundException $e) { + $this->entitiesMembersRequest->create($member); + } + } + + + /** + * @param string $memberId + * + * @throws Exception + */ + public function deleteMember(string $memberId): void { + $this->entitiesMembersRequest->delete($memberId); + + } + + + /** + * @param string $type + * + * @return IEntity[] + * @throws ViewerNotSetException + * @throws ViewerNotSetException + */ + public function getAllEntities(string $type = ''): array { + $viewer = $this->getViewer(); + + return $this->entitiesRequest->viewerGetAll($viewer, $type); + } + + + /** + * @param string $type + * + * @return IEntityAccount[] + */ + public function getAllAccounts(string $type = ''): array { + return $this->entitiesAccountsRequest->getAll($type); + } + + + /** + * @param IEntityAccount $viewer + */ + public function setViewer(IEntityAccount $viewer): void { + $this->viewer = $viewer; + } + + + /** + * @return IEntityAccount + * @throws ViewerNotSetException + */ + public function getViewer(): IEntityAccount { + if ($this->viewer === null) { + throw new ViewerNotSetException('viewer not set'); + } + + return $this->viewer; + } + + + /** + * @param string $needle + * @param string $type + * + * @return IEntity[] + * @throws ViewerNotSetException + */ + public function searchEntities(string $needle, string $type = ''): array { + $viewer = $this->getViewer(); + + $classes = array_merge( + $this->getClasses( + self::INTERFACE_ENTITIES_ACCOUNTS, IEntitiesAccountsSearchEntities::class + ), + $this->getClasses( + self::INTERFACE_ENTITIES, IEntitiesSearchEntities::class + ) + ); + + return $this->entitiesRequest->search($needle, $type, $classes); + } + + + /** + * @param string $needle + * @param string $type + * + * @return IEntityAccount[] + */ + public function searchAccounts(string $needle, string $type = ''): array { + $classes = array_merge( + $this->getClasses( + self::INTERFACE_ENTITIES_ACCOUNTS, IEntitiesAccountsSearchAccounts::class + ) + ); + + return $this->entitiesAccountsRequest->search($needle, $type, $classes); + } + + + /** + * @param string $entityId + * + * @return IEntity + * @throws EntityNotFoundException + */ + public function getEntity(string $entityId): IEntity { + return $this->entitiesRequest->getFromId($entityId); + } + + + /** + * @param string $entityId + * + * @return IEntity + * @throws EntityNotFoundException + * @throws ViewerNotSetException + */ + public function getEntityViewerMembership(string $entityId): IEntity { + $viewer = $this->getViewer(); + + return $this->entitiesRequest->viewerGetFromId($viewer, $entityId); + } + + + /** + * @param string $entityId + * + * @return IEntity + * @throws EntityNotFoundException + */ + public function getViewerMembership(string $entityId): IEntity { + return $this->entitiesRequest->getFromId($entityId); + } + + + /** + * @param string $accountId + * + * @return IEntityAccount + * @throws EntityAccountNotFoundException + */ + public function getAccount(string $accountId): IEntityAccount { + return $this->entitiesAccountsRequest->getFromId($accountId); + } + + + /** + * @param string $memberId + * + * @return IEntityMember + * @throws EntityMemberNotFoundException + */ + public function getMember(string $memberId): IEntityMember { + return $this->entitiesMembersRequest->getFromId($memberId); + } + + + /** + * @param IEntity $entity + */ + public function checkVisibility(IEntity $entity) { + + } + + + /** + * @param IEntity $entity + * + * @return IEntity[] + */ + public function entityBelongsTo(IEntity $entity): array { +// return $this->entitiesMembersRequest->getMembership($entity); +// return $this->entitiesRequest->getMembership($entity); + } + + + /** + * @param IEntity $entity + * + * @return IEntity[] + */ + public function entityGetMembers(IEntity $entity): array { + $cache = $this->cached($entity->getId()); + try { + return $cache->getArray('getMembers'); + } catch (NotCachedException $e) { + } + + $members = $this->entitiesMembersRequest->getMembers($entity); + $cache->setArray($members, 'getMembers'); + + return $members; + } + + + /** + * @param IEntity $entity + * + * @return bool + */ + public function entityHasAdminRights(IEntity $entity): bool { + $cache = $this->cached($entity->getId()); + try { + return $cache->getBool('hasAdminRights'); + } catch (NotCachedException $e) { + } + + try { + /** @var IEntitiesAdminRights $class */ + $class = $this->getClass( + self::INTERFACE_ENTITIES, $entity->getType(), IEntitiesAdminRights::class + ); + } catch (EntityTypeNotFoundException | ImplementationNotFoundException $e) { + return false; + } + + $hasAdminRights = $class->hasAdminRights($entity); + $cache->setBool($hasAdminRights, 'hasAdminRights'); + + return $hasAdminRights; + } + + + /** + * @param IEntityAccount $account + * + * @return IEntityMember[] + */ + public function accountBelongsTo(IEntityAccount $account): array { + $cache = $this->cached($account->getId()); + try { + return $cache->getArray('belongsTo'); + } catch (NotCachedException $e) { + } + + $belongsTo = $this->entitiesMembersRequest->getMembership($account); + $cache->setArray($belongsTo, 'belongsTo'); + + return $belongsTo; + } + + + /** + * @param IEntityAccount $account + * + * @return bool + */ + public function accountHasAdminRights(IEntityAccount $account): bool { + $cache = $this->cached($account->getId()); + try { + return $cache->getBool('hasAdminRights'); + } catch (NotCachedException $e) { + } + + $hasAdminRights = $this->checkAccountHasAdminRights($account); + $cache->setBool($hasAdminRights, 'hasAdminRights'); + + return $hasAdminRights; + } + + + /** + * @param IEntityAccount $account + * + * @return bool + */ + private function checkAccountHasAdminRights(IEntityAccount $account) { + try { + /** @var IEntitiesAdminRights $class */ + $this->getClass( + self::INTERFACE_ENTITIES_ACCOUNTS, $account->getType(), + IEntitiesAccountsHasAdminRights::class + ); + + return true; + } catch (EntityTypeNotFoundException | ImplementationNotFoundException $e) { + } + + foreach ($account->belongsTo() as $to) { + if ($to->getEntity() + ->hasAdminRights()) { + return true; + } + } + + return false; + } + + + public function entityPointOfView(IEntity $entity): IEntityMember { + + } + + + /** + * @param IEntityAccount $account + * @param string $entityId + * + * @throws EntityMemberLevelException + * @throws EntityNotFoundException + * @throws ViewerNotSetException + */ + public function accountInviteTo(IEntityAccount $account, string $entityId): void { + $entity = $this->getEntityViewerMembership($entityId); + echo json_encode($entity->getViewer()); + if ($entity->getViewer() + ->getLevel() < IEntityMember::LEVEL_MODERATOR) { + throw new EntityMemberLevelException(); + } + + //$this->checkVisibility($entity); + + $member = new EntityMember(); + $member->setAccountId($account->getId()); + $member->setEntityId($entity->getId()); +// $member->setLevel(); +// $member->setStatus(); + + $this->entitiesMembersRequest->create($member); + } + + +// +// /** +// * @param IEntity $entity +// * +// * @return IEntity +// * @throws EntityNotFoundException +// */ +// public function searchEntity(IEntity $entity): IEntity { +// return $this->entitiesRequest->search($entity); +// } + + + /** + * @param IEntity $entity + * + * @throws EntityCreationException + */ + public function confirmCreationStatus(IEntity $entity): void { + + try { + /** @var IEntitiesConfirmCreation $class */ + $class = $this->getClass( + self::INTERFACE_ENTITIES, $entity->getType(), IEntitiesConfirmCreation::class + ); + } catch (ImplementationNotFoundException $e) { + return; + } catch (EntityTypeNotFoundException $e) { + throw new EntityCreationException(); + } + + $class->confirmCreationStatus($entity); + } + + + /** + * @param IEntity $entity + * + * @return IEntity + * @throws EntityNotFoundException + * @throws EntityTypeNotFoundException + */ + public function searchDuplicateEntity(IEntity $entity): IEntity { + + try { + /** @var IEntitiesSearchDuplicate $class */ + $class = $this->getClass( + self::INTERFACE_ENTITIES, $entity->getType(), IEntitiesSearchDuplicate::class + ); + } catch (ImplementationNotFoundException $e) { + throw new EntityNotFoundException(); + } + + $qb = $this->entitiesRequest->getEntitiesSelectSql( + 'search for duplicate Entity: ' . json_encode($entity) + ); + $class->buildSearchDuplicate($qb, $entity); + + return $this->entitiesRequest->getItemFromRequest($qb); + } + + + /** + * @param IEntitiesQueryBuilder $qb + * @param float $time + * @param Exception|null $e + */ + public function logSql(IEntitiesQueryBuilder $qb, float $time, $e = null): void { + $log = [ + 'comment' => $qb->getComment(), + 'sql' => $qb->getSQL(), + 'values' => $qb->getParameters(), + 'time' => $time + ]; + + if ($e !== null) { + $log['error'] = [ + 'exception' => get_class($e), + 'message' => $e->getMessage() + ]; + } + + $this->logSql[] = $log; + } + + + /** + * @param IEntityAccount $account + * + * @return IEntityAccount + * @throws EntityAccountNotFoundException + * @throws EntityTypeNotFoundException + */ + private function searchDuplicateEntityAccount(IEntityAccount $account): IEntityAccount { + + try { + /** @var IEntitiesAccountsSearchDuplicate $class */ + $class = $this->getClass( + self::INTERFACE_ENTITIES_ACCOUNTS, $account->getType(), + IEntitiesAccountsSearchDuplicate::class + ); + } catch (ImplementationNotFoundException $e) { + throw new EntityAccountNotFoundException(); + } + + $qb = $this->entitiesAccountsRequest->getEntitiesAccountsSelectSql( + 'search for duplicate EntityAccount: ' . json_encode($account) + ); + $class->buildSearchDuplicate($qb, $account); + + return $this->entitiesAccountsRequest->getItemFromRequest($qb); + } + + + /** + * @param string $interface + * @param string $type + * @param string $implements + * + * @return stdClass + * @throws EntityTypeNotFoundException + * @throws ImplementationNotFoundException + */ + private function getClass(string $interface, string $type, $implements = '') { + $this->retrieveClasses(); + + foreach ($this->classes as $entityType) { + + if ($entityType->getInterface() !== $interface || $entityType->getType() !== $type) { + continue; + } + + try { + if ($entityType->hasClass()) { + $class = $entityType->getClass(); + } else { + $class = OC::$server->query($entityType->getClassName()); + $entityType->setClass($class); + } + } catch (QueryException $e) { + throw new EntityTypeNotFoundException($e->getMessage()); + } + + if ($implements === '') { + return $class; + } + + if (!($class instanceof $implements)) { + throw new ImplementationNotFoundException( + get_class($class) . ' does not implement ' . $implements + ); + } + + return $class; + } + + throw new EntityTypeNotFoundException(); + } + + + /** + * @param string $interface + * @param string $implements + * + * @return stdClass[] + */ + private function getClasses(string $interface, string $implements = ''): array { + $this->retrieveClasses(); + + $classes = []; + foreach ($this->classes as $entityType) { + if ($entityType->getInterface() !== $interface) { + continue; + } + + try { + if ($entityType->hasClass()) { + $class = $entityType->getClass(); + } else { + $class = OC::$server->query($entityType->getClassName()); + $entityType->setClass($class); + } + } catch (QueryException $e) { + continue; + } + + if ($implements !== '' && !($class instanceof $implements)) { + continue; + } + + $classes[] = $class; + } + + return $classes; + } + + + /** + * + */ + private function retrieveClasses(): void { + if (!empty($this->classes)) { + return; + } + + $this->classes = $this->entitiesTypesRequest->getClasses(); + } + + + /** + * + */ + public function __destruct() { + if (empty($this->logSql)) { + return; + } + + $toLog = [ + 'date' => date('Y-m-d_H:i:s'), + 'count' => count($this->logSql), + 'log' => $this->logSql + ]; + + if ($this->config->getSystemValue('entities.log.sql', '0') === '2') { + $filename = $this->config->getSystemValue('datadirectory') . '/entities_manager.log'; + $temp = fopen($filename, 'a'); + fwrite( + $temp, json_encode($toLog) . "\n" + ); + fclose($temp); + + return; + } + + $this->logger->log(1, json_encode($toLog)); + } + + +} + diff --git a/lib/private/Entities/Exceptions/EntityAccountAlreadyExistsException.php b/lib/private/Entities/Exceptions/EntityAccountAlreadyExistsException.php new file mode 100644 index 0000000000000..fabe6e02398e6 --- /dev/null +++ b/lib/private/Entities/Exceptions/EntityAccountAlreadyExistsException.php @@ -0,0 +1,40 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Exceptions; + + +use Exception; + + +class EntityAccountAlreadyExistsException extends Exception { + +} + diff --git a/lib/private/Entities/Exceptions/EntityAccountCreationException.php b/lib/private/Entities/Exceptions/EntityAccountCreationException.php new file mode 100644 index 0000000000000..8cde7dc489a4e --- /dev/null +++ b/lib/private/Entities/Exceptions/EntityAccountCreationException.php @@ -0,0 +1,40 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Exceptions; + + +use Exception; + + +class EntityAccountCreationException extends Exception { + +} + diff --git a/lib/private/Entities/Exceptions/EntityAccountNotFoundException.php b/lib/private/Entities/Exceptions/EntityAccountNotFoundException.php new file mode 100644 index 0000000000000..1757a18e6179d --- /dev/null +++ b/lib/private/Entities/Exceptions/EntityAccountNotFoundException.php @@ -0,0 +1,40 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Exceptions; + + +use Exception; + + +class EntityAccountNotFoundException extends Exception { + +} + diff --git a/lib/private/Entities/Exceptions/EntityAlreadyExistsException.php b/lib/private/Entities/Exceptions/EntityAlreadyExistsException.php new file mode 100644 index 0000000000000..fefdc7f000699 --- /dev/null +++ b/lib/private/Entities/Exceptions/EntityAlreadyExistsException.php @@ -0,0 +1,40 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Exceptions; + + +use Exception; + + +class EntityAlreadyExistsException extends Exception { + +} + diff --git a/lib/private/Entities/Exceptions/EntityCreationException.php b/lib/private/Entities/Exceptions/EntityCreationException.php new file mode 100644 index 0000000000000..4576a4e866290 --- /dev/null +++ b/lib/private/Entities/Exceptions/EntityCreationException.php @@ -0,0 +1,40 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Exceptions; + + +use Exception; + + +class EntityCreationException extends Exception { + +} + diff --git a/lib/private/Entities/Exceptions/EntityMemberAlreadyExistsException.php b/lib/private/Entities/Exceptions/EntityMemberAlreadyExistsException.php new file mode 100644 index 0000000000000..e94a34a02c5b3 --- /dev/null +++ b/lib/private/Entities/Exceptions/EntityMemberAlreadyExistsException.php @@ -0,0 +1,40 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Exceptions; + + +use Exception; + + +class EntityMemberAlreadyExistsException extends Exception { + +} + diff --git a/lib/private/Entities/Exceptions/EntityMemberCreationException.php b/lib/private/Entities/Exceptions/EntityMemberCreationException.php new file mode 100644 index 0000000000000..365b8b3398644 --- /dev/null +++ b/lib/private/Entities/Exceptions/EntityMemberCreationException.php @@ -0,0 +1,40 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Exceptions; + + +use Exception; + + +class EntityMemberCreationException extends Exception { + +} + diff --git a/lib/private/Entities/Exceptions/EntityMemberLevelException.php b/lib/private/Entities/Exceptions/EntityMemberLevelException.php new file mode 100644 index 0000000000000..612c9449d2bbd --- /dev/null +++ b/lib/private/Entities/Exceptions/EntityMemberLevelException.php @@ -0,0 +1,40 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Exceptions; + + +use Exception; + + +class EntityMemberLevelException extends Exception { + +} + diff --git a/lib/private/Entities/Exceptions/EntityMemberNotFoundException.php b/lib/private/Entities/Exceptions/EntityMemberNotFoundException.php new file mode 100644 index 0000000000000..b657bd640b67c --- /dev/null +++ b/lib/private/Entities/Exceptions/EntityMemberNotFoundException.php @@ -0,0 +1,40 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Exceptions; + + +use Exception; + + +class EntityMemberNotFoundException extends Exception { + +} + diff --git a/lib/private/Entities/Exceptions/EntityNotFoundException.php b/lib/private/Entities/Exceptions/EntityNotFoundException.php new file mode 100644 index 0000000000000..8b4a4ab2cfa81 --- /dev/null +++ b/lib/private/Entities/Exceptions/EntityNotFoundException.php @@ -0,0 +1,40 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Exceptions; + + +use Exception; + + +class EntityNotFoundException extends Exception { + +} + diff --git a/lib/private/Entities/Exceptions/EntityTypeNotFoundException.php b/lib/private/Entities/Exceptions/EntityTypeNotFoundException.php new file mode 100644 index 0000000000000..68f45ad1cb826 --- /dev/null +++ b/lib/private/Entities/Exceptions/EntityTypeNotFoundException.php @@ -0,0 +1,40 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Exceptions; + + +use Exception; + + +class EntityTypeNotFoundException extends Exception { + +} + diff --git a/lib/private/Entities/Exceptions/ImplementationNotFoundException.php b/lib/private/Entities/Exceptions/ImplementationNotFoundException.php new file mode 100644 index 0000000000000..325af415c8f8e --- /dev/null +++ b/lib/private/Entities/Exceptions/ImplementationNotFoundException.php @@ -0,0 +1,40 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Exceptions; + + +use Exception; + + +class ImplementationNotFoundException extends Exception { + +} + diff --git a/lib/private/Entities/Exceptions/ViewerNotSetException.php b/lib/private/Entities/Exceptions/ViewerNotSetException.php new file mode 100644 index 0000000000000..406018f85bfa8 --- /dev/null +++ b/lib/private/Entities/Exceptions/ViewerNotSetException.php @@ -0,0 +1,40 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Exceptions; + + +use Exception; + + +class ViewerNotSetException extends Exception { + +} + diff --git a/lib/private/Entities/FullMockup.php b/lib/private/Entities/FullMockup.php new file mode 100644 index 0000000000000..e0c64df93d1a3 --- /dev/null +++ b/lib/private/Entities/FullMockup.php @@ -0,0 +1,43 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities; + + +class FullMockup { + + + public function __call($method, $args) { + } + + +} + + diff --git a/lib/private/Entities/Helper/EntitiesHelper.php b/lib/private/Entities/Helper/EntitiesHelper.php new file mode 100644 index 0000000000000..26797497ecce3 --- /dev/null +++ b/lib/private/Entities/Helper/EntitiesHelper.php @@ -0,0 +1,288 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Helper; + + +use daita\NcSmallPhpTools\Traits\TStringTools; +use Exception; +use OC\Entities\Classes\IEntities\Account; +use OC\Entities\Classes\IEntities\AdminGroup; +use OC\Entities\Classes\IEntities\GlobalGroup; +use OC\Entities\Classes\IEntities\Group; +use OC\Entities\Classes\IEntities\User; +use OC\Entities\Classes\IEntitiesAccounts\LocalAdmin; +use OC\Entities\Classes\IEntitiesAccounts\LocalUser; +use OC\Entities\Classes\IEntitiesAccounts\MailAddress; +use OC\Entities\Db\EntitiesAccountsRequest; +use OC\Entities\Db\EntitiesMembersRequest; +use OC\Entities\Db\EntitiesRequest; +use OC\Entities\Db\EntitiesTypesRequest; +use OC\Entities\Exceptions\EntityAccountAlreadyExistsException; +use OC\Entities\Exceptions\EntityAccountCreationException; +use OC\Entities\Exceptions\EntityAccountNotFoundException; +use OC\Entities\Exceptions\EntityAlreadyExistsException; +use OC\Entities\Exceptions\EntityCreationException; +use OC\Entities\Exceptions\EntityMemberAlreadyExistsException; +use OC\Entities\Exceptions\EntityNotFoundException; +use OC\Entities\Model\Entity; +use OC\Entities\Model\EntityAccount; +use OC\Entities\Model\EntityMember; +use OC\Entities\Model\EntityType; +use OCP\Entities\Helper\IEntitiesHelper; +use OCP\Entities\IEntitiesManager; +use OCP\Entities\Implementation\IEntities\IEntities; +use OCP\Entities\Implementation\IEntitiesAccounts\IEntitiesAccounts; +use OCP\Entities\Model\IEntity; +use OCP\Entities\Model\IEntityAccount; +use OCP\Entities\Model\IEntityMember; +use OCP\Entities\Model\IEntityType; + + +/** + * Class EntitiesManager + * + * @package OCP\Entities\Helper + */ +class EntitiesHelper implements IEntitiesHelper { + + + use TStringTools; + + + /** @var IEntitiesManager */ + private $entitiesManager; + + /** @var EntitiesRequest */ + private $entitiesRequest; + + /** @var EntitiesAccountsRequest */ + private $entitiesAccountsRequest; + + /** @var EntitiesMembersRequest */ + private $entitiesMembersRequest; + + /** @var EntitiesTypesRequest */ + private $entitiesTypesRequest; + + + /** @var IEntity */ + private $temporaryLocalAccount; + + + /** + * EntitiesHelper constructor. + * + * @param IEntitiesManager $entitiesManager + * @param EntitiesRequest $entitiesRequest + * @param EntitiesAccountsRequest $entitiesAccountsRequest + * @param EntitiesMembersRequest $entitiesMembersRequest + * @param EntitiesTypesRequest $entitiesTypesRequest + */ + public function __construct( + IEntitiesManager $entitiesManager, + EntitiesRequest $entitiesRequest, + EntitiesAccountsRequest $entitiesAccountsRequest, + EntitiesMembersRequest $entitiesMembersRequest, + EntitiesTypesRequest $entitiesTypesRequest + ) { + $this->entitiesManager = $entitiesManager; + $this->entitiesRequest = $entitiesRequest; + $this->entitiesAccountsRequest = $entitiesAccountsRequest; + $this->entitiesMembersRequest = $entitiesMembersRequest; + $this->entitiesTypesRequest = $entitiesTypesRequest; + } + + + /** + * @param string $userId + * @param string $displayName + * + * @return IEntity + * @throws EntityAccountAlreadyExistsException + * @throws EntityAccountCreationException + * @throws EntityAlreadyExistsException + * @throws EntityCreationException + * @throws EntityMemberAlreadyExistsException + */ + public function createLocalUser(string $userId, string $displayName = ''): IEntity { + + $account = new EntityAccount(); + $account->setType(LocalUser::TYPE); + $account->setAccount($userId); + + $this->entitiesManager->saveAccount($account); + + $entity = new Entity(); + $entity->setVisibility(IEntity::VISIBILITY_ALL); + $entity->setAccess(IEntity::ACCESS_LIMITED); + $entity->setType(User::TYPE); + $entity->setName($displayName); + $this->entitiesManager->saveEntity($entity, $account->getId()); + + return $entity; + } + + + /** + * @param string $entityId + * @param string $userId + * @param int $level + * @param string $status + * + * @return IEntityMember + * @throws EntityAccountNotFoundException + * @throws EntityNotFoundException + * @throws EntityMemberAlreadyExistsException + */ + public function addLocalMember( + string $entityId, string $userId, int $level = IEntityMember::LEVEL_MEMBER, + string $status = '' + ): IEntityMember { + + $entity = $this->entitiesManager->getEntity($entityId); + $account = $this->getLocalAccount($userId); + + $entityMember = new EntityMember(); + $entityMember->setEntityId($entity->getId()); + $entityMember->setAccountId($account->getId()); + $entityMember->setLevel($level); + $entityMember->setStatus(IEntityMember::STATUS_MEMBER); + $entityMember->setAccount($account); + + $this->entitiesManager->saveMember($entityMember); + + return $entityMember; + } + + + /** + * @param string $userId + * + * @return IEntityAccount + * @throws EntityAccountNotFoundException + */ + public function getLocalAccount(string $userId): IEntityAccount { + return $this->entitiesAccountsRequest->getFromAccount($userId, LocalUser::TYPE); + } + + + public function inviteLocalMember(string $entityId, string $userId): IEntityMember { + } + + public function addVirtualMember(string $entityId, string $type, string $account + ): IEntityMember { + } + + + /** + * @param string $interface + * + * @return IEntityType[] + */ + public function getEntityTypes(string $interface = ''): array { + return $this->entitiesTypesRequest->getClasses($interface); + } + + + /** + * @param bool $admin + * + * @return IEntityAccount + * @throws EntityAccountAlreadyExistsException + * @throws EntityAccountCreationException + */ + public function temporaryLocalAccount(bool $admin = false): IEntityAccount { + if ($this->temporaryLocalAccount !== null) { + throw new EntityAccountAlreadyExistsException( + 'A temporary account already exist in this session' + ); + } + + $type = LocalUser::TYPE; + if ($admin) { + $type = LocalAdmin::TYPE; + } + + $account = new EntityAccount(); + $account->setType($type); + $account->setAccount('temp.' . $this->uuid(14)); + $account->setDeleteIn('+1 day'); + $this->entitiesManager->saveAccount($account); + $this->temporaryLocalAccount = $account; + + return $account; + } + + + /** + * + */ + public function destroyTemporaryLocalAccount() { + if ($this->temporaryLocalAccount !== null) { + $this->entitiesManager->deleteAccount($this->temporaryLocalAccount->getId()); + } + } + + + /** + * + * @throws Exception + */ + public function refreshInstall(): void { + $this->entitiesRequest->clearAll(); + $this->entitiesAccountsRequest->clearAll(); + $this->entitiesMembersRequest->clearAll(); + $this->entitiesTypesRequest->clearAll(); + + $entityTypes = [ + new EntityType(IEntities::INTERFACE, User::TYPE, User::class), + new EntityType(IEntities::INTERFACE, Account::TYPE, Account::class), + new EntityType(IEntities::INTERFACE, Group::TYPE, Group::class), + new EntityType(IEntities::INTERFACE, GlobalGroup::TYPE, GlobalGroup::class), + new EntityType(IEntities::INTERFACE, AdminGroup::TYPE, AdminGroup::class), + + new EntityType(IEntitiesAccounts::INTERFACE, LocalUser::TYPE, LocalUser::class), + new EntityType(IEntitiesAccounts::INTERFACE, LocalAdmin::TYPE, LocalAdmin::class), + new EntityType(IEntitiesAccounts::INTERFACE, MailAddress::TYPE, MailAddress::class) + ]; + + foreach ($entityTypes as $entityType) { + $this->entitiesTypesRequest->create($entityType); + } + } + + + public function __destruct() { + $this->destroyTemporaryLocalAccount(); + } + +} + diff --git a/lib/private/Entities/Helper/EntitiesMigrationHelper.php b/lib/private/Entities/Helper/EntitiesMigrationHelper.php new file mode 100644 index 0000000000000..1171e8063b068 --- /dev/null +++ b/lib/private/Entities/Helper/EntitiesMigrationHelper.php @@ -0,0 +1,265 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Helper; + + +use daita\NcSmallPhpTools\Model\EmptyMockup; +use Exception; +use OC; +use OC\Entities\Classes\IEntities\AdminGroup; +use OC\Entities\Classes\IEntities\GlobalGroup; +use OC\Entities\Db\EntitiesRequest; +use OC\Entities\Exceptions\EntityNotFoundException; +use OC\Entities\Exceptions\EntityTypeNotFoundException; +use OC\Entities\Model\Entity; +use OCP\Entities\Helper\IEntitiesHelper; +use OCP\Entities\Helper\IEntitiesMigrationHelper; +use OCP\Entities\IEntitiesManager; +use OCP\Entities\Model\IEntity; +use OCP\IGroup; +use OCP\IGroupManager; +use OCP\IUserManager; +use Symfony\Component\Console\Output\ConsoleOutput; + + +/** + * Class EntitiesManager + * + * @package OCP\Entities\Helper + */ +class EntitiesMigrationHelper implements IEntitiesMigrationHelper { + + + /** @var bool */ + private $isCLI; + + /** @var IEntitiesManager */ + private $entitiesManager; + + /** @var IEntitiesHelper */ + private $entitiesHelper; + + /** @var EntitiesRequest */ + private $entitiesRequest; + + /** @var IUserManager */ + private $userManager; + + /** @var IGroupManager */ + private $groupManager; + + + /** @var ConsoleOutput */ + private $output = null; + + + /** + * EntitiesMigrationHelper constructor. + * + * @param bool $isCLI + * @param IEntitiesManager $entitiesManager + * @param IEntitiesHelper $entitiesHelper + * @param EntitiesRequest $entitiesRequest + * @param IUserManager $userManager + * @param IGroupManager $groupManager + */ + public function __construct( + $isCLI, IEntitiesManager $entitiesManager, IEntitiesHelper $entitiesHelper, + EntitiesRequest $entitiesRequest, IUserManager $userManager, IGroupManager $groupManager + ) { + + $this->isCLI = $isCLI; + if ($isCLI === true) { + $this->output = new ConsoleOutput(); + } else { + $this->output = new EmptyMockup(); + } + + $this->entitiesManager = $entitiesManager; + $this->entitiesHelper = $entitiesHelper; + $this->entitiesRequest = $entitiesRequest; + + $this->userManager = $userManager; + $this->groupManager = $groupManager; + } + + + /** + * + */ + public function migrateUsers(): void { + $this->output->writeln('### Migrating users'); + + $users = $this->userManager->search(''); + foreach ($users as $user) { + $this->output->write('- ' . $user->getUID() . ': ', false); + + try { + $entity = $this->entitiesHelper->createLocalUser( + $user->getUID(), $user->getDisplayName() + ); + $this->output->write( + 'account ' . $entity->getOwner() + ->getId() . ', entity ' + . '' . $entity->getId() . '', true + ); + } catch (Exception $e) { + $this->output->write('' . $e->getMessage() . '', true); + continue; + } + + } + + $this->output->writeln(''); + } + + + /** + * + * @throws Exception + */ + public function migrateGroups(): void { + $this->output->writeln('### Migrating groups'); + + $groups = $this->groupManager->search(''); + foreach ($groups as $group) { + $this->output->write('- ' . $group->getGID() . ': ', false); + + $entity = $this->createGroupEntity($group->getGID(), ($group->getGID() === 'admin')); + + try { + $knownEntity = $this->entitiesManager->searchDuplicateEntity($entity); + + $entity->setId($knownEntity->getId()); + $this->output->write( + 'Entity already exists (' . $knownEntity->getId() . ')', true + ); + + } catch (EntityTypeNotFoundException $e) { + $this->output->write('Unknown Entity Type', true); + continue; + } catch (EntityNotFoundException $e) { + $this->entitiesRequest->create($entity); + $this->output->write('' . $entity->getId() . '', true); + } + + +// +// +// +// } catch (EntityAlreadyExistsException $e) { +//// $this->output->write('' . $e->getMessage() . '', true); +// } catch (EntityCreationException $e) { +//// $this->output->write('' . $e->getMessage() . '', true); +// continue; +// } + + $this->manageGroupMembers($entity, $group); + } + + } + + + public function migrateCircles(): void { + } + + + public function migrateRooms(): void { + } + + + /** + * @param string $groupId + * @param bool $isAdmin + * + * @return IEntity + */ + private function createGroupEntity(string $groupId, bool $isAdmin = false): IEntity { + $entity = new Entity(); + $entity->setVisibility(IEntity::VISIBILITY_MEMBERS); + $entity->setAccess(IEntity::ACCESS_LIMITED); + $entity->setName($groupId); + if ($isAdmin) { + $entity->setType(AdminGroup::TYPE); + } else { + $entity->setType(GlobalGroup::TYPE); + } + + return $entity; + } + +// +// /** +// * @param string $groupId +// * +// * @return IEntity +// * @throws EntityNotFoundExceptionAlias +// * @throws EntityTypeNotFoundException +// */ +// public function getGroupByName(string $groupId): IEntity { +// $entity = new Entity(); +// $entity->setVisibility(IEntity::VISIBILITY_MEMBERS); +// $entity->setAccess(IEntity::ACCESS_LIMITED); +// $entity->setName($groupId); +// $entity->setType(Group::TYPE); +// +// return $this->entitiesManager->searchDuplicateEntity($entity); +// } + + + /** + * @param IEntity $entity + * @param IGroup $group + */ + private function manageGroupMembers(IEntity $entity, IGroup $group): void { + //$this->output->writeln(' - Adding members to ' . $entity->getId() . ''); + + foreach ($group->getUsers() as $user) { + $this->output->write(' * Adding ' . $user->getUID() . ': ', false); + + try { + $member = + $this->entitiesHelper->addLocalMember($entity->getId(), $user->getUID()); + + $this->output->write( + 'account ' . $member->getAccountId() . ', member ' + . '' . $member->getId() . '', true + ); + } catch (Exception $e) { + $this->output->write('' . $e->getMessage() . '', true); + + continue; + } + } + } + +} + diff --git a/lib/private/Entities/Model/Entity.php b/lib/private/Entities/Model/Entity.php new file mode 100644 index 0000000000000..b89104c1efb04 --- /dev/null +++ b/lib/private/Entities/Model/Entity.php @@ -0,0 +1,429 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Model; + + +use daita\NcSmallPhpTools\Traits\TArrayTools; +use daita\NcSmallPhpTools\Traits\TStringTools; +use DateTime; +use Exception; +use JsonSerializable; +use OC; +use OC\Entities\Exceptions\EntityMemberNotFoundException; +use OCP\Entities\Model\IEntity; +use OCP\Entities\Model\IEntityAccount; +use OCP\Entities\Model\IEntityMember; + + +/** + * Class Entity + * + * @package OC\Entities\Model + */ +class Entity implements IEntity, JsonSerializable { + + + use TArrayTools; + use TStringTools; + + + /** @var string */ + private $id = ''; + + /** @var string */ + private $type = ''; + + /** @var string */ + private $ownerId = ''; + + /** @var IEntityAccount */ + private $owner; + + /** @var IEntityMember */ + private $viewer; + + /** @var int */ + private $visibility = 0; + + /** @var int */ + private $access = 0; + + /** @var string */ + private $name = ''; + + /** @var int */ + private $creation = 0; + + /** @var IEntityMember[] */ + private $members = []; + + + /** + * Entity constructor. + * + * @param string $id + */ + public function __construct(string $id = '') { + $this->id = $id; + + if ($this->id === '') { + $this->id = $this->uuid(11); + } + } + + + /** + * @return string + */ + public function getId(): string { + return $this->id; + } + + /** + * @param string $id + * + * @return IEntity + */ + public function setId(string $id): IEntity { + $this->id = $id; + + return $this; + } + + + /** + * @return string + */ + public function getType(): string { + return $this->type; + } + + /** + * @param string $type + * + * @return IEntity + */ + public function setType(string $type): IEntity { + $this->type = $type; + + return $this; + } + + + /** + * @return string + */ + public function getOwnerId(): string { + if ($this->hasOwner()) { + try { + return $this->getOwner() + ->getId(); + } catch (EntityMemberNotFoundException $e) { + } + } + + return $this->ownerId; + } + + /** + * @param string $ownerId + * + * @return IEntity + */ + public function setOwnerId(string $ownerId): IEntity { + $this->ownerId = $ownerId; + + return $this; + } + + + /** + * @return int + */ + public function getVisibility(): int { + return $this->visibility; + } + + /** + * @param int $visibility + * + * @return IEntity + */ + public function setVisibility(int $visibility): IEntity { + $this->visibility = $visibility; + + return $this; + } + + /** + * @return string + */ + public function getVisibilityString(): string { + return $this->get((string)$this->visibility, IEntity::CONVERT_VISIBILITY, ''); + } + + + /** + * @return int + */ + public function getAccess(): int { + return $this->access; + } + + /** + * @param int $access + * + * @return IEntity + */ + public function setAccess(int $access): IEntity { + $this->access = $access; + + return $this; + } + + /** + * @return string + */ + public function getAccessString(): string { + return $this->get((string)$this->access, IEntity::CONVERT_ACCESS, ''); + } + + + /** + * @return string + */ + public function getName(): string { + return $this->name; + } + + /** + * @param string $name + * + * @return IEntity + */ + public function setName(string $name): IEntity { + $this->name = $name; + + return $this; + } + +// +// /** +// * @return IEntityMember[] +// */ +// public function getMembers(): array { +// return $this->members; +// } +// +// /** +// * @param IEntityMember[] $members +// * +// * @return IEntity +// */ +// public function setMembers(array $members): IEntity { +// $this->members = $members; +// +// return $this; +// } +// +// /** +// * @param IEntityMember[] $members +// * +// * @return IEntity +// */ +// public function addMembers(array $members): IEntity { +// $this->members = array_merge($this->members, $members); +// +// return $this; +// } +// +// /** +// * @param IEntityMember $member +// * +// * @return IEntity +// */ +// public function addMember(IEntityMember $member): IEntity { +// $this->members[] = $member; +// +// return $this; +// } + + + /** + * @return int + */ + public function getCreation(): int { + return $this->creation; + } + + /** + * @param int $creation + * + * @return IEntity + */ + public function setCreation(int $creation): IEntity { + $this->creation = $creation; + + return $this; + } + + + /** + * @return bool + */ + public function hasOwner(): bool { + return ($this->owner !== null); + } + + /** + * @return IEntityAccount + * @throws EntityMemberNotFoundException + */ + public function getOwner(): IEntityAccount { + if ($this->owner !== null) { + return $this->owner; + } + + // TODO: return IEntityAccount instead of IEntityMember +// foreach ($this->getMembers() as $member) { +// if ($member->getLevel() === IEntityMember::LEVEL_OWNER) { +// return $member; +// } +// } + + throw new EntityMemberNotFoundException('Cannot find Owner'); + } + + public function setOwner(IEntityAccount $owner): IEntity { + $this->owner = $owner; + + return $this; + } + + + /** + * @return bool + */ + public function hasViewer(): bool { + return ($this->viewer !== null); + } + + /** + * @return IEntityMember + * @throws EntityMemberNotFoundException + */ + public function getViewer(): IEntityMember { + if ($this->viewer !== null) { + return $this->viewer; + } + + throw new EntityMemberNotFoundException('Cannot find Viewer'); + } + + public function setViewer(IEntityMember $viewer): IEntity { + $this->viewer = $viewer; + + return $this; + } + + + /** + * @param array $data + * + * @return IEntity + */ + public function importFromDatabase(array $data): IEntity { + $this->setId($this->get('id', $data, '')); + $this->setType($this->get('type', $data, '')); + $this->setOwnerId($this->get('owner_id', $data, '')); + $this->setVisibility($this->getInt('visibility', $data, 0)); + $this->setAccess($this->getInt('access', $data, 0)); + $this->setName($this->get('name', $data, '')); + + try { + $creation = new DateTime($this->get('creation', $data, '')); + $this->setCreation($creation->getTimestamp()); + } catch (Exception $e) { + } + + return $this; + } + + + /** + * @return array + */ + public function jsonSerialize(): array { + return [ + 'id' => $this->getId(), + 'type' => $this->getType(), + 'owner_id' => $this->getOwnerId(), + 'visibility' => $this->getVisibility(), + 'access' => $this->getAccess(), + 'name' => $this->getName(), + 'creation' => $this->getCreation() + ]; + } + + /** + * @return IEntity[] + */ + public function belongsTo(): array { + return OC::$server->getEntitiesManager() + ->entityBelongsTo($this); + } + + + /** + * @return IEntityMember[] + */ + public function getMembers(): array { + return OC::$server->getEntitiesManager() + ->entityGetMembers($this); + } + + + public function pointOfView(): IEntityMember { + return OC::$server->getEntitiesManager() + ->entityPointOfView($this); + } + + + /** + * @return bool + */ + public function hasAdminRights(): bool { + return OC::$server->getEntitiesManager() + ->entityHasAdminRights($this); + } + +} + diff --git a/lib/private/Entities/Model/EntityAccount.php b/lib/private/Entities/Model/EntityAccount.php new file mode 100644 index 0000000000000..87b44a48a5200 --- /dev/null +++ b/lib/private/Entities/Model/EntityAccount.php @@ -0,0 +1,262 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Model; + + +use daita\NcSmallPhpTools\Model\Options; +use daita\NcSmallPhpTools\Traits\TArrayTools; +use daita\NcSmallPhpTools\Traits\TStringTools; +use DateTime; +use Exception; +use JsonSerializable; +use OC; +use OCP\Entities\Model\IEntityAccount; +use OCP\Entities\Model\IEntityMember; + + +/** + * Class EntityAccount + * + * @package OC\Entities\Model + */ +class EntityAccount implements IEntityAccount, JsonSerializable { + + + use TArrayTools; + use TStringTools; + + + /** @var string */ + private $id = ''; + + /** @var string */ + private $type = ''; + + /** @var string */ + private $account = ''; + + /** @var int */ + private $deleteOn = 0; + + /** @var int */ + private $creation = 0; + + /** @var Options */ + private $options; + + /** + * EntityAccount constructor. + * + * @param string $id + */ + public function __construct(string $id = '') { + $this->options = new Options(); + $this->id = $id; + + if ($this->id === '') { + $this->id = $this->uuid(11); + } + } + + + /** + * @return string + */ + public function getId(): string { + return $this->id; + } + + /** + * @param string $id + * + * @return IEntityAccount + */ + public function setId(string $id): IEntityAccount { + $this->id = $id; + + return $this; + } + + + /** + * @return string + */ + public function getType(): string { + return $this->type; + } + + /** + * @param string $type + * + * @return IEntityAccount + */ + public function setType(string $type): IEntityAccount { + $this->type = $type; + + return $this; + } + + + /** + * @return string + */ + public function getAccount(): string { + return $this->account; + } + + /** + * @param string $account + * + * @return IEntityAccount + */ + public function setAccount(string $account): IEntityAccount { + $this->account = $account; + + return $this; + } + + + /** + * @return int + */ + public function getDeleteOn(): int { + return $this->deleteOn; + } + + /** + * @param int $deleteOn + * + * @return IEntityAccount + */ + public function setDeleteOn(int $deleteOn): IEntityAccount { + $this->deleteOn = $deleteOn; + + return $this; + } + + /** + * @param string $in + * + * @return IEntityAccount + * @throws Exception + */ + public function setDeleteIn(string $in): IEntityAccount { + $dTime = new DateTime($in); + + $this->setDeleteOn($dTime->getTimestamp()); + + return $this; + } + + + /** + * @return int + */ + public function getCreation(): int { + return $this->creation; + } + + /** + * @param int $creation + * + * @return IEntityAccount + */ + public function setCreation(int $creation): IEntityAccount { + $this->creation = $creation; + + return $this; + } + + + public function getOptions(): Options { + return $this->options; + } + + + /** + * @param array $data + * + * @return IEntityAccount + */ + public function importFromDatabase(array $data): IEntityAccount { + $this->setId($this->get('id', $data, '')); + $this->setType($this->get('type', $data, '')); + $this->setAccount($this->get('account', $data, '')); + $this->setDeleteOn($this->getInt('delete_on', $data, 0)); + + try { + $creation = new DateTime($this->get('creation', $data, '')); + $this->setCreation($creation->getTimestamp()); + } catch (Exception $e) { + } + + return $this; + } + + + /** + * @return array + */ + public function jsonSerialize(): array { + return [ + 'id' => $this->getId(), + 'type' => $this->getType(), + 'account' => $this->getAccount(), + 'creation' => $this->getCreation() + ]; + } + + + /** + * @return IEntityMember[] + */ + public function belongsTo(): array { + return OC::$server->getEntitiesManager() + ->accountBelongsTo($this); + } + + + public function hasAdminRights(): bool { + return OC::$server->getEntitiesManager() + ->accountHasAdminRights($this); + } + + + /** + * @param string $entityId + */ + public function inviteTo(string $entityId): void { + OC::$server->getEntitiesManager() + ->accountInviteTo($this, $entityId); + } + +} + diff --git a/lib/private/Entities/Model/EntityMember.php b/lib/private/Entities/Model/EntityMember.php new file mode 100644 index 0000000000000..822a86d3d0610 --- /dev/null +++ b/lib/private/Entities/Model/EntityMember.php @@ -0,0 +1,347 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Model; + + +use daita\NcSmallPhpTools\Traits\TArrayTools; +use daita\NcSmallPhpTools\Traits\TStringTools; +use DateTime; +use Exception; +use JsonSerializable; +use OC\Entities\Exceptions\EntityAccountNotFoundException; +use OC\Entities\Exceptions\EntityNotFoundException; +use OCP\Entities\Model\IEntity; +use OCP\Entities\Model\IEntityAccount; +use OCP\Entities\Model\IEntityMember; + + +/** + * Class EntityMember + * + * @package OC\Entities\Model + */ +class EntityMember implements IEntityMember, JsonSerializable { + + + use TArrayTools; + use TStringTools; + + + /** @var string */ + private $id = ''; + + /** @var string */ + private $entityId = ''; + + /** @var IEntity */ + private $entity = null; + + /** @var string */ + private $accountId = ''; + + /** @var IEntityAccount */ + private $account = null; + + /** @var string */ + private $slaveEntityId = ''; + + /** @var string */ + private $status = ''; + + /** @var int */ + private $level = 0; + + /** @var int */ + private $creation = 0; + + + /** + * EntityMember constructor. + * + * @param string $id + */ + public function __construct(string $id = '') { + $this->id = $id; + + if ($this->id === '') { + $this->id = $this->uuid(11); + } + } + + + /** + * @return string + */ + public function getId(): string { + return $this->id; + } + + /** + * @param string $id + * + * @return IEntityMember + */ + public function setId(string $id): IEntityMember { + $this->id = $id; + + return $this; + } + + + /** + * @return string + */ + public function getEntityId(): string { + try { + return $this->getEntity() + ->getId(); + } catch (EntityNotFoundException $e) { + } + + return $this->entityId; + } + + /** + * @param string $entityId + * + * @return IEntityMember + */ + public function setEntityId(string $entityId): IEntityMember { + $this->entityId = $entityId; + + return $this; + } + + + /** + * @return bool + */ + public function hasEntity(): bool { + return ($this->entity !== null); + } + + /** + * @return IEntity + * @throws EntityNotFoundException + */ + public function getEntity(): IEntity { + if ($this->entity !== null) { + return $this->entity; + } + + throw new EntityNotFoundException(); + } + + /** + * @param IEntity $entity + * + * @return IEntityMember + */ + public function setEntity(IEntity $entity): IEntityMember { + $this->entity = $entity; + + return $this; + } + + + /** + * @return bool + */ + public function hasAccount(): bool { + return ($this->account !== null); + } + + /** + * @return IEntityAccount + * @throws EntityAccountNotFoundException + */ + public function getAccount(): IEntityAccount { + if ($this->account !== null) { + return $this->account; + } + + throw new EntityAccountNotFoundException(); + } + + /** + * @param IEntityAccount $account + */ + public function setAccount(IEntityAccount $account) { + $this->account = $account; + } + + + /** + * @return string + */ + public function getAccountId(): string { + try { + return $this->getAccount() + ->getId(); + } catch (EntityAccountNotFoundException $e) { + } + + return $this->accountId; + } + + /** + * @param string $accountId + * + * @return IEntityMember + */ + public function setAccountId(string $accountId): IEntityMember { + $this->accountId = $accountId; + + return $this; + } + + + /** + * @return string + */ + public function getSlaveEntityId(): string { + return $this->slaveEntityId; + } + + /** + * @param string $slaveEntityId + * + * @return IEntityMember + */ + public function setSlaveEntityId(string $slaveEntityId): IEntityMember { + $this->slaveEntityId = $slaveEntityId; + + return $this; + } + + + /** + * @return string + */ + public function getStatus(): string { + return $this->status; + } + + /** + * @param string $status + * + * @return IEntityMember + */ + public function setStatus(string $status): IEntityMember { + $this->status = $status; + + return $this; + } + + + /** + * @return int + */ + public function getLevel(): int { + return $this->level; + } + + /** + * @param int $level + * + * @return IEntityMember + */ + public function setLevel(int $level): IEntityMember { + $this->level = $level; + + return $this; + } + + public function getLevelString(): string { + return $this->get((string) $this->level, IEntityMember::CONVERT_LEVEL, ''); + } + + + /** + * @return int + */ + public function getCreation(): int { + return $this->creation; + } + + /** + * @param int $creation + * + * @return IEntityMember + */ + public function setCreation(int $creation): IEntityMember { + $this->creation = $creation; + + return $this; + } + + + /** + * @param array $data + * + * @return IEntityMember + */ + public function importFromDatabase(array $data): IEntityMember { + $this->setId($this->get('id', $data, '')); + $this->setEntityId($this->get('entity_id', $data, '')); + $this->setAccountId($this->get('account_id', $data, '')); + $this->setSlaveEntityId($this->get('slave_entity_id', $data, '')); + $this->setStatus($this->get('status', $data, '')); + $this->setLevel($this->getInt('level', $data, 0)); + + try { + $creation = new DateTime($this->get('creation', $data, '')); + $this->setCreation($creation->getTimestamp()); + } catch (Exception $e) { + } + + return $this; + } + + + /** + * @return array + */ + public function jsonSerialize(): array { + return [ + 'id' => $this->getId(), + 'entity_id' => $this->getEntityId(), + 'account_id' => $this->getAccountId(), + 'slave_entity_id' => $this->getSlaveEntityId(), + 'type' => $this->getStatus(), + 'level' => $this->getLevel(), + 'account' => $this->account, + 'creation' => $this->getCreation() + ]; + } + +} + diff --git a/lib/private/Entities/Model/EntityType.php b/lib/private/Entities/Model/EntityType.php new file mode 100644 index 0000000000000..570a0f628e915 --- /dev/null +++ b/lib/private/Entities/Model/EntityType.php @@ -0,0 +1,209 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Entities\Model; + + +use daita\NcSmallPhpTools\Traits\TArrayTools; +use daita\NcSmallPhpTools\Traits\TStringTools; +use JsonSerializable; +use OCP\Entities\Model\IEntityType; +use stdClass; + + +/** + * Class EntityAccount + * + * @package OC\Entities\Model + */ +class EntityType implements IEntityType, JsonSerializable { + + + use TArrayTools; + use TStringTools; + + + /** @var int */ + private $id = 0; + + /** @var string */ + private $type = ''; + + /** @var string */ + private $interface = ''; + + /** @var string */ + private $className = ''; + + /** @var stdClass */ + private $class = null; + + + /** + * EntityType constructor. + * + * @param string $interface + * @param string $type + * @param string $className + */ + public function __construct(string $interface = '', string $type = '', string $className = '') { + $this->interface = $interface; + $this->type = $type; + $this->className = $className; + } + + + /** + * @return int + */ + public function getId(): int { + return $this->id; + } + + /** + * @param int $id + * + * @return IEntityType + */ + public function setId(int $id): IEntityType { + $this->id = $id; + + return $this; + } + + + /** + * @return string + */ + public function getType(): string { + return $this->type; + } + + /** + * @param string $type + * + * @return IEntityType + */ + public function setType(string $type): IEntityType { + $this->type = $type; + + return $this; + } + + + /** + * @return string + */ + public function getInterface(): string { + return $this->interface; + } + + /** + * @param string $interface + * + * @return IEntityType + */ + public function setInterface(string $interface): IEntityType { + $this->interface = $interface; + + return $this; + } + + + /** + * @return string + */ + public function getClassName(): string { + return $this->className; + } + + /** + * @param string $className + * + * @return IEntityType + */ + public function setClassName(string $className): IEntityType { + $this->className = $className; + + return $this; + } + + + /** + * @return bool + */ + public function hasClass(): bool { + return ($this->class !== null); + } + + /** + * @return stdClass + */ + public function getClass() { + return $this->class; + } + + /** + * @param stdClass $class + */ + public function setClass($class): void { + $this->class = $class; + } + + + /** + * @param array $data + * + * @return IEntityType + */ + public function importFromDatabase(array $data): IEntityType { + $this->setId($this->getInt('id', $data, 0)); + $this->setType($this->get('type', $data, '')); + $this->setInterface($this->get('interface', $data, '')); + $this->setClassName($this->get('class', $data, '')); + + return $this; + } + + + /** + * @return array + */ + public function jsonSerialize(): array { + return [ + 'id' => $this->getId(), + 'type' => $this->getType(), + 'interface' => $this->getInterface(), + 'class' => $this->getClassName() + ]; + } + +} + diff --git a/lib/private/Server.php b/lib/private/Server.php index 408b457ec390a..198a2653313fa 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -70,6 +70,9 @@ use OC\Contacts\ContactsMenu\ContactsStore; use OC\Diagnostics\EventLogger; use OC\Diagnostics\QueryLogger; +use OC\Entities\Helper\EntitiesHelper; +use OC\Entities\EntitiesManager; +use OC\Entities\Helper\EntitiesMigrationHelper; use OC\Federation\CloudFederationFactory; use OC\Federation\CloudFederationProviderManager; use OC\Federation\CloudIdManager; @@ -126,6 +129,7 @@ use OCA\Theming\ImageManager; use OCA\Theming\ThemingDefaults; +use OCA\Theming\Util; use OCP\Accounts\IAccountManager; use OCP\App\IAppManager; use OCP\AppFramework\Utility\ITimeFactory; @@ -133,7 +137,9 @@ use OCP\Contacts\ContactsMenu\IContactsStore; use OCP\Dashboard\IDashboardManager; use OCP\Defaults; -use OCA\Theming\Util; +use OCP\Entities\Helper\IEntitiesHelper; +use OCP\Entities\Helper\IEntitiesMigrationHelper; +use OCP\Entities\IEntitiesManager; use OCP\Federation\ICloudFederationFactory; use OCP\Federation\ICloudFederationProviderManager; use OCP\Federation\ICloudIdManager; @@ -1204,6 +1210,10 @@ public function __construct($webRoot, \OC\Config $config) { $this->registerAlias(IInitialStateService::class, InitialStateService::class); + $this->registerAlias(IEntitiesManager::class, EntitiesManager::class); + $this->registerAlias(IEntitiesHelper::class, EntitiesHelper::class); + $this->registerAlias(IEntitiesMigrationHelper::class, EntitiesMigrationHelper::class); + $this->connectDispatcher(); } @@ -2064,4 +2074,29 @@ public function getRemoteInstanceFactory() { public function getStorageFactory() { return $this->query(IStorageFactory::class); } + + /** + * @return IEntitiesManager + * @throws QueryException + */ + public function getEntitiesManager() { + return $this->query(IEntitiesManager::class); + } + + /** + * @return IEntitiesHelper + * @throws QueryException + */ + public function getEntitiesHelper() { + return $this->query(IEntitiesHelper::class); + } + + /** + * @return IEntitiesMigrationHelper + * @throws QueryException + */ + public function getEntitiesMigrationHelper() { + return $this->query(IEntitiesMigrationHelper::class); + } + } diff --git a/lib/public/Entities/Helper/IEntitiesHelper.php b/lib/public/Entities/Helper/IEntitiesHelper.php new file mode 100644 index 0000000000000..b337d189c6b00 --- /dev/null +++ b/lib/public/Entities/Helper/IEntitiesHelper.php @@ -0,0 +1,115 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Entities\Helper; + + +use OC\Entities\Exceptions\EntityAccountAlreadyExistsException; +use OC\Entities\Exceptions\EntityAccountCreationException; +use OC\Entities\Exceptions\EntityAccountNotFoundException; +use OC\Entities\Exceptions\EntityAlreadyExistsException; +use OC\Entities\Exceptions\EntityCreationException; +use OC\Entities\Exceptions\EntityMemberAlreadyExistsException; +use OCP\Entities\Model\IEntity; +use OCP\Entities\Model\IEntityAccount; +use OCP\Entities\Model\IEntityMember; +use OCP\Entities\Model\IEntityType; + +/** + * Interface IEntitiesMigrationHelper + * + * @since 17.0.0 + * + * @package OCP\Entities + */ +interface IEntitiesHelper { + + + /** + * @param string $userId + * @param string $displayName + * + * @return IEntity + * @throws EntityAccountCreationException + * @throws EntityCreationException + * @throws EntityAlreadyExistsException + */ + public function createLocalUser(string $userId, string $displayName = ''): IEntity; + + + /** + * @param string $userId + * + * @return IEntityAccount + * @throws EntityAccountNotFoundException + */ + public function getLocalAccount(string $userId): IEntityAccount; + + + /** + * @param string $entityId + * @param string $userId + * @param int $level + * @param string $status + * + * @return IEntityMember + * @throws EntityAccountCreationException + * @throws EntityCreationException + * @throws EntityAlreadyExistsException + * @throws EntityAccountAlreadyExistsException + * @throws EntityMemberAlreadyExistsException + */ + public function addLocalMember( + string $entityId, string $userId, int $level = IEntityMember::LEVEL_MEMBER, + string $status = '' + ): IEntityMember; + + public function inviteLocalMember(string $entityId, string $userId): IEntityMember; + + public function addVirtualMember(string $entityId, string $type, string $account): IEntityMember; + + /** + * @param string $interface + * + * @return IEntityType[] + */ + public function getEntityTypes(string $interface = ''): array; + + /** + * @param bool $admin + * + * @return IEntityAccount + */ + public function temporaryLocalAccount(bool $admin = false): IEntityAccount; + + public function refreshInstall(); + +} + diff --git a/lib/public/Entities/Helper/IEntitiesMigrationHelper.php b/lib/public/Entities/Helper/IEntitiesMigrationHelper.php new file mode 100644 index 0000000000000..f976ac9f94b0c --- /dev/null +++ b/lib/public/Entities/Helper/IEntitiesMigrationHelper.php @@ -0,0 +1,56 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Entities\Helper; + + +/** + * Interface IEntitiesMigrationHelper + * + * @since 17.0.0 + * + * @package OCP\Entities + */ +interface IEntitiesMigrationHelper { + + + public function migrateUsers(): void; + + + public function migrateGroups(): void; + + + public function migrateCircles(): void; + + + public function migrateRooms(): void; + +} + diff --git a/lib/public/Entities/IEntitiesManager.php b/lib/public/Entities/IEntitiesManager.php new file mode 100644 index 0000000000000..46daf31a25640 --- /dev/null +++ b/lib/public/Entities/IEntitiesManager.php @@ -0,0 +1,253 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Entities; + + +use Exception; +use OC\Entities\Exceptions\EntityAccountAlreadyExistsException; +use OC\Entities\Exceptions\EntityAccountCreationException; +use OC\Entities\Exceptions\EntityAccountNotFoundException; +use OC\Entities\Exceptions\EntityAlreadyExistsException; +use OC\Entities\Exceptions\EntityCreationException; +use OC\Entities\Exceptions\EntityMemberAlreadyExistsException; +use OC\Entities\Exceptions\EntityMemberNotFoundException; +use OC\Entities\Exceptions\EntityNotFoundException; +use OC\Entities\Exceptions\EntityTypeNotFoundException; +use OCP\Entities\Model\IEntity; +use OCP\Entities\Model\IEntityAccount; +use OCP\Entities\Model\IEntityMember; + + +/** + * Interface IEntitiesManager + * + * @since 17.0.0 + * + * @package OCP\Entities + */ +interface IEntitiesManager { + + + /** + * @param IEntity $entity + * @param string $ownerId + * + * @throws EntityCreationException + * @throws EntityAlreadyExistsException + * @throws EntityMemberAlreadyExistsException + */ + public function saveEntity(IEntity $entity, string $ownerId = ''): void; + + /** + * @param string $entityId + * + * @return mixed + */ + public function deleteEntity(string $entityId): void; + + + /** + * @param IEntity $entity + * + * @return IEntity + * @throws EntityNotFoundException + * @throws EntityTypeNotFoundException + */ + public function searchDuplicateEntity(IEntity $entity): IEntity; + + + /** + * @param IEntityAccount $account + * + * @throws EntityAccountCreationException + * @throws EntityAccountAlreadyExistsException + */ + public function saveAccount(IEntityAccount $account): void; + + /** + * @param string $accountId + * + * @return mixed + */ + public function deleteAccount(string $accountId): void; + + + /** + * @param IEntityMember $member + * + * @throws EntityMemberAlreadyExistsException + */ + public function saveMember(IEntityMember $member): void; + + /** + * @param string $memberId + * + * @return mixed + */ + public function deleteMember(string $memberId): void; + + + /** + * @param string $type + * + * @return IEntity[] + */ + public function getAllEntities(string $type = ''): array; + + + /** + * @param string $type + * + * @return IEntityAccount[] + */ + public function getAllAccounts(string $type = ''): array; + + + /** + * @param IEntityAccount $viewer + */ + public function setViewer(IEntityAccount $viewer): void; + + + /** + * @param string $needle + * @param string $type + * + * @return IEntity[] + */ + public function searchEntities(string $needle, string $type = ''): array; + + + /** + * @param string $needle + * @param string $type + * + * @return IEntityAccount[] + */ + public function searchAccounts(string $needle, string $type = ''): array; + + + /** + * @param string $entityId + * + * @return IEntity + * @throws EntityNotFoundException + */ + public function getEntity(string $entityId): IEntity; + + + /** + * @param string $accountId + * + * @return IEntityAccount + * @throws EntityAccountNotFoundException + */ + public function getAccount(string $accountId): IEntityAccount; + + + /** + * @param string $memberId + * + * @return IEntityMember + * @throws EntityMemberNotFoundException + */ + public function getMember(string $memberId): IEntityMember; + + + /** + * @param IEntity $entity + * + * @return IEntity[] + */ + public function entityBelongsTo(IEntity $entity): array; + + + /** + * @param IEntity $entity + * + * @return IEntityMember[] + */ + public function entityGetMembers(IEntity $entity): array; + + + /** + * @param IEntity $entity + * + * @return bool + */ + public function entityHasAdminRights(IEntity $entity): bool; + + + /** + * @param IEntityAccount $account + * + * @return IEntityMember[] + */ + public function accountBelongsTo(IEntityAccount $account): array; + + + /** + * @param IEntityAccount $account + * + * @return bool + */ + public function accountHasAdminRights(IEntityAccount $account): bool; + + + /** + * @param IEntityAccount $account + * @param string $entityId + * + * @return mixed + */ + public function accountInviteTo(IEntityAccount $account, string $entityId): void; + + + /** + * @param IEntitiesQueryBuilder $param + * @param float $time + * @param Exception|null $e + * + * @return mixed + */ + public function logSql(IEntitiesQueryBuilder $param, float $time, $e = null); + + + /** + * @param IEntity $entity + * + * @return IEntityMember + */ + public function entityPointOfView(IEntity $entity): IEntityMember; + + +} + diff --git a/lib/public/Entities/IEntitiesQueryBuilder.php b/lib/public/Entities/IEntitiesQueryBuilder.php new file mode 100644 index 0000000000000..5852ae6b2f914 --- /dev/null +++ b/lib/public/Entities/IEntitiesQueryBuilder.php @@ -0,0 +1,63 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Entities; + + +use daita\NcSmallPhpTools\IExtendedQueryBuilder; + + +/** + * Interface IEntitiesQueryBuilder + * + * @since 17.0.0 + * + * @package OCP\Entities + */ +interface IEntitiesQueryBuilder extends IExtendedQueryBuilder { + + public function getComment(): array; + + public function limitToInterface(string $type): IEntitiesQueryBuilder; + + public function limitToType(string $type): IEntitiesQueryBuilder; + + public function limitToOwnerId(string $type): IEntitiesQueryBuilder; + + public function limitToName(string $name): IEntitiesQueryBuilder; + + public function limitToAccount(string $account): IEntitiesQueryBuilder; + +// public function limitToAccess(string $access); + +// public function limitToVisibility(string $visibility); + +} + diff --git a/lib/public/Entities/Interface/IEntities/IEntities.php b/lib/public/Entities/Interface/IEntities/IEntities.php new file mode 100644 index 0000000000000..97f86b13eb01e --- /dev/null +++ b/lib/public/Entities/Interface/IEntities/IEntities.php @@ -0,0 +1,48 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Entities\Implementation\IEntities; + + +use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\Entities\Model\IEntity; + + +/** + * Interface IEntities + * + * @package OCP\Entities\Implementation\IEntities + */ +interface IEntities { + + const INTERFACE = 'IEntities'; + +} + diff --git a/lib/public/Entities/Interface/IEntities/IEntitiesAdminCreation.php b/lib/public/Entities/Interface/IEntities/IEntitiesAdminCreation.php new file mode 100644 index 0000000000000..d2ecd1ebaaa24 --- /dev/null +++ b/lib/public/Entities/Interface/IEntities/IEntitiesAdminCreation.php @@ -0,0 +1,42 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Entities\Implementation\IEntities; + + +/** + * Interface IEntitiesAdminCreation + * + * @package OCP\Entities\Implementation\IEntities + */ +interface IEntitiesAdminCreation { + +} + diff --git a/lib/public/Entities/Interface/IEntities/IEntitiesAdminRights.php b/lib/public/Entities/Interface/IEntities/IEntitiesAdminRights.php new file mode 100644 index 0000000000000..3f954463f0e67 --- /dev/null +++ b/lib/public/Entities/Interface/IEntities/IEntitiesAdminRights.php @@ -0,0 +1,53 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Entities\Implementation\IEntities; + + +use OCP\Entities\Model\IEntity; + + +/** + * Interface IEntitiesAdminRights + * + * @package OCP\Entities\Implementation\IEntities + */ +interface IEntitiesAdminRights { + + + /** + * @param IEntity $entity + * + * @return bool + */ + public function hasAdminRights(IEntity $entity): bool; + +} + diff --git a/lib/public/Entities/Interface/IEntities/IEntitiesConfirmCreation.php b/lib/public/Entities/Interface/IEntities/IEntitiesConfirmCreation.php new file mode 100644 index 0000000000000..6d121c9668b96 --- /dev/null +++ b/lib/public/Entities/Interface/IEntities/IEntitiesConfirmCreation.php @@ -0,0 +1,49 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Entities\Implementation\IEntities; + + +use OC\Entities\Exceptions\EntityCreationException; +use OCP\Entities\Model\IEntity; + + +interface IEntitiesConfirmCreation { + + + /** + * @param IEntity $entity + * + * @throws EntityCreationException + */ + public function confirmCreationStatus(IEntity $entity): void; + +} + diff --git a/lib/public/Entities/Interface/IEntities/IEntitiesOwnerFree.php b/lib/public/Entities/Interface/IEntities/IEntitiesOwnerFree.php new file mode 100644 index 0000000000000..7c1d73328d0de --- /dev/null +++ b/lib/public/Entities/Interface/IEntities/IEntitiesOwnerFree.php @@ -0,0 +1,42 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Entities\Implementation\IEntities; + + +/** + * Interface IEntitiesOwnerFree + * + * @package OCP\Entities\Implementation\IEntities + */ +interface IEntitiesOwnerFree { + +} + diff --git a/lib/public/Entities/Interface/IEntities/IEntitiesOwnerIsNotMember.php b/lib/public/Entities/Interface/IEntities/IEntitiesOwnerIsNotMember.php new file mode 100644 index 0000000000000..8f9341a7af0f4 --- /dev/null +++ b/lib/public/Entities/Interface/IEntities/IEntitiesOwnerIsNotMember.php @@ -0,0 +1,46 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Entities\Implementation\IEntities; + + +use OCP\DB\QueryBuilder\ICompositeExpression; +use OCP\Entities\IEntitiesQueryBuilder; + + +/** + * Interface IEntitiesOwnerIsNotMember + * + * @package OCP\Entities\Implementation\IEntities + */ +interface IEntitiesOwnerIsNotMember { + +} + diff --git a/lib/public/Entities/Interface/IEntities/IEntitiesSearchDuplicate.php b/lib/public/Entities/Interface/IEntities/IEntitiesSearchDuplicate.php new file mode 100644 index 0000000000000..b826e83d36df0 --- /dev/null +++ b/lib/public/Entities/Interface/IEntities/IEntitiesSearchDuplicate.php @@ -0,0 +1,43 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Entities\Implementation\IEntities; + + +use OCP\Entities\IEntitiesQueryBuilder; +use OCP\Entities\Model\IEntity; + + +interface IEntitiesSearchDuplicate { + + public function buildSearchDuplicate(IEntitiesQueryBuilder $qb, IEntity $entity); + +} + diff --git a/lib/public/Entities/Interface/IEntities/IEntitiesSearchEntities.php b/lib/public/Entities/Interface/IEntities/IEntitiesSearchEntities.php new file mode 100644 index 0000000000000..d70409ca4dd9f --- /dev/null +++ b/lib/public/Entities/Interface/IEntities/IEntitiesSearchEntities.php @@ -0,0 +1,55 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Entities\Implementation\IEntities; + + +use OCP\DB\QueryBuilder\ICompositeExpression; +use OCP\Entities\IEntitiesQueryBuilder; + + +/** + * Interface IEntitiesSearchEntities + * + * @package OCP\Entities\Implementation\IEntities + */ +interface IEntitiesSearchEntities { + + + /** + * @param IEntitiesQueryBuilder $qb + * @param string $needle + * + * @return ICompositeExpression + */ + public function exprSearchEntities(IEntitiesQueryBuilder $qb, string $needle): ICompositeExpression; + +} + diff --git a/lib/public/Entities/Interface/IEntitiesAccounts/IEntitiesAccounts.php b/lib/public/Entities/Interface/IEntitiesAccounts/IEntitiesAccounts.php new file mode 100644 index 0000000000000..725a1bb284bd9 --- /dev/null +++ b/lib/public/Entities/Interface/IEntitiesAccounts/IEntitiesAccounts.php @@ -0,0 +1,44 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Entities\Implementation\IEntitiesAccounts; + + +/** + * Interface IEntitiesAccounts + * + * @package OCP\Entities\Implementation\IEntitiesAccounts + */ +interface IEntitiesAccounts { + + const INTERFACE = 'IEntitiesAccounts'; + +} + diff --git a/lib/public/Entities/Interface/IEntitiesAccounts/IEntitiesAccountsHasAdminRights.php b/lib/public/Entities/Interface/IEntitiesAccounts/IEntitiesAccountsHasAdminRights.php new file mode 100644 index 0000000000000..80030f1e73784 --- /dev/null +++ b/lib/public/Entities/Interface/IEntitiesAccounts/IEntitiesAccountsHasAdminRights.php @@ -0,0 +1,42 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Entities\Implementation\IEntitiesAccounts; + + +/** + * Interface IEntitiesAccountsAdminRights + * + * @package OCP\Entities\Implementation\IEntitiesAccounts + */ +interface IEntitiesAccountsHasAdminRights { + +} + diff --git a/lib/public/Entities/Interface/IEntitiesAccounts/IEntitiesAccountsSearchAccounts.php b/lib/public/Entities/Interface/IEntitiesAccounts/IEntitiesAccountsSearchAccounts.php new file mode 100644 index 0000000000000..9816b5ca12f4c --- /dev/null +++ b/lib/public/Entities/Interface/IEntitiesAccounts/IEntitiesAccountsSearchAccounts.php @@ -0,0 +1,54 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Entities\Implementation\IEntitiesAccounts; + + +use OCP\DB\QueryBuilder\ICompositeExpression; +use OCP\Entities\IEntitiesQueryBuilder; + + +/** + * Interface IEntitiesAccountsSearchDuplicate + * + * @package OCP\Entities\Implementation\IEntitiesAccounts + */ +interface IEntitiesAccountsSearchAccounts { + + /** + * @param IEntitiesQueryBuilder $qb + * @param string $needle + * + * @return ICompositeExpression + */ + public function exprSearchAccounts(IEntitiesQueryBuilder $qb, string $needle): ICompositeExpression; + +} + diff --git a/lib/public/Entities/Interface/IEntitiesAccounts/IEntitiesAccountsSearchDuplicate.php b/lib/public/Entities/Interface/IEntitiesAccounts/IEntitiesAccountsSearchDuplicate.php new file mode 100644 index 0000000000000..d1abe88d85f37 --- /dev/null +++ b/lib/public/Entities/Interface/IEntitiesAccounts/IEntitiesAccountsSearchDuplicate.php @@ -0,0 +1,48 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Entities\Implementation\IEntitiesAccounts; + + +use OCP\Entities\IEntitiesQueryBuilder; +use OCP\Entities\Model\IEntityAccount; + + +/** + * Interface IEntitiesAccountsSearchDuplicate + * + * @package OCP\Entities\Implementation\IEntitiesAccounts + */ +interface IEntitiesAccountsSearchDuplicate { + + public function buildSearchDuplicate(IEntitiesQueryBuilder $qb, IEntityAccount $entity); + +} + diff --git a/lib/public/Entities/Interface/IEntitiesAccounts/IEntitiesAccountsSearchEntities.php b/lib/public/Entities/Interface/IEntitiesAccounts/IEntitiesAccountsSearchEntities.php new file mode 100644 index 0000000000000..7b50d68cc11a6 --- /dev/null +++ b/lib/public/Entities/Interface/IEntitiesAccounts/IEntitiesAccountsSearchEntities.php @@ -0,0 +1,54 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Entities\Implementation\IEntitiesAccounts; + + +use OCP\DB\QueryBuilder\ICompositeExpression; +use OCP\Entities\IEntitiesQueryBuilder; + + +/** + * Interface IEntitiesAccountsSearchDuplicate + * + * @package OCP\Entities\Implementation\IEntitiesAccounts + */ +interface IEntitiesAccountsSearchEntities { + + /** + * @param IEntitiesQueryBuilder $qb + * @param string $needle + * + * @return ICompositeExpression + */ + public function exprSearchEntities(IEntitiesQueryBuilder $qb, string $needle): ICompositeExpression; + +} + diff --git a/lib/public/Entities/Model/IEntity.php b/lib/public/Entities/Model/IEntity.php new file mode 100644 index 0000000000000..1d1aff32ae435 --- /dev/null +++ b/lib/public/Entities/Model/IEntity.php @@ -0,0 +1,128 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Entities\Model; + + +/** + * Interface IEntity + * + * @package OCP\Entities\Model + */ +interface IEntity { + + + const VISIBILITY_ALL = 0; + const VISIBILITY_MEMBERS = 1; + const VISIBILITY_MODERATORS = 5; + const VISIBILITY_ADMIN = 8; + const VISIBILITY_NONE = 9; + + const CONVERT_VISIBILITY = [ + 0 => 'all', + 1 => 'members', + 5 => 'moderators', + 8 => 'admin', + 9 => 'none' + ]; + + const ACCESS_LIMITED = 0; + const ACCESS_INVITE_ONLY = 3; + const ACCESS_REQUEST_NEEDED = 6; + const ACCESS_FREE = 9; + + const CONVERT_ACCESS = [ + 0 => 'limited', + 3 => 'invite_only', + 6 => 'request_needed', + 9 => 'free' + ]; + + + public function getId(): string; + + public function setId(string $id): IEntity; + + public function getType(): string; + + public function getOwnerId(): string; + + public function getVisibility(): int; + + public function getAccess(): int; + + public function getVisibilityString(): string; + + public function getAccessString(): string; + + public function getName(): string; + + public function setCreation(int $creation): IEntity; + + public function getCreation(): int; + +// public function getMembers(): array; +// +// public function setMembers(array $members): IEntity; +// +// public function addMembers(array $members): IEntity; +// +// public function addMember(IEntityMember $members): IEntity; + + public function hasOwner(): bool; + + public function setOwner(IEntityAccount $owner): IEntity; + + public function getOwner(): IEntityAccount; + + public function hasViewer(): bool; + + public function setViewer(IEntityMember $viewer): IEntity; + + public function getViewer(): IEntityMember; + + + /** + * @return IEntity[] + */ + public function belongsTo(): array; + + /** + * @return IEntityMember[] + */ + public function getMembers(): array; + + /** + * @return bool + */ + public function hasAdminRights(): bool; + +} + diff --git a/lib/public/Entities/Model/IEntityAccount.php b/lib/public/Entities/Model/IEntityAccount.php new file mode 100644 index 0000000000000..f33a6429f9e6e --- /dev/null +++ b/lib/public/Entities/Model/IEntityAccount.php @@ -0,0 +1,69 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Entities\Model; + + +use daita\NcSmallPhpTools\Model\Options; + + +/** + * Interface IEntityAccount + * + * @package OCP\Entities\Model + */ +interface IEntityAccount { + + + public function getId(): string; + + public function getType(): string; + + public function getAccount(): string; + + public function getDeleteOn(): int; + + public function getCreation(): int; + + public function setCreation(int $creation): IEntityAccount; + + public function getOptions(): Options; + + /** + * @return IEntityMember[] + */ + public function belongsTo(): array; + + public function hasAdminRights(): bool; + + public function inviteTo(string $getId): void; + +} + diff --git a/lib/public/Entities/Model/IEntityMember.php b/lib/public/Entities/Model/IEntityMember.php new file mode 100644 index 0000000000000..8ce2556c69abf --- /dev/null +++ b/lib/public/Entities/Model/IEntityMember.php @@ -0,0 +1,99 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Entities\Model; + + +/** + * Interface IEntityMember + * + * @package OCP\Entities\Model + */ +interface IEntityMember { + + + const LEVEL_MEMBER = 1; + const LEVEL_MODERATOR = 5; + const LEVEL_ADMIN = 8; + const LEVEL_OWNER = 9; + + const CONVERT_LEVEL = [ + 0 => 'none', + 1 => 'member', + 5 => 'moderator', + 8 => 'admin', + 9 => 'owner' + ]; + + const STATUS_INVITED = 'invited'; + const STATUS_REQUESTING = 'requesting'; + const STATUS_MEMBER = 'member'; + + + public function getId(): string; + +// public function setId(string $id): IEntityMember; + + public function getEntityId(): string; + +// public function setEntityId(string $entityId): IEntityMember; + + public function getEntity(): IEntity; + + public function hasAccount(): bool; + + public function getAccount(): IEntityAccount; + +// public function setAccount(IEntityAccount $account); + + public function getAccountId(): string; + +// public function setAccountId(string $accountId): IEntityMember; + + public function getSlaveEntityId(): string; + +// public function setSlaveEntityId(string $slaveEntityId): IEntityMember; + + public function getStatus(): string; + +// public function setStatus(string $status): IEntityMember; + + public function getLevel(): int; + + public function getLevelString(): string; + +// public function setLevel(int $level): IEntityMember; + + public function getCreation(): int; + + public function setCreation(int $creation): IEntityMember; + +} + diff --git a/lib/public/Entities/Model/IEntityType.php b/lib/public/Entities/Model/IEntityType.php new file mode 100644 index 0000000000000..6af1c55d09837 --- /dev/null +++ b/lib/public/Entities/Model/IEntityType.php @@ -0,0 +1,58 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Entities\Model; + + +use stdClass; + +/** + * Interface IEntityType + * + * @package OCP\Entities\Model + */ +interface IEntityType { + + public function getId(): int; + + public function getType(): string; + + public function getInterface(): string; + + public function getClassName(): string; + + public function hasClass(): bool; + + public function getClass(); + + public function setClass($class); + +} + diff --git a/version.php b/version.php index f0f2ccb52bbc5..8f0b17207cc18 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ // between betas, final and RCs. This is _not_ the public version number. Reset minor/patchlevel // when updating major/minor version number. -$OC_Version = array(17, 0, 0, 1); +$OC_Version = array(17, 0, 0, 2); // The human readable string $OC_VersionString = '17.0.0 alpha';