Skip to content

Commit

Permalink
FEATURE: Allow modifying basic workspace visibility in edit dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebobo committed Dec 19, 2024
1 parent 49d23d4 commit 22a564e
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 19 deletions.
41 changes: 40 additions & 1 deletion Neos.Workspace.Ui/Classes/Controller/WorkspaceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@
use Neos\Neos\Domain\Model\User;
use Neos\Neos\Domain\Model\WorkspaceClassification;
use Neos\Neos\Domain\Model\WorkspaceDescription;
use Neos\Neos\Domain\Model\WorkspaceRole;
use Neos\Neos\Domain\Model\WorkspaceRoleAssignment;
use Neos\Neos\Domain\Model\WorkspaceRoleAssignments;
use Neos\Neos\Domain\Model\WorkspaceRoleSubject;
use Neos\Neos\Domain\Model\WorkspaceTitle;
use Neos\Neos\Domain\NodeLabel\NodeLabelGeneratorInterface;
use Neos\Neos\Domain\Repository\SiteRepository;
Expand Down Expand Up @@ -301,6 +304,15 @@ public function editAction(WorkspaceName $workspaceName): void
}

$workspaceMetadata = $this->workspaceService->getWorkspaceMetadata($contentRepositoryId, $workspace->workspaceName);
$workspaceRoleAssignments = $this->workspaceService->getWorkspaceRoleAssignments($contentRepositoryId, $workspace->workspaceName);
$isShared = false;
if ($workspaceMetadata->classification === WorkspaceClassification::SHARED) {
foreach ($workspaceRoleAssignments as $roleAssignment) {
if ($roleAssignment->role === WorkspaceRole::COLLABORATOR) {
$isShared = true;
}
}
}

$editWorkspaceDto = new EditWorkspaceFormData(
workspaceName: $workspace->workspaceName,
Expand All @@ -309,6 +321,7 @@ public function editAction(WorkspaceName $workspaceName): void
workspaceHasChanges: $this->computePendingChanges($workspace, $contentRepository)->total > 0,
baseWorkspaceName: $workspace->baseWorkspaceName,
baseWorkspaceOptions: $this->prepareBaseWorkspaceOptions($contentRepository, $workspaceName),
isShared: $isShared,
);

