mirror of
https://github.com/nuxsmin/sysPass.git
synced 2026-02-25 04:11:24 +01:00
137 lines
4.2 KiB
PHP
137 lines
4.2 KiB
PHP
<?php
|
|
/**
|
|
* sysPass
|
|
*
|
|
* @author nuxsmin
|
|
* @link https://syspass.org
|
|
* @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
|
|
*
|
|
* This file is part of sysPass.
|
|
*
|
|
* sysPass is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* sysPass 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 General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
namespace SP\Modules\Web\Controllers;
|
|
|
|
use SP\Core\Acl\Acl;
|
|
use SP\Core\Events\Event;
|
|
use SP\Core\Events\EventMessage;
|
|
use SP\Http\JsonResponse;
|
|
use SP\Modules\Web\Controllers\Helpers\Grid\AccountGrid;
|
|
use SP\Modules\Web\Controllers\Traits\ItemTrait;
|
|
use SP\Modules\Web\Controllers\Traits\JsonTrait;
|
|
use SP\Services\Account\AccountService;
|
|
|
|
/**
|
|
* Class AccountManagerController
|
|
*
|
|
* @package SP\Modules\Web\Controllers
|
|
*/
|
|
final class AccountManagerController extends ControllerBase
|
|
{
|
|
use JsonTrait, ItemTrait;
|
|
|
|
/**
|
|
* @var AccountService
|
|
*/
|
|
protected $accountService;
|
|
|
|
/**
|
|
* @throws \SP\Core\Exceptions\ConstraintException
|
|
* @throws \SP\Core\Exceptions\QueryException
|
|
*/
|
|
public function searchAction()
|
|
{
|
|
if (!$this->acl->checkUserAccess(Acl::ACCOUNTMGR_SEARCH)) {
|
|
return $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('No tiene permisos para realizar esta operación'));
|
|
}
|
|
|
|
$this->view->addTemplate('datagrid-table', 'grid');
|
|
$this->view->assign('index', $this->request->analyzeInt('activetab', 0));
|
|
$this->view->assign('data', $this->getSearchGrid());
|
|
|
|
return $this->returnJsonResponseData(['html' => $this->render()]);
|
|
}
|
|
|
|
/**
|
|
* getSearchGrid
|
|
*
|
|
* @return $this
|
|
* @throws \SP\Core\Exceptions\ConstraintException
|
|
* @throws \SP\Core\Exceptions\QueryException
|
|
*/
|
|
protected function getSearchGrid()
|
|
{
|
|
$itemSearchData = $this->getSearchData($this->configData->getAccountCount(), $this->request);
|
|
|
|
$accountGrid = $this->dic->get(AccountGrid::class);
|
|
|
|
return $accountGrid->updatePager($accountGrid->getGrid($this->accountService->search($itemSearchData)), $itemSearchData);
|
|
}
|
|
|
|
/**
|
|
* Delete action
|
|
*
|
|
* @param $id
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function deleteAction($id = null)
|
|
{
|
|
try {
|
|
if ($id === null) {
|
|
$this->accountService->deleteByIdBatch($this->getItemsIdFromRequest($this->request));
|
|
|
|
$this->deleteCustomFieldsForItem(Acl::ACCOUNT, $id);
|
|
|
|
$this->eventDispatcher->notifyEvent('delete.account.selection',
|
|
new Event($this, EventMessage::factory()->addDescription(__u('Cuentas eliminadas')))
|
|
);
|
|
|
|
return $this->returnJsonResponseData(JsonResponse::JSON_SUCCESS, __u('Cuentas eliminadas'));
|
|
}
|
|
|
|
$accountDetails = $this->accountService->getById($id)->getAccountVData();
|
|
|
|
$this->accountService->delete($id);
|
|
|
|
$this->deleteCustomFieldsForItem(Acl::ACCOUNT, $id);
|
|
|
|
$this->eventDispatcher->notifyEvent('delete.account',
|
|
new Event($this, EventMessage::factory()
|
|
->addDescription(__u('Cuenta eliminada'))
|
|
->addDetail(__u('Cuenta'), $accountDetails->getName())
|
|
->addDetail(__u('Cliente'), $accountDetails->getClientName()))
|
|
);
|
|
|
|
return $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Cuenta eliminada'));
|
|
} catch (\Exception $e) {
|
|
processException($e);
|
|
|
|
return $this->returnJsonResponseException($e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Initialize class
|
|
*
|
|
* @throws \SP\Services\Auth\AuthException
|
|
*/
|
|
protected function initialize()
|
|
{
|
|
$this->checkLoggedIn();
|
|
|
|
$this->accountService = $this->dic->get(AccountService::class);
|
|
}
|
|
} |