Skip to content

Commit

Permalink
IBX-3966: Used user_content_type_identifier configuration key insid…
Browse files Browse the repository at this point in the history
…e user service
  • Loading branch information
ViniTou committed Oct 4, 2022
1 parent 30b2587 commit 9f8bedd
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 14 deletions.
3 changes: 3 additions & 0 deletions src/bundle/Core/ApiLoader/RepositoryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ public function buildRepository(
'default_version_archive_limit' => $config['options']['default_version_archive_limit'],
'remove_archived_versions_on_publish' => $config['options']['remove_archived_versions_on_publish'],
],
'user' => [
'user_content_type_identifier' => $this->configResolver->getParameter('user_content_type_identifier'),
],
],
$this->logger
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Bundle\Core\DependencyInjection\Configuration\Parser;

use Ibexa\Bundle\Core\DependencyInjection\Configuration\AbstractParser;
use Ibexa\Bundle\Core\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface;
use Symfony\Component\Config\Definition\Builder\NodeBuilder;

/**
* Configuration parser for user identifier configuration.
*
* Example configuration:
* ```yaml
* ibexa:
* system:
* default: # configuration per siteaccess or siteaccess group
* user_content_type_identifier: ['user', 'my_custom_user_identifier']
* ```
*/
class UserIdentifier extends AbstractParser
{
/**
* Adds semantic configuration definition.
*
* @param \Symfony\Component\Config\Definition\Builder\NodeBuilder $nodeBuilder Node just under ezpublish.system.<siteaccess>
*/
public function addSemanticConfig(NodeBuilder $nodeBuilder)
{
$nodeBuilder
->arrayNode('user_content_type_identifier')
->info('User Content Type identifier configuration.')
->example(['user', 'my_custom_user_identifier'])
->requiresAtLeastOneElement()
->prototype('scalar')->end()
->end();
}

/**
* {@inheritdoc}
*/
public function mapConfig(array &$scopeSettings, $currentScope, ContextualizerInterface $contextualizer): void
{
if (empty($scopeSettings['user_content_type_identifier'])) {
return;
}

$contextualizer->setContextualParameter(
'user_content_type_identifier',
$currentScope,
$scopeSettings['user_content_type_identifier']
);
}
}

