* [ADD] Added default permissions for accounts based on user, group and profiles.

* [MOD] Updated translations
* [MOD] Code refactoring
This commit is contained in:
nuxsmin
2018-08-30 01:41:57 +02:00
parent 7a938b677b
commit cd10389100
55 changed files with 21491 additions and 17631 deletions

View File

@@ -328,7 +328,7 @@
<action multiple="1">
<id>304</id>
<name>CLIENT_CREATE</name>
<text>Nuevo CLiente</text>
<text>Nuevo Cliente</text>
<route>client/create</route>
</action>
<action multiple="1">
@@ -829,4 +829,40 @@
<text>Buscar Notificación</text>
<route>notification/search</route>
</action>
<action multiple="1">
<id>1801</id>
<name>ACCOUNT_DEFAULT_PERMISSION</name>
<text>Gestión Permisos</text>
<route>accountDefaultPermission/index</route>
</action>
<action multiple="1">
<id>1802</id>
<name>ACCOUNT_DEFAULT_PERMISSION_SEARCH</name>
<text>Buscar Permiso</text>
<route>accountDefaultPermission/search</route>
</action>
<action multiple="1">
<id>1803</id>
<name>ACCOUNT_DEFAULT_PERMISSION_VIEW</name>
<text>Ver Permiso</text>
<route>accountDefaultPermission/view</route>
</action>
<action multiple="1">
<id>1804</id>
<name>ACCOUNT_DEFAULT_PERMISSION_CREATE</name>
<text>Nuevo Permiso</text>
<route>accountDefaultPermission/create</route>
</action>
<action multiple="1">
<id>1805</id>
<name>ACCOUNT_DEFAULT_PERMISSION_EDIT</name>
<text>Editar Permiso</text>
<route>accountDefaultPermission/edit</route>
</action>
<action multiple="1">
<id>1806</id>
<name>ACCOUNT_DEFAULT_PERMISSION_DELETE</name>
<text>Eliminar Permiso</text>
<route>accountDefaultPermission/delete</route>
</action>
</actions>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -27,12 +27,14 @@ namespace SP\Modules\Web\Controllers;
use SP\Core\Acl\Acl;
use SP\Core\Events\Event;
use SP\DataModel\ItemSearchData;
use SP\Modules\Web\Controllers\Helpers\Grid\AccountDefaultPermissionGrid;
use SP\Modules\Web\Controllers\Helpers\Grid\AuthTokenGrid;
use SP\Modules\Web\Controllers\Helpers\Grid\PublicLinkGrid;
use SP\Modules\Web\Controllers\Helpers\Grid\UserGrid;
use SP\Modules\Web\Controllers\Helpers\Grid\UserGroupGrid;
use SP\Modules\Web\Controllers\Helpers\Grid\UserProfileGrid;
use SP\Modules\Web\Controllers\Helpers\TabsGridHelper;
use SP\Services\Account\AccountDefaultPermissionService;
use SP\Services\AuthToken\AuthTokenService;
use SP\Services\PublicLink\PublicLinkService;
use SP\Services\User\UserService;
@@ -89,6 +91,10 @@ final class AccessManagerController extends ControllerBase
$this->tabsGridHelper->addTab($this->getUsersProfileList());
}
if ($this->checkAccess(Acl::ACCOUNT_DEFAULT_PERMISSION)) {
$this->tabsGridHelper->addTab($this->getAccountDefaultPermissionList());
}
if ($this->checkAccess(Acl::AUTHTOKEN)) {
$this->tabsGridHelper->addTab($this->getApiTokensList());
}
@@ -175,6 +181,20 @@ final class AccessManagerController extends ControllerBase
->updatePager();
}
/**
* Returns API tokens data tab
*
* @return \SP\Html\DataGrid\DataGridTab
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
protected function getAccountDefaultPermissionList()
{
return $this->dic->get(AccountDefaultPermissionGrid::class)
->getGrid($this->dic->get(AccountDefaultPermissionService::class)->search($this->itemSearchData))
->updatePager();
}
/**
* @return TabsGridHelper
*/

View File

@@ -0,0 +1,352 @@
<?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\Core\Exceptions\ValidationException;
use SP\DataModel\AccountDefaultPermissionData;
use SP\DataModel\AccountPermission;
use SP\Http\JsonResponse;
use SP\Modules\Web\Controllers\Helpers\Grid\AccountDefaultPermissionGrid;
use SP\Modules\Web\Controllers\Traits\ItemTrait;
use SP\Modules\Web\Controllers\Traits\JsonTrait;
use SP\Modules\Web\Forms\AccountDefaultPermissionForm;
use SP\Mvc\Controller\CrudControllerInterface;
use SP\Mvc\View\Components\SelectItemAdapter;
use SP\Services\Account\AccountDefaultPermissionService;
use SP\Services\User\UserService;
use SP\Services\UserGroup\UserGroupService;
/**
* Class AccountDefaultPermissionController
*
* @package SP\Modules\Web\Controllers
*/
class AccountDefaultPermissionController extends ControllerBase implements CrudControllerInterface
{
use JsonTrait, ItemTrait;
/**
* @var AccountDefaultPermissionService
*/
protected $accountDefaultPermissionService;
/**
* View action
*
* @param $id
*
* @return bool
*/
public function viewAction($id)
{
if (!$this->acl->checkUserAccess(Acl::ACCOUNT_DEFAULT_PERMISSION_VIEW)) {
return $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('No tiene permisos para realizar esta operación'));
}
$this->view->assign('header', __('Ver Permiso'));
$this->view->assign('isView', true);
try {
$this->setViewData($id);
$this->eventDispatcher->notifyEvent('show.accountDefaultPermission', new Event($this));
return $this->returnJsonResponseData(['html' => $this->render()]);
} catch (\Exception $e) {
processException($e);
return $this->returnJsonResponseException($e);
}
}
/**
* Sets view data for displaying permissions' data
*
* @param $permissionId
*
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
* @throws \SP\Repositories\NoSuchItemException
*/
protected function setViewData($permissionId = null)
{
$this->view->addTemplate('account_default_permission', 'itemshow');
$accountDefaultPermissionData = $permissionId ? $this->accountDefaultPermissionService->getById($permissionId) : new AccountDefaultPermissionData();
$accountPermission = $accountDefaultPermissionData->getAccountPermission() ?: new AccountPermission();
$this->view->assign('permission', $accountDefaultPermissionData);
$users = SelectItemAdapter::factory(UserService::getItemsBasic());
$this->view->assign('users', $users->getItemsFromModelSelected([$accountDefaultPermissionData->getUserId()]));
$this->view->assign('usersView', $users->getItemsFromModelSelected($accountPermission->getUsersView()));
$this->view->assign('usersEdit', $users->getItemsFromModelSelected($accountPermission->getUsersEdit()));
$userGroups = SelectItemAdapter::factory(UserGroupService::getItemsBasic());
$this->view->assign('userGroups', $userGroups->getItemsFromModelSelected([$accountDefaultPermissionData->getUserGroupId()]));
$this->view->assign('userGroupsView', $userGroups->getItemsFromModelSelected($accountPermission->getUserGroupsView()));
$this->view->assign('userGroupsEdit', $userGroups->getItemsFromModelSelected($accountPermission->getUserGroupsEdit()));
$this->view->assign('userProfiles', SelectItemAdapter::factory(UserGroupService::getItemsBasic())
->getItemsFromModelSelected([$accountDefaultPermissionData->getUserProfileId()]));
$this->view->assign('sk', $this->session->generateSecurityKey());
$this->view->assign('nextAction', Acl::getActionRoute(Acl::ACCESS_MANAGE));
if ($this->view->isView === true) {
$this->view->assign('disabled', 'disabled');
$this->view->assign('readonly', 'readonly');
} else {
$this->view->assign('disabled');
$this->view->assign('readonly');
}
}
/**
* Search action
*
* @return bool
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function searchAction()
{
if (!$this->acl->checkUserAccess(Acl::ACCOUNT_DEFAULT_PERMISSION_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);
$grid = $this->dic->get(AccountDefaultPermissionGrid::class);
return $grid->updatePager(
$grid->getGrid($this->accountDefaultPermissionService->search($itemSearchData)),
$itemSearchData
);
}
/**
* Create action
*/
public function createAction()
{
if (!$this->acl->checkUserAccess(Acl::ACCOUNT_DEFAULT_PERMISSION_CREATE)) {
return $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('No tiene permisos para realizar esta operación'));
}
$this->view->assign(__FUNCTION__, 1);
$this->view->assign('header', __('Nuevo Permiso'));
$this->view->assign('isView', false);
$this->view->assign('route', 'accountDefaultPermission/saveCreate');
try {
$this->setViewData();
$this->eventDispatcher->notifyEvent('show.accountDefaultPermission.create', new Event($this));
return $this->returnJsonResponseData(['html' => $this->render()]);
} catch (\Exception $e) {
processException($e);
return $this->returnJsonResponseException($e);
}
}
/**
* Edit action
*
* @param $id
*
* @return bool
*/
public function editAction($id)
{
if (!$this->acl->checkUserAccess(Acl::ACCOUNT_DEFAULT_PERMISSION_EDIT)) {
return $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('No tiene permisos para realizar esta operación'));
}
$this->view->assign('header', __('Editar Permiso'));
$this->view->assign('isView', false);
$this->view->assign('route', 'accountDefaultPermission/saveEdit/' . $id);
try {
$this->setViewData($id);
$this->eventDispatcher->notifyEvent('show.accountDefaultPermission.edit', new Event($this));
return $this->returnJsonResponseData(['html' => $this->render()]);
} catch (\Exception $e) {
processException($e);
return $this->returnJsonResponseException($e);
}
}
/**
* Delete action
*
* @param $id
*
* @return bool
*/
public function deleteAction($id = null)
{
if (!$this->acl->checkUserAccess(Acl::ACCOUNT_DEFAULT_PERMISSION_DELETE)) {
return $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('No tiene permisos para realizar esta operación'));
}
try {
if ($id === null) {
$this->accountDefaultPermissionService->deleteByIdBatch($this->getItemsIdFromRequest($this->request));
$this->eventDispatcher->notifyEvent('delete.accountDefaultPermission',
new Event($this,
EventMessage::factory()
->addDescription(__u('Permisos eliminados')))
);
return $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Permisos eliminados'));
}
$this->accountDefaultPermissionService->delete($id);
$this->eventDispatcher->notifyEvent('delete.accountDefaultPermission',
new Event($this,
EventMessage::factory()
->addDescription(__u('Permiso eliminado'))
->addDetail(__u('ID'), $id))
);
return $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Permiso eliminado'));
} catch (\Exception $e) {
processException($e);
return $this->returnJsonResponseException($e);
}
}
/**
* Saves create action
*/
public function saveCreateAction()
{
if (!$this->acl->checkUserAccess(Acl::ACCOUNT_DEFAULT_PERMISSION_CREATE)) {
return $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('No tiene permisos para realizar esta operación'));
}
try {
$form = new AccountDefaultPermissionForm($this->dic);
$form->validate(Acl::ACCOUNT_DEFAULT_PERMISSION_CREATE);
$id = $this->accountDefaultPermissionService->create($form->getItemData());
$this->eventDispatcher->notifyEvent('create.accountDefaultPermission',
new Event($this,
EventMessage::factory()
->addDescription(__u('Permiso creado'))
->addDetail(__u('ID'), $id))
);
return $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Permiso creado'));
} catch (ValidationException $e) {
return $this->returnJsonResponseException($e);
} catch (\Exception $e) {
processException($e);
return $this->returnJsonResponseException($e);
}
}
/**
* Saves edit action
*
* @param $id
*
* @return bool
*/
public function saveEditAction($id)
{
if (!$this->acl->checkUserAccess(Acl::ACCOUNT_DEFAULT_PERMISSION_EDIT)) {
return $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('No tiene permisos para realizar esta operación'));
}
try {
$form = new AccountDefaultPermissionForm($this->dic, $id);
$form->validate(Acl::ACCOUNT_DEFAULT_PERMISSION_EDIT);
$this->accountDefaultPermissionService->update($form->getItemData());
$this->eventDispatcher->notifyEvent('edit.accountDefaultPermission',
new Event($this,
EventMessage::factory()
->addDescription(__u('Permiso actualizado'))
->addDetail(__u('ID'), $id))
);
return $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Permiso actualizado'));
} catch (ValidationException $e) {
return $this->returnJsonResponseException($e);
} catch (\Exception $e) {
processException($e);
return $this->returnJsonResponseException($e);
}
}
/**
* Initialize class
*
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
* @throws \SP\Services\Auth\AuthException
*/
protected function initialize()
{
$this->checkLoggedIn();
$this->accountDefaultPermissionService = $this->dic->get(AccountDefaultPermissionService::class);
}
}

View File

