Skip to content

Commit

Permalink
Merge pull request #5132 from neos/feature/4255-new-workspace-managem…
Browse files Browse the repository at this point in the history
…ent-ui

FEATURE: New workspace module (fusion & htmx) v1
  • Loading branch information
mhsdesign authored Jan 13, 2025
2 parents f20b28c + f3fe1d0 commit 9890ab7
Show file tree
Hide file tree
Showing 100 changed files with 3,898 additions and 1,232 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
*/
private array $tags;


private function __construct(SubtreeTag ...$tags)
{
$tagsByValue = [];
Expand Down Expand Up @@ -83,6 +82,11 @@ public function intersection(self $other): self
return self::fromArray(array_intersect_key($this->tags, $other->tags));
}

public function difference(self $other): self
{
return self::fromArray(array_diff_key($this->tags, $other->tags));
}

public function merge(self $other): self
{
return self::fromArray(array_merge($this->tags, $other->tags));
Expand All @@ -106,6 +110,11 @@ public function toStringArray(): array
return $this->map(static fn (SubtreeTag $tag) => $tag->value);
}

public function equals(SubtreeTags $other): bool
{
return count($this->tags) === count($other->tags) && array_diff_key($this->tags, $other->tags) === [];
}

public function getIterator(): \Traversable
{
yield from array_values($this->tags);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ public function toStringArray(): array
return $this->map(static fn (SubtreeTag $tag) => $tag->value);
}

public function equals(NodeTags $other): bool
{
return $this->tags->equals($other->tags)
&& $this->inheritedTags->equals($other->inheritedTags);
}

public function getIterator(): Traversable
{
foreach ($this->tags as $tag) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,44 @@ public function intersectionTests(array $tags1, array $tags2, array $expectedRes
self::assertSame($expectedResult, SubtreeTags::fromStrings(...$tags1)->intersection(SubtreeTags::fromStrings(...$tags2))->toStringArray());
}

public static function differenceDataProvider(): iterable
{
yield 'empty' => ['tags1' => [], 'tags2' => [], 'expectedResult' => []];
yield 'one empty' => ['tags1' => [], 'tags2' => ['foo'], 'expectedResult' => []];
yield 'two empty' => ['tags1' => ['foo'], 'tags2' => [], 'expectedResult' => ['foo']];
yield 'no intersection' => ['tags1' => ['foo', 'bar'], 'tags2' => ['baz', 'foos'], 'expectedResult' => ['foo', 'bar']];
yield 'with intersection' => ['tags1' => ['foo', 'bar', 'baz'], 'tags2' => ['baz', 'bars', 'foo'], 'expectedResult' => ['bar']];
yield 'with intersection reversed' => ['tags1' => ['baz', 'bars', 'foo'], 'tags2' => ['foo', 'bar', 'baz'], 'expectedResult' => ['bars']];
}

/**
* @test
* @dataProvider differenceDataProvider
*/
public function differenceTests(array $tags1, array $tags2, array $expectedResult): void
{
self::assertSame($expectedResult, SubtreeTags::fromStrings(...$tags1)->difference(SubtreeTags::fromStrings(...$tags2))->toStringArray());
}


public static function equalsDataProvider(): iterable
{
yield 'empty' => ['tags1' => [], 'tags2' => [], 'expectedResult' => true];
yield 'one empty' => ['tags1' => [], 'tags2' => ['foo'], 'expectedResult' => false];
yield 'other empty' => ['tags1' => ['foo'], 'tags2' => [], 'expectedResult' => false];
yield 'equals' => ['tags1' => ['foo', 'bar'], 'tags2' => ['foo', 'bar'], 'expectedResult' => true];
yield 'equals reversed' => ['tags1' => ['foo', 'bar'], 'tags2' => ['bar', 'foo'], 'expectedResult' => true];
}

/**
* @test
* @dataProvider equalsDataProvider
*/
public function equalsTests(array $tags1, array $tags2, bool $expectedResult): void
{
self::assertSame($expectedResult, SubtreeTags::fromStrings(...$tags1)->equals(SubtreeTags::fromStrings(...$tags2)));
}

public static function mergeDataProvider(): iterable
{
yield 'empty' => ['tags1' => [], 'tags2' => [], 'expectedResult' => []];
Expand Down
15 changes: 15 additions & 0 deletions Neos.Neos/Classes/Domain/Model/WorkspaceRoleAssignments.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ public static function createForSharedWorkspace(UserId $userId): self
);
}

/**
* Default role assignment to be specified at creation via {@see WorkspaceService::createSharedWorkspace()}
*
* The specified user is manager
*/
public static function createForPrivateWorkspace(UserId $userId): self
{
return new self(
WorkspaceRoleAssignment::createForUser(
$userId,
WorkspaceRole::MANAGER,
)
);
}

public function isEmpty(): bool
{
return $this->assignments === [];
Expand Down
Loading

0 comments on commit 9890ab7

Please sign in to comment.