Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 26 additions & 42 deletions src/bundle/Controller/User/ProfileEditController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,51 +28,28 @@
use Ibexa\Core\FieldType\User\Type as UserFieldType;
use Symfony\Component\Form\Form;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

final class ProfileEditController extends Controller
{
private Repository $repository;

private UserService $userService;

private LocationService $locationService;

private UserProfileConfigurationInterface $configuration;

private PermissionResolver $permissionResolver;

private LanguageService $languageService;

private ActionDispatcherInterface $userActionDispatcher;

private GroupedContentFormFieldsProviderInterface $groupedContentFormFieldsProvider;

public function __construct(
Repository $repository,
UserService $userService,
LocationService $locationService,
UserProfileConfigurationInterface $configuration,
PermissionResolver $permissionResolver,
LanguageService $languageService,
ActionDispatcherInterface $userActionDispatcher,
GroupedContentFormFieldsProviderInterface $groupedContentFormFieldsProvider
private readonly Repository $repository,
private readonly UserService $userService,
private readonly LocationService $locationService,
private readonly UserProfileConfigurationInterface $configuration,
private readonly PermissionResolver $permissionResolver,
private readonly LanguageService $languageService,
private readonly ActionDispatcherInterface $userActionDispatcher,
private readonly GroupedContentFormFieldsProviderInterface $groupedContentFormFieldsProvider
) {
$this->repository = $repository;
$this->userService = $userService;
$this->locationService = $locationService;
$this->configuration = $configuration;
$this->permissionResolver = $permissionResolver;
$this->languageService = $languageService;
$this->userActionDispatcher = $userActionDispatcher;
$this->groupedContentFormFieldsProvider = $groupedContentFormFieldsProvider;
}

/**
* @return \Ibexa\ContentForms\User\View\UserUpdateView|\Symfony\Component\HttpFoundation\Response
*/
public function editAction(Request $request, ?string $languageCode)
public function editAction(Request $request, ?string $languageCode): UserUpdateView|Response
{
$user = $this->userService->loadUser($this->permissionResolver->getCurrentUserReference()->getUserId());
$user = $this->userService->loadUser(
$this->permissionResolver->getCurrentUserReference()->getUserId()
);

if (!$this->isUserProfileAvailable($user)) {
throw $this->createNotFoundException();
}
Expand All @@ -81,19 +58,25 @@ public function editAction(Request $request, ?string $languageCode)
throw $this->createAccessDeniedException();
}

$languageCode ??= $user->contentInfo->mainLanguageCode;
$languageCode ??= $user->getContentInfo()->getMainLanguageCode();

$data = (new UserUpdateMapper())->mapToFormData($user, $user->getContentType(), [
'languageCode' => $languageCode,
'filter' => static fn (Field $field): bool => $field->fieldTypeIdentifier !== UserFieldType::FIELD_TYPE_IDENTIFIER,
'filter' => static fn (Field $field): bool => $field->getFieldTypeIdentifier() !== UserFieldType::FIELD_TYPE_IDENTIFIER,
]);

$form = $this->createForm(
UserUpdateType::class,
$data,
[
'languageCode' => $languageCode,
'mainLanguageCode' => $user->contentInfo->mainLanguageCode,
'mainLanguageCode' => $user->getContentInfo()->getMainLanguageCode(),
'struct' => $data,
//This is **the only permissible case for nullable content**. It stems from the fact that
//one's own user profile editing shouldn't undergo permissions checks. Otherwise, it
//would be impossible to composer role that would allow that out of the box for all users
//that are assigned to it.
'content' => null,
]
);

Expand All @@ -107,14 +90,15 @@ public function editAction(Request $request, ?string $languageCode)

$location = $this->repository->sudo(
fn (): Location => $this->locationService->loadLocation(
(int)$user->versionInfo->contentInfo->mainLocationId
(int)$user->getVersionInfo()->getContentInfo()->getMainLocationId()
)
);

$parentLocation = null;
try {
$parentLocation = $this->locationService->loadLocation($location->parentLocationId);
} catch (UnauthorizedException $e) {
} catch (UnauthorizedException) {
//do nothing
}

return new UserUpdateView(
Expand Down
4 changes: 3 additions & 1 deletion src/bundle/Controller/UserOnTheFlyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public function createUserAction(
$form = $this->createForm(UserCreateType::class, $data, [
'languageCode' => $language->languageCode,
'mainLanguageCode' => $language->languageCode,
'struct' => $data,
]);

$form->handleRequest($request);
Expand Down Expand Up @@ -195,7 +196,8 @@ public function editUserAction(
[
'location' => $location,
'languageCode' => $languageCode,
'mainLanguageCode' => $user->contentInfo->mainLanguageCode,
'mainLanguageCode' => $user->getContentInfo()->getMainLanguageCode(),
'struct' => $contentUpdate,
]
);

Expand Down
Loading