@@ -126,7 +126,7 @@ final class AuthTokenController extends ControllerBase implements CrudController
*/
protected function setViewData($authTokenId = null)
{
$this->view->addTemplate('authtoken', 'itemshow');
$this->view->addTemplate('auth_token', 'itemshow');
$authToken = $authTokenId ? $this->authTokenService->getById($authTokenId) : new AuthTokenData();

View File

@@ -126,7 +126,7 @@ final class CustomFieldController extends ControllerBase implements CrudControll
*/
protected function setViewData($customFieldId = null)
{
$this->view->addTemplate('customfield', 'itemshow');
$this->view->addTemplate('custom_field', 'itemshow');
$customField = $customFieldId ? $this->customFieldService->getById($customFieldId) : new CustomFieldDefinitionData();

View File

@@ -29,6 +29,7 @@ use SP\Core\Acl\Acl;
use SP\Core\Acl\ActionsInterface;
use SP\Core\Acl\UnauthorizedPageException;
use SP\Core\Exceptions\SPException;
use SP\DataModel\AccountPermission;
use SP\DataModel\Dto\AccountAclDto;
use SP\DataModel\Dto\AccountDetailsResponse;
use SP\Http\Uri;
@@ -38,6 +39,7 @@ use SP\Mvc\View\Components\SelectItemAdapter;
use SP\Repositories\NoSuchItemException;
use SP\Services\Account\AccountAcl;
use SP\Services\Account\AccountAclService;
use SP\Services\Account\AccountDefaultPermissionService;
use SP\Services\Account\AccountHistoryService;
use SP\Services\Account\AccountService;
use SP\Services\Category\CategoryService;
@@ -61,25 +63,29 @@ final class AccountHelper extends HelperBase
/**
* @var Acl
*/
protected $acl;
private $acl;
/**
* @var AccountService
*/
protected $accountService;
private $accountService;
/**
* @var AccountHistoryService
*/
protected $accountHistoryService;
private $accountHistoryService;
/**
* @var PublicLinkService
*/
protected $publicLinkService;
private $publicLinkService;
/**
* @var AccountDefaultPermissionService
*/
private $accountDefaultPermissionService;
/**
* @var string
*/
private $actionId;
/**
* @var \SP\Services\Account\AccountAcl
* @var AccountAcl
*/
private $accountAcl;
/**
@@ -120,28 +126,34 @@ final class AccountHelper extends HelperBase
$selectUserGroups = SelectItemAdapter::factory(UserGroupService::getItemsBasic());
$selectTags = SelectItemAdapter::factory(TagService::getItemsBasic());
$this->view->assign('otherUsersView', $selectUsers->getItemsFromModelSelected(
SelectItemAdapter::getIdFromArrayOfObjects(array_filter($accountDetailsResponse->getUsers(), function ($value) {
$usersView = SelectItemAdapter::getIdFromArrayOfObjects(
array_filter($accountDetailsResponse->getUsers(), function ($value) {
return (int)$value->isEdit === 0;
})), $accountData->getUserId()));
}));
$this->view->assign('otherUsersEdit', $selectUsers->getItemsFromModelSelected(
SelectItemAdapter::getIdFromArrayOfObjects(array_filter($accountDetailsResponse->getUsers(), function ($value) {
$usersEdit = SelectItemAdapter::getIdFromArrayOfObjects(
array_filter($accountDetailsResponse->getUsers(), function ($value) {
return (int)$value->isEdit === 1;
})), $accountData->getUserId()));
}));
$this->view->assign('otherUserGroupsView', $selectUserGroups->getItemsFromModelSelected(
SelectItemAdapter::getIdFromArrayOfObjects(array_filter($accountDetailsResponse->getUserGroups(), function ($value) {
$userGroupsView = SelectItemAdapter::getIdFromArrayOfObjects(
array_filter($accountDetailsResponse->getUserGroups(), function ($value) {
return (int)$value->isEdit === 0;
})), $accountData->getUserGroupId()));
}));
$this->view->assign('otherUserGroupsEdit', $selectUserGroups->getItemsFromModelSelected(
SelectItemAdapter::getIdFromArrayOfObjects(array_filter($accountDetailsResponse->getUserGroups(), function ($value) {
$userGroupsEdit = SelectItemAdapter::getIdFromArrayOfObjects(
array_filter($accountDetailsResponse->getUserGroups(), function ($value) {
return (int)$value->isEdit === 1;
})), $accountData->getUserGroupId()));
}));
$this->view->assign('otherUsersView', $selectUsers->getItemsFromModelSelected($usersView, $accountData->getUserId()));
$this->view->assign('otherUsersEdit', $selectUsers->getItemsFromModelSelected($usersEdit, $accountData->getUserId()));
$this->view->assign('otherUserGroupsView', $selectUserGroups->getItemsFromModelSelected($userGroupsView, $accountData->getUserGroupId()));
$this->view->assign('otherUserGroupsEdit', $selectUserGroups->getItemsFromModelSelected($userGroupsEdit, $accountData->getUserGroupId()));
$this->view->assign('users', $selectUsers->getItemsFromModelSelected([$accountData->getUserId()]));
$this->view->assign('userGroups', $selectUserGroups->getItemsFromModelSelected([$accountData->getUserGroupId()]));
$this->view->assign('tags', $selectTags->getItemsFromModelSelected(SelectItemAdapter::getIdFromArrayOfObjects($accountDetailsResponse->getTags())));
$this->view->assign('historyData', $this->accountHistoryService->getHistoryForAccount($this->accountId));
@@ -212,7 +224,7 @@ final class AccountHelper extends HelperBase
*
* @param AccountDetailsResponse $accountDetailsResponse
*
* @return \SP\Services\Account\AccountAcl
* @return AccountAcl
* @throws AccountPermissionException
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
@@ -298,7 +310,7 @@ final class AccountHelper extends HelperBase
public function setViewForBlank($actionId)
{
$this->actionId = $actionId;
$this->accountAcl = new \SP\Services\Account\AccountAcl($actionId);
$this->accountAcl = new AccountAcl($actionId);
$this->checkActionAccess();
@@ -307,15 +319,17 @@ final class AccountHelper extends HelperBase
$this->accountAcl->setShowPermission($userData->getIsAdminApp() || $userData->getIsAdminAcc() || $userProfileData->isAccPermission());
$accountPermission = $this->accountDefaultPermissionService->getForCurrentUser()->getAccountPermission() ?: new AccountPermission();
$selectUsers = SelectItemAdapter::factory(UserService::getItemsBasic());
$selectUserGroups = SelectItemAdapter::factory(UserGroupService::getItemsBasic());
$selectTags = SelectItemAdapter::factory(TagService::getItemsBasic());
$this->view->assign('accountPassDateChange', date('Y-m-d', time() + 7776000));
$this->view->assign('otherUsersView', $selectUsers->getItemsFromModel());
$this->view->assign('otherUsersEdit', $selectUsers->getItemsFromModel());
$this->view->assign('otherUserGroupsView', $selectUserGroups->getItemsFromModel());
$this->view->assign('otherUserGroupsEdit', $selectUserGroups->getItemsFromModel());
$this->view->assign('otherUsersView', $selectUsers->getItemsFromModelSelected($accountPermission->getUsersView()));
$this->view->assign('otherUsersEdit', $selectUsers->getItemsFromModelSelected($accountPermission->getUsersEdit()));
$this->view->assign('otherUserGroupsView', $selectUserGroups->getItemsFromModelSelected($accountPermission->getUserGroupsView()));
$this->view->assign('otherUserGroupsEdit', $selectUserGroups->getItemsFromModelSelected($accountPermission->getUserGroupsEdit()));
$this->view->assign('userGroups', $selectUserGroups->getItemsFromModel());
$this->view->assign('tags', $selectTags->getItemsFromModel());
@@ -376,9 +390,10 @@ final class AccountHelper extends HelperBase
protected function initialize()
{
$this->acl = $this->dic->get(Acl::class);
$this->accountService = $this->dic->get(AccountService::class);;
$this->accountHistoryService = $this->dic->get(AccountHistoryService::class);;
$this->publicLinkService = $this->dic->get(PublicLinkService::class);;
$this->accountService = $this->dic->get(AccountService::class);
$this->accountHistoryService = $this->dic->get(AccountHistoryService::class);
$this->publicLinkService = $this->dic->get(PublicLinkService::class);
$this->accountDefaultPermissionService = $this->dic->get(AccountDefaultPermissionService::class);
$this->view->assign('changesHash');
$this->view->assign('chkUserEdit');

View File

@@ -0,0 +1,199 @@
<?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\Helpers\Grid;
use SP\Core\Acl\Acl;
use SP\Core\Acl\ActionsInterface;
use SP\Html\DataGrid\DataGridAction;
use SP\Html\DataGrid\DataGridActionSearch;
use SP\Html\DataGrid\DataGridActionType;
use SP\Html\DataGrid\DataGridData;
use SP\Html\DataGrid\DataGridHeader;
use SP\Html\DataGrid\DataGridInterface;
use SP\Html\DataGrid\DataGridTab;
use SP\Storage\Database\QueryResult;
/**
* Class AccountDefaultPermissionGrid
*
* @package SP\Modules\Web\Controllers\Helpers\Grid
*/
final class AccountDefaultPermissionGrid extends GridBase
{
/**
* @var QueryResult
*/
private $queryResult;
/**
* @param QueryResult $queryResult
*
* @return DataGridInterface
*/
public function getGrid(QueryResult $queryResult): DataGridInterface
{
$this->queryResult = $queryResult;
$grid = $this->getGridLayout();
$searchAction = $this->getSearchAction();
$grid->setDataActions($this->getSearchAction());
$grid->setPager($this->getPager($searchAction));
$grid->setDataActions($this->getCreateAction());
$grid->setDataActions($this->getEditAction());
$deleteAction = $this->getDeleteAction();
$grid->setDataActions($deleteAction);
$grid->setDataActions($deleteAction, true);
$grid->setTime(round(getElapsedTime($this->queryTimeStart), 5));
return $grid;
}
/**
* @return DataGridInterface
*/
protected function getGridLayout(): DataGridInterface
{
// Grid
$gridTab = new DataGridTab($this->view->getTheme());
$gridTab->setId('tblAccountDefaultPermission');
$gridTab->setDataRowTemplate('datagrid-rows', 'grid');
$gridTab->setDataPagerTemplate('datagrid-nav-full', 'grid');
$gridTab->setHeader($this->getHeader());
$gridTab->setData($this->getData());
$gridTab->setTitle(__('Permisos por Defecto'));
return $gridTab;
}
/**
* @return DataGridHeader
*/
protected function getHeader(): DataGridHeader
{
// Grid Header
$gridHeader = new DataGridHeader();
$gridHeader->addHeader(__('Usuario'));
$gridHeader->addHeader(__('Grupo'));
$gridHeader->addHeader(__('Perfil'));
$gridHeader->addHeader(__('Prioridad'));
$gridHeader->addHeader(__('Forzado'));
return $gridHeader;
}
/**
* @return DataGridData
*/
protected function getData(): DataGridData
{
// Grid Data
$gridData = new DataGridData();
$gridData->setDataRowSourceId('id');
$gridData->addDataRowSource('userName');
$gridData->addDataRowSource('userGroupName');
$gridData->addDataRowSource('userProfileName');
$gridData->addDataRowSource('priority');
$gridData->addDataRowSource('fixed', false, function ($value) {
return $value === 1 ? __('SI') : __('NO');
});
$gridData->setData($this->queryResult);
return $gridData;
}
/**
* @return DataGridActionSearch
*/
private function getSearchAction()
{
// Grid Actions
$gridActionSearch = new DataGridActionSearch();
$gridActionSearch->setId(ActionsInterface::ACCOUNT_DEFAULT_PERMISSION_SEARCH);
$gridActionSearch->setType(DataGridActionType::SEARCH_ITEM);
$gridActionSearch->setName('frmSearchPermission');
$gridActionSearch->setTitle(__('Buscar Permiso'));
$gridActionSearch->setOnSubmitFunction('appMgmt/search');
$gridActionSearch->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNT_DEFAULT_PERMISSION_SEARCH));
return $gridActionSearch;
}
/**
* @return DataGridAction
*/
private function getCreateAction()
{
$gridAction = new DataGridAction();
$gridAction->setId(ActionsInterface::ACCOUNT_DEFAULT_PERMISSION_CREATE);
$gridAction->setType(DataGridActionType::MENUBAR_ITEM);
$gridAction->setName(__('Nuevo Permiso'));
$gridAction->setTitle(__('Nuevo Permiso'));
$gridAction->setIcon($this->icons->getIconAdd());
$gridAction->setSkip(true);
$gridAction->setOnClickFunction('appMgmt/show');
$gridAction->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNT_DEFAULT_PERMISSION_CREATE));
return $gridAction;
}
/**
* @return DataGridAction
*/
private function getEditAction()
{
$gridAction = new DataGridAction();
$gridAction->setId(ActionsInterface::ACCOUNT_DEFAULT_PERMISSION_EDIT);
$gridAction->setType(DataGridActionType::EDIT_ITEM);
$gridAction->setName(__('Editar Permiso'));
$gridAction->setTitle(__('Editar Permiso'));
$gridAction->setIcon($this->icons->getIconEdit());
$gridAction->setOnClickFunction('appMgmt/show');
$gridAction->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNT_DEFAULT_PERMISSION_EDIT));
return $gridAction;
}
/**
* @return DataGridAction
*/
private function getDeleteAction()
{
$gridAction = new DataGridAction();
$gridAction->setId(ActionsInterface::ACCOUNT_DEFAULT_PERMISSION_DELETE);
$gridAction->setType(DataGridActionType::DELETE_ITEM);
$gridAction->setName(__('Eliminar Permiso'));
$gridAction->setTitle(__('Eliminar Permiso'));
$gridAction->setIcon($this->icons->getIconDelete());
$gridAction->setOnClickFunction('appMgmt/delete');
$gridAction->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNT_DEFAULT_PERMISSION_DELETE));
return $gridAction;
}
}

View File

