<commit_before><?php
/**
 * This file is part of MeCms.
 *
 * MeCms is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * MeCms is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with MeCms.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author      <NAME> <<EMAIL>>
 * @copyright   Copyright (c) 2016, <NAME> for Nova Atlantis Ltd
 * @license     http://www.gnu.org/licenses/agpl.txt AGPL License
 * @link        http://git.novatlantis.it Nova Atlantis Ltd
 */
namespace MeCms\Controller\Admin;

use MeCms\Controller\AppController;

/**
 * UsersGroups controller
 * @property \MeCms\Model\Table\UsersGroupsTable $UsersGroups
 */
class UsersGroupsController extends AppController
{
    /**
     * Check if the provided user is authorized for the request
     * @param array $user The user to check the authorization of. If empty
     *  the user in the session will be used
     * @return bool `true` if the user is authorized, otherwise `false`
     * @uses MeCms\Controller\Component\AuthComponent::isGroup()
     */
    public function isAuthorized($user = null)
    {
        //Only admins can access this controller
        return $this->Auth->isGroup('admin');
    }

    /**
     * Lists usersGroups
     * @return void
     */
    public function index()
    {
        $this->paginate['order'] = ['name' => 'ASC'];

        $groups = $this->paginate($this->UsersGroups->find());

        $this->set(compact('groups'));
    }

    /**
     * Adds users group
     * @return \Cake\Network\Response|null|void
     */
    public function add()
    {
        $group = $this->UsersGroups->newEntity();

        if ($this->request->is('post')) {
            $group = $this->UsersGroups->patchEntity($group, $this->request->getData());

            if ($this->UsersGroups->save($group)) {
                $this->Flash->success(__d('me_cms', 'The operation has been performed correctly'));

                return $this->redirect(['action' => 'index']);
            } else {
                $this->Flash->error(__d('me_cms', 'The operation has not been performed correctly'));
            }
        }

        $this->set(compact('group'));
    }

    /**
     * Edits users group
     * @param string $id Users Group ID
     * @return \Cake\Network\Response|null|void
     */
    public function edit($id = null)
    {
        $group = $this->UsersGroups->get($id);

        if ($this->request->is(['patch', 'post', 'put'])) {
            $group = $this->UsersGroups->patchEntity($group, $this->request->getData());

            if ($this->UsersGroups->save($group)) {
                $this->Flash->success(__d('me_cms', 'The operation has been performed correctly'));

                return $this->redirect(['action' => 'index']);
            } else {
                $this->Flash->error(__d('me_cms', 'The operation has not been performed correctly'));
            }
        }

        $this->set(compact('group'));
    }
    /**
     * Deletes users group
     * @param string $id Users Group ID
     * @return \Cake\Network\Response|null
     */
    public function delete($id = null)
    {
        $this->request->allowMethod(['post', 'delete']);

        $group = $this->UsersGroups->get($id);

        //Before deleting, checks if the group is a necessary group or if the group has some users
        if ($id > 3 && !$group->user_count) {
            if ($this->UsersGroups->delete($group)) {
                $this->Flash->success(__d('me_cms', 'The operation has been performed correctly'));
            } else {
                $this->Flash->error(__d('me_cms', 'The operation has not been performed correctly'));
            }
        } elseif ($id <= 3) {
            $this->Flash->alert(__d('me_cms', 'You cannot delete this users group'));
        } else {
            $this->Flash->alert(__d(
                'me_cms',
                'Before deleting this, you must delete or reassign all items that belong to this element'
            ));
        }

        return $this->redirect(['action' => 'index']);
    }
}
<commit_msg>fixed code<commit_after><?php
/**
 * This file is part of MeCms.
 *
 * MeCms is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * MeCms is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with MeCms.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author      <NAME> <<EMAIL>>
 * @copyright   Copyright (c) 2016, <NAME> for Nova Atlantis Ltd
 * @license     http://www.gnu.org/licenses/agpl.txt AGPL License
 * @link        http://git.novatlantis.it Nova Atlantis Ltd
 */
namespace MeCms\Controller\Admin;

use MeCms\Controller\AppController;

/**
 * UsersGroups controller
 * @property \MeCms\Model\Table\UsersGroupsTable $UsersGroups
 */
class UsersGroupsController extends AppController
{
    /**
     * Check if the provided user is authorized for the request
     * @param array $user The user to check the authorization of. If empty
     *  the user in the session will be used
     * @return bool `true` if the user is authorized, otherwise `false`
     * @uses MeCms\Controller\Component\AuthComponent::isGroup()
     */
    public function isAuthorized($user = null)
    {
        //Only admins can access this controller
        return $this->Auth->isGroup('admin');
    }

    /**
     * Lists usersGroups
     * @return void
     */
    public function index()
    {
        $this->paginate['order'] = ['name' => 'ASC'];

        $groups = $this->paginate($this->UsersGroups->find());

        $this->set(compact('groups'));
    }

    /**
     * Adds users group
     * @return \Cake\Network\Response|null|void
     */
    public function add()
    {
        $group = $this->UsersGroups->newEntity();

        if ($this->request->is('post')) {
            $group = $this->UsersGroups->patchEntity($group, $this->request->getData());

            if ($this->UsersGroups->save($group)) {
                $this->Flash->success(__d('me_cms', 'The operation has been performed correctly'));

                return $this->redirect(['action' => 'index']);
            }

            $this->Flash->error(__d('me_cms', 'The operation has not been performed correctly'));
        }

        $this->set(compact('group'));
    }

    /**
     * Edits users group
     * @param string $id Users Group ID
     * @return \Cake\Network\Response|null|void
     */
    public function edit($id = null)
    {
        $group = $this->UsersGroups->get($id);

        if ($this->request->is(['patch', 'post', 'put'])) {
            $group = $this->UsersGroups->patchEntity($group, $this->request->getData());

            if ($this->UsersGroups->save($group)) {
                $this->Flash->success(__d('me_cms', 'The operation has been performed correctly'));

                return $this->redirect(['action' => 'index']);
            }

            $this->Flash->error(__d('me_cms', 'The operation has not been performed correctly'));
        }

        $this->set(compact('group'));
    }
    /**
     * Deletes users group
     * @param string $id Users Group ID
     * @return \Cake\Network\Response|null
     */
    public function delete($id = null)
    {
        $this->request->allowMethod(['post', 'delete']);

        $group = $this->UsersGroups->get($id);

        //Before deleting, checks if the group is a necessary group or if the group has some users
        if ($id > 3 && !$group->user_count) {
            $this->UsersGroups->deleteOrFail($group);

            $this->Flash->success(__d('me_cms', 'The operation has been performed correctly'));
        } elseif ($id <= 3) {
            $this->Flash->alert(__d('me_cms', 'You cannot delete this users group'));
        } else {
            $this->Flash->alert(__d('me_cms', 'Before deleting this, you must delete or reassign all items that belong to this element'));
        }

        return $this->redirect(['action' => 'index']);
    }
}

{'fraction_non_alphanumeric': 0.14033890594791312, 'fraction_numerical': 0.001592175594222677, 'mean_word_length': 2.469033530571992, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 131, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '126055', 'n_tokens_mistral': 2495, 'n_tokens_neox': 2385, 'n_words': 748}