-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IBX-2493: Added option to invite other users to DXP & register from i…
…nvitation (#35) * IBX-2493: Added option for SA aware registered user content type * IBX-2493: Added possibility of inviting other users to given SA * IBX-2493: Added limitation system for user / invite * IBX-1543: Added option to consume invitation * IBX-2493: Added unit tests for new Limitation and Invitation validation * IBX-2493: Fixed role filtering * IBX-2493: Added group filtering * IBX-2493: Fixed code style * IBX-2493: Redo UserGroup ChoiceLoader * IBX-2493: Fixed minor issues after code review * IBX-2493: Refactored to use create struct * [CS]: Fixed codestyle * Used Batch iterator * Fixed service name * Used SA identifier instead of full object * Extracted persistence layer * Changed properties/classes visibility * Added minor fixes after review * Moved stuff around * Fixed callables
- Loading branch information
Showing
53 changed files
with
2,946 additions
and
32 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,90 @@ | ||
<?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\User\Controller; | ||
|
||
use Ibexa\Contracts\User\Invitation\Exception\InvitationAlreadyExistsException; | ||
use Ibexa\Contracts\User\Invitation\Exception\UserAlreadyExistsException; | ||
use Ibexa\Contracts\User\Invitation\InvitationCreateStruct; | ||
use Ibexa\Contracts\User\Invitation\InvitationSender; | ||
use Ibexa\Contracts\User\Invitation\InvitationService; | ||
use Ibexa\User\ExceptionHandler\ActionResultHandler; | ||
use Ibexa\User\Form\Type\Invitation\UserInvitationType; | ||
use Ibexa\User\View\Invitation\FormView; | ||
use Symfony\Component\Form\FormFactoryInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
final class UserInvitationController extends Controller | ||
{ | ||
private InvitationService $invitationService; | ||
|
||
private InvitationSender $mailSender; | ||
|
||
private FormFactoryInterface $formFactory; | ||
|
||
private ActionResultHandler $actionResultHandler; | ||
|
||
public function __construct( | ||
InvitationService $invitationService, | ||
InvitationSender $mailSender, | ||
FormFactoryInterface $formFactory, | ||
ActionResultHandler $actionResultHandler | ||
) { | ||
$this->invitationService = $invitationService; | ||
$this->mailSender = $mailSender; | ||
$this->formFactory = $formFactory; | ||
$this->actionResultHandler = $actionResultHandler; | ||
} | ||
|
||
public function inviteUser(Request $request): FormView | ||
{ | ||
$form = $this->formFactory->create(UserInvitationType::class); | ||
$form->handleRequest($request); | ||
|
||
if ($form->isSubmitted() && $form->isValid()) { | ||
/** @var \Ibexa\User\Form\Data\UserInvitationData $data */ | ||
$data = $form->getData(); | ||
try { | ||
$invitation = $this->invitationService->createInvitation( | ||
new InvitationCreateStruct( | ||
$data->getEmail(), | ||
$data->getSiteaccess()->name, | ||
$data->getUserGroup(), | ||
$data->getRole(), | ||
$data->getRoleLimitation(), | ||
) | ||
); | ||
|
||
$this->mailSender->sendInvitation($invitation); | ||
|
||
$this->actionResultHandler->success( | ||
/** @Desc("Invitation send to '%email%' updated.") */ | ||
'user_invitation.send.success', | ||
['%email%' => $data->getEmail()], | ||
'user_invitation' | ||
); | ||
} catch (InvitationAlreadyExistsException $e) { | ||
$this->actionResultHandler->error( | ||
/** @Desc("Invitation for '%email%' already exist.") */ | ||
'user_invitation.send.invitation_exist', | ||
['%email%' => $data->getEmail()], | ||
'user_invitation' | ||
); | ||
} catch (UserAlreadyExistsException $e) { | ||
$this->actionResultHandler->error( | ||
/** @Desc("User with '%email%' already exist.") */ | ||
'user_invitation.send.user_exist', | ||
['%email%' => $data->getEmail()], | ||
'user_invitation' | ||
); | ||
} | ||
} | ||
|
||
return new FormView(null, ['form' => $form->createView()]); | ||
} | ||
} |
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
90 changes: 90 additions & 0 deletions
90
src/bundle/DependencyInjection/Configuration/Parser/UserInvitation.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,90 @@ | ||
<?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\User\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; | ||
|
||
/* | ||
* Example configuration: | ||
* ```yaml | ||
* ibexa: | ||
* system: | ||
* default: # configuration per siteaccess or siteaccess group | ||
* user_invitation: | ||
* hash_expiration_time: P1D | ||
* templates: | ||
* mail: "@@App/invitation/mail.html.twig" | ||
* ``` | ||
*/ | ||
class UserInvitation extends AbstractParser | ||
{ | ||
/** | ||
* Adds semantic configuration definition. | ||
* | ||
* @param \Symfony\Component\Config\Definition\Builder\NodeBuilder $nodeBuilder Node just under ezpublish.system.<siteaccess> | ||
*/ | ||
public function addSemanticConfig(NodeBuilder $nodeBuilder) | ||
{ | ||
$nodeBuilder | ||
->arrayNode('user_invitation') | ||
->info('User invitation configuration') | ||
->children() | ||
->scalarNode('hash_expiration_time') | ||
->defaultValue('P2D') | ||
->end() | ||
->arrayNode('templates') | ||
->info('User invitation templates.') | ||
->children() | ||
->scalarNode('form') | ||
->info('Template to use for registration form rendering.') | ||
->end() | ||
->scalarNode('mail') | ||
->info('Template to use for registration confirmation rendering.') | ||
->end() | ||
->end() | ||
->end() | ||
->end() | ||
->end(); | ||
} | ||
|
||
public function mapConfig(array &$scopeSettings, $currentScope, ContextualizerInterface $contextualizer) | ||
{ | ||
if (empty($scopeSettings['user_invitation'])) { | ||
return; | ||
} | ||
|
||
$settings = $scopeSettings['user_invitation']; | ||
|
||
if (!empty($settings['hash_expiration_time'])) { | ||
$contextualizer->setContextualParameter( | ||
'user_invitation.hash_expiration_time', | ||
$currentScope, | ||
$settings['hash_expiration_time'] | ||
); | ||
} | ||
|
||
if (!empty($settings['templates']['form'])) { | ||
$contextualizer->setContextualParameter( | ||
'user_invitation.templates.form', | ||
$currentScope, | ||
$settings['templates']['form'] | ||
); | ||
} | ||
|
||
if (!empty($settings['templates']['mail'])) { | ||
$contextualizer->setContextualParameter( | ||
'user_invitation.templates.mail', | ||
$currentScope, | ||
$settings['templates']['mail'] | ||
); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
services: | ||
Ibexa\User\EventListener\BuildSchemaSubscriber: | ||
autoconfigure: true | ||
public: false | ||
arguments: | ||
- '@=service("kernel").locateResource("@IbexaUserBundle/Resources/config/storage/schema.yaml")' |
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
Oops, something went wrong.