@@ -82,7 +82,7 @@ final class ClientGrid extends GridBase
{
// Grid
$gridTab = new DataGridTab($this->view->getTheme());
$gridTab->setId('tblCustomers');
$gridTab->setId('tblClients');
$gridTab->setDataRowTemplate('datagrid-rows', 'grid');
$gridTab->setDataPagerTemplate('datagrid-nav-full', 'grid');
$gridTab->setHeader($this->getHeader());
@@ -133,7 +133,7 @@ final class ClientGrid extends GridBase
$gridActionSearch = new DataGridActionSearch();
$gridActionSearch->setId(ActionsInterface::CLIENT_SEARCH);
$gridActionSearch->setType(DataGridActionType::SEARCH_ITEM);
$gridActionSearch->setName('frmSearchCustomer');
$gridActionSearch->setName('frmSearchClient');
$gridActionSearch->setTitle(__('Buscar Cliente'));
$gridActionSearch->setOnSubmitFunction('appMgmt/search');
$gridActionSearch->addData('action-route', Acl::getActionRoute(ActionsInterface::CLIENT_SEARCH));

View File

@@ -128,7 +128,7 @@ final class PublicLinkController extends ControllerBase implements CrudControlle
*/
protected function setViewData($publicLinkId = null)
{
$this->view->addTemplate('publiclink', 'itemshow');
$this->view->addTemplate('public_link', 'itemshow');
$publicLink = $publicLinkId ? $this->publicLinkService->getById($publicLinkId) : new PublicLinkListData();

View File

@@ -218,7 +218,7 @@ final class UserController extends ControllerBase implements CrudControllerInter
return $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('No tiene permisos para realizar esta operación'));
}
$this->view->addTemplate('userpass', 'itemshow');
$this->view->addTemplate('user_pass', 'itemshow');
$this->view->assign(__FUNCTION__, 1);
$this->view->assign('header', __('Cambio de Clave'));

View File

@@ -132,7 +132,7 @@ final class UserGroupController extends ControllerBase implements CrudController
*/
protected function setViewData($userGroupId = null)
{
$this->view->addTemplate('usergroup', 'itemshow');
$this->view->addTemplate('user_group', 'itemshow');
$group = $userGroupId ? $this->userGroupService->getById($userGroupId) : new UserGroupData();

View File

@@ -126,7 +126,7 @@ final class UserProfileController extends ControllerBase implements CrudControll
*/
protected function setViewData($profileId = null)
{
$this->view->addTemplate('userprofile', 'itemshow');
$this->view->addTemplate('user_profile', 'itemshow');
$profile = $profileId ? $this->userProfileService->getById($profileId) : new UserProfileData();

View File

@@ -0,0 +1,126 @@
<?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\Forms;
use SP\Core\Acl\ActionsInterface;
use SP\Core\Exceptions\ValidationException;
use SP\DataModel\AccountDefaultPermissionData;
use SP\DataModel\AccountPermission;
/**
* Class AccountDefaultPermissionForm
*
* @package SP\Modules\Web\Forms
*/
final class AccountDefaultPermissionForm extends FormBase implements FormInterface
{
/**
* @var AccountDefaultPermissionData
*/
protected $accountDefaultPermissionData;
/**
* Validar el formulario
*
* @param $action
*
* @return AccountDefaultPermissionForm
* @throws ValidationException
*/
public function validate($action)
{
switch ($action) {
case ActionsInterface::ACCOUNT_DEFAULT_PERMISSION_CREATE:
case ActionsInterface::ACCOUNT_DEFAULT_PERMISSION_EDIT:
$this->analyzeRequestData();
$this->checkCommon();
break;
}
return $this;
}
/**
* Analizar los datos de la petición HTTP
*
* @return void
*/
protected function analyzeRequestData()
{
$this->accountDefaultPermissionData = new AccountDefaultPermissionData();
if ($this->itemId > 0) {
$this->accountDefaultPermissionData->setId($this->itemId);
}
if ($userId = $this->request->analyzeInt('user_id')) {
$this->accountDefaultPermissionData->setUserId($userId);
}
if ($userGroupId = $this->request->analyzeInt('user_group_id')) {
$this->accountDefaultPermissionData->setUserGroupId($userGroupId);
}
if ($userProfileId = $this->request->analyzeInt('user_profile_id')) {
$this->accountDefaultPermissionData->setUserProfileId($userProfileId);
}
$this->accountDefaultPermissionData->setFixed((int)$this->request->analyzeBool('fixed_enabled', false));
$this->accountDefaultPermissionData->setPriority($this->request->analyzeInt('priority'));
$accountPermission = new AccountPermission();
$accountPermission->setUsersView($this->request->analyzeArray('users_view', null, []));
$accountPermission->setUsersEdit($this->request->analyzeArray('users_edit', null, []));
$accountPermission->setUserGroupsView($this->request->analyzeArray('user_groups_view', null, []));
$accountPermission->setUserGroupsEdit($this->request->analyzeArray('user_groups_edit', null, []));
$this->accountDefaultPermissionData->setAccountPermission($accountPermission);
}
/**
* @throws ValidationException
*/
protected function checkCommon()
{
if (!$this->accountDefaultPermissionData->getUserId()
&& !$this->accountDefaultPermissionData->getUserGroupId()
&& !$this->accountDefaultPermissionData->getUserProfileId()
) {
throw new ValidationException(__u('Es necesario asignar un elemento del tipo usuario, grupo o perfil'));
}
if (!$this->accountDefaultPermissionData->getAccountPermission()->hasItems()) {
throw new ValidationException(__u('No hay permisos definidos'));
}
}
/**
* @return AccountDefaultPermissionData
*/
public function getItemData()
{
return $this->accountDefaultPermissionData;
}
}

View File

@@ -0,0 +1,211 @@
<?php
/** @var $icons \SP\Core\UI\ThemeIcons */
/** @var $permission \SP\DataModel\AccountDefaultPermissionData */
?>
<div id="box-popup">
<h2 class="center"><?php echo $header; ?><i class="btn-popup-close material-icons">close</i></h2>
<form method="post" name="frmAccountDefaultGroup" id="frmAccountDefaultGroup" class="form-action"
data-onsubmit="appMgmt/save"
data-action-route="<?php echo isset($route) ? $route : ''; ?>"
data-activetab="<?php echo isset($activeTab) ? $activeTab : ''; ?>"
data-hash="">
<table class="popup-data">
<tbody>
<tr>
<td class="descField"><?php echo __('Usuario'); ?></td>
<td class="valField">
<div class="lowres-title"><?php echo __('Usuario'); ?></div>
<select id="selUser" name="user_id" class="select-box select-box-deselect"
title="<?php echo __('Usuario'); ?>" <?php echo $disabled; ?>>
<option value=""><?php echo __('Seleccionar Usuario'); ?></option>
<?php /** @var \SP\Mvc\View\Components\SelectItem[] $users */
foreach ($users as $user): ?>
<option
value="<?php echo $user->getId(); ?>" <?php echo $user->isSelected() ? 'selected' : ''; ?>><?php echo $user->getName(); ?></option>
<?php endforeach; ?>
</select>
</td>
</tr>
<tr>
<td class="descField"><?php echo __('Grupo'); ?></td>
<td class="valField">
<div class="lowres-title"><?php echo __('Grupo'); ?></div>
<select id="selUserGroup" name="user_group_id" class="select-box select-box-deselect"
title="<?php echo __('Grupo'); ?>" <?php echo $disabled; ?>>
<option value=""><?php echo __('Seleccionar Grupo'); ?></option>
<?php /** @var \SP\Mvc\View\Components\SelectItem[] $userGroups */
foreach ($userGroups as $userGroup): ?>
<option
value="<?php echo $userGroup->getId(); ?>" <?php echo $userGroup->isSelected() ? 'selected' : ''; ?>><?php echo $userGroup->getName(); ?></option>
<?php endforeach; ?>
</select>
</td>
</tr>
<tr>
<td class="descField"><?php echo __('Perfil'); ?></td>
<td class="valField">
<div class="lowres-title"><?php echo __('Perfil'); ?></div>
<select id="selUserProfile" name="user_profile_id" class="select-box select-box-deselect"
title="<?php echo __('Perfil'); ?>" <?php echo $disabled; ?>>
<option value=""><?php echo __('Seleccionar Perfil'); ?></option>
<?php /** @var \SP\Mvc\View\Components\SelectItem[] $userProfiles */
foreach ($userProfiles as $userProfile): ?>
<option
value="<?php echo $userProfile->getId(); ?>" <?php echo $userProfile->isSelected() ? 'selected' : ''; ?>><?php echo $userProfile->getName(); ?></option>
<?php endforeach; ?>
</select>
</td>
</tr>
<tr>
<td class="descField">
<?php echo __('Prioridad'); ?>
<div id="help-priority"
class="icon material-icons <?php echo $icons->getIconHelp()->getClass(); ?>"><?php echo $icons->getIconHelp()->getIcon(); ?></div>
<div class="mdl-tooltip mdl-tooltip--large" for="help-priority">
<p>
<?php echo __('Prioridad de asignación en caso de coincidir con otros permisos asignados por usuario, grupo o perfil.'); ?>
</p>
</div>
</td>
<td class="valField">
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input id="priority" name="priority" type="number" step="1"
pattern="[0-9]{1,3}" class="mdl-textfield__input mdl-color-text--indigo-400"
maxlength="3" min="0" max="128"
value="<?php echo $permission->getPriority(); ?>"/>
<label class="mdl-textfield__label"
for="priority"><?php echo __('Prioridad de asignación'); ?></label>
</div>
</td>
</tr>
<tr>
<td class="descField"></td>
<td class="valField">
<ul class="mdl-list">
<li class="mdl-list__item mdl-list__item--two-line">
<div class="mdl-switch__box">
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect" for="fixed_enabled">
<input type="checkbox" id="fixed_enabled"
class="mdl-switch__input"
name="fixed_enabled" <?php echo $permission->getFixed() ? 'checked' : ''; ?>/>
</label>
</div>
<span class="mdl-list__item-primary-content">
<span><?php echo __('Forzado'); ?></span>
<span class="mdl-list__item-sub-title">
<?php echo __('Indica si los permisos serán forzados al crear o modificar la cuenta.'); ?>
<br>
<?php echo __('Los permisos serán añadidos a los existentes.'); ?>
</span>
</span>
</li>
</ul>
</td>
</tr>
<tr>
<td class="descField"><?php echo __('Usuarios'); ?></td>
<td class="valField">
<div class="account-permissions">
<div class="tag-list-box">
<div class="tag-list-header"><?php echo __('Ver'); ?></div>
<select id="users_view" name="users_view[]" multiple="multiple"
class="select-box">
<option value=""><?php echo __('Seleccionar Usuarios'); ?></option>
<?php /** @var \SP\Mvc\View\Components\SelectItem[] $usersView */
foreach ($usersView as $user): ?>
<?php if ($user->isSkip()): continue; endif; ?>
<option
value="<?php echo $user->getId(); ?>"
<?php echo $user->isSelected() ? 'selected' : '' ?>><?php echo $user->getName(); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="tag-list-box">
<div class="tag-list-header"><?php echo __('Editar'); ?></div>
<select id="users_edit" name="users_edit[]" multiple="multiple"
class="select-box">
<option value=""><?php echo __('Seleccionar Usuarios'); ?></option>
<?php /** @var \SP\Mvc\View\Components\SelectItem[] $usersEdit */
foreach ($usersEdit as $user): ?>
<?php if ($user->isSkip()): continue; endif; ?>
<option
value="<?php echo $user->getId(); ?>"
<?php echo $user->isSelected() ? 'selected' : '' ?>><?php echo $user->getName(); ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
</td>
</tr>
<tr>
<td class="descField"><?php echo __('Grupos'); ?></td>
<td class="valField">
<div class="account-permissions">
<div class="tag-list-box">
<div class="tag-list-header"><?php echo __('Ver'); ?></div>
<select id="user_groups_view" name="user_groups_view[]" multiple="multiple"
class="select-box">
<option value=""><?php echo __('Seleccionar Grupos'); ?></option>
<?php /** @var \SP\Mvc\View\Components\SelectItem[] $userGroupsView */
foreach ($userGroupsView as $userGroup): ?>
<?php if ($userGroup->isSkip()): continue; endif; ?>
<option
value="<?php echo $userGroup->getId(); ?>"
<?php echo $userGroup->isSelected() ? 'selected' : '' ?>><?php echo $userGroup->getName(); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="tag-list-box">
<div class="tag-list-header"><?php echo __('Editar'); ?></div>
<select id="user_groups_edit" name="user_groups_edit[]" multiple="multiple"
class="select-box">
<option value=""><?php echo __('Seleccionar Grupos'); ?></option>
<?php /** @var \SP\Mvc\View\Components\SelectItem[] $userGroupsEdit */
foreach ($userGroupsEdit as $userGroup): ?>
<?php if ($userGroup->isSkip()): continue; endif; ?>
<option
value="<?php echo $userGroup->getId(); ?>"
<?php echo $userGroup->isSelected() ? 'selected' : '' ?>><?php echo $userGroup->getName(); ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
</td>
</tr>
</tbody>
</table>
<input type="hidden" name="sk" value="">
<input type="hidden" name="isAjax" value="1">
</form>
<div class="action-in-box">
<button
class="mdl-button mdl-js-button mdl-button--fab mdl-button--mini-fab mdl-button--colored <?php echo $icons->getIconSave()->getClassButton(); ?>"
form="frmAccountDefaultGroup" title="<?php echo $icons->getIconSave()->getTitle(); ?>">
<i class="material-icons"><?php echo $icons->getIconSave()->getIcon(); ?></i>
</button>
</div>
</div>
<script>
sysPassApp.sk.set("<?php echo $sk; ?>");
</script>

View File

@@ -8,7 +8,7 @@
<div id="box-popup">
<h2 class="center"><?php echo $header; ?><i class="btn-popup-close material-icons">close</i></h2>
<form method="post" name="frmCustomers" id="frmCustomers" class="form-action"
<form method="post" name="frmClients" id="frmClients" class="form-action"
data-onsubmit="appMgmt/save"
data-action-route="<?php echo isset($route) ? $route : ''; ?>"
data-activetab="<?php echo isset($activeTab) ? $activeTab : ''; ?>"
@@ -76,7 +76,7 @@
<div class="action-in-box">
<button
class="mdl-button mdl-js-button mdl-button--fab mdl-button--mini-fab mdl-button--colored <?php echo $icons->getIconSave()->getClassButton(); ?>"
form="frmCustomers" title="<?php echo $icons->getIconSave()->getTitle(); ?>">
form="frmClients" title="<?php echo $icons->getIconSave()->getTitle(); ?>">
<i class="material-icons"><?php echo $icons->getIconSave()->getIcon(); ?></i>
</button>
</div>

View File

@@ -255,6 +255,13 @@ final class Acl implements ActionsInterface
case self::AUTHTOKEN_EDIT:
case self::AUTHTOKEN_DELETE:
return $userProfile->isMgmApiTokens();
case self::ACCOUNT_DEFAULT_PERMISSION:
case self::ACCOUNT_DEFAULT_PERMISSION_SEARCH:
case self::ACCOUNT_DEFAULT_PERMISSION_VIEW:
case self::ACCOUNT_DEFAULT_PERMISSION_CREATE:
case self::ACCOUNT_DEFAULT_PERMISSION_EDIT:
case self::ACCOUNT_DEFAULT_PERMISSION_DELETE:
return $userProfile->isMgmAccountDefaultPermissions();
case self::EVENTLOG:
case self::EVENTLOG_SEARCH:
case self::EVENTLOG_CLEAR:

View File

@@ -169,6 +169,12 @@ interface ActionsInterface
const EVENTLOG = 1701;
const EVENTLOG_SEARCH = 1702;
const EVENTLOG_CLEAR = 1703;
const ACCOUNT_DEFAULT_PERMISSION = 1801;
const ACCOUNT_DEFAULT_PERMISSION_SEARCH = 1802;
const ACCOUNT_DEFAULT_PERMISSION_VIEW = 1803;
const ACCOUNT_DEFAULT_PERMISSION_CREATE = 1804;
const ACCOUNT_DEFAULT_PERMISSION_EDIT = 1805;
const ACCOUNT_DEFAULT_PERMISSION_DELETE = 1806;
const ITEMS_MANAGE = 5001;
const ACCESS_MANAGE = 5002;
const USERSETTINGS = 5010;

View File

@@ -0,0 +1,237 @@
<?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\DataModel;
use SP\Util\Util;
/**
* Class AccountDefaultPermission
*
* @package SP\DataModel
*/
class AccountDefaultPermissionData extends DataModelBase
{
/**
* @var int
*/
public $id;
/**
* @var int
*/
public $userId;
/**
* @var int
*/
public $userGroupId;
/**
* @var int
*/
public $userProfileId;
/**
* @var int
*/
public $fixed;
/**
* @var int
*/
public $priority;
/**
* @var string
*/
public $permission;
/**
* @var AccountPermission
*/
private $accountPermission;
/**
* @return int
*/
public function getId(): int
{
return $this->id !== null ? (int)$this->id : null;
}
/**
* @param int $id
*
* @return AccountDefaultPermissionData
*/
public function setId(int $id)
{
$this->id = $id;
return $this;
}
/**
* @return int
*/
public function getUserId()
{
return $this->userId !== null ? (int)$this->userId : null;
}
/**
* @param int $userId
*
* @return AccountDefaultPermissionData
*/
public function setUserId(int $userId)
{
$this->userId = $userId;
return $this;
}
/**
* @return int
*/
public function getUserGroupId()
{
return $this->userGroupId !== null ? (int)$this->userGroupId : null;
}
/**
* @param int $userGroupId
*
* @return AccountDefaultPermissionData
*/
public function setUserGroupId(int $userGroupId)
{
$this->userGroupId = $userGroupId;
return $this;
}
/**
* @return int
*/
public function getUserProfileId()
{
return $this->userProfileId !== null ? (int)$this->userProfileId : null;
}
/**
* @param int $userProfileId
*
* @return AccountDefaultPermissionData
*/
public function setUserProfileId(int $userProfileId)
{
$this->userProfileId = $userProfileId;
return $this;
}
/**
* @return int
*/
public function getFixed(): int
{
return (int)$this->fixed;
}
/**
* @param int $fixed
*
* @return AccountDefaultPermissionData
*/
public function setFixed(int $fixed)
{
$this->fixed = $fixed;
return $this;
}
/**
* @return int
*/
public function getPriority(): int
{
return (int)$this->priority;
}
/**
* @param int $priority
*
* @return AccountDefaultPermissionData
*/
public function setPriority(int $priority)
{
$this->priority = $priority;
return $this;
}
/**
* @return string
*/
public function getPermission()
{
return $this->permission;
}
/**
* @return string
*/
public function getHash()
{
return sha1((int)$this->userId . (int)$this->userGroupId . (int)$this->userProfileId . (int)$this->priority);
}
/**
* @return $this
*/
public function hydrate()
{
if ($this->permission !== null) {
$this->accountPermission = Util::unserialize(AccountPermission::class, $this->permission);
}
return $this;
}
/**
* @return AccountPermission
*/
public function getAccountPermission()
{
return $this->accountPermission;
}
/**
* @param AccountPermission $accountPermission
*
* @return AccountDefaultPermissionData
*/
public function setAccountPermission(AccountPermission $accountPermission)
{
$this->accountPermission = $accountPermission;
$this->permission = serialize($accountPermission);
return $this;
}
}

View File

@@ -0,0 +1,141 @@
<?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\DataModel;
/**
* Class AccountPermission
*
* @package SP\DataModel
*/
class AccountPermission
{
/**
* @var array
*/
private $usersView = [];
/**
* @var array
*/
private $usersEdit = [];
/**
* @var array
*/
private $userGroupsView = [];
/**
* @var array
*/
private $userGroupsEdit = [];
/**
* @return array
*/
public function getUsersView(): array
{
return $this->usersView;
}
/**
* @param array $usersView
*
* @return AccountPermission
*/
public function setUsersView(array $usersView)
{
$this->usersView = $usersView;
return $this;
}
/**
* @return array
*/
public function getUsersEdit(): array
{
return $this->usersEdit;
}
/**
* @param array $usersEdit
*
* @return AccountPermission
*/
public function setUsersEdit(array $usersEdit)
{
$this->usersEdit = $usersEdit;
return $this;
}
/**
* @return array
*/
public function getUserGroupsView(): array
{
return $this->userGroupsView;
}
/**
* @param array $userGroupsView
*
* @return AccountPermission
*/
public function setUserGroupsView(array $userGroupsView)
{
$this->userGroupsView = $userGroupsView;
return $this;
}
/**
* @return array
*/
public function getUserGroupsEdit(): array
{
return $this->userGroupsEdit;
}
/**
* @param array $userGroupsEdit
*
* @return AccountPermission
*/
public function setUserGroupsEdit(array $userGroupsEdit)
{
$this->userGroupsEdit = $userGroupsEdit;
return $this;
}
/**
* @return bool
*/
public function hasItems()
{
return count($this->usersView) > 0
|| count($this->usersEdit) > 0
|| count($this->userGroupsView) > 0
|| count($this->userGroupsEdit) > 0;
}
}

View File

@@ -51,7 +51,7 @@ class CategoryData extends DataModelBase implements DataModelInterface
public $hash = '';
/**
* categoryData constructor.
* accountDefaultPermissionData constructor.
*
* @param int $id
* @param string $name

View File

@@ -141,6 +141,10 @@ class ProfileData
* @var bool
*/
protected $mgmFiles = false;
/**
* @var bool
*/
protected $mgmAccountDefaultPermissions = false;
/**
* @var bool
*/
@@ -761,4 +765,24 @@ class ProfileData
return $this;
}
/**
* @return bool
*/
public function isMgmAccountDefaultPermissions(): bool
{
return $this->mgmAccountDefaultPermissions;
}
/**
* @param bool $mgmAccountDefaultPermissions
*
* @return ProfileData
*/
public function setMgmAccountDefaultPermissions(bool $mgmAccountDefaultPermissions)
{
$this->mgmAccountDefaultPermissions = $mgmAccountDefaultPermissions;
return $this;
}
}

