Add new group to a role.
In other word, grant a role to a group.
Id of added group should be specified in request.

@param Pluf_HTTP_Request $request
@param array $match
483092
public static function add($request, $match)
    {
        $perm = Pluf_Shortcuts_GetObjectOr404('User_Role', $match['role_id']);
        $group = Pluf_Shortcuts_GetObjectOr404('User_Group', isset($match['group_id']) ? $match['group_id'] : $request->REQUEST['group_id']);
        $perm->setAssoc($group);
        return $group;
    }
220194
public function create($request, $match)
    {
        // Check amount
        $amount = $request->REQUEST['amount'];
        if ($amount <= 0.0) {
            throw new Pluf_Exception_BadRequest('Invalid amount. Amount should be positive value.');
        }
        // Check wallets and permissions to access wallets
        Pluf::loadFunction('Pluf_Shortcuts_GetObjectOr404');
        $fromWallet = Pluf_Shortcuts_GetObjectOr404('Bank_Wallet', $match['parentId']);
        if ($request->user->getId() !== $fromWallet->owner_id) {
            throw new Pluf_Exception_PermissionDenied("Permission is denied");
        }
        if ($fromWallet->deleted) {
            throw new Pluf_Exception_DoesNotExist("Source wallet is deleted!");
        }
        $toWallet = Pluf_Shortcuts_GetObjectOr404('Bank_Wallet', $request->REQUEST['to_wallet_id']);
        if ($toWallet->deleted) {
            throw new Pluf_Exception_DoesNotExist("Destination wallet is deleted!");
        }
        // Check for invalid transfer
        if ($fromWallet->id === $toWallet->id) {
            throw new Pluf_Exception_BadRequest('Invalid transfer. Source and destination wallet of transfer could not be same.');
        }
        // Check currency of wallets
        if ($fromWallet->currency !== $toWallet->currency) {
            throw new Pluf_Exception_BadRequest('Invalid transfer. Could not transfer between wallets with different currency.');
        }
        // Check if balance of source wallet is sufficeint
        $sourceBalance = $fromWallet->total_deposit - $fromWallet->total_withdraw;
        if ($sourceBalance < $amount) {
            throw new Pluf_Exception_BadRequest('Insufficeint balance [balance: ' . $sourceBalance . ', transfer: ' . $amount . '].');
        }
        // Create transfer
        $transfer = new Bank_Transfer();
        $transfer->_a['cols']['amount']['editable'] = true;
        $transfer->_a['cols']['acting_id']['editable'] = true;
        $transfer->_a['cols']['from_wallet_id']['editable'] = true;
        $transfer->_a['cols']['to_wallet_id']['editable'] = true;
        Pluf::loadFunction('Pluf_Shortcuts_GetFormForModel');
        $data = array_merge($request->REQUEST, array(
            'acting_id' => $request->user->id,
            'from_wallet_id' => $fromWallet->id,
            'to_wallet_id' => $toWallet->id
        ));
        $form = Pluf_Shortcuts_GetFormForModel($transfer, $data);
        $transfer = $form->save();
        // Update balance of wallets
        $fromWallet->total_withdraw += $transfer->amount;
        $fromWallet->update();
        $toWallet->total_deposit += $transfer->amount;
        $toWallet->update();

        // Notify user
        if (! Pluf::f('test_unit', false)) {
            $context = array(
                'fromWallet' => $fromWallet,
                'toWallet' => $toWallet,
                'user' => $request->user,
                'transfer' => $transfer
            );
            User_Notify::push($fromWallet->get_owner(), array(
                'Message' => 'Bank/Message/wallet-transfer.txt'
            ), $context);
            User_Notify::push($toWallet->get_owner(), array(
                'Message' => 'Bank/Message/wallet-transfer.txt'
            ), $context);
        }

        return $transfer;
    }
654103
public function update ($request, $match, $p)
    {
        // check collection
        if (isset($match['collectionId'])) {
            $collectionId = $match['collectionId'];
            $request->REQUEST['collection'] = $collectionId;
        } else {
            $collectionId = $request->REQUEST['collection'];
        }
        $collection = Pluf_Shortcuts_GetObjectOr404('Collection_Collection', 
                $collectionId);
        $document = Pluf_Shortcuts_GetObjectOr404('Collection_Document', 
                $match['modelId']);
        if ($document->collection !== $collection->id) {
            throw new Pluf_Exception_DoesNotExist(
                    'Document with id (' . $document->id .
                             ') does not exist in collection with id (' .
                             $collection->id . ')');
        }
        // update document
        $plufService = new Pluf_Views();
        return $plufService->updateObject($request, $match, $p);
    }
