Skip to content

Commit

Permalink
TASK: Adjustments after workspace service fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Dec 12, 2024
1 parent 021743c commit 27e056c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
31 changes: 17 additions & 14 deletions Classes/Controller/WorkspaceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,10 @@ public function reviewAction(WorkspaceName $workspace): void
$workspaceMetadata = $this->workspaceService->getWorkspaceMetadata($contentRepositoryId, $workspace);
$baseWorkspaceMetadata = null;
$baseWorkspacePermissions = null;
if ($workspaceObj->baseWorkspaceName !== null) {
$baseWorkspace = $contentRepository->findWorkspaceByName($workspaceObj->baseWorkspaceName);
assert($baseWorkspace !== null);
$baseWorkspace = $workspaceObj->baseWorkspaceName !== null
? $contentRepository->findWorkspaceByName($workspaceObj->baseWorkspaceName)
: null;
if ($baseWorkspace !== null) {
$baseWorkspaceMetadata = $this->workspaceService->getWorkspaceMetadata($contentRepositoryId, $baseWorkspace->workspaceName);
$baseWorkspacePermissions = $this->authorizationService->getWorkspacePermissions($contentRepositoryId, $baseWorkspace->workspaceName, $this->securityContext->getRoles(), $currentUser->getId());
}
Expand All @@ -225,7 +226,7 @@ public function reviewAction(WorkspaceName $workspace): void
'baseWorkspaceName' => $workspaceObj->baseWorkspaceName,
'baseWorkspaceLabel' => $baseWorkspaceMetadata?->title->value,
'canPublishToBaseWorkspace' => $baseWorkspacePermissions?->write ?? false,
'canPublishToWorkspace' => $workspacePermissions?->write ?? false,
'canPublishToWorkspace' => $workspacePermissions->write,
'siteChanges' => $this->computeSiteChanges($workspaceObj, $contentRepository),
'contentDimensions' => $contentRepository->getContentDimensionSource()->getContentDimensionsOrderedByPriority()
]);
Expand Down Expand Up @@ -369,10 +370,10 @@ public function updateAction(
);

// Update Base Workspace
$this->workspaceService->setBaseWorkspace(
$this->workspacePublishingService->changeBaseWorkspace(
$contentRepositoryId,
$workspaceName,
$baseWorkspace,
$baseWorkspace
);

$this->addFlashMessage(
Expand Down Expand Up @@ -495,19 +496,19 @@ public function editWorkspaceRoleAssignmentsAction(WorkspaceName $workspaceName)
$workspaceRoleAssignments = [];

foreach ($this->workspaceService->getWorkspaceRoleAssignments($contentRepositoryId, $workspaceName) as $workspaceRoleAssignment) {
$subjectLabel = match ($workspaceRoleAssignment->subjectType) {
$subjectLabel = match ($workspaceRoleAssignment->subject->type) {
WorkspaceRoleSubjectType::USER => $this->userService->findUserById(UserId::fromString($workspaceRoleAssignment->subject->value))?->getLabel(),
default => $workspaceRoleAssignment->subject->value,
WorkspaceRoleSubjectType::GROUP => $workspaceRoleAssignment->subject->value,
};

$roleLabel = $workspaceRoleAssignment->role->value;

$workspaceRoleAssignments[] = new RoleAssignmentListItem(
subjectValue: $workspaceRoleAssignment->subject->value,
subjectLabel: $subjectLabel,
subjectTypeValue: $workspaceRoleAssignment->subjectType->value,
subjectTypeValue: $workspaceRoleAssignment->subject->type->value,
roleLabel: $roleLabel,
subjectType: $workspaceRoleAssignment->subjectType->value,
subjectType: $workspaceRoleAssignment->subject->type->value,
);
}

Expand Down Expand Up @@ -572,8 +573,8 @@ public function addWorkspaceRoleAssignmentAction(
{
// TODO: Validate if user can add role assignment to workspace

$subject = WorkspaceRoleSubject::fromString($subjectValue);
$subjectType = WorkspaceRoleSubjectType::from($subjectTypeValue);
$subject = WorkspaceRoleSubject::create($subjectType, $subjectValue);
$role = WorkspaceRole::from($roleValue);

if ($subjectType === WorkspaceRoleSubjectType::USER) {
Expand Down Expand Up @@ -612,8 +613,10 @@ public function deleteWorkspaceRoleAssignmentAction(WorkspaceName $workspaceName
$this->workspaceService->unassignWorkspaceRole(
$contentRepositoryId,
$workspaceName,
WorkspaceRoleSubjectType::from($subjectType),
WorkspaceRoleSubject::fromString($subjectValue),
WorkspaceRoleSubject::create(
WorkspaceRoleSubjectType::from($subjectType),
$subjectValue
)
);
} catch (\Exception $e) {
// TODO: error handling
Expand Down Expand Up @@ -1535,7 +1538,7 @@ private function addUserRoleAssignment(WorkspaceName $workspaceName, WorkspaceRo
);
}

private function addGroupRoleAssignment(WorkspaceName $workspaceName, WorkspaceRoleSubject $subject, WorkspaceRole $role)
private function addGroupRoleAssignment(WorkspaceName $workspaceName, WorkspaceRoleSubject $subject, WorkspaceRole $role): void
{
// TODO check if group exists?
$this->workspaceService->assignWorkspaceRole(
Expand Down
4 changes: 2 additions & 2 deletions Classes/ViewModel/RoleAssignmentListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
#[Flow\Proxy(false)]
final readonly class RoleAssignmentListItem
{
// todo $subjectType and $subjectTypeValue are exact the same???
public function __construct(
public string $subjectValue,
public string $subjectLabel,
public string $subjectTypeValue,
public string $roleLabel,
public string $subjectType,
)
{
) {
}
}

0 comments on commit 27e056c

Please sign in to comment.