From a055f3b3eb71f607fe572c968a6c3d062c2987ab Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Tue, 29 Oct 2013 16:09:50 +0100 Subject: [PATCH] admin log --- .../Thelia/Config/Resources/routing/admin.xml | 4 + .../Controller/Admin/AdminLogsController.php | 31 +++ core/lib/Thelia/Model/AdminLogQuery.php | 38 +++- templates/admin/default/admin-logs.html | 190 ++++++++++-------- templates/admin/default/ajax/logger.html | 13 ++ .../default/assets/less/thelia/logger.less | 25 +++ .../default/assets/less/thelia/thelia.less | 9 + 7 files changed, 222 insertions(+), 88 deletions(-) create mode 100644 templates/admin/default/ajax/logger.html create mode 100644 templates/admin/default/assets/less/thelia/logger.less diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index d7df6e5fa..27bb58c72 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -830,6 +830,10 @@ Thelia\Controller\Admin\AdminLogsController::defaultAction + + Thelia\Controller\Admin\AdminLogsController::loadLoggerAjaxAction + + diff --git a/core/lib/Thelia/Controller/Admin/AdminLogsController.php b/core/lib/Thelia/Controller/Admin/AdminLogsController.php index e6e364d15..244baf747 100644 --- a/core/lib/Thelia/Controller/Admin/AdminLogsController.php +++ b/core/lib/Thelia/Controller/Admin/AdminLogsController.php @@ -24,6 +24,7 @@ namespace Thelia\Controller\Admin; use Thelia\Core\Security\AccessManager; +use Thelia\Model\AdminLogQuery; class AdminLogsController extends BaseAdminController { @@ -36,4 +37,34 @@ class AdminLogsController extends BaseAdminController // Render the edition template. return $this->render('admin-logs'); } + + public function loadLoggerAjaxAction() + { + $entries = array(); + foreach( AdminLogQuery::getEntries( + $this->getRequest()->request->get('admins', array()), + null, + null, + array_merge($this->getRequest()->request->get('resources', array()), $this->getRequest()->request->get('modules', array())) + ) as $entry) { + + $entries[] = array( + "head" => sprintf( + "[%s][%s][%s:%s]", + date('Y-m-d H:i:s', $entry->getCreatedAt()->getTimestamp()), + $entry->getAdminLogin(), + $entry->getResource(), + $entry->getAction() + ), + "data" => $entry->getMessage(), + ); + } + + return $this->render( + 'ajax/logger', + array( + 'entries' => $entries, + ) + ); + } } diff --git a/core/lib/Thelia/Model/AdminLogQuery.php b/core/lib/Thelia/Model/AdminLogQuery.php index 43a054bbb..8e9fb7eab 100755 --- a/core/lib/Thelia/Model/AdminLogQuery.php +++ b/core/lib/Thelia/Model/AdminLogQuery.php @@ -2,6 +2,7 @@ namespace Thelia\Model; +use Propel\Runtime\ActiveQuery\Criteria; use Thelia\Model\Base\AdminLogQuery as BaseAdminLogQuery; @@ -15,6 +16,41 @@ use Thelia\Model\Base\AdminLogQuery as BaseAdminLogQuery; * long as it does not already exist in the output directory. * */ -class AdminLogQuery extends BaseAdminLogQuery { +class AdminLogQuery extends BaseAdminLogQuery +{ + /** + * @param null $login + * @param \DateTime $maxDateTime + * @param \DateTime $minDateTime + * @param null $resources + * @param null $actions + * + * @return array|mixed|\Propel\Runtime\Collection\ObjectCollection + */ + public static function getEntries($login = null, \DateTime $maxDateTime = null, \DateTime $minDateTime = null, $resources = null, $actions = null) + { + $search = self::create(); + if(null !== $minDateTime) { + $search->filterByCreatedAt($minDateTime->getTimestamp(), Criteria::GREATER_EQUAL); + } + + if(null !== $maxDateTime) { + $search->filterByCreatedAt($maxDateTime->getTimestamp(), Criteria::LESS_EQUAL); + } + + if(null !== $resources) { + $search->filterByResource($resources); + } + + if(null !== $actions) { + $search->filterByAction($actions); + } + + if(null !== $login) { + $search->filterByAdminLogin($login); + } + + return $search->find(); + } } // AdminLogQuery diff --git a/templates/admin/default/admin-logs.html b/templates/admin/default/admin-logs.html index da9d5bf3e..5acb35667 100755 --- a/templates/admin/default/admin-logs.html +++ b/templates/admin/default/admin-logs.html @@ -13,7 +13,7 @@ {module_include location='admin_logs_top'} @@ -22,99 +22,84 @@
-
{intl l="Configuration variables"}
+
{intl l="Administration logs"}
- {form name="thelia.admin.mailing-system.update"} +
-
- -
-
- -
+
+
+
+
- {form_hidden_fields form=$form} +
+ Administrators : +
- {if $form_error}
{$form_error_message}
{/if} - - {form_field form=$form field='enabled'} -
- - - - -
- -
-
- {/form_field} - - {form_field form=$form field='host'} -
- - -
- {/form_field} - - {form_field form=$form field='port'} -
- - -
- {/form_field} - - {form_field form=$form field='encryption'} -
- - -
- {/form_field} - - {form_field form=$form field='username'} -
- - -
- {/form_field} - - {form_field form=$form field='password'} -
- - -
- {/form_field} - - {form_field form=$form field='authmode'} -
- - -
- {/form_field} - - {form_field form=$form field='timeout'} -
- - -
- {/form_field} - - {form_field form=$form field='sourceip'} -
- - -
- {/form_field} - -
-
- +
+ {loop type="admin" name="admin-list" backend_context="1"} + {if ($LOOP_COUNT-1)%4 == 0 AND $LOOP_COUNT != 0 AND $LOOP_COUNT != $LOOP_TOTAL}
+
+ {/if} +
+ +
+ {/loop} +
- +
- {/form} +
+
+ Resources : +
+ +
+ {loop type="resource" name="resources-list" backend_context="1"} + {if ($LOOP_COUNT-1)%4 == 0 AND $LOOP_COUNT != 0 AND $LOOP_COUNT != $LOOP_TOTAL} +
+
+ {/if} +
+ + +
+ {/loop} +
+ +
+ +
+
+ Modules : +
+ +
+ {loop type="module" name="modules-list" backend_context="1"} + {if ($LOOP_COUNT-1)%4 == 0 AND $LOOP_COUNT != 0 AND $LOOP_COUNT != $LOOP_TOTAL} +
+
+ {/if} +
+ + +
+ {/loop} +
+ +
+ +
+
+ +
+
+ +
+ +
@@ -134,8 +119,39 @@