continue CRUD user

This commit is contained in:
Julien Fastré 2021-09-23 13:30:04 +02:00
parent b5c2dd7bd2
commit 72b1916da8
12 changed files with 231 additions and 423 deletions

View File

@ -118,7 +118,7 @@ class CRUDController extends AbstractController
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$this->onFormValid($entity, $form, $request); $this->onFormValid($action, $entity, $form, $request);
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
$this->onPreRemove($action, $entity, $form, $request); $this->onPreRemove($action, $entity, $form, $request);
@ -607,7 +607,7 @@ class CRUDController extends AbstractController
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$this->onFormValid($entity, $form, $request); $this->onFormValid($action, $entity, $form, $request);
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
$this->onPreFlush($action, $entity, $form, $request); $this->onPreFlush($action, $entity, $form, $request);
@ -706,7 +706,7 @@ class CRUDController extends AbstractController
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$this->onFormValid($entity, $form, $request); $this->onFormValid($action, $entity, $form, $request);
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
$this->onPrePersist($action, $entity, $form, $request); $this->onPrePersist($action, $entity, $form, $request);
@ -716,7 +716,7 @@ class CRUDController extends AbstractController
$this->onPreFlush($action, $entity, $form, $request); $this->onPreFlush($action, $entity, $form, $request);
$em->flush(); $em->flush();
$this->onPostFlush($action, $entity, $form, $request); $this->onPostFlush($action, $entity, $form, $request);
$this->getPaginatorFactory();
$this->addFlash('success', $this->generateFormSuccessMessage($action, $entity)); $this->addFlash('success', $this->generateFormSuccessMessage($action, $entity));
$result = $this->onBeforeRedirectAfterSubmission($action, $entity, $form, $request); $result = $this->onBeforeRedirectAfterSubmission($action, $entity, $form, $request);
@ -1084,12 +1084,7 @@ class CRUDController extends AbstractController
return null; return null;
} }
/** protected function onFormValid(string $action, object $entity, FormInterface $form, Request $request)
* @param object $entity
* @param FormInterface $form
* @param Request $request
*/
protected function onFormValid(object $entity, FormInterface $form, Request $request)
{ {
} }

View File

