Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added Usergroups (CRUD) and Usergroup-Handling and filters to userlist #17

Merged
merged 1 commit into from

1 participant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 531 additions and 8 deletions.
  1. +2 −0  src/CuteFlow/CoreBundle/Controller/UserController.php
  2. +173 −0 src/CuteFlow/CoreBundle/Controller/UserGroupController.php
  3. +5 −0 src/CuteFlow/CoreBundle/DataFixtures/ORM/UserAdminData.php
  4. +48 −2 src/CuteFlow/CoreBundle/Entity/User.php
  5. +106 −0 src/CuteFlow/CoreBundle/Entity/UserGroup.php
  6. +6 −0 src/CuteFlow/CoreBundle/Form/UserFilterType.php
  7. +21 −0 src/CuteFlow/CoreBundle/Form/UserGroupType.php
  8. +2 −0  src/CuteFlow/CoreBundle/Form/UserType.php
  9. +15 −0 src/CuteFlow/CoreBundle/Model/Repository/UserGroupRepository.php
  10. +7 −0 src/CuteFlow/CoreBundle/Model/Repository/UserRepository.php
  11. +11 −1 src/CuteFlow/CoreBundle/Model/UserFilter.php
  12. +18 −2 src/CuteFlow/CoreBundle/Resources/translations/messages.de.xliff
  13. +6 −0 src/CuteFlow/CoreBundle/Resources/views/User/edit.html.twig
  14. +3 −0  src/CuteFlow/CoreBundle/Resources/views/User/list.html.twig
  15. +29 −0 src/CuteFlow/CoreBundle/Resources/views/UserGroup/edit.html.twig
  16. +47 −0 src/CuteFlow/CoreBundle/Resources/views/UserGroup/index.html.twig
  17. +29 −0 src/CuteFlow/CoreBundle/Resources/views/UserGroup/new.html.twig
  18. +3 −3 src/CuteFlow/CoreBundle/Resources/views/admin.html.twig
