-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! IBX-6645: Added user profile page
- Loading branch information
Showing
6 changed files
with
190 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Bundle\AdminUi\Controller\User; | ||
|
||
use Ibexa\AdminUi\Specification\UserProfile\IsProfileAvailable; | ||
use Ibexa\AdminUi\UserProfile\UserProfileConfigurationInterface; | ||
use Ibexa\ContentForms\Data\Mapper\UserUpdateMapper; | ||
use Ibexa\ContentForms\Form\ActionDispatcher\ActionDispatcherInterface; | ||
use Ibexa\ContentForms\Form\Type\User\UserUpdateType; | ||
use Ibexa\ContentForms\User\View\UserUpdateView; | ||
use Ibexa\Contracts\AdminUi\Controller\Controller; | ||
use Ibexa\Contracts\ContentForms\Content\Form\Provider\GroupedContentFormFieldsProviderInterface; | ||
use Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException; | ||
use Ibexa\Contracts\Core\Repository\LanguageService; | ||
use Ibexa\Contracts\Core\Repository\LocationService; | ||
use Ibexa\Contracts\Core\Repository\PermissionResolver; | ||
use Ibexa\Contracts\Core\Repository\Repository; | ||
use Ibexa\Contracts\Core\Repository\UserService; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Field; | ||
use Ibexa\Contracts\Core\Repository\Values\User\User; | ||
use Ibexa\Core\Base\Exceptions\UnauthorizedException as CoreUnauthorizedException; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
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 | ||
) { | ||
$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, int $userId, string $languageCode = 'eng-GB') | ||
{ | ||
$user = $this->userService->loadUser($this->permissionResolver->getCurrentUserReference()->getUserId()); | ||
if (!$this->isUserProfileAvailable($user)) { | ||
throw $this->createNotFoundException(); | ||
} | ||
|
||
if (!$this->permissionResolver->canUser('user', 'selfedit', $user)) { | ||
throw new CoreUnauthorizedException('user', 'selfedit', ['userId' => $user->getUserId()]); | ||
} | ||
|
||
$userUpdate = (new UserUpdateMapper())->mapToFormData($user, $user->getContentType(), [ | ||
'languageCode' => $languageCode, | ||
'filter' => static fn (Field $field): bool => $field->fieldTypeIdentifier !== 'ezuser', | ||
]); | ||
|
||
$form = $this->createForm( | ||
UserUpdateType::class, | ||
$userUpdate, | ||
[ | ||
'languageCode' => $languageCode, | ||
'mainLanguageCode' => $user->contentInfo->mainLanguageCode, | ||
] | ||
); | ||
|
||
$form->handleRequest($request); | ||
if ($form->isSubmitted() && $form->isValid() && null !== $form->getClickedButton()) { | ||
Check failure on line 97 in src/bundle/Controller/User/ProfileEditController.php GitHub Actions / Tests (7.4)
Check failure on line 97 in src/bundle/Controller/User/ProfileEditController.php GitHub Actions / Tests (8.0)
|
||
$this->userActionDispatcher->dispatchFormAction($form, $userUpdate, $form->getClickedButton()->getName()); | ||
Check failure on line 98 in src/bundle/Controller/User/ProfileEditController.php GitHub Actions / Tests (7.4)
Check failure on line 98 in src/bundle/Controller/User/ProfileEditController.php GitHub Actions / Tests (8.0)
|
||
if ($response = $this->userActionDispatcher->getResponse()) { | ||
return $response; | ||
} | ||
} | ||
|
||
$location = $this->repository->sudo(function () use ($user) { | ||
return $this->locationService->loadLocation( | ||
(int)$user->versionInfo->contentInfo->mainLocationId | ||
); | ||
}); | ||
|
||
$parentLocation = null; | ||
try { | ||
$parentLocation = $this->locationService->loadLocation($location->parentLocationId); | ||
} catch (UnauthorizedException $e) { | ||
} | ||
|
||
return new UserUpdateView( | ||
null, | ||
[ | ||
'form' => $form->createView(), | ||
'language_code' => $languageCode, | ||
'language' => $this->languageService->loadLanguage($languageCode), | ||
'content_type' => $user->getContentType(), | ||
'user' => $user, | ||
'location' => $location, | ||
'parent_location' => $parentLocation, | ||
'grouped_fields' => $this->groupedContentFormFieldsProvider->getGroupedFields( | ||
$form->get('fieldsData')->all() | ||
), | ||
] | ||
); | ||
} | ||
|
||
private function isUserProfileAvailable(User $user): bool | ||
{ | ||
return (new IsProfileAvailable($this->configuration))->isSatisfiedBy($user); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
tests/bundle/DependencyInjection/Configuration/Parser/UserProfileTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Tests\Bundle\AdminUi\DependencyInjection\Configuration\Parser; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
final class UserProfileTest extends TestCase | ||
{ | ||
} |