bug fixes and permission tests

This commit is contained in:
Dennis Eichhorn 2022-01-22 21:56:00 +01:00
parent bd25adaa6e
commit 8deb92f7a3
9 changed files with 391 additions and 56 deletions

View File

@ -150,7 +150,7 @@
"children": []
},
{
"id": 1000105301,
"id": 1000105401,
"pid": "/admin/module",
"type": 3,
"subtype": 1,
@ -158,14 +158,14 @@
"uri": "{/prefix}admin/module/route/list?{?}",
"target": "self",
"icon": null,
"order": 10,
"order": 15,
"from": "Admin",
"permission": { "permission": 2, "type": null, "element": null },
"parent": 1000105001,
"children": []
},
{
"id": 1000105401,
"id": 1000105501,
"pid": "/admin/module",
"type": 3,
"subtype": 1,
@ -173,7 +173,7 @@
"uri": "{/prefix}admin/module/log?{?}",
"target": "self",
"icon": null,
"order": 15,
"order": 20,
"from": "Admin",
"permission": { "permission": 2, "type": null, "element": null },
"parent": 1000105001,

View File

@ -418,6 +418,23 @@ final class BackendController extends Controller
$view->setTemplate('/Modules/Admin/Theme/Backend/modules-route-list');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1000105001, $request, $response));
$module = $request->getData('id') ?? '';
$view->setData('module', $module);
$appPath = __DIR__ . '/../../../Web';
$activeRoutes = [];
$apps = \scandir($appPath);
foreach ($apps as $app) {
if (!\is_file(__DIR__ . '/../../../Web/' . $app . '/Routes.php')) {
continue;
}
$activeRoutes[$app] = include __DIR__ . '/../../../Web/' . $app . '/Routes.php';
}
$view->setData('routes', $activeRoutes);
return $view;
}

View File

@ -135,12 +135,20 @@ final class AccountMapper extends DataMapperFactory
$groupPermissions = empty($groups)
? []
: GroupPermissionMapper::getAll()->where('group', \array_keys($account->getGroups()), 'in')->execute();
: GroupPermissionMapper::getAll()
->where('group', \array_keys($account->getGroups()), 'in')
->where('element', null)
->execute();
foreach ($groupPermissions as $permission) {
$account->addPermissions(\is_array($permission) ? $permission : [$permission]);
}
$accountPermissions = AccountPermissionMapper::getAll()->where('account', $id)->execute();
$accountPermissions = AccountPermissionMapper::getAll()
->where('account', $id)
->where('element', null)
->execute();
foreach ($accountPermissions as $permission) {
$account->addPermissions(\is_array($permission) ? $permission : [$permission]);
}

View File

