Skip to content

Commit c6e4352

Browse files
authored
Merge pull request #4174 from neos/feature/4173-initiatingUserId-from-neos-user
FEATURE: Set InitiatingUserId from authenticated Neos user
2 parents 0a0b327 + 98d9baf commit c6e4352

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Neos\Neos\UserIdProvider;
6+
7+
use Neos\ContentRepository\Core\SharedModel\User\UserId;
8+
use Neos\ContentRepository\Core\SharedModel\User\UserIdProviderInterface;
9+
use Neos\Neos\Domain\Service\UserService;
10+
11+
/**
12+
* @api
13+
*/
14+
final class UserIdProvider implements UserIdProviderInterface
15+
{
16+
public function __construct(
17+
private readonly UserService $userService
18+
) {
19+
}
20+
21+
public function getUserId(): UserId
22+
{
23+
$userId = $this->userService->getCurrentUserIdentifier();
24+
if ($userId === null) {
25+
return UserId::forSystemUser();
26+
}
27+
return UserId::fromString($userId->value);
28+
}
29+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Neos\Neos\UserIdProvider;
6+
7+
use Neos\ContentRepository\Core\Factory\ContentRepositoryId;
8+
use Neos\ContentRepository\Core\SharedModel\User\UserIdProviderInterface;
9+
use Neos\ContentRepositoryRegistry\Factory\UserIdProvider\UserIdProviderFactoryInterface;
10+
use Neos\Flow\Annotations as Flow;
11+
use Neos\Neos\Domain\Service\UserService;
12+
13+
/**
14+
* Implementation of the Neos AssetUsageStrategyInterface in order to protect assets in use
15+
* to be deleted via the Media Module.
16+
*
17+
* @api
18+
*/
19+
#[Flow\Scope('singleton')]
20+
final class UserIdProviderFactory implements UserIdProviderFactoryInterface
21+
{
22+
public function __construct(
23+
private readonly UserService $userService
24+
) {
25+
}
26+
27+
/**
28+
* @param array<string, mixed> $options
29+
*/
30+
public function build(ContentRepositoryId $contentRepositoryId, array $options): UserIdProviderInterface
31+
{
32+
return new UserIdProvider($this->userService);
33+
}
34+
}

Neos.Neos/Configuration/Settings.ContentRepositoryRegistry.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ Neos:
22
ContentRepositoryRegistry:
33
presets:
44
'default':
5+
6+
userIdProvider:
7+
factoryObjectName: Neos\Neos\UserIdProvider\UserIdProviderFactory
8+
59
projections:
610
'Neos.Neos:DocumentUriPathProjection':
711
factoryObjectName: Neos\Neos\FrontendRouting\Projection\DocumentUriPathProjectionFactory

0 commit comments

Comments
 (0)