Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX: Remove Neos WorkspaceName #4534

Merged
merged 5 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,32 +91,6 @@ public function findOneByCurrentContentStreamId(
return $workspace;
}

/**
* @return array<string,Workspace>
*/
public function findByPrefix(WorkspaceName $prefix): array
{
$result = [];

$connection = $this->client->getConnection();
$workspaceRows = $connection->executeQuery(
'
SELECT * FROM ' . $this->tableName . '
WHERE workspaceName LIKE :workspaceNameLike
',
[
'workspaceNameLike' => $prefix->value . '%'
]
)->fetchAllAssociative();

foreach ($workspaceRows as $workspaceRow) {
$similarlyNamedWorkspace = $this->createWorkspaceFromDatabaseRow($workspaceRow);
$result[$similarlyNamedWorkspace->workspaceName->value] = $similarlyNamedWorkspace;
}

return $result;
}

/**
* @return array<string,Workspace>
* @throws \Doctrine\DBAL\DBALException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,53 +15,52 @@
namespace Neos\Neos\Controller\Module\Management;

use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Dto\NodeIdsToPublishOrDiscard;
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Dto\NodeIdToPublishOrDiscard;
use Neos\ContentRepository\Core\Feature\WorkspaceCreation\Exception\WorkspaceAlreadyExists;
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindAncestorNodesFilter;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodeTypeConstraints;
use Neos\ContentRepository\Core\SharedModel\Node\NodeName;
use Neos\Flow\I18n\Exception\IndexOutOfBoundsException;
use Neos\Flow\I18n\Exception\InvalidFormatPlaceholderException;
use Neos\Flow\Mvc\Exception\StopActionException;
use Neos\Neos\Domain\Model\SiteNodeName;
use Neos\Neos\PendingChangesProjection\ChangeFinder;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\Projection\Workspace\Workspace;
use Neos\ContentRepository\Core\Feature\WorkspaceCreation\Command\CreateWorkspace;
use Neos\ContentRepository\Core\Feature\WorkspaceCreation\Exception\WorkspaceAlreadyExists;
use Neos\ContentRepository\Core\Feature\WorkspaceModification\Command\ChangeWorkspaceOwner;
use Neos\ContentRepository\Core\Feature\WorkspaceModification\Command\DeleteWorkspace;
use Neos\ContentRepository\Core\Feature\WorkspaceModification\Command\RenameWorkspace;
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Command\DiscardIndividualNodesFromWorkspace;
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Command\DiscardWorkspace;
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Command\PublishIndividualNodesFromWorkspace;
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Command\PublishWorkspace;
use Neos\ContentRepository\Core\Feature\WorkspaceModification\Command\RenameWorkspace;
use Neos\ContentRepository\Core\Feature\WorkspaceModification\Command\DeleteWorkspace;
use Neos\ContentRepository\Core\Feature\WorkspaceModification\Command\ChangeWorkspaceOwner;
use Neos\Neos\FrontendRouting\NodeAddress;
use Neos\Neos\FrontendRouting\NodeAddressFactory;
use Neos\ContentRepository\Core\SharedModel\User\UserId;
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Dto\NodeIdsToPublishOrDiscard;
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Dto\NodeIdToPublishOrDiscard;
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindAncestorNodesFilter;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints;
use Neos\ContentRepository\Core\Projection\Workspace\Workspace;
use Neos\ContentRepository\Core\SharedModel\Node\NodeName;
use Neos\ContentRepository\Core\SharedModel\User\UserId;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceDescription;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceTitle;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Diff\Diff;
use Neos\Diff\Renderer\Html\HtmlArrayRenderer;
use Neos\Neos\Controller\Module\ModuleTranslationTrait;
use Neos\Neos\Domain\Model\WorkspaceName as NeosWorkspaceName;
use Neos\Flow\Annotations as Flow;
use Neos\Error\Messages\Message;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\I18n\Exception\IndexOutOfBoundsException;
use Neos\Flow\I18n\Exception\InvalidFormatPlaceholderException;
use Neos\Flow\Mvc\ActionRequest;
use Neos\Flow\Mvc\Exception\StopActionException;
use Neos\Flow\Package\PackageManager;
use Neos\Flow\Property\PropertyMapper;
use Neos\Flow\Security\Context;
use Neos\Media\Domain\Model\AssetInterface;
use Neos\Media\Domain\Model\ImageInterface;
use Neos\Neos\Controller\Module\AbstractModuleController;
use Neos\Neos\Controller\Module\ModuleTranslationTrait;
use Neos\Neos\Domain\Model\SiteNodeName;
use Neos\Neos\Domain\Model\User;
use Neos\Neos\Domain\Repository\SiteRepository;
use Neos\Neos\Domain\Service\UserService;
use Neos\Neos\Domain\Service\WorkspaceNameBuilder;
use Neos\Neos\FrontendRouting\NodeAddress;
use Neos\Neos\FrontendRouting\NodeAddressFactory;
use Neos\Neos\FrontendRouting\SiteDetection\SiteDetectionResult;
use Neos\Neos\PendingChangesProjection\ChangeFinder;

/**
* The Neos Workspaces module controller
Expand Down Expand Up @@ -121,8 +120,7 @@ public function indexAction()

$currentAccount = $this->securityContext->getAccount();
$userWorkspace = $contentRepository->getWorkspaceFinder()->findOneByName(
NeosWorkspaceName::fromAccountIdentifier($currentAccount->getAccountIdentifier())
->toContentRepositoryWorkspaceName()
WorkspaceNameBuilder::fromAccountIdentifier($currentAccount->getAccountIdentifier())
);
if (is_null($userWorkspace)) {
throw new \RuntimeException('Current user has no workspace', 1645485990);
Expand Down Expand Up @@ -462,8 +460,7 @@ public function rebaseAndRedirectAction(Node $targetNode, Workspace $targetWorks
$contentRepository = $this->contentRepositoryRegistry->get($contentRepositoryId);

$currentAccount = $this->securityContext->getAccount();
$personalWorkspaceName = NeosWorkspaceName::fromAccountIdentifier($currentAccount->getAccountIdentifier())
->toContentRepositoryWorkspaceName();
$personalWorkspaceName = WorkspaceNameBuilder::fromAccountIdentifier($currentAccount->getAccountIdentifier());
$personalWorkspace = $contentRepository->getWorkspaceFinder()->findOneByName($personalWorkspaceName);
/** @var Workspace $personalWorkspace */