@ -4,8 +4,10 @@ namespace Chill\MainBundle\Controller;
use Chill\MainBundle\CRUD\Controller\AbstractCRUDController; use Chill\MainBundle\CRUD\Controller\AbstractCRUDController;
use Chill\MainBundle\CRUD\Controller\CRUDController; use Chill\MainBundle\CRUD\Controller\CRUDController;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\User;
@ -13,10 +15,10 @@ use Chill\MainBundle\Form\UserType;
use Chill\MainBundle\Entity\GroupCenter; use Chill\MainBundle\Entity\GroupCenter;
use Chill\MainBundle\Form\Type\ComposedGroupCenterType; use Chill\MainBundle\Form\Type\ComposedGroupCenterType;
use Chill\MainBundle\Form\UserPasswordType; use Chill\MainBundle\Form\UserPasswordType;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface; use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter;
/** /**
@ -48,63 +50,38 @@ class UserController extends CRUDController
* @param ValidatorInterface $validator * @param ValidatorInterface $validator
*/ */
public function __construct( public function __construct(
LoggerInterface $logger, LoggerInterface $chillLogger,
ValidatorInterface $validator, ValidatorInterface $validator,
UserPasswordEncoderInterface $passwordEncoder UserPasswordEncoderInterface $passwordEncoder
) { ) {
$this->logger = $logger; $this->logger = $chillLogger;
$this->validator = $validator; $this->validator = $validator;
$this->passwordEncoder = $passwordEncoder; $this->passwordEncoder = $passwordEncoder;
} }
/** protected function createFormFor(string $action, $entity, string $formClass = null, array $formOptions = []): FormInterface
* Creates a new User entity.
*
*/
public function new(Request $request): Response
{ {
$user = new User(); // for "new", add special config
$form = $this->createCreateForm($user); if ('new' === $action) {
$form->handleRequest($request); return $this->createForm(UserType::class, $entity, array(
'is_creation' => true
if ($form->isSubmitted() && $form->isValid()) { ));
$em = $this->getDoctrine()->getManager();
$user->setPassword($this->passwordEncoder
->encodePassword($user, $form['plainPassword']->getData()));
$em->persist($user);
$em->flush();
return $this->redirect($this->generateUrl('admin_user_show', array('id' => $user->getId())));
} elseif ($form->isSubmitted() && !$form->isValid()){
} }
return $this->render('@ChillMain/User/new.html.twig', array( // default behaviour
'entity' => $user, return parent::createFormFor($action, $entity, $formClass, $formOptions);
'form' => $form->createView(),
));
} }
/** protected function onPrePersist(string $action, $entity, FormInterface $form, Request $request)
* Creates a form to create a User entity.
*
* @param User $entity The entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createCreateForm(User $entity)
{ {
$form = $this->createForm(UserType::class, $entity, array( // for "new", encode the password
'action' => $this->generateUrl('admin_user_create'), if ('new' === $action) {
'method' => 'POST', $entity->setPassword($this->passwordEncoder
'is_creation' => true ->encodePassword($entity, $form['plainPassword']->getData()));
)); }
$form->add('submit', SubmitType::class, array('label' => 'Create')); // default behaviour
parent::onPrePersist($action, $entity, $form, $request);
return $form;
} }
/** /**
@ -126,55 +103,63 @@ class UserController extends CRUDController
)); ));
} }
/**
* Displays a form to edit an existing User entity. protected function generateTemplateParameter(string $action, $entity, Request $request, array $defaultTemplateParameters = [])
*
*/
public function editAction($id)
{ {
$em = $this->getDoctrine()->getManager(); // add mini-forms for edit action
if ("edit" === $action) {
$user = $em->getRepository('ChillMainBundle:User')->find($id); return array_merge(
$defaultTemplateParameters,
if (!$user) { [
throw $this->createNotFoundException('Unable to find User entity.'); 'add_groupcenter_form' => $this->createAddLinkGroupCenterForm($entity, $request)->createView(),
'delete_groupcenter_form' => array_map(
function(\Symfony\Component\Form\Form $form) {
return $form->createView();
},
iterator_to_array($this->getDeleteLinkGroupCenterByUser($entity, $request), true)
)
]
);
} }
$editForm = $this->createEditForm($user); // default behaviour
return parent::generateTemplateParameter($action, $entity, $request, $defaultTemplateParameters);
return $this->render('@ChillMain/User/edit.html.twig', array(
'entity' => $user,
'edit_form' => $editForm->createView(),
'add_groupcenter_form' => $this->createAddLinkGroupCenterForm($user)->createView(),
'delete_groupcenter_form' => array_map(
function(\Symfony\Component\Form\Form $form) {
return $form->createView();
},
iterator_to_array($this->getDeleteLinkGroupCenterByUser($user), true))
));
} }
/** /**
* Displays a form to edit the user password. * Displays a form to edit the user password.
* *
* @Route("/{_locale}/admin/user/{id}/edit_password", name="admin_user_edit_password")
*/ */
public function editPasswordAction($id) public function editPasswordAction(User $user, Request $request)
{ {
$em = $this->getDoctrine()->getManager(); $editForm = $this->createEditPasswordForm($user, $request);
$editForm->handleRequest($request);
$user = $em->getRepository('ChillMainBundle:User')->find($id); if ($editForm->isSubmitted() && $editForm->isValid()) {
$password = $editForm->get('new_password')->getData();
if (!$user) { // logging for prod
throw $this->createNotFoundException('Unable to find User entity.'); $this->logger->info('update password for an user', [
'by' => $this->getUser()->getUsername(),
'user' => $user->getUsername()
]);
$user->setPassword($this->passwordEncoder->encodePassword($user, $password));
$this->getDoctrine()->getManager()->flush();
$this->addFlash('success', $this->get('translator')->trans('Password successfully updated!'));
return $this->redirect(
$request->query->has('returnPath') ? $request->query->get('returnPath') :
$this->generateUrl('chill_crud_admin_user_edit', ['id' => $user->getId()])
);
} }
$editForm = $this->createEditPasswordForm($user); return $this->render('@ChillMain/User/edit_password.html.twig', [
return $this->render('@ChillMain/User/edit_password.html.twig', array(
'entity' => $user, 'entity' => $user,
'edit_form' => $editForm->createView() 'edit_form' => $editForm->createView()
)); ]);
} }
/** /**
@ -186,9 +171,6 @@ class UserController extends CRUDController
private function createEditPasswordForm(User $user) private function createEditPasswordForm(User $user)
{ {
return $this->createForm(UserPasswordType::class, null, array( return $this->createForm(UserPasswordType::class, null, array(
'action' =>
$this->generateUrl('admin_user_update_password', array('id' => $user->getId())),
'method' => 'PUT',
'user' => $user 'user' => $user
)) ))
->add('submit', SubmitType::class, array('label' => 'Change password')) ->add('submit', SubmitType::class, array('label' => 'Change password'))
@ -196,7 +178,11 @@ class UserController extends CRUDController
; ;
} }
public function deleteLinkGroupCenterAction($uid, $gcid) /**
* @Route("/{_locale}/admin/main/user/{uid}/delete_link_groupcenter/{gcid}",
* name="admin_user_delete_groupcenter")
*/
public function deleteLinkGroupCenterAction($uid, $gcid, Request $request): RedirectResponse
{ {
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
@ -218,7 +204,7 @@ class UserController extends CRUDController
} catch (\RuntimeException $ex) { } catch (\RuntimeException $ex) {
$this->addFlash('error', $this->get('translator')->trans($ex->getMessage())); $this->addFlash('error', $this->get('translator')->trans($ex->getMessage()));
return $this->redirect($this->generateUrl('admin_user_edit', array('id' => $uid))); return $this->redirect($this->generateUrl('chill_crud_admin_user_edit', array('id' => $uid)));
} }
$em->flush(); $em->flush();
@ -226,11 +212,15 @@ class UserController extends CRUDController
$this->addFlash('success', $this->get('translator') $this->addFlash('success', $this->get('translator')
->trans('The permissions where removed.')); ->trans('The permissions where removed.'));
return $this->redirect($this->generateUrl('admin_user_edit', array('id' => $uid))); return $this->redirect($this->generateUrl('chill_crud_admin_user_edit', array('id' => $uid)));
} }
public function addLinkGroupCenterAction(Request $request, $uid) /**
* @Route("/{_locale}/admin/main/user/{uid}/add_link_groupcenter",
* name="admin_user_add_groupcenter")
*/
public function addLinkGroupCenterAction(Request $request, $uid): RedirectResponse
{ {
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
@ -240,7 +230,7 @@ class UserController extends CRUDController
throw $this->createNotFoundException('Unable to find User entity.'); throw $this->createNotFoundException('Unable to find User entity.');
} }
$form = $this->createAddLinkGroupCenterForm($user); $form = $this->createAddLinkGroupCenterForm($user, $request);
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isValid()) { if ($form->isValid()) {
@ -254,8 +244,12 @@ class UserController extends CRUDController
$this->addFlash('success', $this->get('translator')->trans('The ' $this->addFlash('success', $this->get('translator')->trans('The '
. 'permissions have been successfully added to the user')); . 'permissions have been successfully added to the user'));
return $this->redirect($this->generateUrl('admin_user_edit', $returnPathParams = $request->query->has('returnPath') ?
array('id' => $uid))); ['returnPath' => $request->query->get('returnPath')] : [];
return $this->redirect($this->generateUrl('chill_crud_admin_user_edit',
\array_merge(['id' => $uid], $returnPathParams)));
} else { } else {
foreach($this->validator->validate($user) as $error) foreach($this->validator->validate($user) as $error)
$this->addFlash('error', $error->getMessage()); $this->addFlash('error', $error->getMessage());
@ -293,104 +287,6 @@ class UserController extends CRUDController
return $groupCenterManaged; return $groupCenterManaged;
} }
/**
* Creates a form to edit a User entity.
*
* @param User $user The entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createEditForm(User $user)
{
$form = $this->createForm(UserType::class, $user, array(
'action' => $this->generateUrl('admin_user_update', array('id' => $user->getId())),
'method' => 'PUT',
));
$form->add('submit', SubmitType::class, array('label' => 'Update'));
return $form;
}
/**
* Edits an existing User entity.
*
*/
public function updateAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$user = $em->getRepository('ChillMainBundle:User')->find($id);
if (!$user) {
throw $this->createNotFoundException('Unable to find User entity.');
}
$editForm = $this->createEditForm($user);
$editForm->handleRequest($request);
if ($editForm->isValid()) {
$em->flush();
return $this->redirect($this->generateUrl('admin_user_edit', array('id' => $id)));
}
return $this->render('@ChillMain/User/edit.html.twig', array(
'entity' => $user,
'edit_form' => $editForm->createView(),
'add_groupcenter_form' => $this->createAddLinkGroupCenterForm($user)->createView(),
'delete_groupcenter_form' => array_map(
function(\Symfony\Component\Form\Form $form) {
return $form->createView();
},
iterator_to_array($this->getDeleteLinkGroupCenterByUser($user), true))
));
}
/**
* Edits the user password
*
*/
public function updatePasswordAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$user = $em->getRepository('ChillMainBundle:User')->find($id);
if (!$user) {
throw $this->createNotFoundException('Unable to find User entity.');
}
$editForm = $this->createEditPasswordForm($user);
$editForm->handleRequest($request);
if ($editForm->isValid()) {
$password = $editForm->get('new_password')->getData();
// logging for prod
$this->logger->info('update password for an user', [
'by' => $this->getUser()->getUsername(),
'user' => $user->getUsername()
]);
$user->setPassword($this->get('security.password_encoder')
->encodePassword($user, $password));
$em->flush();
$this->addFlash('success', $this->get('translator')->trans('Password successfully updated!'));
return $this->redirect($this->generateUrl('admin_user_edit', array('id' => $id)));
}
return $this->render('@ChillMain/User/edit_password.html.twig', array(
'entity' => $user,
'edit_form' => $editForm->createView(),
));
}
/** /**
* Creates a form to delete a link to a GroupCenter * Creates a form to delete a link to a GroupCenter
* *
@ -398,11 +294,13 @@ class UserController extends CRUDController
* *
* @return \Symfony\Component\Form\Form The form * @return \Symfony\Component\Form\Form The form
*/ */
private function createDeleteLinkGroupCenterForm(User $user, GroupCenter $groupCenter) private function createDeleteLinkGroupCenterForm(User $user, GroupCenter $groupCenter, $request)
{ {
$returnPathParams = $request->query->has('returnPath') ? ['returnPath' => $request->query->get('returnPath')] : [];
return $this->createFormBuilder() return $this->createFormBuilder()
->setAction($this->generateUrl('admin_user_delete_group_center', ->setAction($this->generateUrl('admin_user_delete_groupcenter',
array('uid' => $user->getId(), 'gcid' => $groupCenter->getId()))) array_merge($returnPathParams, ['uid' => $user->getId(), 'gcid' => $groupCenter->getId()])))
->setMethod('DELETE') ->setMethod('DELETE')
->add('submit', SubmitType::class, array('label' => 'Delete')) ->add('submit', SubmitType::class, array('label' => 'Delete'))
->getForm() ->getForm()
@ -415,11 +313,13 @@ class UserController extends CRUDController
* @param User $user * @param User $user
* @return \Symfony\Component\Form\Form * @return \Symfony\Component\Form\Form
*/ */
private function createAddLinkGroupCenterForm(User $user) private function createAddLinkGroupCenterForm(User $user, Request $request)
{ {
$returnPathParams = $request->query->has('returnPath') ? ['returnPath' => $request->query->get('returnPath')] : [];
return $this->createFormBuilder() return $this->createFormBuilder()
->setAction($this->generateUrl('admin_user_add_group_center', ->setAction($this->generateUrl('admin_user_add_groupcenter',
array('uid' => $user->getId()))) array_merge($returnPathParams, ['uid' => $user->getId()])))
->setMethod('POST') ->setMethod('POST')
->add(self::FORM_GROUP_CENTER_COMPOSED, ComposedGroupCenterType::class) ->add(self::FORM_GROUP_CENTER_COMPOSED, ComposedGroupCenterType::class)
->add('submit', SubmitType::class, array('label' => 'Add a new groupCenter')) ->add('submit', SubmitType::class, array('label' => 'Add a new groupCenter'))
@ -431,11 +331,11 @@ class UserController extends CRUDController
* *
* @param User $user * @param User $user
*/ */
private function getDeleteLinkGroupCenterByUser(User $user) private function getDeleteLinkGroupCenterByUser(User $user, Request $request)
{ {
foreach ($user->getGroupCenters() as $groupCenter) { foreach ($user->getGroupCenters() as $groupCenter) {
yield $groupCenter->getId() => $this yield $groupCenter->getId() => $this
->createDeleteLinkGroupCenterForm($user, $groupCenter); ->createDeleteLinkGroupCenterForm($user, $groupCenter, $request);
} }
} }
} }

View File

@ -307,9 +307,11 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
], ],
'new' => [ 'new' => [
'role' => 'ROLE_ADMIN', 'role' => 'ROLE_ADMIN',
'template' => '@ChillMain/User/new.html.twig'
], ],
'edit' => [ 'edit' => [
'role' => 'ROLE_ADMIN', 'role' => 'ROLE_ADMIN',
'template' => '@ChillMain/User/edit.html.twig'
] ]
] ]
] ]