class_alias(UserIdentifier::class, 'EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Configuration\Parser\UserIdentifier');
class_alias(UserIdentifier::class, 'Ibexa\Bundle\AdminUi\DependencyInjection\Configuration\Parser\UserIdentifier');
1 change: 1 addition & 0 deletions src/bundle/Core/IbexaCoreBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public function getContainerExtension()
new ConfigParser\IO(new ComplexSettingParser()),
new ConfigParser\UrlChecker(),
new ConfigParser\TwigVariablesParser(),
new ConfigParser\UserIdentifier(),
],
[
new RepositoryConfigParser\Storage(),
Expand Down
1 change: 1 addition & 0 deletions src/bundle/Core/Resources/config/default_settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ parameters:
ibexa.site_access.config.default.storage_dir: "storage" # Where to place new files for storage, it's relative to var directory
ibexa.site_access.config.default.binary_dir: "original"
ibexa.site_access.config.default.anonymous_user_id: 10 # The ID of the user to be used for everyone who is not logged in
ibexa.site_access.config.default.user_content_type_identifier: ['user']
ibexa.site_access.config.default.api_keys: { google_maps: ~ } # Google Maps APIs v3 key (https://developers.google.com/maps/documentation/javascript/get-api-key)

# IO
Expand Down
7 changes: 6 additions & 1 deletion src/lib/Base/Container/ApiLoader/RepositoryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function __construct(
* directly to make sure you get an instance wrapped inside Event / Cache / * functionality.
*
* @param string[] $languages
* @param string[] $userContentTypeIdentifierList
*/
public function buildRepository(
PersistenceHandler $persistenceHandler,
Expand All @@ -81,7 +82,8 @@ public function buildRepository(
ContentFilteringHandler $contentFilteringHandler,
LocationFilteringHandler $locationFilteringHandler,
PasswordValidatorInterface $passwordValidator,
array $languages
array $languages,
array $userContentTypeIdentifierList
): Repository {
return new $this->repositoryClass(
$persistenceHandler,
Expand All @@ -108,6 +110,9 @@ public function buildRepository(
'policyMap' => $this->policyMap,
],
'languages' => $languages,
'user' => [
'user_content_type_identifier' => $userContentTypeIdentifierList,
],
],
);
}
Expand Down
32 changes: 19 additions & 13 deletions src/lib/Repository/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Ibexa\Contracts\Core\Repository\Values\Content\Location;
use Ibexa\Contracts\Core\Repository\Values\Content\LocationQuery;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\ContentTypeId as CriterionContentTypeId;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\ContentTypeIdentifier as CriterionContentTypeIdentifier;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\LocationId as CriterionLocationId;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\LogicalAnd as CriterionLogicalAnd;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\ParentLocationId as CriterionParentLocationId;
Expand Down Expand Up @@ -114,7 +115,7 @@ public function __construct(
// Union makes sure default settings are ignored if provided in argument
$this->settings = $settings + [
'defaultUserPlacement' => 12,
'userClassID' => 4, // @todo Rename this settings to swap out "Class" for "Type"
'userClassID' => 4, // @deprecated, use `user_content_type_identifier` configuration instead
'userGroupClassID' => 3,
'hashType' => $passwordHashGenerator->getDefaultHashType(),
'siteName' => 'ibexa.co',
Expand Down Expand Up @@ -1043,11 +1044,15 @@ public function loadUsersOfUserGroup(

$searchQuery = new LocationQuery();

$contentTypesCriterions = [];

foreach ($this->settings['user_content_type_identifier'] as $contentTypeIdentifier) {
$contentTypesCriterions[] = new CriterionContentTypeIdentifier($contentTypeIdentifier);
}
$contentTypesCriterions[] = new CriterionParentLocationId($mainGroupLocation->id);

$searchQuery->filter = new CriterionLogicalAnd(
[
new CriterionContentTypeId($this->settings['userClassID']),
new CriterionParentLocationId($mainGroupLocation->id),
]
$contentTypesCriterions
);

$searchQuery->offset = $offset;
Expand Down Expand Up @@ -1077,7 +1082,11 @@ public function loadUsersOfUserGroup(
public function isUser(APIContent $content): bool
{
// First check against config for fast check
if ($this->settings['userClassID'] == $content->getVersionInfo()->getContentInfo()->contentTypeId) {
if (in_array(
$content->getVersionInfo()->getContentInfo()->getContentType()->identifier,
$this->settings['user_content_type_identifier'],
true
)) {
return true;
}

Expand Down Expand Up @@ -1114,9 +1123,8 @@ public function isUserGroup(APIContent $content): bool
public function newUserCreateStruct(string $login, string $email, string $password, string $mainLanguageCode, ?ContentType $contentType = null): APIUserCreateStruct
{
if ($contentType === null) {
$contentType = $this->repository->getContentTypeService()->loadContentType(
$this->settings['userClassID']
);
$defaultIdentifier = reset($this->settings['user_content_type_identifier']);
$contentType = $this->repository->getContentTypeService()->loadContentTypeByIdentifier($defaultIdentifier);
}

$fieldDefIdentifier = '';
Expand Down Expand Up @@ -1206,10 +1214,8 @@ public function validatePassword(string $password, PasswordValidationContext $co
$errors = [];

if ($context === null) {
$contentType = $this->repository->getContentTypeService()->loadContentType(
$this->settings['userClassID']
);

$defaultIdentifier = reset($this->settings['user_content_type_identifier']);
$contentType = $this->repository->getContentTypeService()->loadContentTypeByIdentifier($defaultIdentifier);
$context = new PasswordValidationContext([
'contentType' => $contentType,
]);
Expand Down
1 change: 1 addition & 0 deletions src/lib/Resources/settings/repository/inner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ services:
- '@Ibexa\Contracts\Core\Persistence\Filter\Location\Handler'
- '@Ibexa\Core\Repository\User\PasswordValidatorInterface'
- '%languages%'
- '%user_content_type_identifier_list%'

Ibexa\Core\Repository\ContentService:
class: Ibexa\Core\Repository\ContentService
Expand Down
1 change: 1 addition & 0 deletions src/lib/Resources/settings/repository/siteaccessaware.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ parameters:
ibexa.io.dir.storage: var/ibexa_demo_site/storage
ibexa.legacy.url_prefix: var/ibexa_demo_site/storage
ibexa.url_prefix: var/ibexa_demo_site/storage
user_content_type_identifier_list: ['user']

services:
Ibexa\Core\Repository\SiteAccessAware\Repository:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ parameters:
name_field_identifier: name
parent_location_id: 51

ibexa.site_access.config.default.user_content_type_identifier: ['user']

services:
Ibexa\Core\FieldType\ImageAsset\AssetMapper:
arguments:
Expand Down

0 comments on commit 9f8bedd

Please sign in to comment.