<commit_before><?php

namespace Oro\Bundle\UserBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

use YsTools\BackUrlBundle\Annotation\BackUrl;

use Oro\Bundle\UserBundle\Entity\Group;
use Oro\Bundle\UserBundle\Datagrid\GroupDatagridManager;

/**
 * @Route("/group")
 * @BackUrl("back", useSession=true)
 */
class GroupController extends Controller
{
    /**
     * Create group form
     *
     * @Route("/create", name="oro_user_group_create")
     * @Template("OroUserBundle:Group:edit.html.twig")
     */
    public function createAction()
    {
        return $this->editAction(new Group());
    }

    /**
     * Edit group form
     *
     * @Route("/edit/{id}", name="oro_user_group_edit", requirements={"id"="\d+"}, defaults={"id"=0})
     * @Template
     */
    public function editAction(Group $entity)
    {
        if ($this->get('oro_user.form.handler.group')->process($entity)) {
            $this->get('session')->getFlashBag()->add('success', 'Group successfully saved');

            if (!$this->getRequest()->get('_widgetContainer')) {
                BackUrl::triggerRedirect();

                return $this->redirect($this->generateUrl('oro_user_group_index'));
            }
        }

        /** @var $gridManager GroupDatagridManager */
        $gridManager = $this->get('oro_user.group_user_datagrid_manager');

        $this->initializeQueryFactory($entity);
        $gridManager->getRouteGenerator()->setRouteParameters(array('id' => $entity->getId()));

        $datagrid = $gridManager->getDatagrid();

        return array(
            'datagrid' => $datagrid->createView(),
            'form'     => $this->get('oro_user.form.group')->createView(),
        );
    }

    /**
     * Get grid data
     *
     * @Route(
     *  "/grid/{id}",
     *  name="oro_user_group_user_grid",
     *  requirements={"id"="\d+"},
     *  defaults={"id"=0, "_format"="json"}
     * )
     * @Template("OroGridBundle:Datagrid:list.json.php")
     */
    public function gridDataAction(Group $entity)
    {
        $this->initializeQueryFactory($entity);

        $datagrid = $this->get('oro_user.group_user_datagrid_manager')->getDatagrid();

        return array('datagrid' => $datagrid->createView());
    }

    /**
     * @Route("/remove/{id}", name="oro_user_group_remove", requirements={"id"="\d+"})
     */
    public function removeAction(Group $entity)
    {
        $em = $this->getDoctrine()->getManager();

        $em->remove($entity);
        $em->flush();

        $this->get('session')->getFlashBag()->add('success', 'Group successfully removed');

        return $this->redirect($this->generateUrl('oro_user_group_index'));
    }

    /**
     * @Route(<commit_msg>BAP-604: Wrong HTTP method and CRSF vulnerability<commit_after><?php

namespace Oro\Bundle\UserBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

use YsTools\BackUrlBundle\Annotation\BackUrl;

use Oro\Bundle\UserBundle\Entity\Group;
use Oro\Bundle\UserBundle\Datagrid\GroupDatagridManager;

/**
 * @Route("/group")
 * @BackUrl("back", useSession=true)
 */
class GroupController extends Controller
{
    /**
     * Create group form
     *
     * @Route("/create", name="oro_user_group_create")
     * @Template("OroUserBundle:Group:edit.html.twig")
     */
    public function createAction()
    {
        return $this->editAction(new Group());
    }

    /**
     * Edit group form
     *
     * @Route("/edit/{id}", name="oro_user_group_edit", requirements={"id"="\d+"}, defaults={"id"=0})
     * @Template
     */
    public function editAction(Group $entity)
    {
        if ($this->get('oro_user.form.handler.group')->process($entity)) {
            $this->get('session')->getFlashBag()->add('success', 'Group successfully saved');

            if (!$this->getRequest()->get('_widgetContainer')) {
                BackUrl::triggerRedirect();

                return $this->redirect($this->generateUrl('oro_user_group_index'));
            }
        }

        /** @var $gridManager GroupDatagridManager */
        $gridManager = $this->get('oro_user.group_user_datagrid_manager');

        $this->initializeQueryFactory($entity);
        $gridManager->getRouteGenerator()->setRouteParameters(array('id' => $entity->getId()));

        $datagrid = $gridManager->getDatagrid();

        return array(
            'datagrid' => $datagrid->createView(),
            'form'     => $this->get('oro_user.form.group')->createView(),
        );
    }

    /**
     * Get grid data
     *
     * @Route(
     *  "/grid/{id}",
     *  name="oro_user_group_user_grid",
     *  requirements={"id"="\d+"},
     *  defaults={"id"=0, "_format"="json"}
     * )
     * @Template("OroGridBundle:Datagrid:list.json.php")
     */
    public function gridDataAction(Group $entity)
    {
        $this->initializeQueryFactory($entity);

        $datagrid = $this->get('oro_user.group_user_datagrid_manager')->getDatagrid();

        return array('datagrid' => $datagrid->createView());
    }

    /**
     * @Route(
{'fraction_non_alphanumeric': 0.17089898053753474, 'fraction_numerical': 0.0012974976830398518, 'mean_word_length': 3.0480120030007503, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 66, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2204550', 'n_tokens_mistral': 1661, 'n_tokens_neox': 1624, 'n_words': 214}