View File

@ -47,9 +47,9 @@ class UserType extends AbstractType
]) ])
->add('label', TextType::class) ->add('label', TextType::class)
->add('mainCenter', EntityType::class, [ ->add('mainCenter', EntityType::class, [
'label' => 'main center', 'label' => 'Main center',
'required' => false, 'required' => false,
'placeholder' => 'choose a main center', 'placeholder' => 'Choose a main center',
'class' => Center::class, 'class' => Center::class,
'query_builder' => function (EntityRepository $er) { 'query_builder' => function (EntityRepository $er) {
$qb = $er->createQueryBuilder('c'); $qb = $er->createQueryBuilder('c');
@ -59,16 +59,16 @@ class UserType extends AbstractType
} }
]) ])
->add('mainScope', EntityType::class, [ ->add('mainScope', EntityType::class, [
'label' => 'Choose a main scope', 'label' => 'Main scope',
'required' => false, 'required' => false,
'placeholder' => 'choose a main scope', 'placeholder' => 'Choose a main scope',
'class' => Scope::class, 'class' => Scope::class,
'choice_label' => function (Scope $c) { 'choice_label' => function (Scope $c) {
return $this->translatableStringHelper->localize($c->getName()); return $this->translatableStringHelper->localize($c->getName());
}, },
]) ])
->add('userJob', EntityType::class, [ ->add('userJob', EntityType::class, [
'label' => 'Choose a job', 'label' => 'user job',
'required' => false, 'required' => false,
'placeholder' => 'choose a job', 'placeholder' => 'choose a job',
'class' => UserJob::class, 'class' => UserJob::class,

View File

@ -1,17 +1,22 @@
{% set formId = crudMainFormId|default('crud_main_form') %}
<div class="{% block crud_content_main_div_class %}{% endblock %}"> <div class="{% block crud_content_main_div_class %}{% endblock %}">
{% block crud_content_header %} {% block crud_content_header %}
<h1>{{ ('crud.'~crud_name~'.title_edit')|trans }}</h1> <h1>{{ ('crud.'~crud_name~'.title_edit')|trans }}</h1>
{% endblock crud_content_header %} {% endblock crud_content_header %}
{% block crud_content_form %} {% block crud_content_form %}
{{ form_start(form) }} {{ form_start(form, { 'attr' : { 'id': formId } } ) }}
{% block crud_content_form_rows %} {% block crud_content_form_rows %}
{% for f in form %} {% for f in form %}
{{ form_row(f) }} {{ form_row(f) }}
{% endfor %} {% endfor %}
{% endblock crud_content_form_rows %} {% endblock crud_content_form_rows %}
{{ form_end(form) }}
{% block crud_content_after_form %}{% endblock %}
{% block crud_content_form_actions %} {% block crud_content_form_actions %}
<ul class="record_actions sticky-form-buttons"> <ul class="record_actions sticky-form-buttons">
{% block content_form_actions_back %} {% block content_form_actions_back %}
@ -30,7 +35,7 @@
</li> </li>
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endblock content_form_actions_delete %} {% endblock content_form_actions_delete %}
{% block content_form_actions_view %} {% block content_form_actions_view %}
{% if chill_crud_action_exists(crud_name, 'view') %} {% if chill_crud_action_exists(crud_name, 'view') %}
{% if is_granted(chill_crud_config('role', crud_name, 'view'), entity) %} {% if is_granted(chill_crud_config('role', crud_name, 'view'), entity) %}
@ -39,17 +44,17 @@
</li> </li>
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endblock content_form_actions_view %} {% endblock content_form_actions_view %}
{% block content_form_actions_save_and_close %} {% block content_form_actions_save_and_close %}
<li class=""> <li class="">
<button type="submit" name="submit" value="save-and-close" class="btn btn-update"> <button type="submit" name="submit" value="save-and-close" class="btn btn-update" form="{{ formId }}">
{{ 'crud.edit.save_and_close'|trans }} {{ 'crud.edit.save_and_close'|trans }}
</button> </button>
</li> </li>
{% endblock %} {% endblock %}
{% block content_form_actions_save_and_show %} {% block content_form_actions_save_and_show %}
<li class=""> <li class="">
<button type="submit" name="submit" value="save-and-show" class="btn btn-update"> <button type="submit" name="submit" value="save-and-show" class="btn btn-update" form="{{ formId }}">
{{ 'crud.edit.save_and_show'|trans }} {{ 'crud.edit.save_and_show'|trans }}
</button> </button>
</li> </li>
@ -58,6 +63,5 @@
</ul> </ul>
{% endblock %} {% endblock %}
{{ form_end(form) }}
{% endblock %} {% endblock %}
</div> </div>

View File

@ -5,14 +5,16 @@
{% block crud_content_form %} {% block crud_content_form %}
{{ form_start(form) }} {{ form_start(form) }}
{% block crud_content_form_rows %} {% block crud_content_form_rows %}
{% for f in form %}{% if f.vars.name != 'submit' %} {% for f in form %}{% if f.vars.name != 'submit' %}
{{ form_row(f) }} {{ form_row(f) }}
{% endif %}{% endfor %} {% endif %}{% endfor %}
{% endblock crud_content_form_rows %} {% endblock crud_content_form_rows %}
{% block crud_content_form_actions %} {% block crud_content_after_form %}{% endblock %}
{% block crud_content_form_actions %}
<ul class="record_actions sticky-form-buttons"> <ul class="record_actions sticky-form-buttons">
{% block content_form_actions_back %} {% block content_form_actions_back %}
<li class="cancel"> <li class="cancel">
@ -20,7 +22,7 @@
{{ 'Cancel'|trans }} {{ 'Cancel'|trans }}
</a> </a>
</li> </li>
{% endblock %} {% endblock %}
{% block content_form_actions_save_and_close %} {% block content_form_actions_save_and_close %}
<li class=""> <li class="">
<button type="submit" name="submit" value="save-and-close" class="btn btn-create"> <button type="submit" name="submit" value="save-and-close" class="btn btn-create">

View File

@ -1,78 +1,55 @@
{% extends '@ChillMain/Admin/layout_permissions.html.twig' %} {% extends '@ChillMain/Admin/Permission/layout_crud_permission_index.html.twig' %}
{% block title %}{{ 'User edit'|trans }}{% endblock %}
{% block admin_content -%} {% block admin_content -%}
<h1>{{ 'User edit'|trans }}</h1> {% embed '@ChillMain/CRUD/_edit_content.html.twig' %}
{% block crud_content_after_form %}
<h2>{{ 'Permissions granted'|trans }}</h2>
{{ form_start(edit_form) }} {% if entity.groupcenters|length > 0 %}
<table>
{{ form_row(edit_form.username) }} <thead>
{{ form_row(edit_form.email) }} <tr>
{{ form_row(edit_form.enabled, { 'label': "User'status"}) }} <th>{{ 'Permission group'|trans }}</th>
<th>{{ 'Center'|trans }}</th>
{{ form_widget(edit_form.submit, { 'attr': { 'class' : 'btn btn-chill-green center' } } ) }} <th>&nbsp;</th>
<a href="{{ path('admin_user_edit_password', { 'id' : entity.id }) }}" class="btn btn-chill-orange">{{ 'Edit password'|trans }}</a> </tr>
</thead>
{{ form_end(edit_form) }} <tbody>
{% for groupcenter in entity.groupcenters %}
<h2>{{ 'Permissions granted'|trans }}</h2> <tr>
<td>
{% if entity.groupcenters|length > 0 %}
<table>
<thead>
<tr>
<th>{{ 'Permission group'|trans }}</th>
<th>{{ 'Center'|trans }}</th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
{% for groupcenter in entity.groupcenters %}
<tr>
<td>
<span class="user_group permissionsgroup"> <span class="user_group permissionsgroup">
{{ groupcenter.permissionsgroup.name }} {{ groupcenter.permissionsgroup.name }}
</span> </span>
</td> </td>
<td> <td>
<span class="user_group center"> <span class="user_group center">
{{ groupcenter.center.name }} {{ groupcenter.center.name }}
</span> </span>
</td> </td>
<td> <td>
{{ form_start(delete_groupcenter_form[groupcenter.id]) }} {{ form_start(delete_groupcenter_form[groupcenter.id]) }}
{{ form_row(delete_groupcenter_form[groupcenter.id].submit, { 'attr': { 'class': 'btn btn-chill-red' } } ) }} {{ form_row(delete_groupcenter_form[groupcenter.id].submit, { 'attr': { 'class': 'btn btn-chill-red' } } ) }}
{{ form_rest(delete_groupcenter_form[groupcenter.id]) }} {{ form_rest(delete_groupcenter_form[groupcenter.id]) }}
{{ form_end(delete_groupcenter_form[groupcenter.id]) }} {{ form_end(delete_groupcenter_form[groupcenter.id]) }}
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
{% else %} {% else %}
<p>{{ 'Any permissions granted to this user'|trans }}.</p> <p>{{ 'Any permissions granted to this user'|trans }}.</p>
{% endif %} {% endif %}
<h3>{{ 'Grant new permissions'|trans }}</h3>
{{ form_start(add_groupcenter_form) }}
{{ form_row(add_groupcenter_form.composed_groupcenter.center) }}
{{ form_row(add_groupcenter_form.composed_groupcenter.permissionsgroup) }}
{{ form_row(add_groupcenter_form.submit, { 'attr' : { 'class': 'btn btn-chill-green' } } ) }}
{{ form_end(add_groupcenter_form) }} <h3>{{ 'Grant new permissions'|trans }}</h3>
<ul class="record_actions"> {{ form_start(add_groupcenter_form) }}
<li> {{ form_row(add_groupcenter_form.composed_groupcenter.center) }}
<a href="{{ path('admin_user_show', { 'id': entity.id }) }}"> {{ form_row(add_groupcenter_form.composed_groupcenter.permissionsgroup) }}
{{ 'show'|trans }} {{ form_row(add_groupcenter_form.submit, { 'attr' : { 'class': 'btn btn-chill-green' } } ) }}
</a>
</li> {{ form_end(add_groupcenter_form) }}
<li>
<a href="{{ path('admin_user') }}"> {% endblock %}
{{ 'Back to the list'|trans }} {% endembed %}
</a>
</li>
</ul>
{% endblock %} {% endblock %}

View File

@ -1,4 +1,4 @@
{% extends '@ChillMain/Admin/layout_permissions.html.twig' %} {% extends '@ChillMain/Admin/Permission/layout_crud_permission_index.html.twig' %}
{% block title %}{{ 'Edit password for %username%'|trans( { '%username%': entity.username } ) }}{% endblock %} {% block title %}{{ 'Edit password for %username%'|trans( { '%username%': entity.username } ) }}{% endblock %}
@ -7,19 +7,17 @@
{{ form_start(edit_form) }} {{ form_start(edit_form) }}
{{ form_row(edit_form.new_password) }} {{ form_row(edit_form.new_password) }}
{{ form_widget(edit_form.submit, { 'attr': { 'class': 'btn btn-chill-orange' } } ) }}
<ul class="record_actions">
<li class="cancel">
<a href="{{ chill_return_path_or('chill_crud_admin_user_index') }}" class="btn btn-cancel">
{{ 'Cancel'|trans }}
</a>
</li>
<li>
{{ form_widget(edit_form.submit, { 'attr': { 'class': 'btn btn-edit' } } ) }}
</li>
</ul>
{{ form_end(edit_form) }} {{ form_end(edit_form) }}
<ul class="record_actions">
<li>
<a href="{{ path('admin_user') }}">
{{ 'Back to the list'|trans }}
</a>
</li>
<li>
<a href="{{ path('admin_user_edit', { 'id' : entity.id }) }}">
{{ 'Back to the user edition'|trans }}
</a>
</li>
</ul>
{% endblock %} {% endblock %}

View File

@ -41,14 +41,14 @@
<td> <td>
<ul class="record_actions"> <ul class="record_actions">
<li> <li>
<a class="btn btn-edit" href="{{ path('admin_user_edit', { 'id': entity.id }) }}"></a> <a class="btn btn-edit" href="{{ path('chill_crud_admin_user_edit', { 'id': entity.id }) }}"></a>
</li> </li>
<li> <li>
<a class="btn btn-edit chill-red" href="{{ path('admin_user_edit_password', { 'id' : entity.id }) }}">{{ 'Edit password'|trans }}</a> <a class="btn btn-chill-red" href="{{ path('admin_user_edit_password', { 'id' : entity.id }) }}" title="{{ 'Edit password'|trans|e('html_attr') }}"><i class="fa fa-asterisk"></i><i class="fa fa-asterisk"></i><i class="fa fa-asterisk"></i></a>
</li> </li>
{% if is_granted('ROLE_ALLOWED_TO_SWITCH') %} {% if is_granted('ROLE_ALLOWED_TO_SWITCH') %}
<li> <li>
<a class="btn chill-blue" href="{{ path('chill_main_homepage', {'_switch_user': entity.username }) }}" title="{{ "Impersonate"|trans|e('html_attr') }}"><i class="fa fa-universal-access"></i></a> <a class="btn btn-chill-blue" href="{{ path('chill_main_homepage', {'_switch_user': entity.username }) }}" title="{{ "Impersonate"|trans|e('html_attr') }}"><i class="fa fa-user-secret"></i></a>
</li> </li>
{% endif %} {% endif %}
</ul> </ul>
@ -59,54 +59,3 @@
{% endblock %} {% endblock %}
{% endembed %} {% endembed %}
{% endblock %} {% endblock %}
{#
<table class="records_list">
<thead>
<tr>
<th>{{ 'Username'|trans|capitalize }}</th>
<th>{{ 'Actions'|trans|capitalize }}</th>
</tr>
</thead>
<tbody>
{% for entity in entities %}
<tr class="{% if entity.isEnabled == false %}user-disabled{% else %}user-enabled{% endif %}" >
<td><a href="{{ path('admin_user_show', { 'id': entity.id }) }}">{{ entity.username }}</a></td>
<td>
<ul>
<li>
<a href="{{ path('admin_user_show', { 'id': entity.id }) }}">{{ 'show'|trans }}</a>
</li>
<li>
<a href="{{ path('admin_user_edit', { 'id': entity.id }) }}">{{ 'edit'|trans }}</a>
</li>
<li>
<a href="{{ path('admin_user_edit_password', { 'id' : entity.id }) }}">{{ 'Edit password'|trans }}</a>
</li>
{% if is_granted('ROLE_ALLOWED_TO_SWITCH') %}
<li>
<a href="{{ path('chill_main_homepage', {'_switch_user': entity.username }) }}">
{{ 'Impersonate'|trans }}
</a>
</li>
{% endif %}
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<ul>
<li>
<a href="{{ path('admin_user_new') }}">
{{ 'Add a new user'|trans|capitalize }}
</a>
</li>
</ul>
{% endblock admin_content %}
#}

View File

@ -1,22 +1,7 @@
{% extends '@ChillMain/Admin/layout_permissions.html.twig' %} {% extends '@ChillMain/Admin/Permission/layout_crud_permission_index.html.twig' %}
{% block title %}{{ 'User creation'|trans }}{% endblock %}
{% block admin_content -%} {% block admin_content -%}
<h1>{{ 'User creation'|trans }}</h1> {% embed '@ChillMain/CRUD/_new_content.html.twig' %}
{% block content_form_actions_save_and_show %}{% endblock %}
{{ form_start(form) }} {% endembed %}
{{ form_row(form.username) }}
{{ form_row(form.email) }}
{{ form_row(form.plainPassword) }}
{{ form_widget(form.submit, { 'attr' : { 'class': 'btn btn-chill-blue' } }) }}
{{ form_end(form) }}
<ul class="record_actions">
<li>
<a href="{{ path('admin_user') }}">
{{ 'Back to the list'|trans }}
</a>
</li>
</ul>
{% endblock %} {% endblock %}

View File

@ -24,10 +24,6 @@ class PermissionMenuBuilder implements \Chill\MainBundle\Routing\LocalMenuBuilde
]); ]);
$menu->addChild('List users', [ $menu->addChild('List users', [
'route' => 'admin_user'
])->setExtras(['order' => 400]);
$menu->addChild('List users CRUD', [
'route' => 'chill_crud_admin_user_index' 'route' => 'chill_crud_admin_user_index'
])->setExtras(['order' => 400]); ])->setExtras(['order' => 400]);

