improve audit logs

This commit is contained in:
Dennis Eichhorn 2020-07-31 00:04:25 +02:00
parent 5c2a348d5e
commit fdb4290ac8
4 changed files with 240 additions and 103 deletions

View File

@ -29,6 +29,7 @@ use phpOMS\DataStorage\Database\RelationType;
use phpOMS\Message\RequestAbstract;
use phpOMS\Message\ResponseAbstract;
use phpOMS\Module\ModuleInfo;
use phpOMS\Utils\StringUtils;
use phpOMS\Views\View;
/**
@ -249,6 +250,27 @@ final class BackendController extends Controller
$editor = new \Modules\Editor\Theme\Backend\Components\Editor\BaseView($this->app->l11nManager, $request, $response);
$view->addData('editor', $editor);
// audit log
if ($request->getData('ptype') === 'p') {
$view->setData('auditlogs',
AuditMapper::withConditional('module', self::MODULE_NAME, [Audit::class])
::withConditional('type', StringUtils::hash(GroupMapper::class), [Audit::class])
::withConditional('ref', (string) $request->getData('id') ?? '0', [Audit::class])
::getBeforePivot((int) $request->getData('audit'), null, 25));
} elseif ($request->getData('ptype') === 'n') {
$view->setData('auditlogs',
AuditMapper::withConditional('module', self::MODULE_NAME, [Audit::class])
::withConditional('type', StringUtils::hash(GroupMapper::class), [Audit::class])
::withConditional('ref', (string) $request->getData('id') ?? '0', [Audit::class])
::getAfterPivot((int) $request->getData('audit'), null, 25));
} else {
$view->setData('auditlogs',
AuditMapper::withConditional('module', self::MODULE_NAME, [Audit::class])
::withConditional('type', StringUtils::hash(GroupMapper::class), [Audit::class])
::withConditional('ref', (string) $request->getData('id') ?? '0', [Audit::class])
::getAfterPivot(0, null, 25));
}
return $view;
}
@ -335,6 +357,15 @@ final class BackendController extends Controller
$groupPermission = GroupMapper::getPermissionForModule($id);
$view->setData('groupPermissions', $groupPermission);
// audit log
if ($request->getData('ptype') === 'p') {
$view->setData('auditlogs', AuditMapper::withConditional('module', (string) $request->getData('id'), [Audit::class])::getBeforePivot((int) $request->getData('audit'), null, 25));
} elseif ($request->getData('ptype') === 'n') {
$view->setData('auditlogs', AuditMapper::withConditional('module', (string) $request->getData('id'), [Audit::class])::getAfterPivot((int) $request->getData('audit'), null, 25));
} else {
$view->setData('auditlogs', AuditMapper::withConditional('module', (string) $request->getData('id'), [Audit::class])::getAfterPivot(0, null, 25));
}
return $view;
}
}

View File

@ -39,7 +39,7 @@ use phpOMS\Uri\UriFactory;
*/
$account = $this->getData('account');
$permissions = $this->getData('permissions');
$audits = $this->getData('auditlogs');
$audits = $this->getData('auditlogs') ?? [];
$previous = empty($audits) ? HttpHeader::getAllHeaders()['Referer'] ?? '{/prefix}admin/account/settings?id={?id}#{\#}' : '{/prefix}admin/account/settings?{?}&audit=' . \reset($audits)->getId() . '&ptype=p#{\#}';
$next = empty($audits) ? HttpHeader::getAllHeaders()['Referer'] ?? '{/prefix}admin/account/settings?id={?id}#{\#}' : '{/prefix}admin/account/settings?{?}&audit=' . \end($audits)->getId() . '&ptype=n#{\#}';
@ -285,7 +285,7 @@ echo $this->getData('nav')->render(); ?>
<colgroup>
<col style="width: 100px">
<col style="width: 150px">
<col style="width: 75px">
<col style="width: 100px">
<col style="width: 75px">
<col>
<col>
@ -306,7 +306,7 @@ echo $this->getData('nav')->render(); ?>
<td ><?= $this->getHtml('Date', 'Auditor') ?>
<tbody>
<?php $count = 0; foreach ($audits as $key => $audit) : ++$count;
$url = \phpOMS\Uri\UriFactory::build('{/prefix}admin/audit/single?{?}&id=' . $audit->getId()); ?>
$url = UriFactory::build('{/prefix}admin/audit/single?{?}&id=' . $audit->getId()); ?>
<tr tabindex="0" data-href="<?= $url; ?>">
<td><?= $audit->getId(); ?>
<td><?= $this->printHtml($audit->getModule()); ?>