Expand Down
81 changes: 0 additions & 81 deletions Neos.Neos/Classes/Domain/Model/WorkspaceName.php

This file was deleted.

35 changes: 35 additions & 0 deletions Neos.Neos/Classes/Domain/Service/WorkspaceNameBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/*
* This file is part of the Neos.Neos 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.
*/


declare(strict_types=1);

namespace Neos\Neos\Domain\Service;

use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;

final class WorkspaceNameBuilder
{
private const PREFIX = 'user-';

public static function fromAccountIdentifier(string $accountIdentifier): WorkspaceName
{
$name = preg_replace('/[^A-Za-z0-9\-]/', '-', self::PREFIX . $accountIdentifier);
if (is_null($name)) {
throw new \InvalidArgumentException(
'Cannot convert account identifier ' . $accountIdentifier . ' to workspace name.',
1645656253
);
}
return WorkspaceName::fromString($name);
}
}
80 changes: 35 additions & 45 deletions Neos.Neos/Classes/Service/EditorContentStreamZookeeper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@
use Neos\ContentRepository\Core\Feature\WorkspaceCreation\Command\CreateWorkspace;
use Neos\ContentRepository\Core\Feature\WorkspaceRebase\Command\RebaseWorkspace;
use Neos\ContentRepository\Core\Projection\Workspace\Workspace;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\User\UserId;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceDescription;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceTitle;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\ContentRepositoryRegistry\Factory\ProjectionCatchUpTrigger\CatchUpTriggerWithSynchronousOption;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Core\Bootstrap;
use Neos\Flow\Http\HttpRequestHandlerInterface;
use Neos\Neos\Domain\Model\WorkspaceName as AdjustmentsWorkspaceName;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Persistence\PersistenceManagerInterface;
use Neos\Flow\Security\Authentication;
use Neos\Flow\Security\Policy\PolicyService;
use Neos\Flow\Security\Policy\Role;
use Neos\Neos\Domain\Model\User;
use Neos\Neos\Domain\Service\WorkspaceNameBuilder;
use Neos\Neos\FrontendRouting\SiteDetection\SiteDetectionResult;
use Neos\Party\Domain\Service\PartyService;