$this->view->assign('editWorkspaceFormData', $editWorkspaceDto);
Expand All @@ -321,13 +334,15 @@ public function editAction(WorkspaceName $workspaceName): void
* @param WorkspaceName $workspaceName The name of the workspace that is being updated
* @param WorkspaceTitle $title Human friendly title of the workspace, for example "Christmas Campaign"
* @param WorkspaceDescription $description A description explaining the purpose of the new workspace
* @param WorkspaceName $baseWorkspace A description explaining the purpose of the new workspace
* @param WorkspaceName $baseWorkspace The base workspace to rebase this workspace onto if modified
* @param string $visibility Allow other editors to collaborate on this workspace if set to "shared"
*/
public function updateAction(
WorkspaceName $workspaceName,
WorkspaceTitle $title,
WorkspaceDescription $description,
WorkspaceName $baseWorkspace,
string $visibility,
): void {
$currentUser = $this->userService->getCurrentUser();
if ($currentUser === null) {
Expand Down Expand Up @@ -369,6 +384,30 @@ public function updateAction(
$description,
);

$workspaceRoleAssignments = $this->workspaceService->getWorkspaceRoleAssignments($contentRepositoryId, $workspaceName);
$sharedRoleAssignment = WorkspaceRoleAssignment::createForGroup(
'Neos.Neos:AbstractEditor',
WorkspaceRole::COLLABORATOR,
);
if ($visibility === 'shared') {
if (!$workspaceRoleAssignments->contains($sharedRoleAssignment)) {
$this->workspaceService->assignWorkspaceRole(
$contentRepositoryId,
$workspaceName,
WorkspaceRoleAssignment::createForGroup(
'Neos.Neos:AbstractEditor',
WorkspaceRole::COLLABORATOR,
)
);
}
} elseif ($visibility === 'private' && $workspaceRoleAssignments->contains($sharedRoleAssignment)) {
$this->workspaceService->unassignWorkspaceRole(
$contentRepositoryId,
$workspaceName,
WorkspaceRoleSubject::createForGroup('Neos.Neos:AbstractEditor'),
);
}

// Update Base Workspace
$this->workspacePublishingService->changeBaseWorkspace(
$contentRepositoryId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function __construct(
public bool $workspaceHasChanges,
public WorkspaceName $baseWorkspaceName,
public array $baseWorkspaceOptions,
public bool $isShared,
) {
}
}
6 changes: 1 addition & 5 deletions Neos.Workspace.Ui/Classes/ViewModel/WorkspaceListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public function isPersonal(): bool

public function isPrivate(): bool
{
if ($this->classification !== WorkspaceClassification::SHARED->value ||
$this->roleAssignments->count() > 1) {
if ($this->classification !== WorkspaceClassification::SHARED->value) {
return false;
}
foreach ($this->roleAssignments as $roleAssignment) {
Expand All @@ -61,9 +60,6 @@ public function isPrivate(): bool

public function isShared(): bool
{
if ($this->roleAssignments->count() > 1) {
return true;
}
foreach ($this->roleAssignments as $roleAssignment) {
if ($roleAssignment->role === WorkspaceRole::COLLABORATOR) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Neos.Workspace.Ui.WorkspaceController.edit = Neos.Fusion:Component {
baseWorkspaceName={props.editWorkspaceFormData.baseWorkspaceName.value}
workspaceHasChanges={props.editWorkspaceFormData.workspaceHasChanges}
baseWorkspaceOptions={props.editWorkspaceFormData.baseWorkspaceOptions}
visibility={props.editWorkspaceFormData.visibility}
isShared={props.editWorkspaceFormData.isShared}
/>
`
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ prototype(Neos.Workspace.Ui:Component.Modal.Edit) < prototype(Neos.Fusion:Compon
workspaceDescription = ''
/// string
baseWorkspaceName = ''
/// string
visibility = ''
/// boolean
workspaceHasChanges = false
/// array<workspaceName: string, workspaceTitle: string>
baseWorkspaceOptions = ${[]}
/// boolean
isShared = false

@private {
i18n = ${I18n.id('').source('Main').package('Neos.Workspace.Ui')}
Expand Down Expand Up @@ -50,6 +50,7 @@ prototype(Neos.Workspace.Ui:Component.Modal.Edit) < prototype(Neos.Fusion:Compon
<Neos.Fusion.Form:Form
form.target.action="update"
form.target.format="htmx"
form.data.visibility={props.isShared ? 'shared' : 'private'}
attributes.class="neos-inline"
attributes.hx-post={form.getTarget()}
attributes.hx-disabled-elt="find button"
Expand Down Expand Up @@ -115,23 +116,16 @@ prototype(Neos.Workspace.Ui:Component.Modal.Edit) < prototype(Neos.Fusion:Compon
<Neos.Fusion.Form:Neos.BackendModule.FieldContainer
label="workspaces.workspace.visibility"
class="neos-control-group"
field.name="visibility"
>
<Neos.Fusion.Form:Radio
renderer.checked={props.visibility == 'shared'}
field.name="visibility"
field.value="shared"
>
<Neos.Fusion.Form:Radio field.value="shared">
{private.i18n.id('workspaces.workspace.visibility.shared')}
</Neos.Fusion.Form:Radio>
<p>
{private.i18n.id('workspaces.workspace.visibility.shared.help')}
</p>
<br/>
<Neos.Fusion.Form:Radio
renderer.checked={props.visibility == 'private'}
field.name="visibility"
field.value="private"
>
<Neos.Fusion.Form:Radio field.value="private">
{private.i18n.id('workspaces.workspace.visibility.private')}
</Neos.Fusion.Form:Radio>
<p>
Expand Down
1 change: 1 addition & 0 deletions Neos.Workspace.Ui/Resources/Public/Styles/Module.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
.workspace-type-column {
padding: 0 0.5ch;
text-align: center;
width: 20px;
}

.workspace-type-column > * {
Expand Down

0 comments on commit 22a564e

Please sign in to comment.