-
-
Notifications
You must be signed in to change notification settings - Fork 247
FEATURE: Command to delete stale workspaces #5770
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
Closed
Closed
Changes from 3 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e62cb5f
FEATURE: Command to delete stale workspaces
sachera 6a2f20e
TASK: Move stale workspace detection logic to WorkspaceService
sachera 09c92e2
TASK: Refactor checking if a workspace has workspaces depending on them
sachera 97836c2
TASK: Remove `@throws` annotations which have no effect on a Flow CLI…
mhsdesign 3db6be5
TASK: Keep time calculation logic in command controller to have Works…
mhsdesign 5e6100a
TASK: Use static `PHPUnit\Framework\Assert` as in other places
mhsdesign 865bea7
TASK: Simplify api of `getStaleWorkspaceNames()` to not include unuse…
mhsdesign adaa2bc
TASK: Introduce typed collections for `WorkspaceNames` and `UserIds`
mhsdesign 8e7240b
TASK: Rename `getStaleWorkspaceNames` to `getStalePersonalWorkspaceNa…
mhsdesign e350988
TASK: countable WorkspaceNames
mhsdesign 28a9527
TASK: Move feature from `ContentRepository` context to own `User` con…
mhsdesign e0e8d44
TASK: Ensure WorkspaceService fully encapsulates stale workspace dele…
mhsdesign 64f9112
WIP: Add failing test that `createPersonalWorkspaceForUserIfMissing()…
mhsdesign 321a7ef
TASK: Do not force specific order in tests for stale workspaces and u…
sachera 336be2f
TASK: Allow any order for set of existing workspaces in tests
sachera 5e988ab
TASK: Recreate personal Workspaces if Metadata still exists but the W…
sachera be9a9d4
TASK: Run WorkspaceMetadata Cleanup after test rather than before to …
sachera 70e390d
WIP: Add testcase to show stale workspace recreation works for "live"…
sachera 445a6eb
Task: Fix linting errors
sachera 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
|
|
||
| namespace Neos\Neos\Domain\Service; | ||
|
|
||
| use DateInterval; | ||
| use Neos\ContentRepository\Core\Feature\Security\Exception\AccessDenied; | ||
| use Neos\ContentRepository\Core\Feature\WorkspaceCreation\Command\CreateRootWorkspace; | ||
| use Neos\ContentRepository\Core\Feature\WorkspaceCreation\Command\CreateWorkspace; | ||
|
|
@@ -27,6 +28,7 @@ | |
| use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry; | ||
| use Neos\Flow\Annotations as Flow; | ||
| use Neos\Flow\Security\Context as SecurityContext; | ||
| use Neos\Flow\Utility\Now; | ||
| use Neos\Neos\Domain\Model\User; | ||
| use Neos\Neos\Domain\Model\UserId; | ||
| use Neos\Neos\Domain\Model\WorkspaceClassification; | ||
|
|
@@ -56,6 +58,7 @@ | |
| private ContentRepositoryAuthorizationService $authorizationService, | ||
| private SecurityContext $securityContext, | ||
| private SoftRemovalGarbageCollector $softRemovalGarbageCollector, | ||
| private Now $now, | ||
| ) { | ||
| } | ||
|
|
||
|
|
@@ -301,6 +304,40 @@ | |
| throw new \RuntimeException(sprintf('Failed to find unique workspace name for "%s" after %d attempts.', $candidate, $attempt - 1), 1725975479); | ||
| } | ||
|
|
||
| /** | ||
| * @param ContentRepositoryId $contentRepositoryId | ||
| * @param DateInterval $interval | ||
| * @return \Traversable<UserId,WorkspaceName> | ||
| * @throws \DateInvalidOperationException | ||
| */ | ||
| public function getStaleWorkspaceNames(ContentRepositoryId $contentRepositoryId, DateInterval $interval): \Traversable | ||
|
Check failure on line 313 in Neos.Neos/Classes/Domain/Service/WorkspaceService.php
|
||
| { | ||
| $contentRepositoryInstance = $this->contentRepositoryRegistry->get($contentRepositoryId); | ||
|
|
||
| $workspaces = $contentRepositoryInstance->findWorkspaces(); | ||
| $probablyStaleWorkspaceNames = array_flip(iterator_to_array( | ||
| $workspaces | ||
| ->filter(fn($workspace) => !$workspace->hasPublishableChanges() && | ||
| $workspaces->getDependantWorkspacesRecursively($workspace->workspaceName)->isEmpty()) | ||
| ->map(fn($workspace) => $workspace->workspaceName->value) | ||
| )); | ||
|
|
||
| $inactiveUserIds = array_flip(array_map( | ||
| fn($userId) => $userId->value, | ||
| iterator_to_array($this->userService->findUserIdsNotLoggedInAfter($this->now->sub($interval))) | ||
| )); | ||
|
|
||
| $personalWorkspaces = $this->metadataAndRoleRepository->findAllPersonalWorkspaceNamesByContentRepositoryId($contentRepositoryId); | ||
| foreach ($personalWorkspaces as $userId => $personalWorkspace) { | ||
| if ( | ||
| array_key_exists($personalWorkspace->value, $probablyStaleWorkspaceNames) && | ||
| array_key_exists($userId->value, $inactiveUserIds) | ||
| ) { | ||
| yield $userId => $personalWorkspace; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // ------------------ | ||
|
|
||
| /** | ||
|
|
||
This file contains hidden or 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 hidden or 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
33 changes: 33 additions & 0 deletions
33
Neos.Neos/Tests/Behavior/Features/ContentRepository/UserService.feature
This file contains hidden or 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,33 @@ | ||
| @flowEntities | ||
| Feature: Neos UserService related features | ||
|
|
||
| Background: | ||
| Given using no content dimensions | ||
| And using the following node types: | ||
| """yaml | ||
| 'Neos.ContentRepository:Root': {} | ||
| """ | ||
| And using identifier "default", I define a content repository | ||
| And I am in content repository "default" | ||
| And the following Neos users exist: | ||
| | Id | Username | First name | Last name | Roles | | ||
| | janedoe | jane.doe | Jane | Doe | Neos.Neos:Administrator | | ||
| | johndoe | john.doe | John | Doe | Neos.Neos:RestrictedEditor,Neos.Neos:UserManager | | ||
| | editor | editor | Edward | Editor | Neos.Neos:Editor | | ||
|
|
||
| Scenario: List user accounts not logged in for some time | ||
| When Neos user "jane.doe" last logged in 9 days ago | ||
| And Neos user "john.doe" last logged in 6 days ago | ||
| And Neos user "editor" last logged in 5 days ago | ||
| Then the following users did not log in within 7 days: | ||
| | Id | | ||
| | janedoe | | ||
| And the following users did not log in within 6 days: | ||
| | Id | | ||
| | janedoe | | ||
| | johndoe | | ||
| And the following users did not log in within 3 days: | ||
| | Id | | ||
| | janedoe | | ||
| | johndoe | | ||
| | editor | |
This file contains hidden or 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 hidden or 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
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.
I would suggest a different naming for the command. The command sounds it removes any stale workspace, but the comment correctly explains its only certain user workspaces. Though a note on their automatic recreation would also be helpful here in the comment.
If we hopefully soonish can extend the removal to other types of workspaces with potential different rules, we have a naming clash. Or what did you think about future future extensions?