forked from neos/neos-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorkspaceHelper.php
78 lines (70 loc) · 2.52 KB
/
WorkspaceHelper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace Neos\Neos\Ui\Fusion\Helper;
/*
* This file is part of the Neos.Neos.Ui package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
use Neos\ContentRepository\Core\Factory\ContentRepositoryId;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Eel\ProtectedContextAwareInterface;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Security\Context;
use Neos\Neos\Domain\Service\WorkspaceNameBuilder;
use Neos\Neos\Ui\ContentRepository\Service\WorkspaceService;
/**
* @internal implementation detail of the Neos Ui to build its initialState.
* and used for the workspace-info endpoint.
*/
class WorkspaceHelper implements ProtectedContextAwareInterface
{
/**
* @Flow\Inject
* @var ContentRepositoryRegistry
*/
protected $contentRepositoryRegistry;
/**
* @Flow\Inject
* @var WorkspaceService
*/
protected $workspaceService;
/**
* @Flow\Inject
* @var Context
*/
protected $securityContext;
/**
* @return array<string,mixed>
*/
public function getPersonalWorkspace(ContentRepositoryId $contentRepositoryId): array
{
$contentRepository = $this->contentRepositoryRegistry->get($contentRepositoryId);
$currentAccount = $this->securityContext->getAccount();
// todo use \Neos\Neos\Service\UserService::getPersonalWorkspaceName instead?
$personalWorkspaceName = WorkspaceNameBuilder::fromAccountIdentifier($currentAccount->getAccountIdentifier());
$personalWorkspace = $contentRepository->getWorkspaceFinder()->findOneByName($personalWorkspaceName);
return !is_null($personalWorkspace)
? [
'name' => $personalWorkspace->workspaceName,
'publishableNodes' => $this->workspaceService->getPublishableNodeInfo($personalWorkspaceName, $contentRepositoryId),
'baseWorkspace' => $personalWorkspace->baseWorkspaceName,
// TODO: FIX readonly flag!
//'readOnly' => !$this->domainUserService->currentUserCanPublishToWorkspace($baseWorkspace)
'readOnly' => false,
'status' => $personalWorkspace->status->value
]
: [];
}
/**
* @param string $methodName
* @return bool
*/
public function allowsCallOfMethod($methodName)
{
return true;
}
}