View File

@@ -0,0 +1,334 @@
<?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\Repositories\Account;
use SP\DataModel\AccountDefaultPermissionData;
use SP\DataModel\ItemSearchData;
use SP\Repositories\Repository;
use SP\Repositories\RepositoryItemInterface;
use SP\Repositories\RepositoryItemTrait;
use SP\Storage\Database\QueryData;
use SP\Storage\Database\QueryResult;
/**
* Class AccountDefaultPermissionRepository
*
* @package SP\Repositories\Account
*/
class AccountDefaultPermissionRepository extends Repository implements RepositoryItemInterface
{
use RepositoryItemTrait;
/**
* Creates an item
*
* @param AccountDefaultPermissionData $itemData
*
* @return int
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function create($itemData)
{
$queryData = new QueryData();
$queryData->setQuery(
'INSERT INTO AccountDefaultPermission
SET userId = ?,
userGroupId = ?,
userProfileId = ?,
`fixed` = ?,
priority = ?,
permission = ?,
`hash` = ?');
$queryData->setParams([
$itemData->getUserId(),
$itemData->getUserGroupId(),
$itemData->getUserProfileId(),
$itemData->getFixed(),
$itemData->getPriority(),
$itemData->getPermission(),
$itemData->getHash()
]);
$queryData->setOnErrorMessage(__u('Error al crear permiso'));
return $this->db->doQuery($queryData)->getLastId();
}
/**
* Updates an item
*
* @param AccountDefaultPermissionData $itemData
*
* @return int
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function update($itemData)
{
$queryData = new QueryData();
$queryData->setQuery(
'UPDATE AccountDefaultPermission
SET userId = ?,
userGroupId = ?,
userProfileId = ?,
`fixed` = ?,
priority = ?,
permission = ?,
`hash` = ?
WHERE id = ? LIMIT 1');
$queryData->setParams([
$itemData->getUserId(),
$itemData->getUserGroupId(),
$itemData->getUserProfileId(),
$itemData->getFixed(),
$itemData->getPriority(),
$itemData->getPermission(),
$itemData->getHash(),
$itemData->getId()
]);
$queryData->setOnErrorMessage(__u('Error al actualizar permiso'));
return $this->db->doQuery($queryData)->getAffectedNumRows();
}
/**
* Deletes an item
*
* @param $id
*
* @return int
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function delete($id)
{
$queryData = new QueryData();
$queryData->setQuery('DELETE FROM AccountDefaultPermission WHERE id = ? LIMIT 1');
$queryData->setParams([$id]);
$queryData->setOnErrorMessage(__u('Error al eliminar permiso'));
return $this->db->doQuery($queryData)->getAffectedNumRows();
}
/**
* Returns the item for given id
*
* @param int $id
*
* @return QueryResult
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function getById($id)
{
$queryData = new QueryData();
$queryData->setMapClassName(AccountDefaultPermissionData::class);
$queryData->setQuery(
'SELECT id, userId, userGroupId, userProfileId, `fixed`, priority, permission
FROM AccountDefaultPermission WHERE id = ? LIMIT 1');
$queryData->setParams([$id]);
return $this->db->doSelect($queryData);
}
/**
* Returns the item for given id
*
* @param int $userId
* @param int $userGroupId
* @param int $userProfileId
*
* @return QueryResult
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function getByFilter(int $userId, int $userGroupId, int $userProfileId)
{
$queryData = new QueryData();
$queryData->setMapClassName(AccountDefaultPermissionData::class);
$queryData->setQuery(
'SELECT id, userId, userGroupId, userProfileId, `fixed`, priority, permission
FROM AccountDefaultPermission
WHERE userId = ? OR userGroupId = ? OR userProfileId = ?
ORDER BY priority DESC, userId DESC, userProfileId DESC, userGroupId DESC
LIMIT 1');
$queryData->setParams([$userId, $userGroupId, $userProfileId]);
return $this->db->doSelect($queryData);
}
/**
* Returns all the items
*
* @return QueryResult
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function getAll()
{
$queryData = new QueryData();
$queryData->setMapClassName(AccountDefaultPermissionData::class);
$queryData->setQuery(
'SELECT id, userId, userGroupId, userProfileId, `fixed`, priority, permission
FROM AccountDefaultPermission');
return $this->db->doSelect($queryData);
}
/**
* Returns all the items for given ids
*
* @param array $ids
*
* @return QueryResult
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function getByIdBatch(array $ids)
{
if (empty($ids)) {
return new QueryResult();
}
$queryData = new QueryData();
$queryData->setMapClassName(AccountDefaultPermissionData::class);
$queryData->setQuery(
'SELECT userId, userGroupId, userProfileId, `fixed`, priority, permission
FROM AccountDefaultPermission WHERE id IN (' . $this->getParamsFromArray($ids) . ')');
$queryData->setParams($ids);
return $this->db->doSelect($queryData);
}
/**
* Deletes all the items for given ids
*
* @param array $ids
*
* @return int
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function deleteByIdBatch(array $ids)
{
if (empty($ids)) {
return 0;
}
$queryData = new QueryData();
$queryData->setQuery('DELETE FROM AccountDefaultPermission WHERE id IN (' . $this->getParamsFromArray($ids) . ')');
$queryData->setParams($ids);
$queryData->setOnErrorMessage(__u('Error al eliminar los permisos'));
return $this->db->doQuery($queryData)->getAffectedNumRows();
}
/**
* Checks whether the item is in use or not
*
* @param $id int
*/
public function checkInUse($id)
{
throw new \RuntimeException('Not implemented');
}
/**
* Checks whether the item is duplicated on updating
*
* @param mixed $itemData
*/
public function checkDuplicatedOnUpdate($itemData)
{
throw new \RuntimeException('Not implemented');
}
/**
* Checks whether the item is duplicated on adding
*
* @param mixed $itemData
*/
public function checkDuplicatedOnAdd($itemData)
{
throw new \RuntimeException('Not implemented');
}
/**
* Searches for items by a given filter
*
* @param ItemSearchData $itemSearchData
*
* @return QueryResult
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function search(ItemSearchData $itemSearchData)
{
$queryData = new QueryData();
$queryData->setSelect(
'ADP.id,
ADP.userId,
ADP.userGroupId,
ADP.userProfileId,
ADP.`fixed`,
ADP.priority,
ADP.permission,
U.name AS userName,
UP.name AS userProfileName,
UG.name AS userGroupName');
$queryData->setFrom('
AccountDefaultPermission ADP
LEFT JOIN User U ON ADP.userId = U.id
LEFT JOIN UserProfile UP ON ADP.userProfileId = UP.id
LEFT JOIN UserGroup UG ON ADP.userGroupId = UG.id');
$queryData->setOrder('id');
if ($itemSearchData->getSeachString() !== '') {
$queryData->setWhere('U.name LIKE ? OR UP.name LIKE ? OR UG.name LIKE ?');
$search = '%' . $itemSearchData->getSeachString() . '%';
$queryData->addParam($search);
$queryData->addParam($search);
$queryData->addParam($search);
}
$queryData->setLimit('?,?');
$queryData->addParam($itemSearchData->getLimitStart());
$queryData->addParam($itemSearchData->getLimitCount());
return $this->db->doSelect($queryData, true);
}
/**
* @param AccountDefaultPermissionData $data
*
* @return string
*/
private function getHash(AccountDefaultPermissionData $data)
{
return sha1((int)$data->getUserId() . (int)$data->getUserGroupId() . (int)$data->getUserProfileId() . (int)$data->getPriority());
}
}

