From 082f9aff8d419babc5ce95b2199dd99051ecfb1f Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Tue, 29 Oct 2013 12:22:34 +0100 Subject: [PATCH 01/17] admin logs --- core/lib/Thelia/Action/BaseAction.php | 18 +- core/lib/Thelia/Action/Document.php | 52 +- core/lib/Thelia/Action/Image.php | 52 +- .../Thelia/Config/Resources/routing/admin.xml | 8 + .../Admin/AbstractCrudController.php | 7 +- .../Controller/Admin/AddressController.php | 4 +- .../Controller/Admin/AdminLogsController.php | 39 + .../Controller/Admin/AreaController.php | 4 +- .../Controller/Admin/BaseAdminController.php | 10 +- .../Controller/Admin/CouponController.php | 2 + .../Controller/Admin/CustomerController.php | 2 +- .../Controller/Admin/FileController.php | 106 +- .../Controller/Admin/LangController.php | 6 +- .../Controller/Admin/ProductController.php | 2 +- .../Controller/Admin/ProfileController.php | 4 +- .../Controller/Admin/SessionController.php | 10 +- .../Controller/Admin/TaxRuleController.php | 2 +- core/lib/Thelia/Model/AdminLog.php | 24 +- core/lib/Thelia/Model/Base/AdminLog.php | 154 +- core/lib/Thelia/Model/Base/AdminLogQuery.php | 68 +- .../lib/Thelia/Model/Map/AdminLogTableMap.php | 46 +- core/lib/Thelia/Tools/FileManager.php | 28 - install/thelia.sql | 4 +- local/config/schema.xml | 2520 +++++++++-------- templates/admin/default/admin-logs.html | 143 + templates/admin/default/configuration.html | 10 +- templates/admin/default/mailing-system.html | 4 +- 27 files changed, 1838 insertions(+), 1491 deletions(-) create mode 100644 core/lib/Thelia/Controller/Admin/AdminLogsController.php create mode 100755 templates/admin/default/admin-logs.html diff --git a/core/lib/Thelia/Action/BaseAction.php b/core/lib/Thelia/Action/BaseAction.php index 33deddf2b..e1edab07d 100755 --- a/core/lib/Thelia/Action/BaseAction.php +++ b/core/lib/Thelia/Action/BaseAction.php @@ -52,8 +52,10 @@ class BaseAction /** * Changes object position, selecting absolute ou relative change. * - * @param $query the query to retrieve the object to move + * @param ModelCriteria $query * @param UpdatePositionEvent $event + * + * @return mixed */ protected function genericUpdatePosition(ModelCriteria $query, UpdatePositionEvent $event) { @@ -71,18 +73,4 @@ class BaseAction return $object->movePositionDown(); } } - - /** - * Helper to append a message to the admin log. - * - * @param string $message - */ - public function adminLogAppend($message) - { - AdminLog::append( - $message, - $this->container->get('request'), - $this->container->get('thelia.securityContext')->getAdminUser() - ); - } } diff --git a/core/lib/Thelia/Action/Document.php b/core/lib/Thelia/Action/Document.php index f048c208e..e38604733 100644 --- a/core/lib/Thelia/Action/Document.php +++ b/core/lib/Thelia/Action/Document.php @@ -143,18 +143,6 @@ class Document extends BaseCachedFile implements EventSubscriberInterface */ public function saveDocument(DocumentCreateOrUpdateEvent $event) { - $this->adminLogAppend( - $this->container->get('thelia.translator')->trans( - 'Saving documents for %parentName% parent id %parentId% (%parentType%)', - array( - '%parentName%' => $event->getParentName(), - '%parentId%' => $event->getParentId(), - '%parentType%' => $event->getDocumentType() - ), - 'document' - ) - ); - $fileManager = new FileManager($this->container); $model = $event->getModelDocument(); @@ -187,18 +175,6 @@ class Document extends BaseCachedFile implements EventSubscriberInterface */ public function updateDocument(DocumentCreateOrUpdateEvent $event) { - $this->adminLogAppend( - $this->container->get('thelia.translator')->trans( - 'Updating documents for %parentName% parent id %parentId% (%parentType%)', - array( - '%parentName%' => $event->getParentName(), - '%parentId%' => $event->getParentId(), - '%parentType%' => $event->getDocumentType() - ), - 'image' - ) - ); - if (null !== $event->getUploadedFile()) { $event->getModelDocument()->setTitle($event->getUploadedFile()->getClientOriginalName()); } @@ -231,33 +207,7 @@ class Document extends BaseCachedFile implements EventSubscriberInterface { $fileManager = new FileManager($this->container); - try { - $fileManager->deleteFile($event->getDocumentToDelete(), $event->getDocumentType(), FileManager::FILE_TYPE_DOCUMENTS); - - $this->adminLogAppend( - $this->container->get('thelia.translator')->trans( - 'Deleting document for %id% with parent id %parentId%', - array( - '%id%' => $event->getDocumentToDelete()->getId(), - '%parentId%' => $event->getDocumentToDelete()->getParentId(), - ), - 'document' - ) - ); - } catch (\Exception $e) { - $this->adminLogAppend( - $this->container->get('thelia.translator')->trans( - 'Fail to delete document for %id% with parent id %parentId% (Exception : %e%)', - array( - '%id%' => $event->getDocumentToDelete()->getId(), - '%parentId%' => $event->getDocumentToDelete()->getParentId(), - '%e%' => $e->getMessage() - ), - 'document' - ) - ); - throw $e; - } + $fileManager->deleteFile($event->getDocumentToDelete(), $event->getDocumentType(), FileManager::FILE_TYPE_DOCUMENTS); } public static function getSubscribedEvents() diff --git a/core/lib/Thelia/Action/Image.php b/core/lib/Thelia/Action/Image.php index 97d4bd095..ed7010a09 100755 --- a/core/lib/Thelia/Action/Image.php +++ b/core/lib/Thelia/Action/Image.php @@ -254,18 +254,6 @@ class Image extends BaseCachedFile implements EventSubscriberInterface */ public function saveImage(ImageCreateOrUpdateEvent $event) { - $this->adminLogAppend( - $this->container->get('thelia.translator')->trans( - 'Saving images for %parentName% parent id %parentId% (%parentType%)', - array( - '%parentName%' => $event->getParentName(), - '%parentId%' => $event->getParentId(), - '%parentType%' => $event->getImageType() - ), - 'image' - ) - ); - $fileManager = new FileManager($this->container); $model = $event->getModelImage(); @@ -297,18 +285,6 @@ class Image extends BaseCachedFile implements EventSubscriberInterface */ public function updateImage(ImageCreateOrUpdateEvent $event) { - $this->adminLogAppend( - $this->container->get('thelia.translator')->trans( - 'Updating images for %parentName% parent id %parentId% (%parentType%)', - array( - '%parentName%' => $event->getParentName(), - '%parentId%' => $event->getParentId(), - '%parentType%' => $event->getImageType() - ), - 'image' - ) - ); - $fileManager = new FileManager($this->container); // Copy and save file if ($event->getUploadedFile()) { @@ -337,33 +313,7 @@ class Image extends BaseCachedFile implements EventSubscriberInterface { $fileManager = new FileManager($this->container); - try { - $fileManager->deleteFile($event->getImageToDelete(), $event->getImageType(), FileManager::FILE_TYPE_IMAGES); - - $this->adminLogAppend( - $this->container->get('thelia.translator')->trans( - 'Deleting image for %id% with parent id %parentId%', - array( - '%id%' => $event->getImageToDelete()->getId(), - '%parentId%' => $event->getImageToDelete()->getParentId(), - ), - 'image' - ) - ); - } catch (\Exception $e) { - $this->adminLogAppend( - $this->container->get('thelia.translator')->trans( - 'Fail to delete image for %id% with parent id %parentId% (Exception : %e%)', - array( - '%id%' => $event->getImageToDelete()->getId(), - '%parentId%' => $event->getImageToDelete()->getParentId(), - '%e%' => $e->getMessage() - ), - 'image' - ) - ); - throw $e; - } + $fileManager->deleteFile($event->getImageToDelete(), $event->getImageType(), FileManager::FILE_TYPE_IMAGES); } /** diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 259c0f54a..d7df6e5fa 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -824,6 +824,14 @@ + + + + Thelia\Controller\Admin\AdminLogsController::defaultAction + + + + diff --git a/core/lib/Thelia/Controller/Admin/AbstractCrudController.php b/core/lib/Thelia/Controller/Admin/AbstractCrudController.php index e38e08a7a..46760eba9 100644 --- a/core/lib/Thelia/Controller/Admin/AbstractCrudController.php +++ b/core/lib/Thelia/Controller/Admin/AbstractCrudController.php @@ -303,7 +303,7 @@ abstract class AbstractCrudController extends BaseAdminController if (null !== $createdObject = $this->getObjectFromEvent($createEvent)) { // Log object creation - $this->adminLogAppend(sprintf("%s %s (ID %s) created", ucfirst($this->objectName), $this->getObjectLabel($createdObject), $this->getObjectId($createdObject))); + $this->adminLogAppend($this->resourceCode, AccessManager::CREATE, sprintf("%s %s (ID %s) created", ucfirst($this->objectName), $this->getObjectLabel($createdObject), $this->getObjectId($createdObject))); } $response = $this->performAdditionalCreateAction($createEvent); @@ -391,7 +391,7 @@ abstract class AbstractCrudController extends BaseAdminController // Log object modification if (null !== $changedObject = $this->getObjectFromEvent($changeEvent)) { - $this->adminLogAppend(sprintf("%s %s (ID %s) modified", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject))); + $this->adminLogAppend($this->resourceCode, AccessManager::UPDATE, sprintf("%s %s (ID %s) modified", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject))); } $response = $this->performAdditionalUpdateAction($changeEvent); @@ -530,7 +530,8 @@ abstract class AbstractCrudController extends BaseAdminController if (null !== $deletedObject = $this->getObjectFromEvent($deleteEvent)) { $this->adminLogAppend( - sprintf("%s %s (ID %s) deleted", ucfirst($this->objectName), $this->getObjectLabel($deletedObject), $this->getObjectId($deletedObject))); + $this->resourceCode, AccessManager::DELETE, + sprintf("%s %s (ID %s) deleted", ucfirst($this->objectName), $this->getObjectLabel($deletedObject), $this->getObjectId($deletedObject))); } $response = $this->performAdditionalDeleteAction($deleteEvent); diff --git a/core/lib/Thelia/Controller/Admin/AddressController.php b/core/lib/Thelia/Controller/Admin/AddressController.php index f934b3279..26f97c9b3 100644 --- a/core/lib/Thelia/Controller/Admin/AddressController.php +++ b/core/lib/Thelia/Controller/Admin/AddressController.php @@ -74,9 +74,9 @@ class AddressController extends AbstractCrudController $this->dispatch(TheliaEvents::ADDRESS_DEFAULT, $addressEvent); - $this->adminLogAppend(sprintf("address %d for customer %d removal", $address_id, $address->getCustomerId())); + $this->adminLogAppend($this->resourceCode, AccessManager::UPDATE, sprintf("address %d for customer %d set as default address", $address_id, $address->getCustomerId())); } catch (\Exception $e) { - \Thelia\Log\Tlog::getInstance()->error(sprintf("error during address removal with message %s", $e->getMessage())); + \Thelia\Log\Tlog::getInstance()->error(sprintf("error during address setting as default with message %s", $e->getMessage())); } $this->redirectToRoute('admin.customer.update.view', array(), array('customer_id' => $address->getCustomerId())); diff --git a/core/lib/Thelia/Controller/Admin/AdminLogsController.php b/core/lib/Thelia/Controller/Admin/AdminLogsController.php new file mode 100644 index 000000000..e6e364d15 --- /dev/null +++ b/core/lib/Thelia/Controller/Admin/AdminLogsController.php @@ -0,0 +1,39 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Controller\Admin; + +use Thelia\Core\Security\AccessManager; + +class AdminLogsController extends BaseAdminController +{ + const RESOURCE_CODE = "admin.admin-logs"; + + public function defaultAction() + { + if (null !== $response = $this->checkAuth(self::RESOURCE_CODE, AccessManager::VIEW)) return $response; + + // Render the edition template. + return $this->render('admin-logs'); + } +} diff --git a/core/lib/Thelia/Controller/Admin/AreaController.php b/core/lib/Thelia/Controller/Admin/AreaController.php index 4126ef741..79c549201 100644 --- a/core/lib/Thelia/Controller/Admin/AreaController.php +++ b/core/lib/Thelia/Controller/Admin/AreaController.php @@ -249,7 +249,7 @@ class AreaController extends AbstractCrudController // Log object modification if (null !== $changedObject = $this->getObjectFromEvent($event)) { - $this->adminLogAppend(sprintf("%s %s (ID %s) modified, new country added", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject))); + $this->adminLogAppend($this->resourceCode, AccessManager::UPDATE, sprintf("%s %s (ID %s) modified, new country added", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject))); } // Redirect to the success URL @@ -303,7 +303,7 @@ class AreaController extends AbstractCrudController // Log object modification if (null !== $changedObject = $this->getObjectFromEvent($event)) { - $this->adminLogAppend(sprintf("%s %s (ID %s) modified, country remove", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject))); + $this->adminLogAppend($this->resourceCode, AccessManager::UPDATE, sprintf("%s %s (ID %s) modified, country remove", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject))); } // Redirect to the success URL diff --git a/core/lib/Thelia/Controller/Admin/BaseAdminController.php b/core/lib/Thelia/Controller/Admin/BaseAdminController.php index e4d9550d3..ad8d46ba0 100755 --- a/core/lib/Thelia/Controller/Admin/BaseAdminController.php +++ b/core/lib/Thelia/Controller/Admin/BaseAdminController.php @@ -51,18 +51,20 @@ class BaseAdminController extends BaseController /** * Helper to append a message to the admin log. * + * @param string $resource + * @param string $action * @param string $message */ - public function adminLogAppend($message) + public function adminLogAppend($resource, $action, $message) { - AdminLog::append($message, $this->getRequest(), $this->getSecurityContext()->getAdminUser()); + AdminLog::append($resource, $action, $message, $this->getRequest(), $this->getSecurityContext()->getAdminUser()); } /** * This method process the rendering of view called from an admin page * * @param unknown $template - * @return Response the reponse which contains the rendered view + * @return Response the response which contains the rendered view */ public function processTemplateAction($template) { @@ -131,7 +133,7 @@ class BaseAdminController extends BaseController } // Log the problem - $this->adminLogAppend("User is not granted for resources %s with accesses %s", implode(", ", $resources), implode(", ", $accesses)); + $this->adminLogAppend(implode(",", $resources), implode(",", $accesses), "User is not granted for resources %s with accesses %s", implode(", ", $resources), implode(", ", $accesses)); // Generate the proper response $response = new Response(); diff --git a/core/lib/Thelia/Controller/Admin/CouponController.php b/core/lib/Thelia/Controller/Admin/CouponController.php index da0ec200a..5cc71ac00 100755 --- a/core/lib/Thelia/Controller/Admin/CouponController.php +++ b/core/lib/Thelia/Controller/Admin/CouponController.php @@ -356,6 +356,7 @@ class CouponController extends BaseAdminController ); $this->adminLogAppend( + AdminResources::COUPON, AccessManager::UPDATE, sprintf( 'Coupon %s (ID %s) conditions updated', $couponEvent->getCouponModel()->getTitle(), @@ -468,6 +469,7 @@ class CouponController extends BaseAdminController ); $this->adminLogAppend( + AdminResources::COUPON, AccessManager::UPDATE, sprintf( 'Coupon %s (ID ) ' . $log, $couponEvent->getTitle(), diff --git a/core/lib/Thelia/Controller/Admin/CustomerController.php b/core/lib/Thelia/Controller/Admin/CustomerController.php index df75333c8..2f946917a 100644 --- a/core/lib/Thelia/Controller/Admin/CustomerController.php +++ b/core/lib/Thelia/Controller/Admin/CustomerController.php @@ -85,7 +85,7 @@ class CustomerController extends BaseAdminController $customerUpdated = $event->getCustomer(); - $this->adminLogAppend(sprintf("Customer with Ref %s (ID %d) modified", $customerUpdated->getRef() , $customerUpdated->getId())); + $this->adminLogAppend(AdminResources::CUSTOMER, AccessManager::UPDATE, sprintf("Customer with Ref %s (ID %d) modified", $customerUpdated->getRef() , $customerUpdated->getId())); if ($this->getRequest()->get("save_mode") == "close") { $this->redirectToRoute("admin.customers"); diff --git a/core/lib/Thelia/Controller/Admin/FileController.php b/core/lib/Thelia/Controller/Admin/FileController.php index 3c2ad0ba9..38b8d74fb 100755 --- a/core/lib/Thelia/Controller/Admin/FileController.php +++ b/core/lib/Thelia/Controller/Admin/FileController.php @@ -130,6 +130,20 @@ class FileController extends BaseAdminController $imageCreateOrUpdateEvent ); + $this->adminLogAppend( + AdminResources::retrieve($parentType), + AccessManager::UPDATE, + $this->container->get('thelia.translator')->trans( + 'Saving images for %parentName% parent id %parentId% (%parentType%)', + array( + '%parentName%' => $event->getParentName(), + '%parentId%' => $event->getParentId(), + '%parentType%' => $event->getImageType() + ), + 'image' + ) + ); + return new ResponseRest(array('status' => true, 'message' => '')); } } @@ -194,6 +208,20 @@ class FileController extends BaseAdminController $documentCreateOrUpdateEvent ); + $this->adminLogAppend( + AdminResources::retrieve($parentType), + AccessManager::UPDATE, + $this->container->get('thelia.translator')->trans( + 'Saving documents for %parentName% parent id %parentId% (%parentType%)', + array( + '%parentName%' => $event->getParentName(), + '%parentId%' => $event->getParentId(), + '%parentType%' => $event->getDocumentType() + ), + 'document' + ) + ); + return new ResponseRest(array('status' => true, 'message' => '')); } } @@ -368,7 +396,7 @@ class FileController extends BaseAdminController $imageUpdated = $event->getModelImage(); - $this->adminLogAppend(sprintf('Image with Ref %s (ID %d) modified', $imageUpdated->getTitle(), $imageUpdated->getId())); + $this->adminLogAppend(AdminResources::retrieve($parentType), AccessManager::UPDATE, sprintf('Image with Ref %s (ID %d) modified', $imageUpdated->getTitle(), $imageUpdated->getId())); if ($this->getRequest()->get('save_mode') == 'close') { $this->redirectToRoute('admin.images'); @@ -445,7 +473,7 @@ class FileController extends BaseAdminController $documentUpdated = $event->getModelDocument(); - $this->adminLogAppend(sprintf('Document with Ref %s (ID %d) modified', $documentUpdated->getTitle(), $documentUpdated->getId())); + $this->adminLogAppend(AdminResources::retrieve($parentType), AccessManager::UPDATE, sprintf('Document with Ref %s (ID %d) modified', $documentUpdated->getTitle(), $documentUpdated->getId())); if ($this->getRequest()->get('save_mode') == 'close') { $this->redirectToRoute('admin.documents'); @@ -509,10 +537,39 @@ class FileController extends BaseAdminController ); // Dispatch Event to the Action - $this->dispatch( - TheliaEvents::IMAGE_DELETE, - $imageDeleteEvent - ); + try { + $this->dispatch( + TheliaEvents::IMAGE_DELETE, + $imageDeleteEvent + ); + + $this->adminLogAppend( + AdminResources::retrieve($parentType), + AccessManager::UPDATE, + $this->container->get('thelia.translator')->trans( + 'Deleting image for %id% with parent id %parentId%', + array( + '%id%' => $event->getDocumentToDelete()->getId(), + '%parentId%' => $event->getDocumentToDelete()->getParentId(), + ), + 'image' + ) + ); + } catch (\Exception $e) { + $this->adminLogAppend( + AdminResources::retrieve($parentType), + AccessManager::UPDATE, + $this->container->get('thelia.translator')->trans( + 'Fail to delete image for %id% with parent id %parentId% (Exception : %e%)', + array( + '%id%' => $event->getDocumentToDelete()->getId(), + '%parentId%' => $event->getDocumentToDelete()->getParentId(), + '%e%' => $e->getMessage() + ), + 'image' + ) + ); + } $message = $this->getTranslator() ->trans( @@ -552,10 +609,39 @@ class FileController extends BaseAdminController ); // Dispatch Event to the Action - $this->dispatch( - TheliaEvents::DOCUMENT_DELETE, - $documentDeleteEvent - ); + try { + $this->dispatch( + TheliaEvents::DOCUMENT_DELETE, + $documentDeleteEvent + ); + + $this->adminLogAppend( + AdminResources::retrieve($parentType), + AccessManager::UPDATE, + $this->container->get('thelia.translator')->trans( + 'Deleting document for %id% with parent id %parentId%', + array( + '%id%' => $event->getDocumentToDelete()->getId(), + '%parentId%' => $event->getDocumentToDelete()->getParentId(), + ), + 'document' + ) + ); + } catch (\Exception $e) { + $this->adminLogAppend( + AdminResources::retrieve($parentType), + AccessManager::UPDATE, + $this->container->get('thelia.translator')->trans( + 'Fail to delete document for %id% with parent id %parentId% (Exception : %e%)', + array( + '%id%' => $event->getDocumentToDelete()->getId(), + '%parentId%' => $event->getDocumentToDelete()->getParentId(), + '%e%' => $e->getMessage() + ), + 'document' + ) + ); + } $message = $this->getTranslator() ->trans( diff --git a/core/lib/Thelia/Controller/Admin/LangController.php b/core/lib/Thelia/Controller/Admin/LangController.php index 8e0ca5d1c..7c9eefad5 100644 --- a/core/lib/Thelia/Controller/Admin/LangController.php +++ b/core/lib/Thelia/Controller/Admin/LangController.php @@ -116,7 +116,7 @@ class LangController extends BaseAdminController } $changedObject = $event->getLang(); - $this->adminLogAppend(sprintf("%s %s (ID %s) modified", 'Lang', $changedObject->getTitle(), $changedObject->getId())); + $this->adminLogAppend(AdminResources::LANGUAGE, AccessManager::UPDATE, sprintf("%s %s (ID %s) modified", 'Lang', $changedObject->getTitle(), $changedObject->getId())); $this->redirectToRoute('/admin/configuration/languages'); } catch (\Exception $e) { $error_msg = $e->getMessage(); @@ -153,7 +153,7 @@ class LangController extends BaseAdminController } $changedObject = $event->getLang(); - $this->adminLogAppend(sprintf("%s %s (ID %s) modified", 'Lang', $changedObject->getTitle(), $changedObject->getId())); + $this->adminLogAppend(AdminResources::LANGUAGE, AccessManager::UPDATE, sprintf("%s %s (ID %s) modified", 'Lang', $changedObject->getTitle(), $changedObject->getId())); } catch (\Exception $e) { \Thelia\Log\Tlog::getInstance()->error(sprintf("Error on changing default languages with message : %s", $e->getMessage())); @@ -189,7 +189,7 @@ class LangController extends BaseAdminController } $createdObject = $createEvent->getLang(); - $this->adminLogAppend(sprintf("%s %s (ID %s) created", 'Lang', $createdObject->getTitle(), $createdObject->getId())); + $this->adminLogAppend(AdminResources::LANGUAGE, AccessManager::CREATE, sprintf("%s %s (ID %s) created", 'Lang', $createdObject->getTitle(), $createdObject->getId())); $this->redirectToRoute('admin.configuration.languages'); diff --git a/core/lib/Thelia/Controller/Admin/ProductController.php b/core/lib/Thelia/Controller/Admin/ProductController.php index 84e16815d..88baf75f7 100644 --- a/core/lib/Thelia/Controller/Admin/ProductController.php +++ b/core/lib/Thelia/Controller/Admin/ProductController.php @@ -931,7 +931,7 @@ class ProductController extends AbstractCrudController // Log object modification if (null !== $changedObject = $event->getProductSaleElement()) { - $this->adminLogAppend(sprintf("Product Sale Element (ID %s) for product reference %s modified", $changedObject->getId(), $event->getProduct()->getRef())); + $this->adminLogAppend($this->resourceCode, AccessManager::UPDATE, sprintf("Product Sale Element (ID %s) for product reference %s modified", $changedObject->getId(), $event->getProduct()->getRef())); } } diff --git a/core/lib/Thelia/Controller/Admin/ProfileController.php b/core/lib/Thelia/Controller/Admin/ProfileController.php index 9db4e9315..909d055b8 100644 --- a/core/lib/Thelia/Controller/Admin/ProfileController.php +++ b/core/lib/Thelia/Controller/Admin/ProfileController.php @@ -330,7 +330,7 @@ class ProfileController extends AbstractCrudController // Log object modification if (null !== $changedObject = $this->getObjectFromEvent($changeEvent)) { - $this->adminLogAppend(sprintf("%s %s (ID %s) modified", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject))); + $this->adminLogAppend($this->resourceCode, AccessManager::UPDATE, sprintf("%s %s (ID %s) modified", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject))); } if ($response == null) { @@ -379,7 +379,7 @@ class ProfileController extends AbstractCrudController // Log object modification if (null !== $changedObject = $this->getObjectFromEvent($changeEvent)) { - $this->adminLogAppend(sprintf("%s %s (ID %s) modified", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject))); + $this->adminLogAppend($this->resourceCode, AccessManager::UPDATE, sprintf("%s %s (ID %s) modified", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject))); } if ($response == null) { diff --git a/core/lib/Thelia/Controller/Admin/SessionController.php b/core/lib/Thelia/Controller/Admin/SessionController.php index 6d8d14416..0f6f1a105 100755 --- a/core/lib/Thelia/Controller/Admin/SessionController.php +++ b/core/lib/Thelia/Controller/Admin/SessionController.php @@ -50,7 +50,7 @@ class SessionController extends BaseAdminController $this->getSecurityContext()->setAdminUser($user); - $this->adminLogAppend("Successful token authentication"); + $this->adminLogAppend("admin", "LOGIN", "Successful token authentication"); // Update the cookie $cookie = $this->createAdminRememberMeCookie($user); @@ -58,7 +58,7 @@ class SessionController extends BaseAdminController // Render the home page return $this->render("home"); } catch (TokenAuthenticationException $ex) { - $this->adminLogAppend("Token based authentication failed."); + $this->adminLogAppend("admin", "LOGIN", "Token based authentication failed."); // Clear the cookie $this->clearRememberMeCookie(); @@ -99,7 +99,7 @@ class SessionController extends BaseAdminController $this->getSecurityContext()->setAdminUser($user); // Log authentication success - AdminLog::append("Authentication successful", $request, $user); + AdminLog::append("admin", "LOGIN", "Authentication successful", $request, $user); /** * FIXME: we have tou find a way to send cookie @@ -122,13 +122,13 @@ class SessionController extends BaseAdminController } catch (AuthenticationException $ex) { // Log authentication failure - AdminLog::append(sprintf("Authentication failure for username '%s'", $authenticator->getUsername()), $request); + AdminLog::append("admin", "LOGIN", sprintf("Authentication failure for username '%s'", $authenticator->getUsername()), $request); $message = $this->getTranslator()->trans("Login failed. Please check your username and password."); } catch (\Exception $ex) { // Log authentication failure - AdminLog::append(sprintf("Undefined error: %s", $ex->getMessage()), $request); + AdminLog::append("admin", "LOGIN", sprintf("Undefined error: %s", $ex->getMessage()), $request); $message = $this->getTranslator()->trans( "Unable to process your request. Please try again (%err).", diff --git a/core/lib/Thelia/Controller/Admin/TaxRuleController.php b/core/lib/Thelia/Controller/Admin/TaxRuleController.php index db3eca4b4..2e6cb2b70 100644 --- a/core/lib/Thelia/Controller/Admin/TaxRuleController.php +++ b/core/lib/Thelia/Controller/Admin/TaxRuleController.php @@ -279,7 +279,7 @@ class TaxRuleController extends AbstractCrudController // Log object modification if (null !== $changedObject = $this->getObjectFromEvent($changeEvent)) { - $this->adminLogAppend(sprintf("%s %s (ID %s) modified", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject))); + $this->adminLogAppend($this->resourceCode, AccessManager::UPDATE, sprintf("%s %s (ID %s) modified", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject))); } if ($response == null) { diff --git a/core/lib/Thelia/Model/AdminLog.php b/core/lib/Thelia/Model/AdminLog.php index e5720fb35..018fa00d3 100755 --- a/core/lib/Thelia/Model/AdminLog.php +++ b/core/lib/Thelia/Model/AdminLog.php @@ -7,16 +7,18 @@ use Thelia\Core\HttpFoundation\Request; use Thelia\Log\Tlog; use Thelia\Model\Base\Admin as BaseAdminUser; -class AdminLog extends BaseAdminLog { - - /** - * A sdimple helper to insert an entry in the admin log +class AdminLog extends BaseAdminLog +{ + /** + * A simple helper to insert an entry in the admin log * - * @param unknown $actionLabel - * @param Request $request - * @param Admin $adminUser - */ - public static function append($actionLabel, Request $request, BaseAdminUser $adminUser = null) { + * @param $resource + * @param $action + * @param $message + * @param Request $request + * @param Base\Admin $adminUser + */ + public static function append($resource, $action, $message, Request $request, BaseAdminUser $adminUser = null) { $log = new AdminLog(); @@ -24,7 +26,9 @@ class AdminLog extends BaseAdminLog { ->setAdminLogin($adminUser !== null ? $adminUser->getLogin() : '') ->setAdminFirstname($adminUser !== null ? $adminUser->getFirstname() : '') ->setAdminLastname($adminUser !== null ? $adminUser->getLastname() : '') - ->setAction($actionLabel) + ->setResource($resource) + ->setAction($action) + ->setMessage($message) ->setRequest($request->__toString()) ; diff --git a/core/lib/Thelia/Model/Base/AdminLog.php b/core/lib/Thelia/Model/Base/AdminLog.php index dfce950eb..abebb7cd9 100644 --- a/core/lib/Thelia/Model/Base/AdminLog.php +++ b/core/lib/Thelia/Model/Base/AdminLog.php @@ -78,12 +78,24 @@ abstract class AdminLog implements ActiveRecordInterface */ protected $admin_lastname; + /** + * The value for the resource field. + * @var string + */ + protected $resource; + /** * The value for the action field. * @var string */ protected $action; + /** + * The value for the message field. + * @var string + */ + protected $message; + /** * The value for the request field. * @var string @@ -412,6 +424,17 @@ abstract class AdminLog implements ActiveRecordInterface return $this->admin_lastname; } + /** + * Get the [resource] column value. + * + * @return string + */ + public function getResource() + { + + return $this->resource; + } + /** * Get the [action] column value. * @@ -423,6 +446,17 @@ abstract class AdminLog implements ActiveRecordInterface return $this->action; } + /** + * Get the [message] column value. + * + * @return string + */ + public function getMessage() + { + + return $this->message; + } + /** * Get the [request] column value. * @@ -558,6 +592,27 @@ abstract class AdminLog implements ActiveRecordInterface return $this; } // setAdminLastname() + /** + * Set the value of [resource] column. + * + * @param string $v new value + * @return \Thelia\Model\AdminLog The current object (for fluent API support) + */ + public function setResource($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->resource !== $v) { + $this->resource = $v; + $this->modifiedColumns[] = AdminLogTableMap::RESOURCE; + } + + + return $this; + } // setResource() + /** * Set the value of [action] column. * @@ -579,6 +634,27 @@ abstract class AdminLog implements ActiveRecordInterface return $this; } // setAction() + /** + * Set the value of [message] column. + * + * @param string $v new value + * @return \Thelia\Model\AdminLog The current object (for fluent API support) + */ + public function setMessage($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->message !== $v) { + $this->message = $v; + $this->modifiedColumns[] = AdminLogTableMap::MESSAGE; + } + + + return $this; + } // setMessage() + /** * Set the value of [request] column. * @@ -691,19 +767,25 @@ abstract class AdminLog implements ActiveRecordInterface $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : AdminLogTableMap::translateFieldName('AdminLastname', TableMap::TYPE_PHPNAME, $indexType)]; $this->admin_lastname = (null !== $col) ? (string) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : AdminLogTableMap::translateFieldName('Action', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : AdminLogTableMap::translateFieldName('Resource', TableMap::TYPE_PHPNAME, $indexType)]; + $this->resource = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : AdminLogTableMap::translateFieldName('Action', TableMap::TYPE_PHPNAME, $indexType)]; $this->action = (null !== $col) ? (string) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : AdminLogTableMap::translateFieldName('Request', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : AdminLogTableMap::translateFieldName('Message', TableMap::TYPE_PHPNAME, $indexType)]; + $this->message = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : AdminLogTableMap::translateFieldName('Request', TableMap::TYPE_PHPNAME, $indexType)]; $this->request = (null !== $col) ? (string) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : AdminLogTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : AdminLogTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } $this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : AdminLogTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 9 + $startcol : AdminLogTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } @@ -716,7 +798,7 @@ abstract class AdminLog implements ActiveRecordInterface $this->ensureConsistency(); } - return $startcol + 8; // 8 = AdminLogTableMap::NUM_HYDRATE_COLUMNS. + return $startcol + 10; // 10 = AdminLogTableMap::NUM_HYDRATE_COLUMNS. } catch (Exception $e) { throw new PropelException("Error populating \Thelia\Model\AdminLog object", 0, $e); @@ -948,9 +1030,15 @@ abstract class AdminLog implements ActiveRecordInterface if ($this->isColumnModified(AdminLogTableMap::ADMIN_LASTNAME)) { $modifiedColumns[':p' . $index++] = 'ADMIN_LASTNAME'; } + if ($this->isColumnModified(AdminLogTableMap::RESOURCE)) { + $modifiedColumns[':p' . $index++] = 'RESOURCE'; + } if ($this->isColumnModified(AdminLogTableMap::ACTION)) { $modifiedColumns[':p' . $index++] = 'ACTION'; } + if ($this->isColumnModified(AdminLogTableMap::MESSAGE)) { + $modifiedColumns[':p' . $index++] = 'MESSAGE'; + } if ($this->isColumnModified(AdminLogTableMap::REQUEST)) { $modifiedColumns[':p' . $index++] = 'REQUEST'; } @@ -983,9 +1071,15 @@ abstract class AdminLog implements ActiveRecordInterface case 'ADMIN_LASTNAME': $stmt->bindValue($identifier, $this->admin_lastname, PDO::PARAM_STR); break; + case 'RESOURCE': + $stmt->bindValue($identifier, $this->resource, PDO::PARAM_STR); + break; case 'ACTION': $stmt->bindValue($identifier, $this->action, PDO::PARAM_STR); break; + case 'MESSAGE': + $stmt->bindValue($identifier, $this->message, PDO::PARAM_STR); + break; case 'REQUEST': $stmt->bindValue($identifier, $this->request, PDO::PARAM_STR); break; @@ -1070,15 +1164,21 @@ abstract class AdminLog implements ActiveRecordInterface return $this->getAdminLastname(); break; case 4: - return $this->getAction(); + return $this->getResource(); break; case 5: - return $this->getRequest(); + return $this->getAction(); break; case 6: - return $this->getCreatedAt(); + return $this->getMessage(); break; case 7: + return $this->getRequest(); + break; + case 8: + return $this->getCreatedAt(); + break; + case 9: return $this->getUpdatedAt(); break; default: @@ -1113,10 +1213,12 @@ abstract class AdminLog implements ActiveRecordInterface $keys[1] => $this->getAdminLogin(), $keys[2] => $this->getAdminFirstname(), $keys[3] => $this->getAdminLastname(), - $keys[4] => $this->getAction(), - $keys[5] => $this->getRequest(), - $keys[6] => $this->getCreatedAt(), - $keys[7] => $this->getUpdatedAt(), + $keys[4] => $this->getResource(), + $keys[5] => $this->getAction(), + $keys[6] => $this->getMessage(), + $keys[7] => $this->getRequest(), + $keys[8] => $this->getCreatedAt(), + $keys[9] => $this->getUpdatedAt(), ); $virtualColumns = $this->virtualColumns; foreach ($virtualColumns as $key => $virtualColumn) { @@ -1169,15 +1271,21 @@ abstract class AdminLog implements ActiveRecordInterface $this->setAdminLastname($value); break; case 4: - $this->setAction($value); + $this->setResource($value); break; case 5: - $this->setRequest($value); + $this->setAction($value); break; case 6: - $this->setCreatedAt($value); + $this->setMessage($value); break; case 7: + $this->setRequest($value); + break; + case 8: + $this->setCreatedAt($value); + break; + case 9: $this->setUpdatedAt($value); break; } // switch() @@ -1208,10 +1316,12 @@ abstract class AdminLog implements ActiveRecordInterface if (array_key_exists($keys[1], $arr)) $this->setAdminLogin($arr[$keys[1]]); if (array_key_exists($keys[2], $arr)) $this->setAdminFirstname($arr[$keys[2]]); if (array_key_exists($keys[3], $arr)) $this->setAdminLastname($arr[$keys[3]]); - if (array_key_exists($keys[4], $arr)) $this->setAction($arr[$keys[4]]); - if (array_key_exists($keys[5], $arr)) $this->setRequest($arr[$keys[5]]); - if (array_key_exists($keys[6], $arr)) $this->setCreatedAt($arr[$keys[6]]); - if (array_key_exists($keys[7], $arr)) $this->setUpdatedAt($arr[$keys[7]]); + if (array_key_exists($keys[4], $arr)) $this->setResource($arr[$keys[4]]); + if (array_key_exists($keys[5], $arr)) $this->setAction($arr[$keys[5]]); + if (array_key_exists($keys[6], $arr)) $this->setMessage($arr[$keys[6]]); + if (array_key_exists($keys[7], $arr)) $this->setRequest($arr[$keys[7]]); + if (array_key_exists($keys[8], $arr)) $this->setCreatedAt($arr[$keys[8]]); + if (array_key_exists($keys[9], $arr)) $this->setUpdatedAt($arr[$keys[9]]); } /** @@ -1227,7 +1337,9 @@ abstract class AdminLog implements ActiveRecordInterface if ($this->isColumnModified(AdminLogTableMap::ADMIN_LOGIN)) $criteria->add(AdminLogTableMap::ADMIN_LOGIN, $this->admin_login); if ($this->isColumnModified(AdminLogTableMap::ADMIN_FIRSTNAME)) $criteria->add(AdminLogTableMap::ADMIN_FIRSTNAME, $this->admin_firstname); if ($this->isColumnModified(AdminLogTableMap::ADMIN_LASTNAME)) $criteria->add(AdminLogTableMap::ADMIN_LASTNAME, $this->admin_lastname); + if ($this->isColumnModified(AdminLogTableMap::RESOURCE)) $criteria->add(AdminLogTableMap::RESOURCE, $this->resource); if ($this->isColumnModified(AdminLogTableMap::ACTION)) $criteria->add(AdminLogTableMap::ACTION, $this->action); + if ($this->isColumnModified(AdminLogTableMap::MESSAGE)) $criteria->add(AdminLogTableMap::MESSAGE, $this->message); if ($this->isColumnModified(AdminLogTableMap::REQUEST)) $criteria->add(AdminLogTableMap::REQUEST, $this->request); if ($this->isColumnModified(AdminLogTableMap::CREATED_AT)) $criteria->add(AdminLogTableMap::CREATED_AT, $this->created_at); if ($this->isColumnModified(AdminLogTableMap::UPDATED_AT)) $criteria->add(AdminLogTableMap::UPDATED_AT, $this->updated_at); @@ -1297,7 +1409,9 @@ abstract class AdminLog implements ActiveRecordInterface $copyObj->setAdminLogin($this->getAdminLogin()); $copyObj->setAdminFirstname($this->getAdminFirstname()); $copyObj->setAdminLastname($this->getAdminLastname()); + $copyObj->setResource($this->getResource()); $copyObj->setAction($this->getAction()); + $copyObj->setMessage($this->getMessage()); $copyObj->setRequest($this->getRequest()); $copyObj->setCreatedAt($this->getCreatedAt()); $copyObj->setUpdatedAt($this->getUpdatedAt()); @@ -1338,7 +1452,9 @@ abstract class AdminLog implements ActiveRecordInterface $this->admin_login = null; $this->admin_firstname = null; $this->admin_lastname = null; + $this->resource = null; $this->action = null; + $this->message = null; $this->request = null; $this->created_at = null; $this->updated_at = null; diff --git a/core/lib/Thelia/Model/Base/AdminLogQuery.php b/core/lib/Thelia/Model/Base/AdminLogQuery.php index 53a5849b5..061b9013d 100644 --- a/core/lib/Thelia/Model/Base/AdminLogQuery.php +++ b/core/lib/Thelia/Model/Base/AdminLogQuery.php @@ -22,7 +22,9 @@ use Thelia\Model\Map\AdminLogTableMap; * @method ChildAdminLogQuery orderByAdminLogin($order = Criteria::ASC) Order by the admin_login column * @method ChildAdminLogQuery orderByAdminFirstname($order = Criteria::ASC) Order by the admin_firstname column * @method ChildAdminLogQuery orderByAdminLastname($order = Criteria::ASC) Order by the admin_lastname column + * @method ChildAdminLogQuery orderByResource($order = Criteria::ASC) Order by the resource column * @method ChildAdminLogQuery orderByAction($order = Criteria::ASC) Order by the action column + * @method ChildAdminLogQuery orderByMessage($order = Criteria::ASC) Order by the message column * @method ChildAdminLogQuery orderByRequest($order = Criteria::ASC) Order by the request column * @method ChildAdminLogQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column * @method ChildAdminLogQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column @@ -31,7 +33,9 @@ use Thelia\Model\Map\AdminLogTableMap; * @method ChildAdminLogQuery groupByAdminLogin() Group by the admin_login column * @method ChildAdminLogQuery groupByAdminFirstname() Group by the admin_firstname column * @method ChildAdminLogQuery groupByAdminLastname() Group by the admin_lastname column + * @method ChildAdminLogQuery groupByResource() Group by the resource column * @method ChildAdminLogQuery groupByAction() Group by the action column + * @method ChildAdminLogQuery groupByMessage() Group by the message column * @method ChildAdminLogQuery groupByRequest() Group by the request column * @method ChildAdminLogQuery groupByCreatedAt() Group by the created_at column * @method ChildAdminLogQuery groupByUpdatedAt() Group by the updated_at column @@ -47,7 +51,9 @@ use Thelia\Model\Map\AdminLogTableMap; * @method ChildAdminLog findOneByAdminLogin(string $admin_login) Return the first ChildAdminLog filtered by the admin_login column * @method ChildAdminLog findOneByAdminFirstname(string $admin_firstname) Return the first ChildAdminLog filtered by the admin_firstname column * @method ChildAdminLog findOneByAdminLastname(string $admin_lastname) Return the first ChildAdminLog filtered by the admin_lastname column + * @method ChildAdminLog findOneByResource(string $resource) Return the first ChildAdminLog filtered by the resource column * @method ChildAdminLog findOneByAction(string $action) Return the first ChildAdminLog filtered by the action column + * @method ChildAdminLog findOneByMessage(string $message) Return the first ChildAdminLog filtered by the message column * @method ChildAdminLog findOneByRequest(string $request) Return the first ChildAdminLog filtered by the request column * @method ChildAdminLog findOneByCreatedAt(string $created_at) Return the first ChildAdminLog filtered by the created_at column * @method ChildAdminLog findOneByUpdatedAt(string $updated_at) Return the first ChildAdminLog filtered by the updated_at column @@ -56,7 +62,9 @@ use Thelia\Model\Map\AdminLogTableMap; * @method array findByAdminLogin(string $admin_login) Return ChildAdminLog objects filtered by the admin_login column * @method array findByAdminFirstname(string $admin_firstname) Return ChildAdminLog objects filtered by the admin_firstname column * @method array findByAdminLastname(string $admin_lastname) Return ChildAdminLog objects filtered by the admin_lastname column + * @method array findByResource(string $resource) Return ChildAdminLog objects filtered by the resource column * @method array findByAction(string $action) Return ChildAdminLog objects filtered by the action column + * @method array findByMessage(string $message) Return ChildAdminLog objects filtered by the message column * @method array findByRequest(string $request) Return ChildAdminLog objects filtered by the request column * @method array findByCreatedAt(string $created_at) Return ChildAdminLog objects filtered by the created_at column * @method array findByUpdatedAt(string $updated_at) Return ChildAdminLog objects filtered by the updated_at column @@ -148,7 +156,7 @@ abstract class AdminLogQuery extends ModelCriteria */ protected function findPkSimple($key, $con) { - $sql = 'SELECT ID, ADMIN_LOGIN, ADMIN_FIRSTNAME, ADMIN_LASTNAME, ACTION, REQUEST, CREATED_AT, UPDATED_AT FROM admin_log WHERE ID = :p0'; + $sql = 'SELECT ID, ADMIN_LOGIN, ADMIN_FIRSTNAME, ADMIN_LASTNAME, RESOURCE, ACTION, MESSAGE, REQUEST, CREATED_AT, UPDATED_AT FROM admin_log WHERE ID = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, PDO::PARAM_INT); @@ -365,6 +373,35 @@ abstract class AdminLogQuery extends ModelCriteria return $this->addUsingAlias(AdminLogTableMap::ADMIN_LASTNAME, $adminLastname, $comparison); } + /** + * Filter the query on the resource column + * + * Example usage: + * + * $query->filterByResource('fooValue'); // WHERE resource = 'fooValue' + * $query->filterByResource('%fooValue%'); // WHERE resource LIKE '%fooValue%' + * + * + * @param string $resource The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildAdminLogQuery The current query, for fluid interface + */ + public function filterByResource($resource = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($resource)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $resource)) { + $resource = str_replace('*', '%', $resource); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(AdminLogTableMap::RESOURCE, $resource, $comparison); + } + /** * Filter the query on the action column * @@ -394,6 +431,35 @@ abstract class AdminLogQuery extends ModelCriteria return $this->addUsingAlias(AdminLogTableMap::ACTION, $action, $comparison); } + /** + * Filter the query on the message column + * + * Example usage: + * + * $query->filterByMessage('fooValue'); // WHERE message = 'fooValue' + * $query->filterByMessage('%fooValue%'); // WHERE message LIKE '%fooValue%' + * + * + * @param string $message The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildAdminLogQuery The current query, for fluid interface + */ + public function filterByMessage($message = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($message)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $message)) { + $message = str_replace('*', '%', $message); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(AdminLogTableMap::MESSAGE, $message, $comparison); + } + /** * Filter the query on the request column * diff --git a/core/lib/Thelia/Model/Map/AdminLogTableMap.php b/core/lib/Thelia/Model/Map/AdminLogTableMap.php index 633d6b4e9..fabd848dc 100644 --- a/core/lib/Thelia/Model/Map/AdminLogTableMap.php +++ b/core/lib/Thelia/Model/Map/AdminLogTableMap.php @@ -57,7 +57,7 @@ class AdminLogTableMap extends TableMap /** * The total number of columns */ - const NUM_COLUMNS = 8; + const NUM_COLUMNS = 10; /** * The number of lazy-loaded columns @@ -67,7 +67,7 @@ class AdminLogTableMap extends TableMap /** * The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */ - const NUM_HYDRATE_COLUMNS = 8; + const NUM_HYDRATE_COLUMNS = 10; /** * the column name for the ID field @@ -89,11 +89,21 @@ class AdminLogTableMap extends TableMap */ const ADMIN_LASTNAME = 'admin_log.ADMIN_LASTNAME'; + /** + * the column name for the RESOURCE field + */ + const RESOURCE = 'admin_log.RESOURCE'; + /** * the column name for the ACTION field */ const ACTION = 'admin_log.ACTION'; + /** + * the column name for the MESSAGE field + */ + const MESSAGE = 'admin_log.MESSAGE'; + /** * the column name for the REQUEST field */ @@ -121,12 +131,12 @@ class AdminLogTableMap extends TableMap * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ protected static $fieldNames = array ( - self::TYPE_PHPNAME => array('Id', 'AdminLogin', 'AdminFirstname', 'AdminLastname', 'Action', 'Request', 'CreatedAt', 'UpdatedAt', ), - self::TYPE_STUDLYPHPNAME => array('id', 'adminLogin', 'adminFirstname', 'adminLastname', 'action', 'request', 'createdAt', 'updatedAt', ), - self::TYPE_COLNAME => array(AdminLogTableMap::ID, AdminLogTableMap::ADMIN_LOGIN, AdminLogTableMap::ADMIN_FIRSTNAME, AdminLogTableMap::ADMIN_LASTNAME, AdminLogTableMap::ACTION, AdminLogTableMap::REQUEST, AdminLogTableMap::CREATED_AT, AdminLogTableMap::UPDATED_AT, ), - self::TYPE_RAW_COLNAME => array('ID', 'ADMIN_LOGIN', 'ADMIN_FIRSTNAME', 'ADMIN_LASTNAME', 'ACTION', 'REQUEST', 'CREATED_AT', 'UPDATED_AT', ), - self::TYPE_FIELDNAME => array('id', 'admin_login', 'admin_firstname', 'admin_lastname', 'action', 'request', 'created_at', 'updated_at', ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, ) + self::TYPE_PHPNAME => array('Id', 'AdminLogin', 'AdminFirstname', 'AdminLastname', 'Resource', 'Action', 'Message', 'Request', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'adminLogin', 'adminFirstname', 'adminLastname', 'resource', 'action', 'message', 'request', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(AdminLogTableMap::ID, AdminLogTableMap::ADMIN_LOGIN, AdminLogTableMap::ADMIN_FIRSTNAME, AdminLogTableMap::ADMIN_LASTNAME, AdminLogTableMap::RESOURCE, AdminLogTableMap::ACTION, AdminLogTableMap::MESSAGE, AdminLogTableMap::REQUEST, AdminLogTableMap::CREATED_AT, AdminLogTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'ADMIN_LOGIN', 'ADMIN_FIRSTNAME', 'ADMIN_LASTNAME', 'RESOURCE', 'ACTION', 'MESSAGE', 'REQUEST', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'admin_login', 'admin_firstname', 'admin_lastname', 'resource', 'action', 'message', 'request', 'created_at', 'updated_at', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ) ); /** @@ -136,12 +146,12 @@ class AdminLogTableMap extends TableMap * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 */ protected static $fieldKeys = array ( - self::TYPE_PHPNAME => array('Id' => 0, 'AdminLogin' => 1, 'AdminFirstname' => 2, 'AdminLastname' => 3, 'Action' => 4, 'Request' => 5, 'CreatedAt' => 6, 'UpdatedAt' => 7, ), - self::TYPE_STUDLYPHPNAME => array('id' => 0, 'adminLogin' => 1, 'adminFirstname' => 2, 'adminLastname' => 3, 'action' => 4, 'request' => 5, 'createdAt' => 6, 'updatedAt' => 7, ), - self::TYPE_COLNAME => array(AdminLogTableMap::ID => 0, AdminLogTableMap::ADMIN_LOGIN => 1, AdminLogTableMap::ADMIN_FIRSTNAME => 2, AdminLogTableMap::ADMIN_LASTNAME => 3, AdminLogTableMap::ACTION => 4, AdminLogTableMap::REQUEST => 5, AdminLogTableMap::CREATED_AT => 6, AdminLogTableMap::UPDATED_AT => 7, ), - self::TYPE_RAW_COLNAME => array('ID' => 0, 'ADMIN_LOGIN' => 1, 'ADMIN_FIRSTNAME' => 2, 'ADMIN_LASTNAME' => 3, 'ACTION' => 4, 'REQUEST' => 5, 'CREATED_AT' => 6, 'UPDATED_AT' => 7, ), - self::TYPE_FIELDNAME => array('id' => 0, 'admin_login' => 1, 'admin_firstname' => 2, 'admin_lastname' => 3, 'action' => 4, 'request' => 5, 'created_at' => 6, 'updated_at' => 7, ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, ) + self::TYPE_PHPNAME => array('Id' => 0, 'AdminLogin' => 1, 'AdminFirstname' => 2, 'AdminLastname' => 3, 'Resource' => 4, 'Action' => 5, 'Message' => 6, 'Request' => 7, 'CreatedAt' => 8, 'UpdatedAt' => 9, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'adminLogin' => 1, 'adminFirstname' => 2, 'adminLastname' => 3, 'resource' => 4, 'action' => 5, 'message' => 6, 'request' => 7, 'createdAt' => 8, 'updatedAt' => 9, ), + self::TYPE_COLNAME => array(AdminLogTableMap::ID => 0, AdminLogTableMap::ADMIN_LOGIN => 1, AdminLogTableMap::ADMIN_FIRSTNAME => 2, AdminLogTableMap::ADMIN_LASTNAME => 3, AdminLogTableMap::RESOURCE => 4, AdminLogTableMap::ACTION => 5, AdminLogTableMap::MESSAGE => 6, AdminLogTableMap::REQUEST => 7, AdminLogTableMap::CREATED_AT => 8, AdminLogTableMap::UPDATED_AT => 9, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'ADMIN_LOGIN' => 1, 'ADMIN_FIRSTNAME' => 2, 'ADMIN_LASTNAME' => 3, 'RESOURCE' => 4, 'ACTION' => 5, 'MESSAGE' => 6, 'REQUEST' => 7, 'CREATED_AT' => 8, 'UPDATED_AT' => 9, ), + self::TYPE_FIELDNAME => array('id' => 0, 'admin_login' => 1, 'admin_firstname' => 2, 'admin_lastname' => 3, 'resource' => 4, 'action' => 5, 'message' => 6, 'request' => 7, 'created_at' => 8, 'updated_at' => 9, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ) ); /** @@ -164,8 +174,10 @@ class AdminLogTableMap extends TableMap $this->addColumn('ADMIN_LOGIN', 'AdminLogin', 'VARCHAR', false, 255, null); $this->addColumn('ADMIN_FIRSTNAME', 'AdminFirstname', 'VARCHAR', false, 255, null); $this->addColumn('ADMIN_LASTNAME', 'AdminLastname', 'VARCHAR', false, 255, null); + $this->addColumn('RESOURCE', 'Resource', 'VARCHAR', false, 255, null); $this->addColumn('ACTION', 'Action', 'VARCHAR', false, 255, null); - $this->addColumn('REQUEST', 'Request', 'LONGVARCHAR', false, null, null); + $this->addColumn('MESSAGE', 'Message', 'LONGVARCHAR', false, null, null); + $this->addColumn('REQUEST', 'Request', 'CLOB', false, null, null); $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); } // initialize() @@ -332,7 +344,9 @@ class AdminLogTableMap extends TableMap $criteria->addSelectColumn(AdminLogTableMap::ADMIN_LOGIN); $criteria->addSelectColumn(AdminLogTableMap::ADMIN_FIRSTNAME); $criteria->addSelectColumn(AdminLogTableMap::ADMIN_LASTNAME); + $criteria->addSelectColumn(AdminLogTableMap::RESOURCE); $criteria->addSelectColumn(AdminLogTableMap::ACTION); + $criteria->addSelectColumn(AdminLogTableMap::MESSAGE); $criteria->addSelectColumn(AdminLogTableMap::REQUEST); $criteria->addSelectColumn(AdminLogTableMap::CREATED_AT); $criteria->addSelectColumn(AdminLogTableMap::UPDATED_AT); @@ -341,7 +355,9 @@ class AdminLogTableMap extends TableMap $criteria->addSelectColumn($alias . '.ADMIN_LOGIN'); $criteria->addSelectColumn($alias . '.ADMIN_FIRSTNAME'); $criteria->addSelectColumn($alias . '.ADMIN_LASTNAME'); + $criteria->addSelectColumn($alias . '.RESOURCE'); $criteria->addSelectColumn($alias . '.ACTION'); + $criteria->addSelectColumn($alias . '.MESSAGE'); $criteria->addSelectColumn($alias . '.REQUEST'); $criteria->addSelectColumn($alias . '.CREATED_AT'); $criteria->addSelectColumn($alias . '.UPDATED_AT'); diff --git a/core/lib/Thelia/Tools/FileManager.php b/core/lib/Thelia/Tools/FileManager.php index a795bcd5e..b4173645e 100644 --- a/core/lib/Thelia/Tools/FileManager.php +++ b/core/lib/Thelia/Tools/FileManager.php @@ -118,20 +118,6 @@ class FileManager $directory = $this->getUploadDir($parentType, $fileType); $fileName = $this->renameFile($model->getId(), $uploadedFile); - $this->adminLogAppend( - $this->translator->trans( - 'Uploading %type% %fileName% to %directory% for parent_id %parentId% (%parentType%)', - array( - '%type%' => $fileType, - '%fileName%' => $uploadedFile->getClientOriginalName(), - '%directory%' => $directory . '/' . $fileName, - '%parentId%' => $parentId, - '%parentType%' => $parentType - ), - 'image' - ) - ); - $newUploadedFile = $uploadedFile->move($directory, $fileName); $model->setFile($fileName); @@ -282,20 +268,6 @@ class FileManager return strtolower(preg_replace('/[^a-zA-Z0-9-_\.]/', '', $string)); } - /** - * Helper to append a message to the admin log. - * - * @param string $message - */ - public function adminLogAppend($message) - { - AdminLog::append( - $message, - $this->container->get('request'), - $this->container->get('thelia.securityContext')->getAdminUser() - ); - } - /** * Delete image from file storage and database * diff --git a/install/thelia.sql b/install/thelia.sql index 79163345b..c20bbc8e2 100755 --- a/install/thelia.sql +++ b/install/thelia.sql @@ -1138,8 +1138,10 @@ CREATE TABLE `admin_log` `admin_login` VARCHAR(255), `admin_firstname` VARCHAR(255), `admin_lastname` VARCHAR(255), + `resource` VARCHAR(255), `action` VARCHAR(255), - `request` TEXT, + `message` TEXT, + `request` LONGTEXT, `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`) diff --git a/local/config/schema.xml b/local/config/schema.xml index ba19efee0..6e547bd19 100755 --- a/local/config/schema.xml +++ b/local/config/schema.xml @@ -1,1259 +1,1261 @@ - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - -
- - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - -
- - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - -
- - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - -
- - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - -
- - - - - - - - -
- - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - -
- - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - -
- - - - - - - - - - -
-
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + +
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + +
+
diff --git a/templates/admin/default/admin-logs.html b/templates/admin/default/admin-logs.html new file mode 100755 index 000000000..da9d5bf3e --- /dev/null +++ b/templates/admin/default/admin-logs.html @@ -0,0 +1,143 @@ +{extends file="admin-layout.tpl"} + +{block name="page-title"}{intl l='Thelia Mailing System'}{/block} + +{block name="check-resource"}admin.configuration.admin-logs{/block} +{block name="check-access"}view{/block} + +{block name="main-content"} +
+ +
+ + + + {module_include location='admin_logs_top'} + +
+
+
+ +
{intl l="Configuration variables"}
+ + {form name="thelia.admin.mailing-system.update"} + +
+ +
+
+ +
+
+ + {form_hidden_fields form=$form} + + {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} + +
+
+ +
+
+ +
+ + {/form} + +
+
+
+ + {module_include location='admin_logs_bottom'} + +
+
+{/block} + +{block name="javascript-initialization"} + {javascripts file='assets/js/bootstrap-switch/bootstrap-switch.js'} + + {/javascripts} + + +{/block} \ No newline at end of file diff --git a/templates/admin/default/configuration.html b/templates/admin/default/configuration.html index a17042b4d..ff9622c45 100644 --- a/templates/admin/default/configuration.html +++ b/templates/admin/default/configuration.html @@ -153,19 +153,19 @@ {loop type="auth" name="pcc6" role="ADMIN" resource="admin.configuration.mailing-system" access="VIEW"} - {intl l='Mailing system'} + {intl l='Mailing system'} {/loop} -{* {loop type="auth" name="pcc7" role="ADMIN" resource="admin.configuration.admin-logs" access="VIEW"} + {loop type="auth" name="pcc7" role="ADMIN" resource="admin.configuration.admin-logs" access="VIEW"} - {intl l='Administration logs'} - + {intl l='Administration logs'} + {/loop} - {loop type="auth" name="pcc8" role="ADMIN" resource="admin.configuration.system-logs" access="VIEW"} +{* {loop type="auth" name="pcc8" role="ADMIN" resource="admin.configuration.system-logs" access="VIEW"} {intl l='System logs'} diff --git a/templates/admin/default/mailing-system.html b/templates/admin/default/mailing-system.html index 8ee5e3e3e..92d205289 100644 --- a/templates/admin/default/mailing-system.html +++ b/templates/admin/default/mailing-system.html @@ -13,7 +13,7 @@ {module_include location='mailing_system_top'} @@ -22,7 +22,7 @@
-
{intl l="Configuration variables"}
+
{intl l="Configuration mailing system"}
{form name="thelia.admin.mailing-system.update"} From c74422f5dc446c7097a9828181dcd0eef5b4f076 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 29 Oct 2013 15:56:03 +0100 Subject: [PATCH 02/17] implement module inclusion --- .../lib/Thelia/Command/BaseModuleGenerate.php | 9 ++++---- .../Core/Template/Smarty/Plugins/Module.php | 23 +++++++++++++++---- core/lib/Thelia/Model/Module.php | 5 ++++ core/lib/Thelia/Model/ModuleQuery.php | 19 ++++++++++++--- 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/core/lib/Thelia/Command/BaseModuleGenerate.php b/core/lib/Thelia/Command/BaseModuleGenerate.php index b26db435b..1a27d9e4c 100755 --- a/core/lib/Thelia/Command/BaseModuleGenerate.php +++ b/core/lib/Thelia/Command/BaseModuleGenerate.php @@ -35,13 +35,14 @@ abstract class BaseModuleGenerate extends ContainerAwareCommand protected $moduleDirectory; protected $reservedKeyWords = array( - "thelia" + 'thelia' ); protected $neededDirectories = array( - "Config", - "Model", - "Loop" + 'Config', + 'Model', + 'Loop', + 'AdminModule' ); protected function verifyExistingModule() diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Module.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Module.php index 52feae096..1c6ab4fd1 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Module.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Module.php @@ -25,6 +25,7 @@ namespace Thelia\Core\Template\Smarty\Plugins; use Thelia\Core\Template\Smarty\SmartyPluginDescriptor; use Thelia\Core\Template\Smarty\AbstractSmartyPlugin; +use Thelia\Model\ModuleQuery; class Module extends AbstractSmartyPlugin { @@ -32,13 +33,27 @@ class Module extends AbstractSmartyPlugin * Process theliaModule template inclusion function * * @param unknown $params - * @param unknown $smarty + * @param \Smarty_Internal_Template $template + * @internal param \Thelia\Core\Template\Smarty\Plugins\unknown $smarty + * * @return string */ - public function theliaModule($params, &$smarty) + public function theliaModule($params, \Smarty_Internal_Template $template) { - // TODO - return ""; + $content = null; + if (array_key_exists('location', $params)) { + $location = $params['location']; + $modules = ModuleQuery::getActivated(); + + foreach ($modules as $module) { + + $file = THELIA_MODULE_DIR . "/". ucfirst($module->getCode()) . "/ModuleAdmin/".$location.".html"; + if(file_exists($file)) { + $content .= file_get_contents($file); + } + } + } + return $template->fetch(sprintf("string:%s", $content)); } /** diff --git a/core/lib/Thelia/Model/Module.php b/core/lib/Thelia/Model/Module.php index b7fb2a443..c9ccd5f8d 100755 --- a/core/lib/Thelia/Model/Module.php +++ b/core/lib/Thelia/Model/Module.php @@ -2,8 +2,13 @@ namespace Thelia\Model; +use Propel\Runtime\Connection\ConnectionInterface; use Thelia\Model\Base\Module as BaseModule; class Module extends BaseModule { + public function postSave(ConnectionInterface $con = null) + { + ModuleQuery::resetActivated(); + } } diff --git a/core/lib/Thelia/Model/ModuleQuery.php b/core/lib/Thelia/Model/ModuleQuery.php index fdfe502a4..aaf2092e6 100755 --- a/core/lib/Thelia/Model/ModuleQuery.php +++ b/core/lib/Thelia/Model/ModuleQuery.php @@ -16,13 +16,26 @@ use Thelia\Model\Base\ModuleQuery as BaseModuleQuery; * */ class ModuleQuery extends BaseModuleQuery { + + protected static $activated = null; /** * @return array|mixed|\PropelObjectCollection */ public static function getActivated() { - return self::create() - ->filterByActivate(1) - ->find(); + if(null === self::$activated) { + self::$activated = self::create() + ->filterByActivate(1) + ->find(); + } + + return self::$activated; } + + public static function resetActivated() + { + self::$activated = null; + } + + } // ModuleQuery From a055f3b3eb71f607fe572c968a6c3d062c2987ab Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Tue, 29 Oct 2013 16:09:50 +0100 Subject: [PATCH 03/17] 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 @@ {/javascripts} + {javascripts file='assets/js/jquery.ui/jquery.ui.datepicker/jquery.ui.datepicker.js'} + + {/javascripts} + + {stylesheets file='assets/js/jquery.ui/jquery.ui.theme.css'} + + {/stylesheets} + {stylesheets file='assets/js/jquery.ui/jquery.ui.datepicker/jquery.ui.datepicker.css'} + + {/stylesheets} + + {javascripts file="assets/js/jquery/jquery.ui.ui.datepicker/i18n/jquery.ui.datepicker-{lang attr="locale"}.js" catchException="true"} + + {/javascripts} + + + - {/javascripts} - {javascripts file='assets/js/main.js'} {/javascripts} @@ -63,10 +59,6 @@ filemanager_title:"{intl l='Files manager'}" , external_plugins: { "filemanager" : "{url file='/tinymce/plugins/filemanager/plugin.min.js'}"} }); - - $(function($){ - {*$('.datepicker').datepicker({ dateFormat: "{$dateFormat}", defaultDate: +60, minDate: "+0m" });*} - }); {/block} diff --git a/templates/admin/default/coupon-update.html b/templates/admin/default/coupon-update.html index f96da1319..138ed28aa 100755 --- a/templates/admin/default/coupon-update.html +++ b/templates/admin/default/coupon-update.html @@ -28,10 +28,6 @@ {/block} {block name="javascript-initialization"} - {javascripts file='assets/bootstrap-datepicker/js/bootstrap-datepicker.js'} - - {/javascripts} - {javascripts file='assets/js/main.js'} {/javascripts} From b8dad621fdd01113f8e9b805292dc41a169d4e75 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 30 Oct 2013 12:19:14 +0100 Subject: [PATCH 07/17] remove temporary home carousel --- templates/default/index.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/default/index.html b/templates/default/index.html index c4204cb83..292aa238a 100644 --- a/templates/default/index.html +++ b/templates/default/index.html @@ -14,16 +14,16 @@
{images file='assets/img/carousel/slider1.png'}img1{/images}
-
+ {*
{images file='assets/img/carousel/slider2.png'}img2{/images}
{images file='assets/img/carousel/slider3.png'}img3{/images} -
+
*}
- - +{* + *}
From 2ee90d35e4b234c7705490a69f8ed141aaccf9b7 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 30 Oct 2013 14:27:45 +0100 Subject: [PATCH 08/17] create administrator update password event --- .../AdministratorUpdatePasswordEvent.php | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php diff --git a/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php b/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php new file mode 100644 index 000000000..70f92532b --- /dev/null +++ b/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php @@ -0,0 +1,84 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Administrator; +use Thelia\Core\Event\ActionEvent; + + +/** + * Class AdministratorUpdatePasswordEvent + * @package Thelia\Core\Event\Administrator + * @author Manuel Raynaud + */ +class AdministratorUpdatePasswordEvent extends ActionEvent +{ + + /** + * @var string administrator login + */ + protected $login; + + /** + * @var string new administrator password + */ + protected $password; + + public function __construct($login) + { + $this->login = $login; + } + + /** + * @param string $password + */ + public function setPassword($password) + { + $this->password = $password; + } + + /** + * @return string + */ + public function getPassword() + { + return $this->password; + } + + /** + * @param string $login + */ + public function setLogin($login) + { + $this->login = $login; + } + + /** + * @return string + */ + public function getLogin() + { + return $this->login; + } + + +} \ No newline at end of file From 434092a33b22f03bef05ac238d103c49400928f9 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Wed, 30 Oct 2013 14:45:50 +0100 Subject: [PATCH 09/17] admin login is now unique --- install/thelia.sql | 1 + local/config/schema.xml | 3 +++ 2 files changed, 4 insertions(+) diff --git a/install/thelia.sql b/install/thelia.sql index c20bbc8e2..b213c114f 100755 --- a/install/thelia.sql +++ b/install/thelia.sql @@ -984,6 +984,7 @@ CREATE TABLE `admin` `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`), + UNIQUE INDEX `login_UNIQUE` (`login`), INDEX `idx_admin_profile_id` (`profile_id`), CONSTRAINT `fk_admin_profile_id` FOREIGN KEY (`profile_id`) diff --git a/local/config/schema.xml b/local/config/schema.xml index 6e547bd19..cc9c4c396 100755 --- a/local/config/schema.xml +++ b/local/config/schema.xml @@ -771,6 +771,9 @@ + + + From 9d011eb5c67b40174eb5d8e89f1e80c8c5c96fa4 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 30 Oct 2013 14:46:21 +0100 Subject: [PATCH 10/17] change command line for creating new administrator --- core/lib/Thelia/Command/CreateAdminUser.php | 2 +- reset_install.bat | 2 +- reset_install.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/lib/Thelia/Command/CreateAdminUser.php b/core/lib/Thelia/Command/CreateAdminUser.php index 857790141..5ac62802a 100644 --- a/core/lib/Thelia/Command/CreateAdminUser.php +++ b/core/lib/Thelia/Command/CreateAdminUser.php @@ -38,7 +38,7 @@ class CreateAdminUser extends ContainerAwareCommand protected function configure() { $this - ->setName("thelia:create-admin") + ->setName("admin:create") ->setDescription("Create a new adminsitration user") ->setHelp("The thelia:create-admin command create a new administration user.") ->addOption( diff --git a/reset_install.bat b/reset_install.bat index 0a12c43d2..f8c0b35e2 100644 --- a/reset_install.bat +++ b/reset_install.bat @@ -26,7 +26,7 @@ if exist local\config\database.yml ( php install\faker.php echo [INFO] Adding admin - php Thelia thelia:create-admin + php Thelia admin:create echo [SUCCESS] Reset done ) diff --git a/reset_install.sh b/reset_install.sh index a91a2dc1c..83288a509 100755 --- a/reset_install.sh +++ b/reset_install.sh @@ -32,7 +32,7 @@ echo -e "\n\033[01;34m[INFO] Installing fixtures\033[00m\n" php install/faker.php echo -e "\n\033[01;34m[INFO] Adding admin\033[00m\n" -php Thelia thelia:create-admin --login_name thelia2 --password thelia2 --last_name thelia2 --first_name thelia2 +php Thelia admin:create --login_name thelia2 --password thelia2 --last_name thelia2 --first_name thelia2 echo -e "\n\033[01;34m[INFO] Clearing caches\033[00m\n" php Thelia cache:clear From a540c503957197666deed1a43fe0466674ceffd5 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Wed, 30 Oct 2013 14:51:13 +0100 Subject: [PATCH 11/17] fix administrators management bug --- templates/admin/default/administrators.html | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/templates/admin/default/administrators.html b/templates/admin/default/administrators.html index 9cb4a792a..c2b8fa521 100644 --- a/templates/admin/default/administrators.html +++ b/templates/admin/default/administrators.html @@ -62,13 +62,20 @@ From b0f3ad69d2e9fbc89f9594535bc5b3c21b955ff9 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 30 Oct 2013 15:01:18 +0100 Subject: [PATCH 12/17] start creating admin password recovery --- core/lib/Thelia/Action/Administrator.php | 16 ++++- .../Thelia/Command/AdminUpdatePassword.php | 63 +++++++++++++++++++ core/lib/Thelia/Command/CreateAdminUser.php | 4 +- .../AdministratorUpdatePasswordEvent.php | 2 +- core/lib/Thelia/Core/Event/TheliaEvents.php | 1 + 5 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 core/lib/Thelia/Command/AdminUpdatePassword.php diff --git a/core/lib/Thelia/Action/Administrator.php b/core/lib/Thelia/Action/Administrator.php index 2bbfce8a8..23167dd40 100644 --- a/core/lib/Thelia/Action/Administrator.php +++ b/core/lib/Thelia/Action/Administrator.php @@ -25,6 +25,7 @@ namespace Thelia\Action; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Core\Event\Administrator\AdministratorEvent; +use Thelia\Core\Event\Administrator\AdministratorUpdatePasswordEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Admin as AdminModel; use Thelia\Model\AdminQuery; @@ -92,15 +93,24 @@ class Administrator extends BaseAction implements EventSubscriberInterface } } + public function updatePassword(AdministratorUpdatePasswordEvent $event) + { + if (null !== $admin = AdminQuery::create()->filterByLogin($event->getLogin())->findOne()) { + $admin->setPassword($event->getPassword()) + ->save(); + } + } + /** * {@inheritDoc} */ public static function getSubscribedEvents() { return array( - TheliaEvents::ADMINISTRATOR_CREATE => array("create", 128), - TheliaEvents::ADMINISTRATOR_UPDATE => array("update", 128), - TheliaEvents::ADMINISTRATOR_DELETE => array("delete", 128), + TheliaEvents::ADMINISTRATOR_CREATE => array('create', 128), + TheliaEvents::ADMINISTRATOR_UPDATE => array('update', 128), + TheliaEvents::ADMINISTRATOR_DELETE => array('delete', 128), + TheliaEvents::ADMINISTRATOR_UPDATEPASSWORD => array('updatePassword', 128) ); } } diff --git a/core/lib/Thelia/Command/AdminUpdatePassword.php b/core/lib/Thelia/Command/AdminUpdatePassword.php new file mode 100644 index 000000000..6b0a0ec48 --- /dev/null +++ b/core/lib/Thelia/Command/AdminUpdatePassword.php @@ -0,0 +1,63 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Command; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputOption; + + +/** + * command line for updating admin password + * + * php Thelia admin:updatePassword + * + * Class AdminUpdatePassword + * @package Thelia\Command + * @author Manuel Raynaud + */ +class AdminUpdatePassword extends ContainerAwareCommand +{ + + /** + * Configures the current command. + */ + protected function configure() + { + $this + ->setName('admin:updatePassword') + ->setDescription('change administrator password') + ->setHelp('The admin:updatePassword command allows you to change the password for a given administrator') + ->addArgument( + 'login', + InputArgument::REQUIRED, + 'Login for administrator you want to change the password' + ) + ->addOption( + 'password', + null, + InputOption::VALUE_REQUIRED, + 'Desired password. If this option is omitted, a random password is generated and shown in this prompt after' + ) + ; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Command/CreateAdminUser.php b/core/lib/Thelia/Command/CreateAdminUser.php index 5ac62802a..988122e7a 100644 --- a/core/lib/Thelia/Command/CreateAdminUser.php +++ b/core/lib/Thelia/Command/CreateAdminUser.php @@ -39,8 +39,8 @@ class CreateAdminUser extends ContainerAwareCommand { $this ->setName("admin:create") - ->setDescription("Create a new adminsitration user") - ->setHelp("The thelia:create-admin command create a new administration user.") + ->setDescription("Create a new administrator user") + ->setHelp("The admin:create command create a new administration user.") ->addOption( 'login_name', null, diff --git a/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php b/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php index 70f92532b..cccb45cc4 100644 --- a/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php +++ b/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php @@ -80,5 +80,5 @@ class AdministratorUpdatePasswordEvent extends ActionEvent return $this->login; } - + } \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index 42b20d8cd..ea3d7686a 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -565,6 +565,7 @@ final class TheliaEvents const ADMINISTRATOR_CREATE = "action.createAdministrator"; const ADMINISTRATOR_UPDATE = "action.updateAdministrator"; const ADMINISTRATOR_DELETE = "action.deleteAdministrator"; + const ADMINISTRATOR_UPDATEPASSWORD = 'action.generatePassword'; // -- Mailing System management --------------------------------------------- From e18c8992f82ecc5882803c1733cd09e2ecf970d8 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 30 Oct 2013 15:33:25 +0100 Subject: [PATCH 13/17] finish admin update password command line --- core/lib/Thelia/Action/Administrator.php | 7 ++-- ...ord.php => AdminUpdatePasswordCommand.php} | 41 ++++++++++++++++++- core/lib/Thelia/Config/Resources/config.xml | 1 + .../AdministratorUpdatePasswordEvent.php | 23 ++++++----- local/modules/Cheque/Config/config.xml | 2 +- 5 files changed, 57 insertions(+), 17 deletions(-) rename core/lib/Thelia/Command/{AdminUpdatePassword.php => AdminUpdatePasswordCommand.php} (70%) diff --git a/core/lib/Thelia/Action/Administrator.php b/core/lib/Thelia/Action/Administrator.php index 23167dd40..15940082a 100644 --- a/core/lib/Thelia/Action/Administrator.php +++ b/core/lib/Thelia/Action/Administrator.php @@ -95,10 +95,9 @@ class Administrator extends BaseAction implements EventSubscriberInterface public function updatePassword(AdministratorUpdatePasswordEvent $event) { - if (null !== $admin = AdminQuery::create()->filterByLogin($event->getLogin())->findOne()) { - $admin->setPassword($event->getPassword()) - ->save(); - } + $admin = $event->getAdmin(); + $admin->setPassword($event->getPassword()) + ->save(); } /** diff --git a/core/lib/Thelia/Command/AdminUpdatePassword.php b/core/lib/Thelia/Command/AdminUpdatePasswordCommand.php similarity index 70% rename from core/lib/Thelia/Command/AdminUpdatePassword.php rename to core/lib/Thelia/Command/AdminUpdatePasswordCommand.php index 6b0a0ec48..d4d0e5fc8 100644 --- a/core/lib/Thelia/Command/AdminUpdatePassword.php +++ b/core/lib/Thelia/Command/AdminUpdatePasswordCommand.php @@ -22,8 +22,15 @@ /*************************************************************************************/ namespace Thelia\Command; + use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; +use Thelia\Core\Event\Administrator\AdministratorUpdatePasswordEvent; +use Thelia\Core\Event\TheliaEvents; +use Thelia\Model\AdminQuery; +use Thelia\Tools\Password; /** @@ -31,11 +38,11 @@ use Symfony\Component\Console\Input\InputOption; * * php Thelia admin:updatePassword * - * Class AdminUpdatePassword + * Class AdminUpdatePasswordCommand * @package Thelia\Command * @author Manuel Raynaud */ -class AdminUpdatePassword extends ContainerAwareCommand +class AdminUpdatePasswordCommand extends ContainerAwareCommand { /** @@ -60,4 +67,34 @@ class AdminUpdatePassword extends ContainerAwareCommand ) ; } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $login = $input->getArgument('login'); + + + if (null === $admin = AdminQuery::create()->filterByLogin($login)->findOne()) { + throw new \RuntimeException(sprintf('Admin with login %s does not exists', $login)); + } + + + $password = $input->getOption('password') ?: Password::generateRandom(); + + $event = new AdministratorUpdatePasswordEvent($admin); + $event->setPassword($password); + + + $this-> + getContainer() + ->get('event_dispatcher') + ->dispatch(TheliaEvents::ADMINISTRATOR_UPDATEPASSWORD, $event); + + $output->writeln(array( + '', + sprintf('admin %s password updated', $login), + sprintf('new password is : %s', $password), + '' + )); + + } } \ No newline at end of file diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index c0af99896..255f70dfd 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -182,6 +182,7 @@ + diff --git a/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php b/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php index cccb45cc4..01a36a206 100644 --- a/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php +++ b/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php @@ -23,6 +23,7 @@ namespace Thelia\Core\Event\Administrator; use Thelia\Core\Event\ActionEvent; +use Thelia\Model\Admin; /** @@ -34,18 +35,18 @@ class AdministratorUpdatePasswordEvent extends ActionEvent { /** - * @var string administrator login + * @var \Thelia\Model\Admin */ - protected $login; + protected $admin; /** * @var string new administrator password */ protected $password; - public function __construct($login) + public function __construct(Admin $admin) { - $this->login = $login; + $this->admin = $admin; } /** @@ -65,20 +66,22 @@ class AdministratorUpdatePasswordEvent extends ActionEvent } /** - * @param string $login + * @param \Thelia\Model\Admin $admin */ - public function setLogin($login) + public function setAdmin(Admin $admin) { - $this->login = $login; + $this->admin = $admin; } /** - * @return string + * @return \Thelia\Model\Admin */ - public function getLogin() + public function getAdmin() { - return $this->login; + return $this->admin; } + + } \ No newline at end of file diff --git a/local/modules/Cheque/Config/config.xml b/local/modules/Cheque/Config/config.xml index 2430f5027..cac3f6b7b 100755 --- a/local/modules/Cheque/Config/config.xml +++ b/local/modules/Cheque/Config/config.xml @@ -1,4 +1,4 @@ - +string Date: Wed, 30 Oct 2013 14:27:45 +0100 Subject: [PATCH 14/17] create administrator update password event --- .../AdministratorUpdatePasswordEvent.php | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php diff --git a/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php b/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php new file mode 100644 index 000000000..b41b83a06 --- /dev/null +++ b/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php @@ -0,0 +1,84 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Administrator; +use Thelia\Core\Event\ActionEvent; + + +/** + * Class AdministratorUpdatePasswordEvent + * @package Thelia\Core\Event\Administrator + * @author Manuel Raynaud + */ +class AdministratorUpdatePasswordEvent extends ActionEvent +{ + + /** + * @var string administrator login + */ + protected $login; + + /** + * @var string new administrator password + */ + protected $password; + + public function __construct($login) + { + $this->login = $login; + } + + /** + * @param string $password + */ + public function setPassword($password) + { + $this->password = $password; + } + + /** + * @return string + */ + public function getPassword() + { + return $this->password; + } + + /** + * @param string $login + */ + public function setLogin($login) + { + $this->login = $login; + } + + /** + * @return string + */ + public function getLogin() + { + return $this->login; + } + + +} \ No newline at end of file From c327b20fd640ffb694a81fd78be406d34f120747 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 30 Oct 2013 14:46:21 +0100 Subject: [PATCH 15/17] change command line for creating new administrator --- core/lib/Thelia/Command/CreateAdminUser.php | 2 +- reset_install.bat | 2 +- reset_install.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/lib/Thelia/Command/CreateAdminUser.php b/core/lib/Thelia/Command/CreateAdminUser.php index 857790141..5ac62802a 100644 --- a/core/lib/Thelia/Command/CreateAdminUser.php +++ b/core/lib/Thelia/Command/CreateAdminUser.php @@ -38,7 +38,7 @@ class CreateAdminUser extends ContainerAwareCommand protected function configure() { $this - ->setName("thelia:create-admin") + ->setName("admin:create") ->setDescription("Create a new adminsitration user") ->setHelp("The thelia:create-admin command create a new administration user.") ->addOption( diff --git a/reset_install.bat b/reset_install.bat index 0a12c43d2..f8c0b35e2 100644 --- a/reset_install.bat +++ b/reset_install.bat @@ -26,7 +26,7 @@ if exist local\config\database.yml ( php install\faker.php echo [INFO] Adding admin - php Thelia thelia:create-admin + php Thelia admin:create echo [SUCCESS] Reset done ) diff --git a/reset_install.sh b/reset_install.sh index a91a2dc1c..83288a509 100755 --- a/reset_install.sh +++ b/reset_install.sh @@ -32,7 +32,7 @@ echo -e "\n\033[01;34m[INFO] Installing fixtures\033[00m\n" php install/faker.php echo -e "\n\033[01;34m[INFO] Adding admin\033[00m\n" -php Thelia thelia:create-admin --login_name thelia2 --password thelia2 --last_name thelia2 --first_name thelia2 +php Thelia admin:create --login_name thelia2 --password thelia2 --last_name thelia2 --first_name thelia2 echo -e "\n\033[01;34m[INFO] Clearing caches\033[00m\n" php Thelia cache:clear From 66c30a1b4c376f6b321638e39b20e76860805cb6 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 30 Oct 2013 15:01:18 +0100 Subject: [PATCH 16/17] start creating admin password recovery --- core/lib/Thelia/Action/Administrator.php | 16 ++++- .../Thelia/Command/AdminUpdatePassword.php | 63 +++++++++++++++++++ core/lib/Thelia/Command/CreateAdminUser.php | 4 +- core/lib/Thelia/Core/Event/TheliaEvents.php | 1 + 4 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 core/lib/Thelia/Command/AdminUpdatePassword.php diff --git a/core/lib/Thelia/Action/Administrator.php b/core/lib/Thelia/Action/Administrator.php index 2bbfce8a8..23167dd40 100644 --- a/core/lib/Thelia/Action/Administrator.php +++ b/core/lib/Thelia/Action/Administrator.php @@ -25,6 +25,7 @@ namespace Thelia\Action; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Core\Event\Administrator\AdministratorEvent; +use Thelia\Core\Event\Administrator\AdministratorUpdatePasswordEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Admin as AdminModel; use Thelia\Model\AdminQuery; @@ -92,15 +93,24 @@ class Administrator extends BaseAction implements EventSubscriberInterface } } + public function updatePassword(AdministratorUpdatePasswordEvent $event) + { + if (null !== $admin = AdminQuery::create()->filterByLogin($event->getLogin())->findOne()) { + $admin->setPassword($event->getPassword()) + ->save(); + } + } + /** * {@inheritDoc} */ public static function getSubscribedEvents() { return array( - TheliaEvents::ADMINISTRATOR_CREATE => array("create", 128), - TheliaEvents::ADMINISTRATOR_UPDATE => array("update", 128), - TheliaEvents::ADMINISTRATOR_DELETE => array("delete", 128), + TheliaEvents::ADMINISTRATOR_CREATE => array('create', 128), + TheliaEvents::ADMINISTRATOR_UPDATE => array('update', 128), + TheliaEvents::ADMINISTRATOR_DELETE => array('delete', 128), + TheliaEvents::ADMINISTRATOR_UPDATEPASSWORD => array('updatePassword', 128) ); } } diff --git a/core/lib/Thelia/Command/AdminUpdatePassword.php b/core/lib/Thelia/Command/AdminUpdatePassword.php new file mode 100644 index 000000000..f6cf8ee64 --- /dev/null +++ b/core/lib/Thelia/Command/AdminUpdatePassword.php @@ -0,0 +1,63 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Command; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputOption; + + +/** + * command line for updating admin password + * + * php Thelia admin:updatePassword + * + * Class AdminUpdatePassword + * @package Thelia\Command + * @author Manuel Raynaud + */ +class AdminUpdatePassword extends ContainerAwareCommand +{ + + /** + * Configures the current command. + */ + protected function configure() + { + $this + ->setName('admin:updatePassword') + ->setDescription('change administrator password') + ->setHelp('The admin:updatePassword command allows you to change the password for a given administrator') + ->addArgument( + 'login', + InputArgument::REQUIRED, + 'Login for administrator you want to change the password' + ) + ->addOption( + 'password', + null, + InputOption::VALUE_REQUIRED, + 'Desired password. If this option is omitted, a random password is generated and shown in this prompt after' + ) + ; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Command/CreateAdminUser.php b/core/lib/Thelia/Command/CreateAdminUser.php index 5ac62802a..988122e7a 100644 --- a/core/lib/Thelia/Command/CreateAdminUser.php +++ b/core/lib/Thelia/Command/CreateAdminUser.php @@ -39,8 +39,8 @@ class CreateAdminUser extends ContainerAwareCommand { $this ->setName("admin:create") - ->setDescription("Create a new adminsitration user") - ->setHelp("The thelia:create-admin command create a new administration user.") + ->setDescription("Create a new administrator user") + ->setHelp("The admin:create command create a new administration user.") ->addOption( 'login_name', null, diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index 42b20d8cd..ea3d7686a 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -565,6 +565,7 @@ final class TheliaEvents const ADMINISTRATOR_CREATE = "action.createAdministrator"; const ADMINISTRATOR_UPDATE = "action.updateAdministrator"; const ADMINISTRATOR_DELETE = "action.deleteAdministrator"; + const ADMINISTRATOR_UPDATEPASSWORD = 'action.generatePassword'; // -- Mailing System management --------------------------------------------- From 78cba61cd56938cdde781278a3c515daffdcd7ec Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 30 Oct 2013 15:33:25 +0100 Subject: [PATCH 17/17] finish admin update password command line --- core/lib/Thelia/Action/Administrator.php | 7 ++-- ...ord.php => AdminUpdatePasswordCommand.php} | 41 ++++++++++++++++++- core/lib/Thelia/Config/Resources/config.xml | 1 + .../AdministratorUpdatePasswordEvent.php | 23 ++++++----- local/modules/Cheque/Config/config.xml | 2 +- 5 files changed, 57 insertions(+), 17 deletions(-) rename core/lib/Thelia/Command/{AdminUpdatePassword.php => AdminUpdatePasswordCommand.php} (70%) diff --git a/core/lib/Thelia/Action/Administrator.php b/core/lib/Thelia/Action/Administrator.php index 23167dd40..15940082a 100644 --- a/core/lib/Thelia/Action/Administrator.php +++ b/core/lib/Thelia/Action/Administrator.php @@ -95,10 +95,9 @@ class Administrator extends BaseAction implements EventSubscriberInterface public function updatePassword(AdministratorUpdatePasswordEvent $event) { - if (null !== $admin = AdminQuery::create()->filterByLogin($event->getLogin())->findOne()) { - $admin->setPassword($event->getPassword()) - ->save(); - } + $admin = $event->getAdmin(); + $admin->setPassword($event->getPassword()) + ->save(); } /** diff --git a/core/lib/Thelia/Command/AdminUpdatePassword.php b/core/lib/Thelia/Command/AdminUpdatePasswordCommand.php similarity index 70% rename from core/lib/Thelia/Command/AdminUpdatePassword.php rename to core/lib/Thelia/Command/AdminUpdatePasswordCommand.php index f6cf8ee64..035dc75e3 100644 --- a/core/lib/Thelia/Command/AdminUpdatePassword.php +++ b/core/lib/Thelia/Command/AdminUpdatePasswordCommand.php @@ -22,8 +22,15 @@ /*************************************************************************************/ namespace Thelia\Command; + use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; +use Thelia\Core\Event\Administrator\AdministratorUpdatePasswordEvent; +use Thelia\Core\Event\TheliaEvents; +use Thelia\Model\AdminQuery; +use Thelia\Tools\Password; /** @@ -31,11 +38,11 @@ use Symfony\Component\Console\Input\InputOption; * * php Thelia admin:updatePassword * - * Class AdminUpdatePassword + * Class AdminUpdatePasswordCommand * @package Thelia\Command * @author Manuel Raynaud */ -class AdminUpdatePassword extends ContainerAwareCommand +class AdminUpdatePasswordCommand extends ContainerAwareCommand { /** @@ -60,4 +67,34 @@ class AdminUpdatePassword extends ContainerAwareCommand ) ; } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $login = $input->getArgument('login'); + + + if (null === $admin = AdminQuery::create()->filterByLogin($login)->findOne()) { + throw new \RuntimeException(sprintf('Admin with login %s does not exists', $login)); + } + + + $password = $input->getOption('password') ?: Password::generateRandom(); + + $event = new AdministratorUpdatePasswordEvent($admin); + $event->setPassword($password); + + + $this-> + getContainer() + ->get('event_dispatcher') + ->dispatch(TheliaEvents::ADMINISTRATOR_UPDATEPASSWORD, $event); + + $output->writeln(array( + '', + sprintf('admin %s password updated', $login), + sprintf('new password is : %s', $password), + '' + )); + + } } \ No newline at end of file diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index c0af99896..255f70dfd 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -182,6 +182,7 @@ + diff --git a/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php b/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php index b41b83a06..e6a5894ac 100644 --- a/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php +++ b/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php @@ -23,6 +23,7 @@ namespace Thelia\Core\Event\Administrator; use Thelia\Core\Event\ActionEvent; +use Thelia\Model\Admin; /** @@ -34,18 +35,18 @@ class AdministratorUpdatePasswordEvent extends ActionEvent { /** - * @var string administrator login + * @var \Thelia\Model\Admin */ - protected $login; + protected $admin; /** * @var string new administrator password */ protected $password; - public function __construct($login) + public function __construct(Admin $admin) { - $this->login = $login; + $this->admin = $admin; } /** @@ -65,20 +66,22 @@ class AdministratorUpdatePasswordEvent extends ActionEvent } /** - * @param string $login + * @param \Thelia\Model\Admin $admin */ - public function setLogin($login) + public function setAdmin(Admin $admin) { - $this->login = $login; + $this->admin = $admin; } /** - * @return string + * @return \Thelia\Model\Admin */ - public function getLogin() + public function getAdmin() { - return $this->login; + return $this->admin; } + + } \ No newline at end of file diff --git a/local/modules/Cheque/Config/config.xml b/local/modules/Cheque/Config/config.xml index 2430f5027..cac3f6b7b 100755 --- a/local/modules/Cheque/Config/config.xml +++ b/local/modules/Cheque/Config/config.xml @@ -1,4 +1,4 @@ - +string
- {loop type="auth" name="can_change" role="ADMIN" resource="admin.configuration.administrator" access="UPDATE"} + {* if admin is current admin : + - can UPDATE anyway + - cannot delete himself + *} + {if $ID == {admin attr="id"}} - {/loop} - - {loop type="auth" name="can_delete" role="ADMIN" resource="admin.configuration.administrator" access="DELETE"} - - {/loop} + {else} + {loop type="auth" name="can_change" role="ADMIN" resource="admin.configuration.administrator" access="UPDATE"} + + {/loop} + {loop type="auth" name="can_delete" role="ADMIN" resource="admin.configuration.administrator" access="DELETE"} + + {/loop} + {/if}