From fdb4290ac8a88255d8dc1cac28bcf0cd333e5225 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 31 Jul 2020 00:04:25 +0200 Subject: [PATCH] improve audit logs --- Controller/BackendController.php | 31 ++++ Theme/Backend/accounts-single.tpl.php | 6 +- Theme/Backend/groups-single.tpl.php | 63 +++++-- Theme/Backend/modules-single.tpl.php | 243 +++++++++++++++++--------- 4 files changed, 240 insertions(+), 103 deletions(-) diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 878adb8..d52ebf7 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -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; } } diff --git a/Theme/Backend/accounts-single.tpl.php b/Theme/Backend/accounts-single.tpl.php index ea9e4c1..07e9fbb 100755 --- a/Theme/Backend/accounts-single.tpl.php +++ b/Theme/Backend/accounts-single.tpl.php @@ -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(); ?> - + @@ -306,7 +306,7 @@ echo $this->getData('nav')->render(); ?> getHtml('Date', 'Auditor') ?> $audit) : ++$count; - $url = \phpOMS\Uri\UriFactory::build('{/prefix}admin/audit/single?{?}&id=' . $audit->getId()); ?> + $url = UriFactory::build('{/prefix}admin/audit/single?{?}&id=' . $audit->getId()); ?> getId(); ?> printHtml($audit->getModule()); ?> diff --git a/Theme/Backend/groups-single.tpl.php b/Theme/Backend/groups-single.tpl.php index fede8e3..0f7d08b 100755 --- a/Theme/Backend/groups-single.tpl.php +++ b/Theme/Backend/groups-single.tpl.php @@ -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(); ?>
-
getHtml('AuditLog') ?>
- +
getHtml('Audits', 'Auditor') ?>
+
+ + + + + + + + + + + - - + - $value) : ++$c; ?> - - +
getHtml('ID', '0', '0'); ?> - Name +
getHtml('ID', '0', '0'); ?> + getHtml('Module', 'Auditor') ?> + getHtml('Type', 'Auditor') ?> + getHtml('Subtype', 'Auditor') ?> + getHtml('Old', 'Auditor') ?> + getHtml('New', 'Auditor') ?> + getHtml('Content', 'Auditor') ?> + getHtml('By', 'Auditor') ?> + getHtml('Date', 'Auditor') ?>
- - - - -
getHtml('Empty', '0', '0'); ?> - + $audit) : ++$count; + $url = UriFactory::build('{/prefix}admin/audit/single?{?}&id=' . $audit->getId()); ?> +
getId(); ?> + printHtml($audit->getModule()); ?> + getType(); ?> + getSubtype(); ?> + printHtml($audit->getOld()); ?> + printHtml($audit->getNew()); ?> + printHtml($audit->getContent()); ?> + printHtml($audit->getCreatedBy()->getName()); ?> + getCreatedAt()->format('Y-m-d H:i'); ?> + + +
getHtml('Empty', '0', '0'); ?> +
-
+
diff --git a/Theme/Backend/modules-single.tpl.php b/Theme/Backend/modules-single.tpl.php index 631365d..de9b83d 100755 --- a/Theme/Backend/modules-single.tpl.php +++ b/Theme/Backend/modules-single.tpl.php @@ -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(); } ?> +
+
+ +
+
+ request->getUri()->getFragment() === 'c-tab-1' ? ' checked' : '' ?>> +
+
+
+
+
printHtml($modules[$id]['name']['external']); ?>
-
-
-
-
printHtml($modules[$id]['name']['external']); ?>
- -
- - - - - - - -
getHtml('Name'); ?> - printHtml($modules[$id]['name']['external']); ?> -
getHtml('Version'); ?> - printHtml($modules[$id]['version']); ?> -
getHtml('CreatedBy'); ?> - printHtml($modules[$id]['creator']['name']); ?> -
getHtml('Website'); ?> - printHtml($modules[$id]['creator']['website']); ?> -
getHtml('Description'); ?> - printHtml($modules[$id]['description']); ?> -
-
-
- -
- -
- -
-
-
- -
+
+ + + + + + + +
getHtml('Name'); ?> + printHtml($modules[$id]['name']['external']); ?> +
getHtml('Version'); ?> + printHtml($modules[$id]['version']); ?> +
getHtml('CreatedBy'); ?> + printHtml($modules[$id]['creator']['name']); ?> +
getHtml('Website'); ?> + printHtml($modules[$id]['creator']['website']); ?> +
getHtml('Description'); ?> + printHtml($modules[$id]['description']); ?> +
-
-
- -
+
+ +
+ +
+ +
+
+
+ +
+
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+
+ +
+
+
+
- -
-
-
- -
-
-
-
- -
+
+ +
+
+
getHtml('Settings'); ?>
+ +
+
- +
+ +
+
+ + + + + + getData('groupPermissions'); + foreach ($groupPermissions as $key => $value) : ++$c; + $url = \phpOMS\Uri\UriFactory::build('{/prefix}admin/group/settings?{?}&id=' . $value->getId()); ?> + +
getHtml('Permissions') ?>
getHtml('ID', '0', '0'); ?> + Type + getHtml('Name'); ?> +
+ Group + getName(); ?> + + +
getHtml('Empty', '0', '0'); ?> + +
+
+
-
- -
-
-
getHtml('Settings'); ?>
- -
+ request->getUri()->getFragment() === 'c-tab-2' ? ' checked' : '' ?>> +
+
+
+
+
getHtml('Audits', 'Auditor') ?>
+ + + + + + + + + + + + + + + + $audit) : ++$count; + $url = UriFactory::build('{/prefix}admin/audit/single?{?}&id=' . $audit->getId()); ?> + +
getHtml('ID', '0', '0'); ?> + getHtml('Module', 'Auditor') ?> + getHtml('Type', 'Auditor') ?> + getHtml('Subtype', 'Auditor') ?> + getHtml('Old', 'Auditor') ?> + getHtml('New', 'Auditor') ?> + getHtml('Content', 'Auditor') ?> + getHtml('By', 'Auditor') ?> + getHtml('Date', 'Auditor') ?> +
getId(); ?> + printHtml($audit->getModule()); ?> + getType(); ?> + getSubtype(); ?> + printHtml($audit->getOld()); ?> + printHtml($audit->getNew()); ?> + printHtml($audit->getContent()); ?> + printHtml($audit->getCreatedBy()->getName()); ?> + getCreatedAt()->format('Y-m-d H:i'); ?> + + +
getHtml('Empty', '0', '0'); ?> + +
+ +
+
- -
-
- - - - - - getData('groupPermissions'); - foreach ($groupPermissions as $key => $value) : ++$c; - $url = \phpOMS\Uri\UriFactory::build('{/prefix}admin/group/settings?{?}&id=' . $value->getId()); ?> - -
getHtml('Permissions') ?>
getHtml('ID', '0', '0'); ?> - Type - getHtml('Name'); ?> -
- Group - getName(); ?> - - -
getHtml('Empty', '0', '0'); ?> - -
-
-