Skip to content

Commit

Permalink
IBX-6645: Added user profile page
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwojs committed Dec 3, 2023
1 parent 8ed6698 commit a2f154a
Show file tree
Hide file tree
Showing 18 changed files with 488 additions and 11 deletions.
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8210,11 +8210,6 @@ parameters:
count: 1
path: src/lib/Menu/UserMenuBuilder.php

-
message: "#^Method Ibexa\\\\AdminUi\\\\Menu\\\\UserMenuBuilder\\:\\:getTranslationMessages\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Menu/UserMenuBuilder.php

-
message: "#^Method Ibexa\\\\AdminUi\\\\Menu\\\\UserPasswordChangeRightSidebarBuilder\\:\\:createStructure\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#"
count: 1
Expand Down
85 changes: 85 additions & 0 deletions src/bundle/Controller/User/ProfileController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?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\UserProfile\UserProfileConfiguration;
use Ibexa\Contracts\AdminUi\Controller\Controller;
use Ibexa\Contracts\Core\Repository\RoleService;
use Ibexa\Contracts\Core\Repository\UserService;
use Ibexa\Contracts\Core\Repository\Values\User\User;
use Symfony\Component\HttpFoundation\Response;

final class ProfileController extends Controller
{
private UserService $userService;

private RoleService $roleService;

private UserProfileConfiguration $configuration;

public function __construct(
UserService $userService,
RoleService $roleService,
UserProfileConfiguration $configuration
) {
$this->userService = $userService;
$this->roleService = $roleService;
$this->configuration = $configuration;
}

public function viewAction(int $userId): Response
{
$user = $this->userService->loadUser($userId);
if (!$this->isUserProfileEnabled($user)) {
throw $this->createNotFoundException();
}

$roles = $this->roleService->getRoleAssignmentsForUser($user, true);

return $this->render(
'@ibexadesign/account/profile/view.html.twig',
[
'user' => $user,
'roles' => $roles,
'field_groups' => $this->configuration->getFieldGroup(),
]
);
}

public function editAction(int $userId): Response
{
$user = $this->userService->loadUser($userId);
if (!$this->isUserProfileEnabled($user)) {
throw $this->createNotFoundException();
}

// TODO: Add language selection ?
return $this->redirectToRoute(
'ibexa.user.update',
[
'contentId' => $user->getUserId(),
'language' => $user->contentInfo->mainLanguageCode,
'versionNo' => $user->versionInfo->versionNo,
]
);
}

private function isUserProfileEnabled(User $user): bool
{
if ($this->configuration->isEnabled()) {
return in_array(
$user->getContentType()->identifier,
$this->configuration->getContentTypes(),
true
);
}

return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?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\DependencyInjection\Configuration\Parser;

use Ibexa\Bundle\Core\DependencyInjection\Configuration\AbstractParser;
use Ibexa\Bundle\Core\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface;
use Symfony\Component\Config\Definition\Builder\NodeBuilder;

final class UserProfile extends AbstractParser
{
public function addSemanticConfig(NodeBuilder $nodeBuilder): void
{
$nodeBuilder
->arrayNode('user_profile')
->addDefaultsIfNotSet()
->children()
->booleanNode('enabled')
->defaultFalse()
->end()
->arrayNode('content_types')
->scalarPrototype()->end()
->defaultValue(['editor'])
->example(['editor', 'administrator'])
->end()
->arrayNode('field_groups')
->defaultValue(['about', 'contact'])
->scalarPrototype()->end()
->example(['about', 'contact'])
->end()
->end()
->end();
}

/**
* @param array<string, mixed> $scopeSettings
* @param string $currentScope
*/
public function mapConfig(array &$scopeSettings, $currentScope, ContextualizerInterface $contextualizer): void
{
if (empty($scopeSettings['user_profile'])) {
return;
}

$contextualizer->setContextualParameter(
'user_profile.enabled',
$currentScope,
$scopeSettings['user_profile']['enabled']
);

$contextualizer->setContextualParameter(
'user_profiler.content_types',
$currentScope,
$scopeSettings['user_profile']['content_types']
);

$contextualizer->setContextualParameter(
'user_profile.field_groups',
$currentScope,
$scopeSettings['user_profile']['field_groups']
);
}
}
1 change: 1 addition & 0 deletions src/bundle/IbexaAdminUiBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ private function getConfigParsers(): array
new Parser\LimitationValueTemplates(),
new Parser\Assets(),
new Parser\AdminUiParser(),
new Parser\UserProfile(),
];
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/bundle/Resources/config/ezplatform_default_settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ parameters:
ibexa.site_access.config.default.subitems_module.limit: 10

# User identifier
ibexa.site_access.config.admin_group.user_content_type_identifier: ['user']
ibexa.site_access.config.admin_group.user_content_type_identifier: ['user', 'editor']

# User Group identifier
ibexa.site_access.config.admin_group.user_group_content_type_identifier: ['user_group']
Expand Down Expand Up @@ -82,3 +82,8 @@ parameters:

ibexa.site_access.config.admin_group.autosave.enabled: true
ibexa.site_access.config.admin_group.autosave.interval: 60

# User profiles
ibexa.site_access.config.admin_group.user_profile.enabled: false
ibexa.site_access.config.admin_group.user_profile.content_types: ['editor', 'user']
ibexa.site_access.config.admin_group.user_profile.field_groups: ['about', 'contact']
12 changes: 12 additions & 0 deletions src/bundle/Resources/config/routing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,18 @@ ibexa.user.invite.to_group:
controller: Ibexa\Bundle\AdminUi\Controller\User\InvitationController::sendInvitationsAction
methods: ['POST']

ibexa.user.profile.view:
path: /user/profile/{userId}/view
controller: Ibexa\Bundle\AdminUi\Controller\User\ProfileController::viewAction
methods: ['GET']
options:
exposed: true

ibexa.user.profile.edit:
path: /user/profile/{userId}/edit
controller: Ibexa\Bundle\AdminUi\Controller\User\ProfileController::editAction
methods: ['GET', 'POST']

#
# Custom URL alias
#
Expand Down
1 change: 1 addition & 0 deletions src/bundle/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ imports:
- { resource: services/form_ui_action_mappers.yaml }
- { resource: services/views.yaml }
- { resource: services/translation.yaml }
- { resource: services/user_profile.yaml }
- { resource: services/user_settings.yaml }
- { resource: services/rest.yaml }
- { resource: services/permissions.yaml }
Expand Down
6 changes: 6 additions & 0 deletions src/bundle/Resources/config/services/controllers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ services:
tags:
- controller.service_arguments

Ibexa\Bundle\AdminUi\Controller\User\ProfileController:
parent: Ibexa\Contracts\AdminUi\Controller\Controller
autowire: true
tags:
- controller.service_arguments

Ibexa\Bundle\AdminUi\Controller\Version\VersionConflictController: ~

Ibexa\Bundle\AdminUi\Controller\VersionController:
Expand Down
14 changes: 14 additions & 0 deletions src/bundle/Resources/config/services/user_profile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
services:
_defaults:
autowire: true
autoconfigure: true
public: false

Ibexa\AdminUi\UserProfile\UserProfileConfiguration: ~

Ibexa\AdminUi\UserProfile\UserProfileFieldGroupsProvider:
decorates: Ibexa\Core\Helper\FieldsGroups\FieldsGroupsList
arguments:
$innerService: '@.inner'


45 changes: 45 additions & 0 deletions src/bundle/Resources/public/scss/_user-profile.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
.ibexa-user-profile-view {
.ibexa-user-profile {
display: flex;

&__aside {
width: 30%;
margin-right: 20px;

.ibexa-user-thumbnail-wrapper {
text-align: center;
margin-bottom: -80px;

.ibexa-user-thumbnail {
background: $ibexa-color-white;
border: calculateRem(1px) solid $ibexa-color-light;
border-radius: 50%;
padding: calculateRem(3px);

&--img {
width: 200px;
height: 200px;
}
}
}

.ibexa-user-profile-info {
padding-top: 100px;
}
}

&__body {
width: 75%;

.ibexa-user-profile-name {
min-height: 120px;
vertical-align: middle;
display: flex;

h1 {
margin: 40px 0;
}
}
}
}
}
1 change: 1 addition & 0 deletions src/bundle/Resources/public/scss/ibexa.scss
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,4 @@
@import 'switcher';
@import 'global-search';
@import 'user-name';
@import 'user-profile';
15 changes: 15 additions & 0 deletions src/bundle/Resources/translations/ibexa_admin_ui.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,26 @@
<target state="new">Select language</target>
<note>key: edit_translation.list.title</note>
</trans-unit>
<trans-unit id="773756d8360258c56797a597252082a335b25e2c" resname="profile.view.title">
<source>User profile</source>
<target state="new">User profile</target>
<note>key: profile.view.title</note>
</trans-unit>
<trans-unit id="e4b8188e898e654dae14fc6b18133958f8e56084" resname="translation.remove.success">
<source>Removed '%languageCode%' translation from '%name%'.</source>
<target state="new">Removed '%languageCode%' translation from '%name%'.</target>
<note>key: translation.remove.success</note>
</trans-unit>
<trans-unit id="d88f09dfa6b5a01de87c36fb97c09902cebcb3cc" resname="user_profile.action.edit">
<source>Edit</source>
<target state="new">Edit</target>
<note>key: user_profile.action.edit</note>
</trans-unit>
<trans-unit id="0f5838e96bc64daa4815d5ffc1acdfab0e9b1af5" resname="user_profile.roles.header">
<source>Roles</source>
<target state="new">Roles</target>
<note>key: user_profile.roles.header</note>
</trans-unit>
<trans-unit id="885ec7aab950e05f729031321cddbb6d7f9c3246" resname="version.delete.success">
<source>Removed version(s) from '%name%'.</source>
<target state="new">Removed version(s) from '%name%'.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/bundle/Resources/translations/ibexa_menu.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,11 @@
<target state="new">Save and close</target>
<note>key: url_wildcard_edit__sidebar_right__save_and_close</note>
</trans-unit>
<trans-unit id="4b4f243361b4b2302972e72a91e95052da5fb703" resname="user___view_profile">
<source>View Profile</source>
<target state="new">View Profile</target>
<note>key: user___view_profile</note>
</trans-unit>
<trans-unit id="06accb26fbb1b72012942af2b3e03f7c138e28c3" resname="user__content">
<source>Logout</source>
<target state="new">Logout</target>
Expand Down
Loading

0 comments on commit a2f154a

Please sign in to comment.