View File

@@ -109,13 +109,13 @@ final class AccountToUserGroupRepository extends Repository
}
/**
* @param \SP\Services\Account\AccountRequest $accountRequest
* @param AccountRequest $accountRequest
*
* @return bool
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function update(\SP\Services\Account\AccountRequest $accountRequest)
public function update(AccountRequest $accountRequest)
{
$this->deleteByAccountId($accountRequest->id);
@@ -140,7 +140,7 @@ final class AccountToUserGroupRepository extends Repository
}
/**
* @param \SP\Services\Account\AccountRequest $accountRequest
* @param AccountRequest $accountRequest
*
* @return int Last ID inserted
* @throws \SP\Core\Exceptions\ConstraintException
@@ -172,7 +172,7 @@ final class AccountToUserGroupRepository extends Repository
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function updateEdit(\SP\Services\Account\AccountRequest $accountRequest)
public function updateEdit(AccountRequest $accountRequest)
{
$this->deleteEditByAccountId($accountRequest->id);
@@ -197,13 +197,13 @@ final class AccountToUserGroupRepository extends Repository
}
/**
* @param \SP\Services\Account\AccountRequest $accountRequest
* @param AccountRequest $accountRequest
*
* @return int
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function addEdit(\SP\Services\Account\AccountRequest $accountRequest)
public function addEdit(AccountRequest $accountRequest)
{
$query = /** @lang SQL */
'INSERT INTO AccountToUserGroup (accountId, userGroupId, isEdit)

View File