View File

@ -16,6 +16,7 @@ use phpOMS\Account\PermissionType;
use phpOMS\Account\GroupStatus;
use phpOMS\Account\PermissionOwner;
use phpOMS\Uri\UriFactory;
use phpOMS\Message\Http\HttpHeader;
/**
* @todo Orange-Management/Modules#122
@ -49,6 +50,10 @@ use phpOMS\Uri\UriFactory;
$group = $this->getData('group');
$permissions = $this->getData('permissions');
$accounts = $group->getAccounts();
$audits = $this->getData('auditlogs') ?? [];
$previous = empty($audits) ? HttpHeader::getAllHeaders()['Referer'] ?? '{/prefix}admin/group/settings?id={?id}#{\#}' : '{/prefix}admin/group/settings?{?}&audit=' . \reset($audits)->getId() . '&ptype=p#{\#}';
$next = empty($audits) ? HttpHeader::getAllHeaders()['Referer'] ?? '{/prefix}admin/group/settings?id={?id}#{\#}' : '{/prefix}admin/group/settings?{?}&audit=' . \end($audits)->getId() . '&ptype=n#{\#}';
echo $this->getData('nav')->render(); ?>
@ -251,24 +256,52 @@ echo $this->getData('nav')->render(); ?>
<div class="row">
<div class="col-xs-12">
<div class="portlet">
<div class="portlet-head"><?= $this->getHtml('AuditLog') ?><i class="fa fa-download floatRight download btn"></i></div>
<table class="default">
<div class="portlet-head"><?= $this->getHtml('Audits', 'Auditor') ?><i class="fa fa-download floatRight download btn"></i></div>
<table class="default fixed">
<colgroup>
<col style="width: 100px">
<col style="width: 150px">
<col style="width: 100px">
<col style="width: 75px">
<col>
<col>
<col>
<col style="width: 125px">
<col style="width: 150px">
</colgroup>
<thead>
<tr>
<td><?= $this->getHtml('ID', '0', '0'); ?>
<td class="wf-100">Name
<tr>
<td><?= $this->getHtml('ID', '0', '0'); ?>
<td ><?= $this->getHtml('Module', 'Auditor') ?>
<td ><?= $this->getHtml('Type', 'Auditor') ?>
<td ><?= $this->getHtml('Subtype', 'Auditor') ?>
<td ><?= $this->getHtml('Old', 'Auditor') ?>
<td ><?= $this->getHtml('New', 'Auditor') ?>
<td ><?= $this->getHtml('Content', 'Auditor') ?>
<td ><?= $this->getHtml('By', 'Auditor') ?>
<td ><?= $this->getHtml('Date', 'Auditor') ?>
<tbody>
<?php $c = 0; foreach ([] as $key => $value) : ++$c; ?>
<tr>
<td><a href="#"><i class="fa fa-times"></i></a>
<td>
<td>
<?php endforeach; ?>
<?php if ($c === 0) : ?>
<tr><td colspan="2" class="empty"><?= $this->getHtml('Empty', '0', '0'); ?>
<?php endif; ?>
<?php $count = 0; foreach ($audits as $key => $audit) : ++$count;
$url = UriFactory::build('{/prefix}admin/audit/single?{?}&id=' . $audit->getId()); ?>
<tr tabindex="0" data-href="<?= $url; ?>">
<td><?= $audit->getId(); ?>
<td><?= $this->printHtml($audit->getModule()); ?>
<td><?= $audit->getType(); ?>
<td><?= $audit->getSubtype(); ?>
<td><?= $this->printHtml($audit->getOld()); ?>
<td><?= $this->printHtml($audit->getNew()); ?>
<td><?= $this->printHtml($audit->getContent()); ?>
<td><?= $this->printHtml($audit->getCreatedBy()->getName()); ?>
<td><?= $audit->getCreatedAt()->format('Y-m-d H:i'); ?>
<?php endforeach; ?>
<?php if ($count === 0) : ?>
<tr><td colspan="9" class="empty"><?= $this->getHtml('Empty', '0', '0'); ?>
<?php endif; ?>
</table>
<div class="portlet-foot"></div>
<div class="portlet-foot">
<a tabindex="0" class="button" href="<?= UriFactory::build($previous); ?>"><?= $this->getHtml('Previous', '0', '0'); ?></a>
<a tabindex="0" class="button" href="<?= UriFactory::build($next); ?>"><?= $this->getHtml('Next', '0', '0'); ?></a>
</div>
</div>
</div>
</div>

View File

@ -12,8 +12,9 @@
*/
declare(strict_types=1);
use Modules\Admin\Models\ModuleStatusUpdateType;
use phpOMS\Message\Http\HttpHeader;
use phpOMS\Uri\UriFactory;
/**
* @var \phpOMS\Views\View $this
@ -22,107 +23,179 @@ $modules = $this->getData('modules');
$active = $this->getData('active');
$installed = $this->getData('installed');
$id = $this->getData('id');
$audits = $this->getData('auditlogs') ?? [];
$nav = $this->getData('nav');
$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#{\#}';
if ($nav !== null) {
echo $this->getData('nav')->render();
}
?>
<div class="tabview tab-2">
<div class="box wf-100 col-xs-12">
<ul class="tab-links">
<li><label for="c-tab-1"><?= $this->getHtml('General'); ?></label></li>
<li><label for="c-tab-2"><?= $this->getHtml('AuditLog'); ?></label></li>
</ul>
</div>
<div class="tab-content">
<input type="radio" id="c-tab-1" name="tabular-2"<?= $this->request->getUri()->getFragment() === 'c-tab-1' ? ' checked' : '' ?>>
<div class="tab">
<div class="row">
<div class="col-xs-12 col-md-4">
<div class="portlet">
<div class="portlet-head"><?= $this->printHtml($modules[$id]['name']['external']); ?></div>
<div class="row">
<div class="col-xs-12 col-md-4">
<div class="portlet">
<div class="portlet-head"><?= $this->printHtml($modules[$id]['name']['external']); ?></div>
<div class="portlet-body">
<table class="list wf-100">
<tbody>
<tr>
<td><?= $this->getHtml('Name'); ?>
<td><?= $this->printHtml($modules[$id]['name']['external']); ?>
<tr>
<td><?= $this->getHtml('Version'); ?>
<td><?= $this->printHtml($modules[$id]['version']); ?>
<tr>
<td><?= $this->getHtml('CreatedBy'); ?>
<td><?= $this->printHtml($modules[$id]['creator']['name']); ?>
<tr>
<td><?= $this->getHtml('Website'); ?>
<td><?= $this->printHtml($modules[$id]['creator']['website']); ?>
<tr>
<td><?= $this->getHtml('Description'); ?>
<td><?= $this->printHtml($modules[$id]['description']); ?>
</table>
</div>
<div class="portlet-foot">
<?php if (isset($active[$id])) : ?>
<form id="fModuleDeactivate" action="<?= \phpOMS\Uri\UriFactory::build('{/api}admin/module/status?module=' . $id); ?>" method="POST">
<button id="fModuleDeactivateButton" name="status" type="submit" value="<?= ModuleStatusUpdateType::DEACTIVATE ?>"><?= $this->getHtml('Deactivate'); ?></button>
</form>
<?php elseif (isset($installed[$id])) : ?>
<div class="ipt-wrap">
<div class="ipt-first">
<form id="fModuleUninstall" action="<?= \phpOMS\Uri\UriFactory::build('{/api}admin/module/status?module=' . $id); ?>" method="POST">
<button id="fModuleUninstallButton" name="status" type="submit" value="<?= ModuleStatusUpdateType::UNINSTALL ?>"><?= $this->getHtml('Uninstall'); ?></button>
</form>
<div class="portlet-body">
<table class="list wf-100">
<tbody>
<tr>
<td><?= $this->getHtml('Name'); ?>
<td><?= $this->printHtml($modules[$id]['name']['external']); ?>
<tr>
<td><?= $this->getHtml('Version'); ?>
<td><?= $this->printHtml($modules[$id]['version']); ?>
<tr>
<td><?= $this->getHtml('CreatedBy'); ?>
<td><?= $this->printHtml($modules[$id]['creator']['name']); ?>
<tr>
<td><?= $this->getHtml('Website'); ?>
<td><?= $this->printHtml($modules[$id]['creator']['website']); ?>
<tr>
<td><?= $this->getHtml('Description'); ?>
<td><?= $this->printHtml($modules[$id]['description']); ?>
</table>
</div>
<div class="ipt-second">
<form id="fModuleActivate" action="<?= \phpOMS\Uri\UriFactory::build('{/api}admin/module/status?module=' . $id); ?>" method="POST">
<button id="fModuleActivateButton" name="status" type="submit" value="<?= ModuleStatusUpdateType::ACTIVATE ?>"><?= $this->getHtml('Activate'); ?></button>
</form>
<div class="portlet-foot">
<?php if (isset($active[$id])) : ?>
<form id="fModuleDeactivate" action="<?= \phpOMS\Uri\UriFactory::build('{/api}admin/module/status?module=' . $id); ?>" method="POST">
<button id="fModuleDeactivateButton" name="status" type="submit" value="<?= ModuleStatusUpdateType::DEACTIVATE ?>"><?= $this->getHtml('Deactivate'); ?></button>
</form>
<?php elseif (isset($installed[$id])) : ?>
<div class="ipt-wrap">
<div class="ipt-first">
<form id="fModuleUninstall" action="<?= \phpOMS\Uri\UriFactory::build('{/api}admin/module/status?module=' . $id); ?>" method="POST">
<button id="fModuleUninstallButton" name="status" type="submit" value="<?= ModuleStatusUpdateType::UNINSTALL ?>"><?= $this->getHtml('Uninstall'); ?></button>
</form>
</div>
<div class="ipt-second">
<form id="fModuleActivate" action="<?= \phpOMS\Uri\UriFactory::build('{/api}admin/module/status?module=' . $id); ?>" method="POST">
<button id="fModuleActivateButton" name="status" type="submit" value="<?= ModuleStatusUpdateType::ACTIVATE ?>"><?= $this->getHtml('Activate'); ?></button>
</form>
</div>
</div>
<?php elseif (isset($modules[$id])) : ?>
<div class="ipt-wrap">
<div class="ipt-first">
<form id="fModuleInstall" action="<?= \phpOMS\Uri\UriFactory::build('{/api}admin/module/status?module=' . $id); ?>" method="POST">
<button id="fModuleInstallButton" name="status" type="submit" value="<?= ModuleStatusUpdateType::INSTALL ?>"><?= $this->getHtml('Install'); ?></button>
</form>
</div>
<div class="ipt-second">
<form id="fModuleDelete" action="<?= \phpOMS\Uri\UriFactory::build('{/api}admin/module/status?module=' . $id); ?>" method="POST">
<button id="fModuleDeleteButton" name="status" type="submit" value="<?= ModuleStatusUpdateType::DELETE ?>"><?= $this->getHtml('Delete'); ?></button>
</form>
</div>
</div>
<?php endif; ?>
</div>
</div>
<?php elseif (isset($modules[$id])) : ?>
<div class="ipt-wrap">
<div class="ipt-first">
<form id="fModuleInstall" action="<?= \phpOMS\Uri\UriFactory::build('{/api}admin/module/status?module=' . $id); ?>" method="POST">
<button id="fModuleInstallButton" name="status" type="submit" value="<?= ModuleStatusUpdateType::INSTALL ?>"><?= $this->getHtml('Install'); ?></button>
</form>
</div>
<div class="ipt-second">
<form id="fModuleDelete" action="<?= \phpOMS\Uri\UriFactory::build('{/api}admin/module/status?module=' . $id); ?>" method="POST">
<button id="fModuleDeleteButton" name="status" type="submit" value="<?= ModuleStatusUpdateType::DELETE ?>"><?= $this->getHtml('Delete'); ?></button>
</form>
</div>
<div class="col-xs-12 col-md-4">
<div class="portlet">
<div class="portlet-head"><?= $this->getHtml('Settings'); ?></div>
<div class="portlet-body">
</div>
</div>
<?php endif; ?>
</div>
<div class="col-xs-12 col-md-4">
<div class="portlet">
<table id="iModuleGroupList" class="default">
<caption><?= $this->getHtml('Permissions') ?><i class="fa fa-download floatRight download btn"></i></caption>
<thead>
<tr>
<td><?= $this->getHtml('ID', '0', '0'); ?><i class="sort-asc fa fa-chevron-up"></i><i class="sort-desc fa fa-chevron-down"></i>
<td>Type<i class="sort-asc fa fa-chevron-up"></i><i class="sort-desc fa fa-chevron-down"></i>
<td class="wf-100"><?= $this->getHtml('Name'); ?><i class="sort-asc fa fa-chevron-up"></i><i class="sort-desc fa fa-chevron-down"></i>
<tbody>
<?php $c = 0; $groupPermissions = $this->getData('groupPermissions');
foreach ($groupPermissions as $key => $value) : ++$c;
$url = \phpOMS\Uri\UriFactory::build('{/prefix}admin/group/settings?{?}&id=' . $value->getId()); ?>
<tr data-href="<?= $url; ?>">
<td><a href="<?= $url; ?>"><i class="fa fa-times"></i></a>
<td><a href="<?= $url; ?>">Group</a>
<td><a href="<?= $url; ?>"><?= $value->getName(); ?></a>
<?php endforeach; ?>
<?php if ($c === 0) : ?>
<tr><td colspan="3" class="empty"><?= $this->getHtml('Empty', '0', '0'); ?>
<?php endif; ?>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="col-xs-12 col-md-4">
<div class="portlet">
<div class="portlet-head"><?= $this->getHtml('Settings'); ?></div>
<div class="portlet-body">
<input type="radio" id="c-tab-2" name="tabular-2"<?= $this->request->getUri()->getFragment() === 'c-tab-2' ? ' checked' : '' ?>>
<div class="tab">
<div class="row">
<div class="col-xs-12">
<div class="portlet">
<div class="portlet-head"><?= $this->getHtml('Audits', 'Auditor') ?><i class="fa fa-download floatRight download btn"></i></div>
<table class="default fixed">
<colgroup>
<col style="width: 100px">
<col style="width: 150px">
<col style="width: 100px">
<col style="width: 75px">
<col>
<col>
<col>
<col style="width: 125px">
<col style="width: 150px">
</colgroup>
<thead>
<tr>
<td><?= $this->getHtml('ID', '0', '0'); ?>
<td ><?= $this->getHtml('Module', 'Auditor') ?>
<td ><?= $this->getHtml('Type', 'Auditor') ?>
<td ><?= $this->getHtml('Subtype', 'Auditor') ?>
<td ><?= $this->getHtml('Old', 'Auditor') ?>
<td ><?= $this->getHtml('New', 'Auditor') ?>
<td ><?= $this->getHtml('Content', 'Auditor') ?>
<td ><?= $this->getHtml('By', 'Auditor') ?>
<td ><?= $this->getHtml('Date', 'Auditor') ?>
<tbody>
<?php $count = 0; foreach ($audits as $key => $audit) : ++$count;
$url = UriFactory::build('{/prefix}admin/audit/single?{?}&id=' . $audit->getId()); ?>
<tr tabindex="0" data-href="<?= $url; ?>">
<td><?= $audit->getId(); ?>
<td><?= $this->printHtml($audit->getModule()); ?>
<td><?= $audit->getType(); ?>
<td><?= $audit->getSubtype(); ?>
<td><?= $this->printHtml($audit->getOld()); ?>
<td><?= $this->printHtml($audit->getNew()); ?>
<td><?= $this->printHtml($audit->getContent()); ?>
<td><?= $this->printHtml($audit->getCreatedBy()->getName()); ?>
<td><?= $audit->getCreatedAt()->format('Y-m-d H:i'); ?>
<?php endforeach; ?>
<?php if ($count === 0) : ?>
<tr><td colspan="9" class="empty"><?= $this->getHtml('Empty', '0', '0'); ?>
<?php endif; ?>
</table>
<div class="portlet-foot">
<a tabindex="0" class="button" href="<?= UriFactory::build($previous); ?>"><?= $this->getHtml('Previous', '0', '0'); ?></a>
<a tabindex="0" class="button" href="<?= UriFactory::build($next); ?>"><?= $this->getHtml('Next', '0', '0'); ?></a>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-xs-12 col-md-4">
<div class="portlet">
<table id="iModuleGroupList" class="default">
<caption><?= $this->getHtml('Permissions') ?><i class="fa fa-download floatRight download btn"></i></caption>
<thead>
<tr>
<td><?= $this->getHtml('ID', '0', '0'); ?><i class="sort-asc fa fa-chevron-up"></i><i class="sort-desc fa fa-chevron-down"></i>
<td>Type<i class="sort-asc fa fa-chevron-up"></i><i class="sort-desc fa fa-chevron-down"></i>
<td class="wf-100"><?= $this->getHtml('Name'); ?><i class="sort-asc fa fa-chevron-up"></i><i class="sort-desc fa fa-chevron-down"></i>
<tbody>
<?php $c = 0; $groupPermissions = $this->getData('groupPermissions');
foreach ($groupPermissions as $key => $value) : ++$c;
$url = \phpOMS\Uri\UriFactory::build('{/prefix}admin/group/settings?{?}&id=' . $value->getId()); ?>
<tr data-href="<?= $url; ?>">
<td><a href="<?= $url; ?>"><i class="fa fa-times"></i></a>
<td><a href="<?= $url; ?>">Group</a>
<td><a href="<?= $url; ?>"><?= $value->getName(); ?></a>
<?php endforeach; ?>
<?php if ($c === 0) : ?>
<tr><td colspan="3" class="empty"><?= $this->getHtml('Empty', '0', '0'); ?>
<?php endif; ?>
</table>
</div>
</div>
</div>