@ -33,10 +33,10 @@ final class AppMapper extends DataMapperFactory
* @since 1.0.0
*/
public const COLUMNS = [
'app_id' => ['name' => 'app_id', 'type' => 'int', 'internal' => 'id'],
'app_name' => ['name' => 'app_name', 'type' => 'string', 'internal' => 'name'],
'app_theme' => ['name' => 'app_theme', 'type' => 'string', 'internal' => 'theme'],
'app_status' => ['name' => 'app_status', 'type' => 'int', 'internal' => 'status'],
'app_id' => ['name' => 'app_id', 'type' => 'int', 'internal' => 'id'],
'app_name' => ['name' => 'app_name', 'type' => 'string', 'internal' => 'name'],
'app_theme' => ['name' => 'app_theme', 'type' => 'string', 'internal' => 'theme'],
'app_status' => ['name' => 'app_status', 'type' => 'int', 'internal' => 'status'],
];
/**

View File

@ -0,0 +1,35 @@
<?php
/**
* Orange Management
*
* PHP Version 8.0
*
* @package Modules\Admin\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Admin\Models;
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
/**
* Mapper class.
*
* @package Modules\Admin\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
final class PermissionAbstractMapper extends DataMapperFactory
{
public static function helper(ConnectionAbstract $connection) : PermissionQueryBuilder
{
return new PermissionQueryBuilder($connection);
}
}

View File

@ -0,0 +1,186 @@
<?php
/**
* Orange Management
*
* PHP Version 8.0
*
* @package Modules\Admin\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Admin\Models;
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
use phpOMS\DataStorage\Database\Query\Builder;
use phpOMS\DataStorage\Database\Query\Where;
/**
* Mapper class.
*
* @package Modules\Admin\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
final class PermissionQueryBuilder
{
private ConnectionAbstract $connection;
private array $groups = [];
private int $account = 0;
private array $units = [null];
private array $apps = [null];
private array $modules = [null];
private array $types = [null];
private int $permission = 0;
public function __construct(ConnectionAbstract $connection)
{
$this->connection = $connection;
}
public function groups(array $groups) : self
{
$this->groups = $groups;
return $this;
}
public function account(int $account) : self
{
$this->account = $account;
return $this;
}
public function units(array $units) : self
{
$this->units = $units;
return $this;
}
public function apps(array $apps) : self
{
$this->apps = $apps;
return $this;
}
public function types(array $types) : self
{
$this->types = $types;
return $this;
}
public function modules(array $modules) : self
{
$this->modules = $modules;
return $this;
}
public function permission(int $permission) : self
{
$this->permission = $permission;
return $this;
}
public function query(string $idField) : Builder
{
$where = new Where($this->connection);
// Handle account permissions
if (!empty($this->account)) {
$accountPermission = new Builder($this->connection);
$accountPermission->select('account_permission_element')
->from('account_permission')
->where('account_permission_account', '=', $this->account);
$subWhere = new Where($this->connection);
foreach ($this->units as $unit) {
$subWhere->orWhere('account_permission_unit', '=', $unit);
}
$accountPermission->where($subWhere);
$subWhere = new Where($this->connection);
foreach ($this->apps as $app) {
$subWhere->orWhere('account_permission_app', '=', $app);
}
$accountPermission->where($subWhere);
$subWhere = new Where($this->connection);
foreach ($this->modules as $module) {
$subWhere->orWhere('account_permission_module', '=', $module);
}
$accountPermission->where($subWhere);
$subWhere = new Where($this->connection);
foreach ($this->types as $type) {
$subWhere->orWhere('account_permission_type', '=', $type);
}
$accountPermission->where($subWhere);
$accountPermission->where('account_permission_permission', '>', $this->permission);
$where->where($idField, 'in', $accountPermission);
}
// Handle group permissions
if (!empty($this->groups)) {
$groupPermission = new Builder($this->connection);
$groupPermission->select('group_permission_element')
->from('group_permission')
->where('group_permission_group', 'IN', $this->groups);
$subWhere = new Where($this->connection);
foreach ($this->units as $unit) {
$subWhere->orWhere('group_permission_unit', '=', $unit);
}
$groupPermission->where($subWhere);
$subWhere = new Where($this->connection);
foreach ($this->apps as $app) {
$subWhere->orWhere('group_permission_app', '=', $app);
}
$groupPermission->where($subWhere);
$subWhere = new Where($this->connection);
foreach ($this->modules as $module) {
$subWhere->orWhere('group_permission_module', '=', $module);
}
$groupPermission->where($subWhere);
$subWhere = new Where($this->connection);
foreach ($this->types as $type) {
$subWhere->orWhere('group_permission_type', '=', $type);
}
$groupPermission->where($subWhere);
$groupPermission->where('group_permission_permission', '>', $this->permission);
$where->orWhere($idField, 'in', $groupPermission);
}
return $where;
}
}

View File

@ -169,7 +169,7 @@ echo $this->getData('nav')->render(); ?>
<label><?= $this->getHtml('Permission'); ?></label>
<span class="checkbox">
<label class="checkbox" for="iPermissionCreate">
<input id="iPermissionCreate" type="checkbox" name="permissioncreate" value="<?= PermissionType::CREATE; ?>">
<input id="iPermissionCreate" type="checkbox" name="permissioncreate" value="<?= PermissionType::CREATE; ?>" data-tpl-text="/perm/c" data-tpl-value="/perm/c">
<span class="checkmark"></span>
<?= $this->getHtml('Create'); ?>
</label>
@ -177,7 +177,7 @@ echo $this->getData('nav')->render(); ?>
<span class="checkbox">
<label class="checkbox" for="iPermissionRead">
<input id="iPermissionRead" type="checkbox" name="permissionread" value="<?= PermissionType::READ; ?>">
<input id="iPermissionRead" type="checkbox" name="permissionread" value="<?= PermissionType::READ; ?>" data-tpl-text="/perm/r" data-tpl-value="/perm/r">
<span class="checkmark"></span>
<?= $this->getHtml('Read'); ?>
</label>
@ -185,7 +185,7 @@ echo $this->getData('nav')->render(); ?>
<span class="checkbox">
<label class="checkbox" for="iPermissionUpdate">
<input id="iPermissionUpdate" type="checkbox" name="permissionupdate" value="<?= PermissionType::MODIFY; ?>">
<input id="iPermissionUpdate" type="checkbox" name="permissionupdate" value="<?= PermissionType::MODIFY; ?>" data-tpl-text="/perm/u" data-tpl-value="/perm/u">
<span class="checkmark"></span>
<?= $this->getHtml('Update'); ?>
</label>
@ -193,7 +193,7 @@ echo $this->getData('nav')->render(); ?>
<span class="checkbox">
<label class="checkbox" for="iPermissionDelete">
<input id="iPermissionDelete" type="checkbox" name="permissiondelete" value="<?= PermissionType::DELETE; ?>">
<input id="iPermissionDelete" type="checkbox" name="permissiondelete" value="<?= PermissionType::DELETE; ?>" data-tpl-text="/perm/d" data-tpl-value="/perm/d">
<span class="checkmark"></span>
<?= $this->getHtml('Delete'); ?>
</label>
@ -201,7 +201,7 @@ echo $this->getData('nav')->render(); ?>
<span class="checkbox">
<label class="checkbox" for="iPermissionPermission">
<input id="iPermissionPermission" type="checkbox" name="permissionpermission" value="<?= PermissionType::PERMISSION; ?>">
<input id="iPermissionPermission" type="checkbox" name="permissionpermission" value="<?= PermissionType::PERMISSION; ?>" data-tpl-text="/perm/p" data-tpl-value="/perm/p">
<span class="checkmark"></span>
<?= $this->getHtml('Permission'); ?>
</label>
@ -211,7 +211,9 @@ echo $this->getData('nav')->render(); ?>
<div class="portlet-foot">
<input type="hidden" name="permissionref" value="<?= $group->getId(); ?>">
<input type="hidden" name="permissionowner" value="<?= PermissionOwner::GROUP; ?>">
<input type="submit" value="<?= $this->getHtml('Add', '0', '0'); ?>">
<input type="submit" class="cancel hidden" value="<?= $this->getHtml('Cancel', '0', '0'); ?>">
<input type="submit" class="update hidden" value="<?= $this->getHtml('Update', '0', '0'); ?>">
<input type="submit" class="save" value="<?= $this->getHtml('Add', '0', '0'); ?>">
</div>
</form>
</div>
@ -220,8 +222,13 @@ echo $this->getData('nav')->render(); ?>
<div class="col-xs-12 col-md-6">
<div class="portlet">
<div class="portlet-head"><?= $this->getHtml('Permissions'); ?><i class="fa fa-download floatRight download btn"></i></div>
<div style="overflow-x:auto;">
<table id="groupPermissions" class="default" data-table-form="fGroupAddPermission">
<div class="slider">
<table id="groupPermissions" class="default"
data-update-content="tbody"
data-update-element="tr"
data-tag="form"
data-update-form="fGroupAddPermission"
data-table-form="fGroupAddPermission">
<thead>
<tr>
<td>
@ -255,23 +262,35 @@ echo $this->getData('nav')->render(); ?>
</td>
</tr>
</template>
<?php $c = 0; foreach ($permissions as $key => $value) : ++$c; $permission = $value->getPermission(); ?>
<?php $c = 0;
foreach ($permissions as $key => $value) : ++$c;
$permission = $value->getPermission(); ?>
<tr>
<td><a href="#"><i class="fa fa-times"></i></a>
<td><a href="#"><i class="fa fa-cogs"></i></a>
<td><i class="fa fa-cogs update btn"></i>
<td><?= $value->getId(); ?>
<td><?= $value->getUnit(); ?>
<td><?= $value->getApp(); ?>
<td><?= $value->getModule(); ?>
<td><?= $value->getType(); ?>
<td><?= $value->getElement(); ?>
<td><?= $value->getComponent(); ?>
<td data-tpl-text="/unit" data-tpl-value="/unit"><?= $value->getUnit(); ?>
<td data-tpl-text="/app" data-tpl-value="/app"><?= $value->getApp(); ?>
<td data-tpl-text="/module" data-tpl-value="/module"><?= $value->getModule(); ?>
<td data-tpl-text="/type" data-tpl-value="/type"><?= $value->getType(); ?>
<td data-tpl-text="/ele" data-tpl-value="/ele"><?= $value->getElement(); ?>
<td data-tpl-text="/comp" data-tpl-value="/comp"><?= $value->getComponent(); ?>
<td>
<?= (PermissionType::CREATE | $permission) === $permission ? 'C' : ''; ?>
<?= (PermissionType::READ | $permission) === $permission ? 'R' : ''; ?>
<?= (PermissionType::MODIFY | $permission) === $permission ? 'U' : ''; ?>
<?= (PermissionType::DELETE | $permission) === $permission ? 'D' : ''; ?>
<?= (PermissionType::PERMISSION | $permission) === $permission ? 'P' : ''; ?>
<?php if ((PermissionType::CREATE | $permission) === $permission) : ?>
<span data-tpl-text="/perm/c" data-tpl-value="/perm/c" data-value="<?= PermissionType::CREATE; ?>">C</span>
<?php endif; ?>
<?php if ((PermissionType::READ | $permission) === $permission) : ?>
<span data-tpl-text="/perm/r" data-tpl-value="/perm/r" data-value="<?= PermissionType::READ; ?>">R</span>
<?php endif; ?>
<?php if ((PermissionType::MODIFY | $permission) === $permission) : ?>
<span data-tpl-text="/perm/u" data-tpl-value="/perm/u" data-value="<?= PermissionType::MODIFY; ?>">U</span>
<?php endif; ?>
<?php if ((PermissionType::DELETE | $permission) === $permission) : ?>
<span data-tpl-text="/perm/d" data-tpl-value="/perm/d" data-value="<?= PermissionType::DELETE; ?>">D</span>
<?php endif; ?>
<?php if ((PermissionType::PERMISSION | $permission) === $permission) : ?>
<span data-tpl-text="/perm/p" data-tpl-value="/perm/p" data-value="<?= PermissionType::PERMISSION; ?>">P</span>
<?php endif; ?>
<?php endforeach; ?>
<?php if ($c === 0) : ?>
<tr><td colspan="10" class="empty"><?= $this->getHtml('Empty', '0', '0'); ?>

View File

@ -1,25 +0,0 @@
<?php
/**
* Orange Management
*
* PHP Version 8.0
*
* @package Modules\Admin\Template\Backend
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
use phpOMS\Message\Http\HttpHeader;
/**
* @var \phpOMS\Views\View $this
*/
$audits = $this->getData('auditlogs') ?? [];
$previous = empty($audits) ? HttpHeader::getAllHeaders()['Referer'] ?? '{/prefix}admin/module/settings?id={?id}#{\#}' : '{/prefix}admin/module/settings?{?}&audit=' . \reset($audits)->getId() . '&ptype=p#{\#}';
$next = empty($audits) ? HttpHeader::getAllHeaders()['Referer'] ?? '{/prefix}admin/module/settings?id={?id}#{\#}' : '{/prefix}admin/module/settings?{?}&audit=' . \end($audits)->getId() . '&ptype=n#{\#}';
echo $this->getData('nav')->render();