@@ -0,0 +1,197 @@
<?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\Services\Account;
use SP\DataModel\AccountDefaultPermissionData;
use SP\DataModel\ItemSearchData;
use SP\Repositories\Account\AccountDefaultPermissionRepository;
use SP\Repositories\NoSuchItemException;
use SP\Services\Service;
use SP\Services\ServiceException;
use SP\Storage\Database\QueryResult;
/**
* Class AccountDefaultPermissionService
*
* @package SP\Services\Account
*/
class AccountDefaultPermissionService extends Service
{
/**
* @var AccountDefaultPermissionRepository
*/
private $accountDefaultPermissionRepository;
/**
* @param AccountDefaultPermissionData $accountDefaultPermissionData
*
* @return int
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function create(AccountDefaultPermissionData $accountDefaultPermissionData)
{
return $this->accountDefaultPermissionRepository->create($accountDefaultPermissionData);
}
/**
* @param AccountDefaultPermissionData $accountDefaultPermissionData
*
* @return int
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function update(AccountDefaultPermissionData $accountDefaultPermissionData)
{
return $this->accountDefaultPermissionRepository->update($accountDefaultPermissionData);
}
/**
* Deletes an item
*
* @param $id
*
* @return AccountDefaultPermissionService
* @throws NoSuchItemException
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function delete($id)
{
if ($this->accountDefaultPermissionRepository->delete($id) === 0) {
throw new NoSuchItemException(__u('Permiso no encontrada'));
}
return $this;
}
/**
* Returns the item for given id
*
* @param int $id
*
* @return AccountDefaultPermissionData
* @throws NoSuchItemException
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function getById($id)
{
$result = $this->accountDefaultPermissionRepository->getById($id);
if ($result->getNumRows() === 0) {
throw new NoSuchItemException(__u('Permiso no encontrada'));
}
/** @var AccountDefaultPermissionData $data */
$data = $result->getData();
return $data->hydrate();
}
/**
* Returns all the items
*
* @return AccountDefaultPermissionData[]
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function getAll()
{
return $this->accountDefaultPermissionRepository->getAll()->getDataAsArray();
}
/**
* Searches for items by a given filter
*
* @param ItemSearchData $itemSearchData
*
* @return QueryResult
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function search(ItemSearchData $itemSearchData)
{
return $this->accountDefaultPermissionRepository->search($itemSearchData);
}
/**
* @return AccountDefaultPermissionData
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function getForCurrentUser()
{
$userData = $this->context->getUserData();
return $this->getForUser($userData->getId(), $userData->getUserGroupId(), $userData->getUserProfileId());
}
/**
* @param int $userId
* @param int $userGroupId
* @param int $userProfileId
*
* @return AccountDefaultPermissionData
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function getForUser(int $userId, int $userGroupId, int $userProfileId)
{
$result = $this->accountDefaultPermissionRepository->getByFilter(
$userId,
$userGroupId,
$userProfileId
);
if ($result->getNumRows() === 1) {
return $result->getData()->hydrate();
}
return null;
}
/**
* @param array $ids
*
* @return int
* @throws ServiceException
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function deleteByIdBatch(array $ids)
{
if (($count = $this->accountDefaultPermissionRepository->deleteByIdBatch($ids)) !== count($ids)) {
throw new ServiceException(__u('Error al eliminar los permisos'), ServiceException::WARNING);
}
return $count;
}
protected function initialize()
{
$this->accountDefaultPermissionRepository = $this->dic->get(AccountDefaultPermissionRepository::class);
}
}

View File

@@ -71,6 +71,10 @@ final class AccountService extends Service implements AccountServiceInterface
* @var AccountToTagRepository
*/
protected $accountToTagRepository;
/**
* @var AccountDefaultPermissionService
*/
protected $accountDefaultPermissionService;
/**
* @param int $id
@@ -201,6 +205,7 @@ final class AccountService extends Service implements AccountServiceInterface
$accountRequest->id = $this->accountRepository->create($accountRequest);
$this->addItems($accountRequest);
$this->addDefaultPermissions($accountRequest->id);
return $accountRequest->id;
}
@@ -243,28 +248,39 @@ final class AccountService extends Service implements AccountServiceInterface
*
* @param AccountRequest $accountRequest
*/
protected function addItems(AccountRequest $accountRequest)
private function addItems(AccountRequest $accountRequest)
{
try {
if ($accountRequest->changePermissions) {
if (is_array($accountRequest->userGroupsView) && !empty($accountRequest->userGroupsView)) {
if (is_array($accountRequest->userGroupsView)
&& !empty($accountRequest->userGroupsView)
) {
$this->accountToUserGroupRepository->add($accountRequest);
}
if (is_array($accountRequest->userGroupsEdit) && !empty($accountRequest->userGroupsEdit)) {
if (is_array($accountRequest->userGroupsEdit)
&& !empty($accountRequest->userGroupsEdit)
) {
$this->accountToUserGroupRepository->addEdit($accountRequest);
}
if (is_array($accountRequest->usersView) && !empty($accountRequest->usersView)) {
if (is_array($accountRequest->usersView)
&& !empty($accountRequest->usersView)
) {
$this->accountToUserRepository->add($accountRequest);
}
if (is_array($accountRequest->usersEdit) && !empty($accountRequest->usersEdit)) {
if (is_array($accountRequest->usersEdit)
&& !empty($accountRequest->usersEdit)
) {
$this->accountToUserRepository->addEdit($accountRequest);
}
}
if (is_array($accountRequest->tags) && !empty($accountRequest->tags)) {
if (is_array($accountRequest->tags)
&& !empty($accountRequest->tags)
) {
$this->accountToTagRepository->add($accountRequest);
}
} catch (SPException $e) {
@@ -272,6 +288,47 @@ final class AccountService extends Service implements AccountServiceInterface
}
}
/**
* @param int $accountId
*
* @throws QueryException
* @throws \SP\Core\Exceptions\ConstraintException
*/
private function addDefaultPermissions(int $accountId)
{
$accountDefaultPermission = $this->accountDefaultPermissionService->getForCurrentUser();
if ($accountDefaultPermission !== null
&& $accountDefaultPermission->getFixed()
) {
$userData = $this->context->getUserData();
$accountPermission = $accountDefaultPermission->getAccountPermission();
$accountRequest = new AccountRequest();
$accountRequest->id = $accountId;
$accountRequest->usersView = array_diff($accountPermission->getUsersView(), [$userData->getId()]);
$accountRequest->usersEdit = array_diff($accountPermission->getUsersEdit(), [$userData->getId()]);
$accountRequest->userGroupsView = array_diff($accountPermission->getUserGroupsView(), [$userData->getUserGroupId()]);
$accountRequest->userGroupsEdit = array_diff($accountPermission->getUserGroupsEdit(), [$userData->getUserGroupId()]);
if (!empty($accountRequest->usersView)) {
$this->accountToUserRepository->add($accountRequest);
}
if (!empty($accountRequest->usersEdit)) {
$this->accountToUserRepository->addEdit($accountRequest);
}
if (!empty($accountRequest->userGroupsView)) {
$this->accountToUserGroupRepository->add($accountRequest);
}
if (!empty($accountRequest->userGroupsEdit)) {
$this->accountToUserGroupRepository->addEdit($accountRequest);
}
}
}
/**
* @param AccountHistoryData $data
*
@@ -321,6 +378,8 @@ final class AccountService extends Service implements AccountServiceInterface
$this->accountRepository->update($accountRequest);
$this->updateItems($accountRequest);
$this->addDefaultPermissions($accountRequest->id);
});
}
@@ -334,7 +393,7 @@ final class AccountService extends Service implements AccountServiceInterface
* @throws ServiceException
* @throws \SP\Core\Exceptions\ConstraintException
*/
protected function addHistory($accountId, $isDelete = false)
private function addHistory($accountId, $isDelete = false)
{
$accountHistoryRepository = $this->dic->get(AccountHistoryService::class);
$configService = $this->dic->get(ConfigService::class);
@@ -356,7 +415,7 @@ final class AccountService extends Service implements AccountServiceInterface
* @throws QueryException
* @throws \SP\Core\Exceptions\ConstraintException
*/
protected function updateItems(AccountRequest $accountRequest)
private function updateItems(AccountRequest $accountRequest)
{
if ($accountRequest->changePermissions) {
if ($accountRequest->updateUserGroupPermissions) {
@@ -461,7 +520,6 @@ final class AccountService extends Service implements AccountServiceInterface
if ($this->accountRepository->delete($id) === 0) {
throw new NoSuchItemException(__u('Cuenta no encontrada'));
}
});
return $this;
@@ -636,5 +694,6 @@ final class AccountService extends Service implements AccountServiceInterface
$this->accountToUserRepository = $this->dic->get(AccountToUserRepository::class);
$this->accountToUserGroupRepository = $this->dic->get(AccountToUserGroupRepository::class);
$this->accountToTagRepository = $this->dic->get(AccountToTagRepository::class);
$this->accountDefaultPermissionService = $this->dic->get(AccountDefaultPermissionService::class);
}
}

View File

@@ -57,7 +57,7 @@ final class Installer extends Service
*/
const VERSION = [3, 0, 0];
const VERSION_TEXT = '3.0-beta';
const BUILD = 18082801;
const BUILD = 18083001;
/**
* @var DatabaseSetupInterface

View File

@@ -45,7 +45,7 @@ final class UpgradeDatabaseService extends Service implements UpgradeInterface
/**
* @var array Versiones actualizables
*/
const UPGRADES = ['300.18010101', '300.18072302', '300.18072501'];
const UPGRADES = ['300.18010101', '300.18072302', '300.18072501', '300.18083001'];
/**
* @var Database

29
schemas/30018083001.sql Normal file
View File

@@ -0,0 +1,29 @@
DELIMITER $$
CREATE TABLE `AccountDefaultPermission`
(
`id` int NOT NULL AUTO_INCREMENT,
`userId` smallint(5) unsigned,
`userGroupId` smallint(5) unsigned,
`userProfileId` smallint(5) unsigned,
`fixed` tinyint(1) unsigned DEFAULT 0 NOT NULL,
`priority` tinyint(3) unsigned DEFAULT 0 NOT NULL,
`permission` blob,
`hash` varbinary(40) NOT NULL,
UNIQUE INDEX `uk_AccountDefaultPermission_01` (`hash`),
CONSTRAINT `fk_AccountDefaultPermission_userId`
FOREIGN KEY (`userId`) REFERENCES `User` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `fk_AccountDefaultPermission_userGroupId`
FOREIGN KEY (`userGroupId`) REFERENCES `UserGroup` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `fk_AccountDefaultPermission_userProfileId`
FOREIGN KEY (`userProfileId`) REFERENCES `UserProfile` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE,
PRIMARY KEY (`id`)
)
ENGINE = InnoDB
DEFAULT CHARSET = utf8 $$

View File

@@ -51,6 +51,37 @@ CREATE TABLE `Account` (
ENGINE = InnoDB
DEFAULT CHARSET = utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `AccountDefaultPermission`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `AccountDefaultPermission`
(
`id` int NOT NULL AUTO_INCREMENT,
`userId` smallint(5) unsigned,
`userGroupId` smallint(5) unsigned,
`userProfileId` smallint(5) unsigned,
`fixed` tinyint(1) unsigned DEFAULT 0 NOT NULL,
`priority` tinyint(3) unsigned DEFAULT 0 NOT NULL,
`permission` blob,
`hash` varbinary(40) NOT NULL,
UNIQUE INDEX `uk_AccountDefaultPermission_01` (`hash`),
CONSTRAINT `fk_AccountDefaultPermission_userId`
FOREIGN KEY (`userId`) REFERENCES `User` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `fk_AccountDefaultPermission_userGroupId`
FOREIGN KEY (`userGroupId`) REFERENCES `UserGroup` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `fk_AccountDefaultPermission_userProfileId`
FOREIGN KEY (`userProfileId`) REFERENCES `UserProfile` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE,
PRIMARY KEY (`id`)
)
ENGINE = InnoDB
DEFAULT CHARSET = utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `AccountFile`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;

View File

@@ -0,0 +1,406 @@
<?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\Tests\Repositories;
use SP\Core\Exceptions\ConstraintException;
use SP\DataModel\AccountDefaultPermissionData;
use SP\DataModel\ItemSearchData;
use SP\Repositories\Account\AccountDefaultPermissionRepository;
use SP\Storage\Database\DatabaseConnectionData;
use SP\Tests\DatabaseTestCase;
use function SP\Tests\setupContext;
/**
* Class AccountDefaultPermissionRepositoryTest
*
* @package SP\Tests\Repositories
*/
class AccountDefaultPermissionRepositoryTest extends DatabaseTestCase
{
/**
* @var AccountDefaultPermissionRepository
*/
private static $repository;
/**
* @throws \DI\DependencyException
* @throws \DI\NotFoundException
* @throws \SP\Core\Context\ContextException
*/
public static function setUpBeforeClass()
{
$dic = setupContext();
self::$dataset = 'syspass_accountDefaultPermission.xml';
// Datos de conexión a la BBDD
self::$databaseConnectionData = $dic->get(DatabaseConnectionData::class);
// Inicializar el repositorio
self::$repository = $dic->get(AccountDefaultPermissionRepository::class);
}
/**
* @throws ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function testDeleteByIdBatch()
{
$this->assertEquals(3, self::$repository->deleteByIdBatch([1, 2, 3, 10]));
$this->assertEquals(2, $this->conn->getRowCount('AccountDefaultPermission'));
$this->assertEquals(0, self::$repository->deleteByIdBatch([]));
}
/**
* @throws ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function testDelete()
{
$this->assertEquals(1, self::$repository->delete(3));
$this->assertEquals(1, self::$repository->delete(4));
$this->assertEquals(0, self::$repository->delete(10));
$this->assertEquals(3, $this->conn->getRowCount('AccountDefaultPermission'));
}
/**
* @throws ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function testGetByIdBatch()
{
$this->assertCount(3, self::$repository->getByIdBatch([1, 2, 3])->getDataAsArray());
$this->assertCount(3, self::$repository->getByIdBatch([1, 2, 5, 10])->getDataAsArray());
$this->assertCount(0, self::$repository->getByIdBatch([])->getDataAsArray());
}
/**
* @throws ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function testUpdate()
{
$data = new AccountDefaultPermissionData();
$data->id = 1;
$data->userGroupId = 1;
$data->fixed = 1;
$data->priority = 1;
$data->permission = 'data';
self::$repository->update($data);
$this->assertEquals($data, self::$repository->getById(1)->getData());
}
/**
* @throws ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function testUpdateDuplicatedHash()
{
$this->expectException(ConstraintException::class);
$data = new AccountDefaultPermissionData();
$data->id = 1;
$data->userGroupId = 1;
$data->fixed = 1;
$data->priority = 10;
$data->permission = 'data';
self::$repository->update($data);
}
/**
* @throws ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function testUpdateUnknownUserId()
{
$this->expectException(ConstraintException::class);
$data = new AccountDefaultPermissionData();
$data->id = 2;
$data->userId = 10;
self::$repository->update($data);
}
/**
* @throws ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function testUpdateUnknownUserGroupId()
{
$this->expectException(ConstraintException::class);
$data = new AccountDefaultPermissionData();
$data->id = 2;
$data->userGroupId = 10;
self::$repository->update($data);
}
/**
* @throws ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function testUpdateUnknownUserProfileId()
{
$this->expectException(ConstraintException::class);
$data = new AccountDefaultPermissionData();
$data->id = 2;
$data->userProfileId = 10;
self::$repository->update($data);
}
/**
* @throws ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function testUpdateUnknownId()
{
$data = new AccountDefaultPermissionData();
$data->id = 10;
$data->userGroupId = 1;
$data->fixed = 1;
$data->priority = 1;
$data->permission = 'data';
self::$repository->update($data);
$this->assertEquals(0, self::$repository->update($data));
}
/**
* @throws ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function testGetById()
{
$data = new AccountDefaultPermissionData();
$data->id = 1;
$data->userId = 1;
$data->fixed = 0;
$data->priority = 0;
$result = self::$repository->getById(1);
$this->assertEquals(1, $result->getNumRows());
$this->assertEquals($data, $result->getData());
}
/**
* @throws ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function testGetAll()
{
$count = $this->conn->getRowCount('AccountDefaultPermission');
$result = self::$repository->getAll();
$this->assertEquals($count, $result->getNumRows());
/** @var AccountDefaultPermissionData[] $data */
$data = $result->getDataAsArray();
$this->assertCount($count, $data);
$this->assertInstanceOf(AccountDefaultPermissionData::class, $data[0]);
$this->assertEquals(1, $data[0]->getId());
$this->assertEquals(1, $data[0]->getUserId());
$this->assertNull($data[0]->getUserGroupId());
$this->assertNull($data[0]->getUserProfileId());
$this->assertNull($data[0]->getPermission());
$this->assertEquals(0, $data[0]->getFixed());
$this->assertEquals(0, $data[0]->getPriority());
$this->assertInstanceOf(AccountDefaultPermissionData::class, $data[1]);
$this->assertEquals(2, $data[1]->getId());
$this->assertInstanceOf(AccountDefaultPermissionData::class, $data[2]);
$this->assertEquals(3, $data[2]->getId());
}
/**
* @throws ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function testSearch()
{
// Search for user's name
$itemSearchData = new ItemSearchData();
$itemSearchData->setLimitCount(10);
$itemSearchData->setSeachString('demo');
$result = self::$repository->search($itemSearchData);
$data = $result->getDataAsArray();
$this->assertEquals(1, $result->getNumRows());
$this->assertCount(1, $data);
$this->assertInstanceOf(\stdClass::class, $data[0]);
$this->assertEquals(4, $data[0]->id);
$this->assertEquals(2, $data[0]->userId);
$this->assertNull($data[0]->userGroupId);
$this->assertNull($data[0]->userProfileId);
$this->assertNull($data[0]->permission);
$this->assertEquals(0, $data[0]->fixed);
$this->assertEquals(0, $data[0]->priority);
$this->assertEquals('sysPass demo', $data[0]->userName);
// Search for group's name
$itemSearchData = new ItemSearchData();
$itemSearchData->setLimitCount(10);
$itemSearchData->setSeachString('admins');
$result = self::$repository->search($itemSearchData);
$data = $result->getDataAsArray();
$this->assertEquals(1, $result->getNumRows());
$this->assertCount(1, $data);
$this->assertInstanceOf(\stdClass::class, $data[0]);
$this->assertEquals(2, $data[0]->id);
$this->assertNull($data[0]->userId);
$this->assertEquals(1, $data[0]->userGroupId);
$this->assertNull($data[0]->userProfileId);
$this->assertNull($data[0]->permission);
$this->assertEquals(0, $data[0]->fixed);
$this->assertEquals(10, $data[0]->priority);
$this->assertEquals('Admins', $data[0]->userGroupName);
// Search for profile's name
$itemSearchData = new ItemSearchData();
$itemSearchData->setLimitCount(10);
$itemSearchData->setSeachString('Usuarios');
$result = self::$repository->search($itemSearchData);
$data = $result->getDataAsArray();
$this->assertEquals(1, $result->getNumRows());
$this->assertCount(1, $data);
$this->assertInstanceOf(\stdClass::class, $data[0]);
$this->assertEquals(5, $data[0]->id);
$this->assertNull($data[0]->userId);
$this->assertNull($data[0]->userGroupId);
$this->assertEquals(3, $data[0]->userProfileId);
$this->assertNull($data[0]->permission);
$this->assertEquals(0, $data[0]->fixed);
$this->assertEquals(10, $data[0]->priority);
$this->assertEquals('Usuarios', $data[0]->userProfileName);
// Search for no results
$itemSearchData = new ItemSearchData();
$itemSearchData->setLimitCount(10);
$itemSearchData->setSeachString('test_permission');
$result = self::$repository->search($itemSearchData);
$data = $result->getDataAsArray();
$this->assertEquals(0, $result->getNumRows());
$this->assertCount(0, $data);
}
/**
* @throws ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function testCreate()
{
$data = new AccountDefaultPermissionData();
$data->id = 6;
$data->userGroupId = 1;
$data->fixed = 1;
$data->priority = 20;
$data->permission = 'data';
$id = self::$repository->create($data);
$this->assertEquals($data->id, $id);
$this->assertEquals($data, self::$repository->getById($id)->getData());
}
/**
* @throws ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function testCreateDuplicatedHash()
{
$this->expectException(ConstraintException::class);
$data = new AccountDefaultPermissionData();
$data->userGroupId = 1;
$data->fixed = 1;
$data->priority = 10;
$data->permission = 'data';
self::$repository->create($data);
}
/**
* @dataProvider userDataProvider
*
* @param int $userId
* @param int $userGroupId
* @param int $userProfileId
* @param int $expected
*
* @throws ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function testGetByFilter($userId, $userGroupId, $userProfileId, $expected)
{
$result = self::$repository->getByFilter($userId, $userGroupId, $userProfileId);
$this->assertEquals(1, $result->getNumRows());
/** @var AccountDefaultPermissionData $data */
$data = $result->getData();
$this->assertInstanceOf(AccountDefaultPermissionData::class, $data);
$this->assertEquals($expected, $data->getId());
}
/**
* @return array
*/
public function userDataProvider()
{
return [
[1, 1, 1, 3],
[1, 2, 2, 1],
[1, 1, 3, 5],
[2, 2, 2, 4],
[2, 2, 3, 5],
[2, 1, 3, 5],
[3, 1, 1, 3],
[3, 1, 2, 2],
];
}
}

View File

@@ -0,0 +1,361 @@
<?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\Tests\Services\Account;
use SP\Core\Exceptions\ConstraintException;
use SP\DataModel\AccountDefaultPermissionData;
use SP\DataModel\AccountPermission;
use SP\DataModel\ItemSearchData;
use SP\Repositories\NoSuchItemException;
use SP\Services\Account\AccountDefaultPermissionService;
use SP\Storage\Database\DatabaseConnectionData;
use SP\Tests\DatabaseTestCase;
use function SP\Tests\setupContext;
/**
* Class AccountDefaultPermissionServiceTest
*
* @package SP\Tests\Services\Account
*/
class AccountDefaultPermissionServiceTest extends DatabaseTestCase
{
/**
* @var AccountDefaultPermissionService
*/
private static $service;
/**
* @throws \DI\NotFoundException
* @throws \SP\Core\Context\ContextException
* @throws \DI\DependencyException
*/
public static function setUpBeforeClass()
{
$dic = setupContext();
self::$dataset = 'syspass_accountDefaultPermission.xml';
// Datos de conexión a la BBDD
self::$databaseConnectionData = $dic->get(DatabaseConnectionData::class);
// Inicializar el servicio
self::$service = $dic->get(AccountDefaultPermissionService::class);
}
/**
* @dataProvider userDataProvider
*
* @param int $userId
* @param int $userGroupId
* @param int $userProfileId
* @param int $expected
*
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function testGetForUser($userId, $userGroupId, $userProfileId, $expected)
{
$result = self::$service->getForUser($userId, $userGroupId, $userProfileId);
$this->assertInstanceOf(AccountDefaultPermissionData::class, $result);
$this->assertEquals($expected, $result->getId());
}
/**
* @return array
*/
public function userDataProvider()
{
return [
[1, 1, 1, 3],
[1, 2, 2, 1],
[1, 1, 3, 5],
[2, 2, 2, 4],
[2, 2, 3, 5],
[2, 1, 3, 5],
[3, 1, 1, 3],
[3, 1, 2, 2],
];
}
/**
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
* @throws \SP\Repositories\NoSuchItemException
*/
public function testGetById()
{
$data = new AccountDefaultPermissionData();
$data->id = 1;
$data->userId = 1;
$data->fixed = 0;
$data->priority = 0;
$result = self::$service->getById(1);
$this->assertInstanceOf(AccountDefaultPermissionData::class, $result);
$this->assertEquals($data, $result);
}
/**
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function testGetAll()
{
$count = $this->conn->getRowCount('AccountDefaultPermission');
$result = self::$service->getAll();
$this->assertCount($count, $result);
$this->assertInstanceOf(AccountDefaultPermissionData::class, $result[0]);
$this->assertEquals(1, $result[0]->getId());
$this->assertEquals(1, $result[0]->getUserId());
$this->assertNull($result[0]->getUserGroupId());
$this->assertNull($result[0]->getUserProfileId());
$this->assertNull($result[0]->getPermission());
$this->assertEquals(0, $result[0]->getFixed());
$this->assertEquals(0, $result[0]->getPriority());
$this->assertInstanceOf(AccountDefaultPermissionData::class, $result[1]);
$this->assertEquals(2, $result[1]->getId());
$this->assertInstanceOf(AccountDefaultPermissionData::class, $result[2]);
$this->assertEquals(3, $result[2]->getId());
}
/**
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
* @throws \SP\Repositories\NoSuchItemException
*/
public function testUpdate()
{
$accountPermission = new AccountPermission();
$accountPermission->setUsersEdit([1, 2]);
$accountPermission->setUsersView([3]);
$accountPermission->setUserGroupsView([2]);
$accountPermission->setUserGroupsEdit([1, 3]);
$data = new AccountDefaultPermissionData();
$data->id = 1;
$data->userGroupId = 1;
$data->fixed = 1;
$data->priority = 1;
$data->setAccountPermission($accountPermission);
self::$service->update($data);
$resultData = self::$service->getById(1);
$this->assertEquals($data, $resultData);
$this->assertEquals($accountPermission, $resultData->getAccountPermission());
}
/**
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function testUpdateUnKnown()
{
$accountPermission = new AccountPermission();
$accountPermission->setUsersEdit([1, 2]);
$accountPermission->setUsersView([3]);
$accountPermission->setUserGroupsView([2]);
$accountPermission->setUserGroupsEdit([1, 3]);
$data = new AccountDefaultPermissionData();
$data->id = 10;
$data->userGroupId = 1;
$data->fixed = 1;
$data->priority = 1;
$this->assertEquals(0, self::$service->update($data));
}
/**
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
* @throws \SP\Repositories\NoSuchItemException
*/
public function testDelete()
{
self::$service
->delete(3)
->delete(4);
$this->assertEquals(3, $this->conn->getRowCount('AccountDefaultPermission'));
}
/**
* @throws NoSuchItemException
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function testDeleteUnKnown()
{
$this->expectException(NoSuchItemException::class);
$this->assertEquals(0, self::$service->delete(10));
}
/**
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function testSearch()
{
// Search for user's name
$itemSearchData = new ItemSearchData();
$itemSearchData->setLimitCount(10);
$itemSearchData->setSeachString('demo');
$result = self::$service->search($itemSearchData);
$data = $result->getDataAsArray();
$this->assertEquals(1, $result->getNumRows());
$this->assertCount(1, $data);
$this->assertInstanceOf(\stdClass::class, $data[0]);
$this->assertEquals(4, $data[0]->id);
$this->assertEquals(2, $data[0]->userId);
$this->assertNull($data[0]->userGroupId);
$this->assertNull($data[0]->userProfileId);
$this->assertNull($data[0]->permission);
$this->assertEquals(0, $data[0]->fixed);
$this->assertEquals(0, $data[0]->priority);
$this->assertEquals('sysPass demo', $data[0]->userName);
// Search for group's name
$itemSearchData = new ItemSearchData();
$itemSearchData->setLimitCount(10);
$itemSearchData->setSeachString('admins');
$result = self::$service->search($itemSearchData);
$data = $result->getDataAsArray();
$this->assertEquals(1, $result->getNumRows());
$this->assertCount(1, $data);
$this->assertInstanceOf(\stdClass::class, $data[0]);
$this->assertEquals(2, $data[0]->id);
$this->assertNull($data[0]->userId);
$this->assertEquals(1, $data[0]->userGroupId);
$this->assertNull($data[0]->userProfileId);
$this->assertNull($data[0]->permission);
$this->assertEquals(0, $data[0]->fixed);
$this->assertEquals(10, $data[0]->priority);
$this->assertEquals('Admins', $data[0]->userGroupName);
// Search for profile's name
$itemSearchData = new ItemSearchData();
$itemSearchData->setLimitCount(10);
$itemSearchData->setSeachString('Usuarios');
$result = self::$service->search($itemSearchData);
$data = $result->getDataAsArray();
$this->assertEquals(1, $result->getNumRows());
$this->assertCount(1, $data);
$this->assertInstanceOf(\stdClass::class, $data[0]);
$this->assertEquals(5, $data[0]->id);
$this->assertNull($data[0]->userId);
$this->assertNull($data[0]->userGroupId);
$this->assertEquals(3, $data[0]->userProfileId);
$this->assertNull($data[0]->permission);
$this->assertEquals(0, $data[0]->fixed);
$this->assertEquals(10, $data[0]->priority);
$this->assertEquals('Usuarios', $data[0]->userProfileName);
// Search for no results
$itemSearchData = new ItemSearchData();
$itemSearchData->setLimitCount(10);
$itemSearchData->setSeachString('test_permission');
$result = self::$service->search($itemSearchData);
$data = $result->getDataAsArray();
$this->assertEquals(0, $result->getNumRows());
$this->assertCount(0, $data);
}
/**
* @throws ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function testGetForCurrentUser()
{
$data = self::$service->getForCurrentUser();
$this->assertInstanceOf(AccountDefaultPermissionData::class, $data);
$this->assertEquals(2, $data->getId());
}
/**
* @throws ConstraintException
* @throws NoSuchItemException
* @throws \SP\Core\Exceptions\QueryException
*/
public function testCreate()
{
$accountPermission = new AccountPermission();
$accountPermission->setUsersEdit([1, 2]);
$accountPermission->setUsersView([3]);
$accountPermission->setUserGroupsView([2]);
$accountPermission->setUserGroupsEdit([1, 3]);
$data = new AccountDefaultPermissionData();
$data->id = 6;
$data->userGroupId = 1;
$data->fixed = 1;
$data->priority = 20;
$data->setAccountPermission($accountPermission);
$id = self::$service->create($data);
$this->assertEquals($data->id, $id);
$this->assertEquals($data, self::$service->getById($id));
}
/**
* @throws ConstraintException
* @throws \SP\Core\Exceptions\QueryException
*/
public function testCreateDuplicatedHash()
{
$accountPermission = new AccountPermission();
$accountPermission->setUsersEdit([1, 2]);
$accountPermission->setUsersView([3]);
$accountPermission->setUserGroupsView([2]);
$accountPermission->setUserGroupsEdit([1, 3]);
$data = new AccountDefaultPermissionData();
$data->userGroupId = 1;
$data->fixed = 1;
$data->priority = 10;
$this->expectException(ConstraintException::class);
self::$service->create($data);
}
}

View File

@@ -9,11 +9,11 @@
<authBasicAutoLoginEnabled>1</authBasicAutoLoginEnabled>
<authBasicDomain></authBasicDomain>
<authBasicEnabled>1</authBasicEnabled>
<backup_hash>d184756286fee739c3e89432061c94734f934b0f</backup_hash>
<backup_hash>e3a34a99dcadc6abf94883a67e91ed05f49eed81</backup_hash>
<checkUpdates>0</checkUpdates>
<checknotices>0</checknotices>
<configDate>1535408508</configDate>
<configHash>5cef8b4dced8063f0705eff442b84143093b3917</configHash>
<configDate>1535584064</configDate>
<configHash>0cf71c39a7de70930b31dd6c12631cbf2849a44b</configHash>
<configSaver></configSaver>
<configVersion></configVersion>
<databaseVersion></databaseVersion>
@@ -32,7 +32,7 @@
<dokuwikiUrlBase></dokuwikiUrlBase>
<dokuwikiUser></dokuwikiUser>
<encryptSession>0</encryptSession>
<export_hash>756074783f565ce7cd838e0dbdb1db695f43acf6</export_hash>
<export_hash>0d5bfbb33cdcc40548d29018157bf99a1c03b528</export_hash>
<filesAllowedExts>
<item type="filesAllowedExts">PDF</item>
<item type="filesAllowedExts">JPG</item>

View File

@@ -540,5 +540,6 @@
<field name="used">0</field>
</row>
</table_data>
<table_data name="AccountDefaultPermission"/>
</database>
</mysqldump>

View File

@@ -432,5 +432,6 @@
<field name="isPrivateGroup">0</field>
</row>
</table_data>
<table_data name="AccountDefaultPermission"/>
</database>
</mysqldump>

View File

@@ -1,27 +1,4 @@
<?xml version="1.0"?>
<!--
~ 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/>.
-->
<mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<database name="syspass">
<table_data name="UserGroup">

View File

@@ -1,27 +1,4 @@
<?xml version="1.0"?>
<!--
~ 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/>.
-->
<mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<database name="syspass">
<table_data name="Account">

View File

@@ -0,0 +1,197 @@
<?xml version="1.0"?>
<mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<database name="syspass-test">
<table_data name="UserProfile">
<row>
<field name="id">1</field>
<field name="name">Admin</field>
<field name="profile" xsi:type="xs:hexBinary">4F3A32343A2253505C446174614D6F64656C5C50726F66696C6544617461223A32393A7B733A31303A22002A0061636356696577223B623A303B733A31343A22002A006163635669657750617373223B623A303B733A31373A22002A0061636356696577486973746F7279223B623A303B733A31303A22002A0061636345646974223B623A303B733A31343A22002A006163634564697450617373223B623A303B733A393A22002A00616363416464223B623A303B733A31323A22002A0061636344656C657465223B623A303B733A31313A22002A0061636346696C6573223B623A303B733A31333A22002A0061636350726976617465223B623A313B733A31383A22002A006163635072697661746547726F7570223B623A313B733A31363A22002A006163635065726D697373696F6E223B623A303B733A31373A22002A006163635075626C69634C696E6B73223B623A303B733A31383A22002A00616363476C6F62616C536561726368223B623A303B733A31363A22002A00636F6E66696747656E6572616C223B623A303B733A31393A22002A00636F6E666967456E6372797074696F6E223B623A303B733A31353A22002A00636F6E6669674261636B7570223B623A303B733A31353A22002A00636F6E666967496D706F7274223B623A303B733A31313A22002A006D676D5573657273223B623A303B733A31323A22002A006D676D47726F757073223B623A303B733A31343A22002A006D676D50726F66696C6573223B623A303B733A31363A22002A006D676D43617465676F72696573223B623A303B733A31353A22002A006D676D437573746F6D657273223B623A303B733A31353A22002A006D676D417069546F6B656E73223B623A303B733A31373A22002A006D676D5075626C69634C696E6B73223B623A303B733A31343A22002A006D676D4163636F756E7473223B623A303B733A31303A22002A006D676D54616773223B623A303B733A31313A22002A006D676D46696C6573223B623A303B733A363A22002A0065766C223B623A303B733A31383A22002A006D676D437573746F6D4669656C6473223B623A303B7D</field>
</row>
<row>
<field name="id">2</field>
<field name="name">Demo</field>
<field name="profile" xsi:type="xs:hexBinary">4F3A32343A2253505C446174614D6F64656C5C50726F66696C6544617461223A32393A7B733A31303A22002A0061636356696577223B623A313B733A31343A22002A006163635669657750617373223B623A313B733A31373A22002A0061636356696577486973746F7279223B623A313B733A31303A22002A0061636345646974223B623A313B733A31343A22002A006163634564697450617373223B623A313B733A393A22002A00616363416464223B623A313B733A31323A22002A0061636344656C657465223B623A313B733A31313A22002A0061636346696C6573223B623A303B733A31333A22002A0061636350726976617465223B623A303B733A31383A22002A006163635072697661746547726F7570223B623A303B733A31363A22002A006163635065726D697373696F6E223B623A303B733A31373A22002A006163635075626C69634C696E6B73223B623A303B733A31383A22002A00616363476C6F62616C536561726368223B623A303B733A31363A22002A00636F6E66696747656E6572616C223B623A303B733A31393A22002A00636F6E666967456E6372797074696F6E223B623A303B733A31353A22002A00636F6E6669674261636B7570223B623A303B733A31353A22002A00636F6E666967496D706F7274223B623A303B733A31313A22002A006D676D5573657273223B623A303B733A31323A22002A006D676D47726F757073223B623A303B733A31343A22002A006D676D50726F66696C6573223B623A303B733A31363A22002A006D676D43617465676F72696573223B623A303B733A31353A22002A006D676D437573746F6D657273223B623A303B733A31353A22002A006D676D417069546F6B656E73223B623A303B733A31373A22002A006D676D5075626C69634C696E6B73223B623A303B733A31343A22002A006D676D4163636F756E7473223B623A303B733A31303A22002A006D676D54616773223B623A303B733A31313A22002A006D676D46696C6573223B623A303B733A363A22002A0065766C223B623A303B733A31383A22002A006D676D437573746F6D4669656C6473223B623A303B7D</field>
</row>
<row>
<field name="id">3</field>
<field name="name">Usuarios</field>
<field name="profile" xsi:type="xs:hexBinary">4F3A32343A2253505C446174614D6F64656C5C50726F66696C6544617461223A32393A7B733A31303A22002A0061636356696577223B623A313B733A31343A22002A006163635669657750617373223B623A313B733A31373A22002A0061636356696577486973746F7279223B623A313B733A31303A22002A0061636345646974223B623A313B733A31343A22002A006163634564697450617373223B623A313B733A393A22002A00616363416464223B623A313B733A31323A22002A0061636344656C657465223B623A313B733A31313A22002A0061636346696C6573223B623A303B733A31333A22002A0061636350726976617465223B623A303B733A31383A22002A006163635072697661746547726F7570223B623A303B733A31363A22002A006163635065726D697373696F6E223B623A303B733A31373A22002A006163635075626C69634C696E6B73223B623A303B733A31383A22002A00616363476C6F62616C536561726368223B623A303B733A31363A22002A00636F6E66696747656E6572616C223B623A303B733A31393A22002A00636F6E666967456E6372797074696F6E223B623A303B733A31353A22002A00636F6E6669674261636B7570223B623A303B733A31353A22002A00636F6E666967496D706F7274223B623A303B733A31313A22002A006D676D5573657273223B623A303B733A31323A22002A006D676D47726F757073223B623A303B733A31343A22002A006D676D50726F66696C6573223B623A303B733A31363A22002A006D676D43617465676F72696573223B623A303B733A31353A22002A006D676D437573746F6D657273223B623A303B733A31353A22002A006D676D417069546F6B656E73223B623A303B733A31373A22002A006D676D5075626C69634C696E6B73223B623A303B733A31343A22002A006D676D4163636F756E7473223B623A303B733A31303A22002A006D676D54616773223B623A303B733A31313A22002A006D676D46696C6573223B623A303B733A363A22002A0065766C223B623A303B733A31383A22002A006D676D437573746F6D4669656C6473223B623A303B7D</field>
</row>
</table_data>
<table_data name="UserGroup">
<row>
<field name="id">1</field>
<field name="name">Admins</field>
<field name="description">sysPass Admins</field>
</row>
<row>
<field name="id">2</field>
<field name="name">Demo</field>
<field name="description"/>
</row>
<row>
<field name="id">3</field>
<field name="name">Usuarios</field>
<field name="description">Grupo Usuarios</field>
</row>
</table_data>
<table_data name="User">
<row>
<field name="id">1</field>
<field name="name">sysPass Admin</field>
<field name="userGroupId">1</field>
<field name="login">admin</field>
<field name="ssoLogin" xsi:nil="true" />
<field name="pass" xsi:type="xs:hexBinary">2432792431302432584B666F627854545234444E4A7956573748365165774153356E5234434E4B7748746A4A614362545333486D72316B37485A4E4F</field>
<field name="mPass" xsi:type="xs:hexBinary">64656635303230306339373130623861363837613161346136323261333134613936303034326531646638643662323838326537383264636261653237326662346562386138326665613134386165666637343132663537363035663034363135623633623961616239303266333933613863323439386539613734343061356337333937326131653663333766326532306136643766356266383137653965376465363438633738663034323333386230303666353461643039363437</field>
<field name="mKey" xsi:type="xs:hexBinary">6465663130303030646566353032303033633166653138613634613233646466323436333064626636616335306634376539356630653063303335636231353938343362626638363932323138366536613330333839663735333832376532356464333436633035393730316433303539333531376233633434386535303539356666663630326263373037373564363330623439313539363862333263353262643961366564306165336439623764626564653633633163346536613330383936616230303639613139356431333736623231333232663766663765386632623838336432363062353835666430393133323631346239303266646463393061313532376638313639623138356563666438653130303435393864623134643464666263393232336432653833386665313333626138393761643532383139666264396336326333306637343964333564313236386464663365383137643339333036616365343964636130316531376163306432616161646362346263613439333763386564656261396139313962363433363833616163333234316330393734343962613033383962616238303432653339656666666332316264643163636436343464643362646565346335666564316164616132653537666537656166353964306331303865396664626135323735396366353265306430336536</field>
<field name="email" xsi:nil="true" />
<field name="notes" xsi:nil="true" />
<field name="loginCount">100</field>
<field name="userProfileId">1</field>
<field name="lastLogin">2018-07-22 22:23:11</field>
<field name="lastUpdate" xsi:nil="true" />
<field name="lastUpdateMPass">1532297701</field>
<field name="isAdminApp">1</field>
<field name="isAdminAcc">0</field>
<field name="isLdap">0</field>
<field name="isDisabled">0</field>
<field name="hashSalt"></field>
<field name="isMigrate">0</field>
<field name="isChangePass">0</field>
<field name="isChangedPass">0</field>
<field name="preferences" xsi:type="xs:hexBinary">4F3A33323A2253505C446174614D6F64656C5C55736572507265666572656E63657344617461223A31303A7B733A373A22757365725F6964223B693A313B733A363A22757365324661223B623A303B733A343A226C616E67223B733A353A2265735F4553223B733A353A227468656D65223B733A31333A226D6174657269616C2D626C7565223B733A31343A22726573756C747350657250616765223B693A363B733A31313A226163636F756E744C696E6B223B623A303B733A393A22736F72745669657773223B623A303B733A393A22746F704E6176626172223B623A303B733A31353A226F7074696F6E616C416374696F6E73223B623A303B733A31343A22726573756C747341734361726473223B623A303B7D</field>
</row>
<row>
<field name="id">2</field>
<field name="name">sysPass demo</field>
<field name="userGroupId">2</field>
<field name="login">demo</field>
<field name="ssoLogin">demo</field>
<field name="pass" xsi:type="xs:hexBinary">2432792431302454726E69756C5763754361433635346F76566F35392E766B4C5433414E31624A6D726A79553462696335325069436A6B5572396669</field>
<field name="mPass" xsi:type="xs:hexBinary">64656635303230303231616533353730373263373165626239393534353966366236636164373235336534316336633534353036336339326136653730616366333930393165373934613865376662386662326664333931383932363562396466303133333631623063323732323339653465373165343839313030646534326265633737623966343238396635633936613837646531343864313963653663643338613131343932623163313765653630326430623532343564346566</field>
<field name="mKey" xsi:type="xs:hexBinary">6465663130303030646566353032303035643534316262633462653032333563313338626561366561333536626436663037353365313035653030333563653166316235336534663364343565366262353335626163396639646538653131316262356334383865336535633637323333666632626365313837626335386135353839373535373034386564353634366361646638623736396132323164363032353435653034306264613135663138323638383665373536313236353361313037306530333261323365636364336339616438323162306363383962643130333035303931653965626332653935313465656631373462663339343664656132393661346262366264343463646333363361643335623032373561356633323430313936346531633131663937313764313139633130633561373161666332356365346534366661623234646663626362326237303964336335316532623834326464303933653230353965373265356638376363366236626239306231346265376264373637663163303937366231313362393630613265636565336633313131663538656131346139353736623332653163303962636435313366383733656664653062373333366238643464646637616237323333373038613264393965633738356139393036306135643262316366306262663739346262663765</field>
<field name="email">demo@syspass.org</field>
<field name="notes">aaaa</field>
<field name="loginCount">12</field>
<field name="userProfileId">2</field>
<field name="lastLogin">2018-04-01 21:29:47</field>
<field name="lastUpdate">2018-04-14 08:47:43</field>
<field name="lastUpdateMPass">1522582852</field>
<field name="isAdminApp">0</field>
<field name="isAdminAcc">0</field>
<field name="isLdap">0</field>
<field name="isDisabled">0</field>
<field name="hashSalt"></field>
<field name="isMigrate">0</field>
<field name="isChangePass">0</field>
<field name="isChangedPass">0</field>
<field name="preferences" xsi:nil="true" />
</row>
<row>
<field name="id">3</field>
<field name="name">User A</field>
<field name="userGroupId">2</field>
<field name="login">user_a</field>
<field name="ssoLogin">user_a</field>
<field name="pass" xsi:type="xs:hexBinary">2432792431302469444B442E2F4F624D79742E6F43594F5249514D5065624454783966744D636A703034365A435976662E765479597A594F6A4C472E</field>
<field name="mPass" xsi:nil="true" />
<field name="mKey" xsi:nil="true" />
<field name="email">user_a@syspass.org</field>
<field name="notes"></field>
<field name="loginCount">0</field>
<field name="userProfileId">1</field>
<field name="lastLogin" xsi:nil="true" />
<field name="lastUpdate">2018-04-14 08:48:08</field>
<field name="lastUpdateMPass">0</field>
<field name="isAdminApp">0</field>
<field name="isAdminAcc">0</field>
<field name="isLdap">0</field>
<field name="isDisabled">0</field>
<field name="hashSalt"></field>
<field name="isMigrate">0</field>
<field name="isChangePass">0</field>
<field name="isChangedPass">0</field>
<field name="preferences" xsi:nil="true" />
</row>
<row>
<field name="id">4</field>
<field name="name">User B</field>
<field name="userGroupId">2</field>
<field name="login">user_b</field>
<field name="ssoLogin" xsi:nil="true" />
<field name="pass" xsi:type="xs:hexBinary">243279243130244C37643658736A663955794F6E583662472E6F384E4F713961674B6F64536B4B5674485350462F6861414E657971517065372E6532</field>
<field name="mPass" xsi:nil="true" />
<field name="mKey" xsi:nil="true" />
<field name="email">user_b@syspass.org</field>
<field name="notes"></field>
<field name="loginCount">0</field>
<field name="userProfileId">1</field>
<field name="lastLogin" xsi:nil="true" />
<field name="lastUpdate">2018-03-30 18:38:32</field>
<field name="lastUpdateMPass">0</field>
<field name="isAdminApp">0</field>
<field name="isAdminAcc">0</field>
<field name="isLdap">0</field>
<field name="isDisabled">0</field>
<field name="hashSalt"></field>
<field name="isMigrate">0</field>
<field name="isChangePass">0</field>
<field name="isChangedPass">0</field>
<field name="preferences" xsi:nil="true" />
</row>
</table_data>
<table_data name="AccountDefaultPermission">
<row>
<field name="id">1</field>
<field name="userId">1</field>
<field name="userGroupId" xsi:nil="true"/>
<field name="userProfileId" xsi:nil="true"/>
<field name="fixed">0</field>
<field name="priority">0</field>
<field name="permission" xsi:nil="true"/>
<field name="hash">e3cbba8883fe746c6e35783c9404b4bc0c7ee9eb</field>
</row>
<row>
<field name="id">2</field>
<field name="userId" xsi:nil="true"/>
<field name="userGroupId">1</field>
<field name="userProfileId" xsi:nil="true"/>
<field name="fixed">0</field>
<field name="priority">10</field>
<field name="permission" xsi:nil="true"/>
<field name="hash">9c5975f336463693254939bfde7042459607d834</field>
</row>
<row>
<field name="id">3</field>
<field name="userId" xsi:nil="true"/>
<field name="userGroupId" xsi:nil="true"/>
<field name="userProfileId">1</field>
<field name="fixed">0</field>
<field name="priority">20</field>
<field name="permission" xsi:nil="true"/>
<field name="hash">19fc3ecd72937e313c4a4a7023eb0ab07890cee7</field>
</row>
<row>
<field name="id">4</field>
<field name="userId">2</field>
<field name="userGroupId" xsi:nil="true"/>
<field name="userProfileId" xsi:nil="true"/>
<field name="fixed">0</field>
<field name="priority">0</field>
<field name="permission" xsi:nil="true"/>
<field name="hash">a4ac914c09d7c097fe1f4f96b897e625b6922069</field>
</row>
<row>
<field name="id">5</field>
<field name="userId" xsi:nil="true"/>
<field name="userGroupId" xsi:nil="true"/>
<field name="userProfileId">3</field>
<field name="fixed">0</field>
<field name="priority">10</field>
<field name="permission" xsi:nil="true"/>
<field name="hash">0e718dd1e04a0f28f7e31ddfaed950e2d70ee477</field>
</row>
</table_data>
</database>
</mysqldump>