View
2  src/CuteFlow/CoreBundle/Controller/UserController.php
@@ -25,6 +25,8 @@ public function listAction()
$em = $this->getDoctrine()->getEntityManager();
$filter = $this->getRequest()->getSession()->get('user.filter', new UserFilter());
+ $filter->setGroup($em->merge($filter->getGroup())); // needed to reattach the deserialized session entity
+
$filterForm = $this->createForm(new UserFilterType(), $filter);
$filterForm->bindRequest($this->getRequest());
$this->getRequest()->getSession()->set('user.filter', $filter);
View
173 src/CuteFlow/CoreBundle/Controller/UserGroupController.php
@@ -0,0 +1,173 @@
+<?php
+
+namespace CuteFlow\CoreBundle\Controller;
+
+use Symfony\Bundle\FrameworkBundle\Controller\Controller;
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
+use CuteFlow\CoreBundle\Entity\UserGroup;
+use CuteFlow\CoreBundle\Form\UserGroupType;
+
+/**
+ * UserGroup controller.
+ *
+ * @Route("/usergroup")
+ */
+class UserGroupController extends Controller
+{
+ /**
+ * Lists all UserGroup entities.
+ *
+ * @Route("/", name="cuteflow_admin_usergroup")
+ * @Template()
+ */
+ public function indexAction()
+ {
+ $em = $this->getDoctrine()->getEntityManager();
+ $entities = $em->getRepository('CuteFlowCoreBundle:UserGroup')->findAll();
+ return array('entities' => $entities);
+ }
+
+ /**
+ * Displays a form to create a new UserGroup entity.
+ *
+ * @Route("/new", name="cuteflow_admin_usergroup_new")
+ * @Template()
+ */
+ public function newAction()
+ {
+ $entity = new UserGroup();
+ $form = $this->createForm(new UserGroupType(), $entity);
+
+ return array(
+ 'entity' => $entity,
+ 'form' => $form->createView()
+ );
+ }
+
+ /**
+ * Creates a new UserGroup entity.
+ *
+ * @Route("/create", name="cuteflow_admin_usergroup_create")
+ * @Method("post")
+ * @Template("CuteFlowCoreBundle:UserGroup:new.html.twig")
+ */
+ public function createAction()
+ {
+ $entity = new UserGroup();
+ $request = $this->getRequest();
+ $form = $this->createForm(new UserGroupType(), $entity);
+ $form->bindRequest($request);
+
+ if ($form->isValid()) {
+ $em = $this->getDoctrine()->getEntityManager();
+ $em->persist($entity);
+ $em->flush();
+
+ $this->getRequest()->getSession()->setFlash('saved.successful', 1);
+ return $this->redirect($this->generateUrl('cuteflow_admin_usergroup', array('id' => $entity->getId())));
+ }
+
+ return array(
+ 'entity' => $entity,
+ 'form' => $form->createView()
+ );
+ }
+
+ /**
+ * Displays a form to edit an existing UserGroup entity.
+ *
+ * @Route("/{id}/edit", name="cuteflow_admin_usergroup_edit")
+ * @Template()
+ */
+ public function editAction($id)
+ {
+ $em = $this->getDoctrine()->getEntityManager();
+
+ $entity = $em->getRepository('CuteFlowCoreBundle:UserGroup')->find($id);
+
+ if (!$entity) {
+ throw $this->createNotFoundException('Unable to find UserGroup entity.');
+ }
+
+ $editForm = $this->createForm(new UserGroupType(), $entity);
+ $deleteForm = $this->createDeleteForm($id);
+
+ return array(
+ 'entity' => $entity,
+ 'edit_form' => $editForm->createView(),
+ 'delete_form' => $deleteForm->createView(),
+ );
+ }
+
+ /**
+ * Edits an existing UserGroup entity.
+ *
+ * @Route("/{id}/update", name="cuteflow_admin_usergroup_update")
+ * @Method("post")
+ * @Template("CuteFlowCoreBundle:UserGroup:edit.html.twig")
+ */
+ public function updateAction($id)
+ {
+ $em = $this->getDoctrine()->getEntityManager();
+
+ $entity = $em->getRepository('CuteFlowCoreBundle:UserGroup')->find($id);
+
+ if (!$entity) {
+ throw $this->createNotFoundException('Unable to find UserGroup entity.');
+ }
+
+ $editForm = $this->createForm(new UserGroupType(), $entity);
+ $deleteForm = $this->createDeleteForm($id);
+
+ $request = $this->getRequest();
+
+ $editForm->bindRequest($request);
+
+ if ($editForm->isValid()) {
+ $em->persist($entity);
+ $em->flush();
+
+ $this->getRequest()->getSession()->setFlash('saved.successful', 1);
+ return $this->redirect($this->generateUrl('cuteflow_admin_usergroup'));
+ }
+
+ return array(
+ 'entity' => $entity,
+ 'edit_form' => $editForm->createView(),
+ 'delete_form' => $deleteForm->createView(),
+ );
+ }
+
+ /**
+ * Deletes a UserGroup entity.
+ *
+ * @Route("/delete/{id}", name="cuteflow_admin_usergroup_delete")
+ */
+ public function deleteAction($id)
+ {
+ $em = $this->getDoctrine()->getEntityManager();
+ $group = $em->find('CuteFlowCoreBundle:UserGroup', $id);
+
+ if (!$group) {
+ throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
+ }
+
+ $em->remove($group);
+ $em->flush();
+
+ $this->getRequest()->getSession()->setFlash('deleted.successful', 1);
+ return new \Symfony\Component\HttpFoundation\RedirectResponse(
+ $this->generateUrl('cuteflow_admin_usergroup')
+ );
+ }
+
+ private function createDeleteForm($id)
+ {
+ return $this->createFormBuilder(array('id' => $id))
+ ->add('id', 'hidden')
+ ->getForm()
+ ;
+ }
+}
View
5 src/CuteFlow/CoreBundle/DataFixtures/ORM/UserAdminData.php
@@ -29,6 +29,11 @@ public function load($manager)
$encoder = $this->container->get('security.encoder_factory')->getEncoder($userAdmin);
$userAdmin->setPassword($encoder->encodePassword('admin', $userAdmin->getSalt()));
+ $group = new \CuteFlow\CoreBundle\Entity\UserGroup();
+ $group->setName('Testgroup');
+
+ $userAdmin->addGroups($group);
+
$manager->persist($userAdmin);
$manager->flush();
}
View
50 src/CuteFlow/CoreBundle/Entity/User.php
@@ -111,7 +111,18 @@ class User implements UserInterface
*/
protected $updatedAt;
- /**
+ /**
+ *
+ * @ORM\ManyToMany(targetEntity="UserGroup", inversedBy="users")
+ * @ORM\JoinTable(name="cf_user_groups",
+ * joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
+ * inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")}
+ * )
+ */
+ protected $groups;
+
+
+ /**
* Set createdAt
*
* @param datetime $createdAt
@@ -443,7 +454,7 @@ public function setDeletedAt($deletedAt)
/**
* Get deletedAt
*
- * @return datetime
+ * @return datetime
*/
public function getDeletedAt()
{
@@ -470,4 +481,39 @@ public function setPlainPassword($plainPassword)
$this->plainPassword = $plainPassword;
}
+
+ /**
+ * Add groups
+ *
+ * @param CuteFlow\CoreBundle\Entity\UserGroup $groups
+ */
+ public function addGroups(\CuteFlow\CoreBundle\Entity\UserGroup $groups)
+ {
+ $this->groups[] = $groups;
+ }
+
+ /**
+ * Get groups
+ *
+ * @return Doctrine\Common\Collections\Collection
+ */
+ public function getGroups()
+ {
+ return $this->groups;
+ }
+
+ /**
+ * Gets the name of the groups which includes the user.
+ *
+ * @return array
+ */
+ public function getGroupNames()
+ {
+ $names = array();
+ foreach ($this->getGroups() as $group) {
+ $names[] = $group->getName();
+ }
+
+ return $names;
+ }
}
View
106 src/CuteFlow/CoreBundle/Entity/UserGroup.php
@@ -0,0 +1,106 @@
+<?php
+
+namespace CuteFlow\CoreBundle\Entity;
+
+use Doctrine\ORM\Mapping as ORM;
+
+/**
+ * CuteFlow\CoreBundle\Entity\UserGroup
+ *
+ * @ORM\Table()
+ * @ORM\Entity(repositoryClass="CuteFlow\CoreBundle\Model\Repository\UserGroupRepository")
+ */
+class UserGroup
+{
+ /**
+ * @var integer $id
+ *
+ * @ORM\Column(name="id", type="integer")
+ * @ORM\Id
+ * @ORM\GeneratedValue(strategy="AUTO")
+ */
+ private $id;
+
+ /**
+ * @var string $name
+ *
+ * @ORM\Column(name="name", type="string", length=255)
+ */
+ private $name;
+
+ /**
+ * @ORM\ManyToMany(targetEntity="User", mappedBy="groups")
+ */
+ protected $users;
+
+
+ /**
+ * Get id
+ *
+ * @return integer
+ */
+ public function getId()
+ {
+ return $this->id;
+ }
+
+ /**
+ * Set name
+ *
+ * @param string $name
+ */
+ public function setName($name)
+ {
+ $this->name = $name;
+ }
+
+ /**
+ * Get name
+ *
+ * @return string
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * Set roles
+ *
+ * @param array $roles
+ */
+ public function setRoles($roles)
+ {
+ $this->roles = $roles;
+ }
+
+ public function __construct()
+ {
+ $this->users = new \Doctrine\Common\Collections\ArrayCollection();
+ }
+
+ /**
+ * Add users
+ *
+ * @param CuteFlow\CoreBundle\Entity\User $users
+ */
+ public function addUsers(\CuteFlow\CoreBundle\Entity\User $users)
+ {
+ $this->users[] = $users;
+ }
+
+ /**
+ * Get users
+ *
+ * @return Doctrine\Common\Collections\Collection
+ */
+ public function getUsers()
+ {
+ return $this->users;
+ }
+
+ public function __toString()
+ {
+ return $this->getName();
+ }
+}
View
6 src/CuteFlow/CoreBundle/Form/UserFilterType.php
@@ -26,5 +26,11 @@ public function buildForm(FormBuilder $builder, array $options)
'label'=>'Username',
'required'=>false
));
+
+ $builder->add('group', 'entity', array(
+ 'class' => 'CuteFlow\\CoreBundle\\Entity\\UserGroup',
+ 'required'=>false,
+ 'label'=>'Usergroup',
+ ));
}
}
View
21 src/CuteFlow/CoreBundle/Form/UserGroupType.php
@@ -0,0 +1,21 @@
+<?php
+
+namespace CuteFlow\CoreBundle\Form;
+
+use Symfony\Component\Form\AbstractType;
+use Symfony\Component\Form\FormBuilder;
+
+class UserGroupType extends AbstractType
+{
+ public function buildForm(FormBuilder $builder, array $options)
+ {
+ $builder
+ ->add('name')
+ ;
+ }
+
+ public function getName()
+ {
+ return 'cuteflow_corebundle_usergrouptype';
+ }
+}
View
2  src/CuteFlow/CoreBundle/Form/UserType.php
@@ -42,5 +42,7 @@ public function buildForm(FormBuilder $builder, array $options)
'label'=>'Has Admin-Rights',
'required'=>false,
));
+
+ $builder->add('groups');
}
}
View
15 src/CuteFlow/CoreBundle/Model/Repository/UserGroupRepository.php
@@ -0,0 +1,15 @@
+<?php
+
+namespace CuteFlow\CoreBundle\Model\Repository;
+
+use Doctrine\ORM\EntityRepository;
+
+/**
+ * UserGroupRepository
+ *
+ * This class was generated by the Doctrine ORM. Add your own custom
+ * repository methods below.
+ */
+class UserGroupRepository extends EntityRepository
+{
+}
View
7 src/CuteFlow/CoreBundle/Model/Repository/UserRepository.php
@@ -47,6 +47,13 @@ public function getFindByFilterQuery(\CuteFlow\CoreBundle\Model\UserFilter $filt
->setParameter('username', $filter->getUsername()."%");
}
+ if ($filter->getGroup() != null) {
+ $group = $filter->getGroup();
+ $query = $query->innerJoin('u.groups', 'g')
+ ->andWhere('g.id=:group')
+ ->setParameter('group', $group->getId());
+ }
+
return $query->getQuery();
}
View
12 src/CuteFlow/CoreBundle/Model/UserFilter.php
@@ -33,8 +33,18 @@ public function getUsername()
return $this->username;
}
+ public function setGroup($group)
+ {
+ $this->group = $group;
+ }
+
+ public function getGroup()
+ {
+ return $this->group;
+ }
+
protected $firstname = null;
protected $lastname = null;
protected $username = null;
-
+ protected $group = null;
}
View
20 src/CuteFlow/CoreBundle/Resources/translations/messages.de.xliff
@@ -95,8 +95,8 @@
<target>Allgemein</target>
</trans-unit>
<trans-unit id="24">
- <source>Workflowgroups</source>
- <target>Workflowgruppen</target>
+ <source>Usergroups</source>
+ <target>Benutzergruppen</target>
</trans-unit>
<trans-unit id="25">
<source>Host</source>
@@ -250,6 +250,22 @@
<source>My Account</source>
<target>Mein Account</target>
</trans-unit>
+ <trans-unit id="63">
+ <source>New usergroup</source>
+ <target>Neue Benutzergruppe</target>
+ </trans-unit>
+ <trans-unit id="64">
+ <source>Edit usergroup</source>
+ <target>Benutzergruppe bearbeiten</target>
+ </trans-unit>
+ <trans-unit id="65">
+ <source>Do you really want to delete this group</source>
+ <target>Wollen Sie diese Gruppe wirklich löschen</target>
+ </trans-unit>
+ <trans-unit id="66">
+ <source>Usergroup</source>
+ <target>Benutzergruppe</target>
+ </trans-unit>
</body>
</file>
</xliff>
View
6 src/CuteFlow/CoreBundle/Resources/views/User/edit.html.twig
@@ -39,8 +39,14 @@
{{ form_label(form.admin) }}
{{ form_widget(form.admin) }}
</p>
+ <p>
+ {{ form_label(form.groups) }}
+ {{ form_widget(form.groups) }}
+ </p>
</div>
+ {{ form_rest(form) }}
+
<input type="submit" value="{% trans %}Save{% endtrans %}" name="commit"/>
&nbsp;&nbsp;&nbsp;<a href="{{ path('cuteflow_admin_user') }}">{% trans %}Back to list{% endtrans %}</a>
</form>
View
3  src/CuteFlow/CoreBundle/Resources/views/User/list.html.twig
@@ -37,6 +37,7 @@
<th>{% trans %}Email{% endtrans %}</th>
<th>{% trans %}Username{% endtrans %}</th>
<th>{% trans %}Administrator{% endtrans %}</th>
+ <th>{% trans %}Usergroups{% endtrans %}</th>
<th>{% trans %}Last login{% endtrans %}</th>
<th>&nbsp;</th>
</tr>
@@ -54,6 +55,7 @@
<img src="/bundles/cuteflowcore/images/toggle_check.png" alt="yes">
{% endif %}
</td>
+ <td>{{ user.getGroupNames() | join(', ') }}</td>
<td>{{ user.lastLogin | localedate() }}</td>
<td>
<small><a href="{{ path('cuteflow_admin_user_edit', {'id': user.id}) }}" class="icon icon-edit">{% trans %}Edit{% endtrans %}</a></small>
@@ -75,6 +77,7 @@
{{ form_row(filterForm.lastname) }}
{{ form_row(filterForm.firstname) }}
{{ form_row(filterForm.username) }}
+ {{ form_row(filterForm.group) }}
<input type="submit" value="{% trans %}Filter{% endtrans %}"/>&nbsp;&nbsp;&nbsp;
<input type="button" value="Reset Filter" onclick="clear_form('#filter-form'); $('#filter-form').submit();"/>
View
29 src/CuteFlow/CoreBundle/Resources/views/UserGroup/edit.html.twig
@@ -0,0 +1,29 @@
+{% extends 'CuteFlowCoreBundle::admin.html.twig' %}
+
+{% block title %}{{ parent() }} - {% trans %}Administration{% endtrans %}{% endblock %}
+
+{% block sidebarclass %}class="nosidebar"{% endblock %}
+
+{% block body %}
+ <h2>{% trans %}Edit usergroup{% endtrans %}</h2>
+
+ {% if form_errors(edit_form) %}
+ <div class="flash error">
+ {{ form_errors(edit_form) }}
+ </div>
+ <br/>
+ {% endif %}
+
+ <form action="{{ path('cuteflow_admin_usergroup_update', { 'id': entity.id }) }}" method="post" {{ form_enctype(edit_form) }}>
+ <div class="box tabular settings">
+ <p>
+ {{ form_label(edit_form.name) }}
+ {{ form_widget(edit_form.name) }}
+ </p>
+ </div>
+
+ {{ form_rest(edit_form) }}
+ <input type="submit" value="{% trans %}Save{% endtrans %}" name="commit"/>
+ &nbsp;&nbsp;&nbsp;<a href="{{ path('cuteflow_admin_usergroup') }}">{% trans %}Back to list{% endtrans %}</a>
+ </form>
+{% endblock %}
View
47 src/CuteFlow/CoreBundle/Resources/views/UserGroup/index.html.twig
@@ -0,0 +1,47 @@
+{% extends 'CuteFlowCoreBundle::admin.html.twig' %}
+
+{% block title %}{{ parent() }} - {% trans %}Administration{% endtrans %}{% endblock %}
+
+{% block contextual %}
+ <a class="icon icon-add" href="{{ path('cuteflow_admin_usergroup_new') }}">{% trans %}New usergroup{% endtrans %}</a>
+{% endblock %}
+
+{% block body %}
+ <h2>{% trans %}Usergroups{% endtrans %}</h2>
+ {% if (app.session.hasFlash('saved.successful')) %}
+ <div class="flash notice">
+ {% trans %}Group successfully saved{% endtrans %}
+ </div>
+ <br/>
+ {% endif %}
+
+ {% if (app.session.hasFlash('deleted.successful')) %}
+ <div class="flash notice">
+ {% trans %}Group successfully deleted{% endtrans %}
+ </div>
+ <br/>
+ {% endif %}
+
+ <table class="list">
+ <thead>
+ <tr>
+ <th>{% trans %}Name{% endtrans %}</th>
+ <th>&nbsp;</th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for entity in entities %}
+ <tr class="{{ cycle(['odd', 'even'], loop.index) }}">
+ <td>{{ entity.name }}</td>
+ <td>
+ <small><a href="{{ path('cuteflow_admin_usergroup_edit', {'id': entity.id}) }}" class="icon icon-edit">{% trans %}Edit{% endtrans %}</a></small>
+ <small><a href="{{ path('cuteflow_admin_usergroup_delete', {'id': entity.id}) }}" onclick="return confirm('{% trans %}Do you really want to delete this group?{% endtrans %}')" class="icon icon-del">{% trans %}Delete{% endtrans %}</a></small>
+ </td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+
+{% endblock %}
+
+
View
29 src/CuteFlow/CoreBundle/Resources/views/UserGroup/new.html.twig
@@ -0,0 +1,29 @@
+{% extends 'CuteFlowCoreBundle::admin.html.twig' %}
+
+{% block title %}{{ parent() }} - {% trans %}Administration{% endtrans %}{% endblock %}
+
+{% block sidebarclass %}class="nosidebar"{% endblock %}
+
+{% block body %}
+ <h2>{% trans %}New usergroup{% endtrans %}</h2>
+
+ {% if form_errors(form) %}
+ <div class="flash error">
+ {{ form_errors(form) }}
+ </div>
+ <br/>
+ {% endif %}
+
+ <form action="{{ path('cuteflow_admin_usergroup_create') }}" method="post" {{ form_enctype(form) }}>
+ <div class="box tabular settings">
+ <p>
+ {{ form_label(form.name) }}
+ {{ form_widget(form.name) }}
+ </p>
+ </div>
+
+ {{ form_rest(form) }}
+ <input type="submit" value="{% trans %}Save{% endtrans %}" name="commit"/>
+ &nbsp;&nbsp;&nbsp;<a href="{{ path('cuteflow_admin_usergroup') }}">{% trans %}Back to list{% endtrans %}</a>
+ </form>
+{% endblock %}
View
6 src/CuteFlow/CoreBundle/Resources/views/admin.html.twig
@@ -21,9 +21,9 @@
</a>
</li>
<li>
- <a class="{{ app.request.attributes.get('_route') == 'cuteflow_admin_groups' ? 'selected' : '' }}"
- href="">
- {% trans %}Workflowgroups{% endtrans %}
+ <a class="{{ app.request.attributes.get('_route') == 'cuteflow_usergroups' ? 'selected' : '' }}"
+ href="{{ path('cuteflow_admin_usergroup')}}">
+ {% trans %}Usergroups{% endtrans %}
</a>
</li>
<li>
Something went wrong with that request. Please try again.