816235
public function find ($request, $match)
    {
        $location = Geo_Shortcuts_GetLocationOr404($match[1]);
        $count = 10;
        $pag = new Pluf_Paginator(new SaaSKM_Vote());
        $pag->list_filters = array(
                'voter'
        );
        $sql = new Pluf_SQL('tenant=%s AND owner_class=%s AND owner_id=%s', 
                array(
                        $request->tenant->id,
                        'Geo_Location',
                        $location->id
                ));
        $pag->forced_where = $sql;
        $list_display = array(
                'vote_value' => __('location title'),
                'vote_comment' => __('description')
        );
        $search_fields = array(
                'voter',
                'vote_comment'
        );
        $sort_fields = array(
                'voter',
                'creation_date',
                'modif_dtime'
        );
        $pag->configure($list_display, $search_fields, $sort_fields);
        $pag->items_per_page = $count;
        $pag->sort_order = array(
                'creation_dtime',
                'DESC'
        );
        $pag->setFromRequest($request);
        return new Pluf_HTTP_Response_Json($pag->render_object());
    }
423701
private function setMatchContext(array $match)
    {
        if (isset($match['_branding'])) {
            $this->context->setParameter('_branding', $match['_branding']);

            $this->siteContext->setCurrentBranding($this->siteContext->getBranding($match['_branding']));
        }

        if (isset($match['_locale'])) {
            $this->context->setParameter('_locale', $match['_locale']);

            $this->siteContext->setCurrentLocale($match['_locale']);
        }
    }
832207
public function putMap ($request, $match)
    {
        if (isset($match['collectionId'])) {
            $collectionId = $match['collectionId'];
        } else {
            $collectionId = $request->REQUEST['collectionId'];
        }
        // $collection = Pluf_Shortcuts_GetObjectOr404('Collection_Collection',
        // $collectionId);
        if (isset($match['documentId'])) {
            $documentId = $match['documentId'];
        } else {
            $documentId = $request->REQUEST['documentId'];
        }
        $document = Pluf_Shortcuts_GetObjectOr404('Collection_Document', 
                $documentId);
        
        if ($document->collection != $collectionId) {
            throw new Pluf_Exception_DoesNotExist(
                    'Document with id (' . $documentId .
                             ') does not exist in collection with id (' .
                             $collectionId . ')');
        }
        
        $this->putDocumentMap($document, $request->REQUEST);
        return new Pluf_HTTP_Response_Json($this->getDocumentMap($document));
    }
49762
public function addRole(Request $request)
    {
        $user = \App\User::findOrfail($request->user_id);
        $user->assignRole($request->role_name);

        return redirect('scaffold-users/edit/'.$request->user_id);
    }
69266
public function addGroupAction(Request $request, $groupId)
    {
        $format = $request->get('_format', 'json');
        $facade = $this->get('jms_serializer')->deserialize(
            $request->getContent(),
            $this->getParameter('open_orchestra_user_admin.facade.user_collection.class'),
            $format
        );
        $users = $this->get('open_orchestra_api.transformer_manager')->get('user_collection')->reverseTransform($facade);
        $group =  $this->get('open_orchestra_user.repository.group')->find($groupId);

        $this->get('open_orchestra_user.repository.user')->addGroup($users, $group);

        return array();
    }
383497
public function tags ($request, $match)
    {
        $location = Geo_Shortcuts_GetLocationOr404($match[1]);
        Geo_Precondition::canEditLocation($request, $location);
        // Pluf pagination
        $pag = new Pluf_Paginator(new SaaSKM_Tag());
        $pag->model_view = 'join_row';
        $pag->forced_where = new Pluf_SQL(
                'saaskm_tag.tenant=%s AND owner_class=%s AND owner_id=%s', 
                array(
                        $request->tenant->id,
                        $location->_a['model'],
                        $location->id
                ));
        $list_display = array(
                'title' => __('location title'),
                'description' => __('description')
        );
        $search_fields = array(
                'name',
                'description'
        );
        $sort_fields = array(
                'creation_date',
                'modif_dtime'
        );
        $pag->configure($list_display, $search_fields, $sort_fields);
        $pag->sort_order = array(
                'creation_dtime',
                'DESC'
        );
        $pag->setFromRequest($request);
        return new Pluf_HTTP_Response_Json($pag->render_object());
    }
