-
-
Notifications
You must be signed in to change notification settings - Fork 188
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
FEATURE: Introduce RoleId
and RoleIds
value objects
#3415
Open
bwaidelich
wants to merge
7
commits into
9.0
Choose a base branch
from
feature/3414-roleIds-value-object
base: 9.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1e61872
FEATURE: Introduce `RoleId` and `RoleIds` value objects
bwaidelich bf67991
Cosmetics to satisfy linter
bwaidelich 52f5e63
more cosmetics
bwaidelich 32bbd2d
Tweak `Role` constructor to accept `RoleId`
bwaidelich 073a2b0
Use simple type in `PolicyService::getRole()`
bwaidelich 4186614
Fix `Role::__toString()`
bwaidelich 40d6023
Cosmetic tweak to satisfy linter
bwaidelich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neos\Flow\Security\Policy; | ||
|
||
/* | ||
* This file is part of the Neos.Flow 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. | ||
*/ | ||
|
||
/** | ||
* A role identifier in the format <Vendor>(.<Package>):<Role>, for example "Some.Package:SomeRole" | ||
*/ | ||
final readonly class RoleId | ||
{ | ||
private const ROLE_IDENTIFIER_PATTERN = '/^(\w+(?:\.\w+)*)\:(\w+)$/'; // Vendor(.Package)?:RoleName | ||
|
||
private string $packageKey; | ||
private string $name; | ||
|
||
private function __construct( | ||
public string $value, | ||
) { | ||
if (preg_match(self::ROLE_IDENTIFIER_PATTERN, $value, $matches) !== 1) { | ||
throw new \InvalidArgumentException('The role id must follow the pattern "Vendor.Package:RoleName", but "' . $value . '" was given. Please check the code or policy configuration creating or defining this role.', 1365446549); | ||
} | ||
$this->packageKey = $matches[1]; | ||
$this->name = $matches[2]; | ||
} | ||
|
||
public static function fromString(string $value): self | ||
{ | ||
return new self($value); | ||
} | ||
|
||
public static function everybody(): self | ||
{ | ||
return new self('Neos.Flow:Everybody'); | ||
} | ||
|
||
public static function anonymous(): self | ||
{ | ||
return new self('Neos.Flow:Anonymous'); | ||
} | ||
|
||
public static function authenticatedUser(): self | ||
{ | ||
return new self('Neos.Flow:AuthenticatedUser'); | ||
} | ||
|
||
/** | ||
* The package key prefix of the id, e.g. "Some.Package" | ||
*/ | ||
public function getPackageKey(): string | ||
{ | ||
return $this->packageKey; | ||
} | ||
|
||
/** | ||
* The name suffix of the id without its package key prefix, e.g. "SomeRole" | ||
*/ | ||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function equals(self $other): bool | ||
{ | ||
return $other->value === $this->value; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And then deprecate the __construct as it is so we can at least open a window for refactoring internally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kitsunet mh,
Role::fromRoleId()
andRole::fromIdentifierString()
sounds wrong to me.. But what do you think ofThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, sounds good! My thought train was not finished really. I was thinking / hoping how we can refactor towards something like RoleIds $parentRoles or somthing, but the static constructors would not necessarily make that easier :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree – there is a lot of potential to improve things, but I wanted to avoid another rabbit hole (like #3410)
Adjusted with 32bbd2d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, totally fair