View File

@ -1,44 +1,44 @@
admin_user: #admin_user:
path: / # path: /
controller: Chill\MainBundle\Controller\UserController::indexAction # controller: Chill\MainBundle\Controller\UserController::indexAction
#
admin_user_show: #admin_user_show:
path: /{id}/show # path: /{id}/show
controller: Chill\MainBundle\Controller\UserController::showAction # controller: Chill\MainBundle\Controller\UserController::showAction
#
admin_user_new: #admin_user_new:
path: /new # path: /new
controller: Chill\MainBundle\Controller\UserController::newAction # controller: Chill\MainBundle\Controller\UserController::newAction
#
admin_user_create: #admin_user_create:
path: /create # path: /create
controller: Chill\MainBundle\Controller\UserController::createAction # controller: Chill\MainBundle\Controller\UserController::createAction
methods: POST # methods: POST
#
admin_user_edit: #admin_user_edit:
path: /{id}/edit # path: /{id}/edit
controller: Chill\MainBundle\Controller\UserController::editAction # controller: Chill\MainBundle\Controller\UserController::editAction
#
admin_user_edit_password: #admin_user_edit_password:
path: /{id}/edit_password # path: /{id}/edit_password
controller: Chill\MainBundle\Controller\UserController::editPasswordAction # controller: Chill\MainBundle\Controller\UserController::editPasswordAction
#
admin_user_update: #admin_user_update:
path: /{id}/update # path: /{id}/update
controller: Chill\MainBundle\Controller\UserController::updateAction # controller: Chill\MainBundle\Controller\UserController::updateAction
methods: [POST, PUT] # methods: [POST, PUT]
#
admin_user_update_password: #admin_user_update_password:
path: /{id}/update_password # path: /{id}/update_password
controller: Chill\MainBundle\Controller\UserController::updatePasswordAction # controller: Chill\MainBundle\Controller\UserController::updatePasswordAction
methods: [POST, PUT] # methods: [POST, PUT]
#
admin_user_delete_group_center: #admin_user_delete_group_center:
path: /{uid}/delete_link_groupcenter/{gcid} # path: /{uid}/delete_link_groupcenter/{gcid}
controller: Chill\MainBundle\Controller\UserController::deleteLinkGroupCenterAction # controller: Chill\MainBundle\Controller\UserController::deleteLinkGroupCenterAction
methods: [DELETE] # methods: [DELETE]
#
admin_user_add_group_center: #admin_user_add_group_center:
path: /{uid}/add_link_groupcenter # path: /{uid}/add_link_groupcenter
controller: Chill\MainBundle\Controller\UserController::addLinkGroupCenterAction # controller: Chill\MainBundle\Controller\UserController::addLinkGroupCenterAction
methods: [POST] # methods: [POST]