1143268
public function remove ($request, $match)
    {
        if (isset($match['collectionId'])) {
            $collectionId = $match['collectionId'];
        } else {
            $collectionId = $request->REQUEST['collectionId'];
        }
        $collection = Pluf_Shortcuts_GetObjectOr404('Collection_Collection', 
                $collectionId);
        if (isset($match['documentId'])) {
            $documentId = $match['documentId'];
        } else {
            $documentId = $request->REQUEST['documentId'];
        }
        $document = Pluf_Shortcuts_GetObjectOr404('Collection_Document', 
                $documentId);
        
        if ($document->collection !== $collection->id) {
            throw new Pluf_Exception_DoesNotExist(
                    'Document with id (' . $documentId .
                             ') does not exist in collection with id (' .
                             $collectionId . ')');
        }
        $documentCopy = Pluf_Shortcuts_GetObjectOr404('Collection_Document', 
                $documentId);
        $document->delete();
        return new Pluf_HTTP_Response_Json($documentCopy);
    }
306163
public function updateAccount($request, $match)
    {
        $model = Pluf_Shortcuts_GetObjectOr404('User_Account', $request->user->id);
        $form = Pluf_Shortcuts_GetFormForUpdateModel($model, $request->REQUEST, array());
        return $form->save();
    }
658829
public static function get($request, $match)
    {
        if (array_key_exists('userId', $match)) {
            $user = Pluf_Shortcuts_GetObjectOr404('User_Account', $match['userId']);
        } else {
            $user = $request->user;
        }
        if($user->isAnonymous()){
            throw new Pluf_Exception_BadRequest('User is not defined');
        }
        return User_Shortcuts_GetAvatar($user);
    }
156825
public static function delete($request, $match)
    {
        $group = Pluf_Shortcuts_GetObjectOr404('User_Group', $match['group_id']);
        $user = Pluf_Shortcuts_GetObjectOr404('User_Account', $match['user_id']);
        $group->delAssoc($user);
        return $user;
    }
1047890
public static function get($request, $match)
    {
        $perm = Pluf_Shortcuts_GetObjectOr404('User_Role', $match['role_id']);
        $groupModel = new User_Group();
        $param = array(
            'view' => 'join_role',
            'filter' => array(
                'id=' . $match['group_id'],
                'role_id=' . $perm->id
            )
        );
        $groups = $groupModel->getList($param);
        if ($groups->count() == 0) {
            throw new Pluf_Exception_DoesNotExist('Group has not such role');
        }
        return $groups[0];
    }
1003644
public function changeEmail ($request, $match)
    {
        $key = $match[1];
        list ($email, $id, $time) = User_Form_UserChangeEmail::validateKey($key);
        if ($id != $request->user->id) {
            throw new Pluf_Exception('user not match');
        }
        // Now we have a change link coming from the right user.
        if ($request->user->email == $email) {
            return new Pluf_HTTP_Response_Json($request->user);
        }
        
        $request->user->email = $email;
        $request->user->update();
        $request->user->setMessage(
                sprintf(
                        __(
                                'Your new email address "%s" has been validated. Thank you!'), 
                        Pluf_esc($email)));
        User_Shortcuts_UpdateLeveFor($request->user, 'user_email_registerd');
        // Return response
        return new Pluf_HTTP_Response_Json($request->user);
    }
82795
public static function delete($request, $match)
    {
        $group = Pluf_Shortcuts_GetObjectOr404('User_Group', $match['group_id']);
        $role = Pluf_Shortcuts_GetObjectOr404('User_Role', $match['role_id']);
        $group->delAssoc($role);
        return $group;
    }
669201
private function internalGet($request, $match){
        if ($request->user->hasPerm('tenant.owner')) {
            $sql = new Pluf_SQL('`key`=%s', array(
                $match['key']
            ));
        } else {
            $sql = new Pluf_SQL('`key`=%s AND `mode`=%s', array(
                $match['key'],
                Tenant_Setting::MOD_PUBLIC
            ));
        }
        $model = new Tenant_Setting();
        $model = $model->getOne(array(
            'filter' => $sql->gen()
        ));
        return $model;
    }