View File

@ -0,0 +1,95 @@
<?php
/**
* Orange Management
*
* PHP Version 8.0
*
* @package Modules\Admin\Template\Backend
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
use phpOMS\Message\Http\HttpHeader;
/**
* @var \phpOMS\Views\View $this
*/
$routes = $this->getData('routes') ?? [];
$module = $this->getData('module') ?? '';
echo $this->getData('nav')->render();
?>
<div class="row">
<div class="col-xs-12">
<div class="portlet">
<div class="portlet-head"><?= $this->getHtml('Routes'); ?><i class="fa fa-download floatRight download btn"></i></div>
<div class="slider">
<table id="navElements" class="default sticky">
<thead>
<tr>
<td><?= $this->getHtml('Active'); ?>
<td><?= $this->getHtml('App'); ?>
<label for="navElements-sort-1">
<input type="radio" name="navElements-sort" id="navElements-sort-1">
<i class="sort-asc fa fa-chevron-up"></i>
</label>
<label for="navElements-sort-2">
<input type="radio" name="navElements-sort" id="navElements-sort-2">
<i class="sort-desc fa fa-chevron-down"></i>
</label>
<label>
<i class="filter fa fa-filter"></i>
</label>
<td><?= $this->getHtml('Route'); ?>
<label for="navElements-sort-5">
<input type="radio" name="navElements-sort" id="navElements-sort-5">
<i class="sort-asc fa fa-chevron-up"></i>
</label>
<label for="navElements-sort-6">
<input type="radio" name="navElements-sort" id="navElements-sort-6">
<i class="sort-desc fa fa-chevron-down"></i>
</label>
<label>
<i class="filter fa fa-filter"></i>
</label>
<td><?= $this->getHtml('Destination'); ?>
<label for="navElements-sort-7">
<input type="radio" name="navElements-sort" id="navElements-sort-7">
<i class="sort-asc fa fa-chevron-up"></i>
</label>
<label for="navElements-sort-8">
<input type="radio" name="navElements-sort" id="navElements-sort-8">
<i class="sort-desc fa fa-chevron-down"></i>
</label>
<label>
<i class="filter fa fa-filter"></i>
</label>
</thead>
<tbody>
<?php $c = 0;
foreach ($routes as $app => $appRoutes) :
foreach ($appRoutes as $uri => $destinations) :
foreach ($destinations as $route) :
if (\stripos($route['dest'], '\Modules\\' . $module . '\Controller') === false) {
continue;
}
++$c;
?>
<tr>
<td><label class="checkbox" for="iActive-<?= $c ?>">
<input id="iActive-<?= $c ?>" type="checkbox" name="active_route" value="<?= $this->printHtml($uri); ?>"<?= true ? ' checked' : ''; ?>>
<span class="checkmark"></span>
</label>
<td><?= $app; ?>
<td><?= $uri; ?>
<td><?= $route['dest']; ?>
<?php endforeach; endforeach; endforeach; ?>
</table>
</div>
</div>
</div>