diff --git a/src/bundle/Controller/User/ProfileEditController.php b/src/bundle/Controller/User/ProfileEditController.php index eb7086a489..2a3c3a0d1e 100644 --- a/src/bundle/Controller/User/ProfileEditController.php +++ b/src/bundle/Controller/User/ProfileEditController.php @@ -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(); } @@ -81,11 +58,11 @@ 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( @@ -93,7 +70,13 @@ public function editAction(Request $request, ?string $languageCode) $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, ] ); @@ -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( diff --git a/src/bundle/Controller/UserOnTheFlyController.php b/src/bundle/Controller/UserOnTheFlyController.php index 512ecaea34..096a1c8be0 100644 --- a/src/bundle/Controller/UserOnTheFlyController.php +++ b/src/bundle/Controller/UserOnTheFlyController.php @@ -101,6 +101,7 @@ public function createUserAction( $form = $this->createForm(UserCreateType::class, $data, [ 'languageCode' => $language->languageCode, 'mainLanguageCode' => $language->languageCode, + 'struct' => $data, ]); $form->handleRequest($request); @@ -195,7 +196,8 @@ public function editUserAction( [ 'location' => $location, 'languageCode' => $languageCode, - 'mainLanguageCode' => $user->contentInfo->mainLanguageCode, + 'mainLanguageCode' => $user->getContentInfo()->getMainLanguageCode(), + 'struct' => $contentUpdate, ] );