Expand Down Expand Up @@ -102,48 +102,38 @@ public function relayEditorAuthentication(Authentication\TokenInterface $token):
break;
}
}

if ($isEditor) {
$user = $this->partyService->getAssignedPartyOfAccount($token->getAccount());
if ($user instanceof User) {
$workspaceName = AdjustmentsWorkspaceName::fromAccountIdentifier(
$token->getAccount()->getAccountIdentifier()
);
$workspace = $contentRepository->getWorkspaceFinder()->findOneByName(
$workspaceName->toContentRepositoryWorkspaceName()
);

if (!$workspace) {
// @todo: find base workspace for user
/** @var Workspace $baseWorkspace */
$baseWorkspace = $contentRepository->getWorkspaceFinder()->findOneByName(WorkspaceName::forLive());
$editorsNewContentStreamId = ContentStreamId::create();
$similarlyNamedWorkspaces = $contentRepository->getWorkspaceFinder()->findByPrefix(
$workspaceName->toContentRepositoryWorkspaceName()
);
if (!empty($similarlyNamedWorkspaces)) {
$workspaceName = $workspaceName->increment($similarlyNamedWorkspaces);
}
mhsdesign marked this conversation as resolved.
Show resolved Hide resolved

$contentRepository->handle(
CreateWorkspace::create(
$workspaceName->toContentRepositoryWorkspaceName(),
$baseWorkspace->workspaceName,
new WorkspaceTitle((string) $user->getName()),
new WorkspaceDescription(''),
$editorsNewContentStreamId,
UserId::fromString($this->persistenceManager->getIdentifierByObject($user))
)
)->block();
} else {
CatchUpTriggerWithSynchronousOption::synchronously(fn() =>
$contentRepository->handle(
RebaseWorkspace::create(
$workspace->workspaceName,
)
)->block());
}
}
if (!$isEditor) {
return;
}
$user = $this->partyService->getAssignedPartyOfAccount($token->getAccount());
if (!$user instanceof User) {
return;
}
$workspaceName = WorkspaceNameBuilder::fromAccountIdentifier(
$token->getAccount()->getAccountIdentifier()
);
$workspace = $contentRepository->getWorkspaceFinder()->findOneByName($workspaceName);
if ($workspace !== null) {
CatchUpTriggerWithSynchronousOption::synchronously(fn() => $contentRepository->handle(
RebaseWorkspace::create(
$workspace->workspaceName,
)
)->block());
return;
}

/** @var Workspace $baseWorkspace */
$baseWorkspace = $contentRepository->getWorkspaceFinder()->findOneByName(WorkspaceName::forLive());
$editorsNewContentStreamId = ContentStreamId::create();
$contentRepository->handle(
CreateWorkspace::create(
$workspaceName,
$baseWorkspace->workspaceName,
new WorkspaceTitle((string) $user->getName()),
new WorkspaceDescription(''),
$editorsNewContentStreamId,
UserId::fromString($this->persistenceManager->getIdentifierByObject($user))
)
)->block();
}
}
4 changes: 2 additions & 2 deletions Neos.Neos/Classes/Utility/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Neos\Neos\Utility;

use Neos\Neos\Domain\Model\WorkspaceName;
use Neos\Neos\Domain\Service\WorkspaceNameBuilder;

/**
* Utility functions for dealing with users in the Content Repository.
Expand All @@ -17,7 +17,7 @@ class User
*/
public static function getPersonalWorkspaceNameForUsername($username): string
{
return (string)WorkspaceName::fromAccountIdentifier($username);
return WorkspaceNameBuilder::fromAccountIdentifier($username)->value;
}

/**
Expand Down
Loading