-
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: FEATURE: Content Repository Privileges
Related: #3732
- Loading branch information
1 parent
1ebc9af
commit 69a9c33
Showing
16 changed files
with
265 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
Neos.ContentRepository.Core/Classes/SharedModel/Privilege/ContentStreamPrivilege.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Neos\ContentRepository\Core\SharedModel\Privilege; | ||
|
||
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamIds; | ||
|
||
/** | ||
* @internal except for custom PrivilegeProviderInterface implementations | ||
*/ | ||
final class ContentStreamPrivilege | ||
{ | ||
private function __construct( | ||
public readonly ?ContentStreamIds $allowedContentStreamIds, | ||
public readonly ?ContentStreamIds $disallowedContentStreamIds, | ||
) { | ||
} | ||
|
||
public static function create(): self | ||
{ | ||
return new self(null, null); | ||
} | ||
|
||
public function with( | ||
ContentStreamIds $allowedContentStreamIds = null, | ||
ContentStreamIds $disallowedContentStreamIds = null, | ||
): self | ||
{ | ||
return new self( | ||
$allowedContentStreamIds ?? $this->allowedContentStreamIds, | ||
$disallowedContentStreamIds ?? $this->disallowedContentStreamIds, | ||
); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Neos.ContentRepository.Core/Classes/SharedModel/Privilege/PrivilegeProviderInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Neos\ContentRepository\Core\SharedModel\Privilege; | ||
|
||
use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints; | ||
|
||
/** | ||
* @internal except for CR factory implementations | ||
*/ | ||
interface PrivilegeProviderInterface | ||
{ | ||
public function getPrivileges(VisibilityConstraints $visibilityConstraints): Privileges; | ||
} |
41 changes: 41 additions & 0 deletions
41
Neos.ContentRepository.Core/Classes/SharedModel/Privilege/Privileges.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Neos\ContentRepository\Core\SharedModel\Privilege; | ||
|
||
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId; | ||
|
||
/** | ||
* @api | ||
*/ | ||
final class Privileges | ||
{ | ||
private function __construct( | ||
public readonly ?ContentStreamPrivilege $contentStreamPrivilege, | ||
|
||
) { | ||
} | ||
|
||
public static function create(): self | ||
{ | ||
return new self(null); | ||
} | ||
|
||
public function with( | ||
ContentStreamPrivilege $contentStreamPrivilege = null, | ||
): self | ||
{ | ||
return new self( | ||
$contentStreamPrivilege ?? $this->contentStreamPrivilege, | ||
); | ||
} | ||
|
||
public function isContentStreamAllowed(ContentStreamId $contentStreamId): bool | ||
{ | ||
if ($this->contentStreamPrivilege === null) { | ||
return true; | ||
} | ||
return $this->contentStreamPrivilege->allowedContentStreamIds->contain($contentStreamId); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
Neos.ContentRepository.Core/Classes/SharedModel/Workspace/ContentStreamIds.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Neos.ContentRepository 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\ContentRepository\Core\SharedModel\Workspace; | ||
|
||
|
||
/** | ||
* @api | ||
* @implements \IteratorAggregate<ContentStreamId> | ||
*/ | ||
final class ContentStreamIds implements \IteratorAggregate | ||
{ | ||
/** | ||
* @param ContentStreamId[] $contentStreamIds | ||
*/ | ||
private function __construct( | ||
private readonly array $contentStreamIds, | ||
) { | ||
if ($this->contentStreamIds === []) { | ||
throw new \InvalidArgumentException('ContentStreamIds must not be empty', 1681306355); | ||
} | ||
} | ||
|
||
public static function fromContentStreamIds(ContentStreamId ...$contentStreamIds): self | ||
{ | ||
return new self($contentStreamIds); | ||
} | ||
|
||
public function getIterator(): \Traversable | ||
{ | ||
return new \ArrayIterator($this->contentStreamIds); | ||
} | ||
|
||
public function contain(ContentStreamId $contentStreamId): bool | ||
{ | ||
foreach ($this->contentStreamIds as $id) { | ||
if ($id->equals($contentStreamId)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
Neos.ContentRepositoryRegistry/Classes/Factory/PrivilegeProvider/FakePrivilegeProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
declare(strict_types=1); | ||
namespace Neos\ContentRepositoryRegistry\Factory\PrivilegeProvider; | ||
|
||
use Neos\ContentRepository\Core\Factory\ContentRepositoryId; | ||
use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints; | ||
use Neos\ContentRepository\Core\SharedModel\Privilege\ContentStreamPrivilege; | ||
use Neos\ContentRepository\Core\SharedModel\Privilege\PrivilegeProviderInterface; | ||
use Neos\ContentRepository\Core\SharedModel\Privilege\Privileges; | ||
use Neos\ContentRepository\Core\SharedModel\User\UserIdProviderInterface; | ||
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamIds; | ||
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class FakePrivilegeProvider implements PrivilegeProviderInterface | ||
{ | ||
public function __construct( | ||
private readonly UserIdProviderInterface $userIdProvider, | ||
private readonly ContentRepositoryRegistry $contentRepositoryRegistry, | ||
private readonly ContentRepositoryId $contentRepositoryId, | ||
) {} | ||
|
||
public function getPrivileges(VisibilityConstraints $visibilityConstraints): Privileges | ||
{ | ||
$userId = $this->userIdProvider->getUserId(); | ||
$contentRepository = $this->contentRepositoryRegistry->get($this->contentRepositoryId); | ||
|
||
$privileges = Privileges::create(); | ||
|
||
$userWorkspace = $contentRepository->getWorkspaceFinder()->findOneByWorkspaceOwner($userId->value); | ||
if ($userWorkspace === null) { | ||
return $privileges; | ||
} | ||
return $privileges->with( | ||
contentStreamPrivilege: ContentStreamPrivilege::create()->with(allowedContentStreamIds: ContentStreamIds::fromContentStreamIds($userWorkspace->currentContentStreamId)) | ||
); | ||
} | ||
} |
Oops, something went wrong.