administrators management
This commit is contained in:
108
core/lib/Thelia/Action/Administrator.php
Normal file
108
core/lib/Thelia/Action/Administrator.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Action;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Thelia\Core\Event\Administrator\AdministratorEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
use Thelia\Model\Admin as AdminModel;
|
||||
use Thelia\Model\AdminQuery;
|
||||
|
||||
class Administrator extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* @param AdministratorEvent $event
|
||||
*/
|
||||
public function create(AdministratorEvent $event)
|
||||
{
|
||||
$administrator = new AdminModel();
|
||||
|
||||
$administrator
|
||||
->setDispatcher($this->getDispatcher())
|
||||
->setFirstname($event->getFirstname())
|
||||
->setLastname($event->getLastname())
|
||||
->setLogin($event->getLogin())
|
||||
->setPassword($event->getPassword())
|
||||
->setProfileId($event->getProfile())
|
||||
;
|
||||
|
||||
$administrator->save();
|
||||
|
||||
$event->setAdministrator($administrator);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AdministratorEvent $event
|
||||
*/
|
||||
public function update(AdministratorEvent $event)
|
||||
{
|
||||
if (null !== $administrator = AdminQuery::create()->findPk($event->getId())) {
|
||||
|
||||
$administrator
|
||||
->setDispatcher($this->getDispatcher())
|
||||
->setFirstname($event->getFirstname())
|
||||
->setLastname($event->getLastname())
|
||||
->setLogin($event->getLogin())
|
||||
->setProfileId($event->getProfile())
|
||||
;
|
||||
|
||||
if('' !== $event->getPassword()) {
|
||||
$administrator->setPassword($event->getPassword());
|
||||
}
|
||||
|
||||
$administrator->save();
|
||||
|
||||
$event->setAdministrator($administrator);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AdministratorEvent $event
|
||||
*/
|
||||
public function delete(AdministratorEvent $event)
|
||||
{
|
||||
if (null !== $administrator = AdminQuery::create()->findPk($event->getId())) {
|
||||
|
||||
$administrator
|
||||
->delete()
|
||||
;
|
||||
|
||||
$event->setAdministrator($administrator);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
use Thelia\Command\ContainerAwareCommand;
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Thelia\Model\Admin;
|
||||
use Thelia\Model\Map\ResourceI18nTableMap;
|
||||
use Thelia\Model\Map\ResourceTableMap;
|
||||
@@ -72,7 +73,7 @@ class GenerateResources extends ContainerAwareCommand
|
||||
);
|
||||
$compteur = 0;
|
||||
foreach($constants as $constant => $value) {
|
||||
if($constant == 'SUPERADMINISTRATOR') {
|
||||
if($constant == AdminResources::SUPERADMINISTRATOR) {
|
||||
continue;
|
||||
}
|
||||
$compteur++;
|
||||
@@ -87,7 +88,7 @@ class GenerateResources extends ContainerAwareCommand
|
||||
);
|
||||
$compteur = 0;
|
||||
foreach($constants as $constant => $value) {
|
||||
if($constant == 'SUPERADMINISTRATOR') {
|
||||
if($constant == AdminResources::SUPERADMINISTRATOR) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -105,7 +106,7 @@ class GenerateResources extends ContainerAwareCommand
|
||||
break;
|
||||
default :
|
||||
foreach($constants as $constant => $value) {
|
||||
if($constant == 'SUPERADMINISTRATOR') {
|
||||
if($constant == AdminResources::SUPERADMINISTRATOR) {
|
||||
continue;
|
||||
}
|
||||
$output->writeln('[' . $constant . "] => " . $value);
|
||||
|
||||
@@ -156,6 +156,11 @@
|
||||
<tag name="kernel.event_subscriber"/>
|
||||
</service>
|
||||
|
||||
<service id="thelia.action.administrator" class="Thelia\Action\Administrator">
|
||||
<argument type="service" id="service_container"/>
|
||||
<tag name="kernel.event_subscriber"/>
|
||||
</service>
|
||||
|
||||
<service id="thelia.action.newsletter" class="Thelia\Action\Newsletter">
|
||||
<argument type="service" id="service_container"/>
|
||||
<tag name="kernel.event_subscriber"/>
|
||||
|
||||
@@ -133,6 +133,9 @@
|
||||
<form name="thelia.admin.profile.resource-access.modification" class="Thelia\Form\ProfileUpdateResourceAccessForm"/>
|
||||
<form name="thelia.admin.profile.module-access.modification" class="Thelia\Form\ProfileUpdateModuleAccessForm"/>
|
||||
|
||||
<form name="thelia.admin.administrator.add" class="Thelia\Form\AdministratorCreationForm"/>
|
||||
<form name="thelia.admin.administrator.update" class="Thelia\Form\AdministratorModificationForm"/>
|
||||
|
||||
<form name="thelia.admin.template.creation" class="Thelia\Form\TemplateCreationForm"/>
|
||||
<form name="thelia.admin.template.modification" class="Thelia\Form\TemplateModificationForm"/>
|
||||
|
||||
@@ -141,8 +144,6 @@
|
||||
|
||||
<form name="thelia.admin.language.creation" class="Thelia\Form\LanguageCreationForm"/>
|
||||
|
||||
<form name="thelia.admin.admin-profile.creation" class="Thelia\Form\AdminProfileCreationForm"/>
|
||||
|
||||
<form name="thelia.admin.area.create" class="Thelia\Form\Area\AreaCreateForm"/>
|
||||
<form name="thelia.admin.area.modification" class="Thelia\Form\Area\AreaModificationForm"/>
|
||||
<form name="thelia.admin.area.country" class="Thelia\Form\Area\AreaCountryForm"/>
|
||||
|
||||
@@ -24,13 +24,6 @@
|
||||
<default key="_controller">Thelia\Controller\Admin\SessionController::checkLoginAction</default>
|
||||
</route>
|
||||
|
||||
<!-- Route to edit admin profile -->
|
||||
<route id="admin.profile.update.view" path="/admin/profile/update" methods="get">
|
||||
<default key="_controller">Thelia\Controller\Admin\AdminController::updateAction</default>
|
||||
</route>
|
||||
|
||||
|
||||
|
||||
<!-- Route to the catalog controller -->
|
||||
|
||||
<route id="admin.catalog" path="/admin/catalog">
|
||||
@@ -791,6 +784,26 @@
|
||||
|
||||
<!-- end profiles management -->
|
||||
|
||||
<!-- administrator management -->
|
||||
|
||||
<route id="admin.configuration.administrators.view" path="/admin/configuration/administrators">
|
||||
<default key="_controller">Thelia\Controller\Admin\AdministratorController::defaultAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.administrators.add" path="/admin/configuration/administrators/add">
|
||||
<default key="_controller">Thelia\Controller\Admin\AdministratorController::createAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.administrators.save" path="/admin/configuration/administrators/save">
|
||||
<default key="_controller">Thelia\Controller\Admin\AdministratorController::processUpdateAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.administrators.delete" path="/admin/configuration/administrators/delete">
|
||||
<default key="_controller">Thelia\Controller\Admin\AdministratorController::deleteAction</default>
|
||||
</route>
|
||||
|
||||
<!-- end administrator management -->
|
||||
|
||||
<!-- feature and features value management -->
|
||||
|
||||
<route id="admin.configuration.features.default" path="/admin/configuration/features">
|
||||
|
||||
201
core/lib/Thelia/Controller/Admin/AdministratorController.php
Normal file
201
core/lib/Thelia/Controller/Admin/AdministratorController.php
Normal file
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Thelia\Core\Event\Administrator\AdministratorEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Form\AdministratorCreationForm;
|
||||
use Thelia\Form\AdministratorModificationForm;
|
||||
use Thelia\Model\AdminQuery;
|
||||
|
||||
|
||||
class AdministratorController extends AbstractCrudController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
'administrator',
|
||||
'manual',
|
||||
'order',
|
||||
|
||||
AdminResources::ADMINISTRATOR,
|
||||
|
||||
TheliaEvents::ADMINISTRATOR_CREATE,
|
||||
TheliaEvents::ADMINISTRATOR_UPDATE,
|
||||
TheliaEvents::ADMINISTRATOR_DELETE
|
||||
);
|
||||
}
|
||||
|
||||
protected function getCreationForm()
|
||||
{
|
||||
return new AdministratorCreationForm($this->getRequest());
|
||||
}
|
||||
|
||||
protected function getUpdateForm()
|
||||
{
|
||||
return new AdministratorModificationForm($this->getRequest());
|
||||
}
|
||||
|
||||
protected function getCreationEvent($formData)
|
||||
{
|
||||
$event = new AdministratorEvent();
|
||||
|
||||
$event->setLogin($formData['login']);
|
||||
$event->setFirstname($formData['firstname']);
|
||||
$event->setLastname($formData['lastname']);
|
||||
$event->setPassword($formData['password']);
|
||||
$event->setProfile($formData['profile'] ? : null);
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
protected function getUpdateEvent($formData)
|
||||
{
|
||||
$event = new AdministratorEvent();
|
||||
|
||||
$event->setId($formData['id']);
|
||||
$event->setLogin($formData['login']);
|
||||
$event->setFirstname($formData['firstname']);
|
||||
$event->setLastname($formData['lastname']);
|
||||
$event->setPassword($formData['password']);
|
||||
$event->setProfile($formData['profile'] ? : null);
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
protected function getDeleteEvent()
|
||||
{
|
||||
$event = new AdministratorEvent();
|
||||
|
||||
$event->setId(
|
||||
$this->getRequest()->get('administrator_id', 0)
|
||||
);
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
protected function eventContainsObject($event)
|
||||
{
|
||||
return $event->hasAdministrator();
|
||||
}
|
||||
|
||||
protected function hydrateObjectForm($object)
|
||||
{
|
||||
$data = array(
|
||||
'id' => $object->getId(),
|
||||
'firstname' => $object->getFirstname(),
|
||||
'lastname' => $object->getLastname(),
|
||||
'login' => $object->getLogin(),
|
||||
'profile' => $object->getProfileId(),
|
||||
);
|
||||
|
||||
// Setup the object form
|
||||
return new AdministratorModificationForm($this->getRequest(), "form", $data);
|
||||
}
|
||||
|
||||
protected function hydrateResourceUpdateForm($object)
|
||||
{
|
||||
$data = array(
|
||||
'id' => $object->getId(),
|
||||
);
|
||||
|
||||
// Setup the object form
|
||||
return new AdministratorUpdateResourceAccessForm($this->getRequest(), "form", $data);
|
||||
}
|
||||
|
||||
protected function hydrateModuleUpdateForm($object)
|
||||
{
|
||||
$data = array(
|
||||
'id' => $object->getId(),
|
||||
);
|
||||
|
||||
// Setup the object form
|
||||
return new AdministratorUpdateModuleAccessForm($this->getRequest(), "form", $data);
|
||||
}
|
||||
|
||||
protected function getObjectFromEvent($event)
|
||||
{
|
||||
return $event->hasAdministrator() ? $event->getAdministrator() : null;
|
||||
}
|
||||
|
||||
protected function getExistingObject()
|
||||
{
|
||||
return AdminQuery::create()
|
||||
->joinWithI18n($this->getCurrentEditionLocale())
|
||||
->findOneById($this->getRequest()->get('administrator_id'));
|
||||
}
|
||||
|
||||
protected function getObjectLabel($object)
|
||||
{
|
||||
return $object->getLogin();
|
||||
}
|
||||
|
||||
protected function getObjectId($object)
|
||||
{
|
||||
return $object->getId();
|
||||
}
|
||||
|
||||
|
||||
protected function renderListTemplate($currentOrder)
|
||||
{
|
||||
// We always return to the feature edition form
|
||||
return $this->render(
|
||||
'administrators',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
protected function renderEditionTemplate()
|
||||
{
|
||||
// We always return to the feature edition form
|
||||
return $this->render('administrators');
|
||||
}
|
||||
|
||||
protected function redirectToEditionTemplate()
|
||||
{
|
||||
// We always return to the feature edition form
|
||||
$this->redirectToListTemplate();
|
||||
}
|
||||
|
||||
protected function performAdditionalCreateAction($updateEvent)
|
||||
{
|
||||
// We always return to the feature edition form
|
||||
$this->redirectToListTemplate();
|
||||
}
|
||||
|
||||
protected function performAdditionalUpdateAction($updateEvent)
|
||||
{
|
||||
// We always return to the feature edition form
|
||||
$this->redirectToListTemplate();
|
||||
}
|
||||
|
||||
protected function redirectToListTemplate()
|
||||
{
|
||||
$this->redirectToRoute(
|
||||
"admin.configuration.administrators.view"
|
||||
);
|
||||
}
|
||||
}
|
||||
120
core/lib/Thelia/Core/Event/Administrator/AdministratorEvent.php
Normal file
120
core/lib/Thelia/Core/Event/Administrator/AdministratorEvent.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event\Administrator;
|
||||
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
use Thelia\Model\Admin;
|
||||
|
||||
class AdministratorEvent extends ActionEvent
|
||||
{
|
||||
protected $administrator = null;
|
||||
protected $id = null;
|
||||
protected $firstname = null;
|
||||
protected $lastname = null;
|
||||
protected $login = null;
|
||||
protected $password = null;
|
||||
protected $profile = null;
|
||||
|
||||
public function __construct(Admin $administrator = null)
|
||||
{
|
||||
$this->administrator = $administrator;
|
||||
}
|
||||
|
||||
public function hasAdministrator()
|
||||
{
|
||||
return ! is_null($this->administrator);
|
||||
}
|
||||
|
||||
public function getAdministrator()
|
||||
{
|
||||
return $this->administrator;
|
||||
}
|
||||
|
||||
public function setAdministrator(Admin $administrator)
|
||||
{
|
||||
$this->administrator = $administrator;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setFirstname($firstname)
|
||||
{
|
||||
$this->firstname = $firstname;
|
||||
}
|
||||
|
||||
public function getFirstname()
|
||||
{
|
||||
return $this->firstname;
|
||||
}
|
||||
|
||||
public function setLastname($lastname)
|
||||
{
|
||||
$this->lastname = $lastname;
|
||||
}
|
||||
|
||||
public function getLastname()
|
||||
{
|
||||
return $this->lastname;
|
||||
}
|
||||
|
||||
public function setLogin($login)
|
||||
{
|
||||
$this->login = $login;
|
||||
}
|
||||
|
||||
public function getLogin()
|
||||
{
|
||||
return $this->login;
|
||||
}
|
||||
|
||||
public function setPassword($password)
|
||||
{
|
||||
$this->password = $password;
|
||||
}
|
||||
|
||||
public function getPassword()
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
public function setProfile($profile)
|
||||
{
|
||||
$this->profile = $profile;
|
||||
}
|
||||
|
||||
public function getProfile()
|
||||
{
|
||||
return $this->profile;
|
||||
}
|
||||
}
|
||||
@@ -555,6 +555,12 @@ final class TheliaEvents
|
||||
const PROFILE_RESOURCE_ACCESS_UPDATE = "action.updateProfileResourceAccess";
|
||||
const PROFILE_MODULE_ACCESS_UPDATE = "action.updateProfileModuleAccess";
|
||||
|
||||
// -- Administrator management ---------------------------------------------
|
||||
|
||||
const ADMINISTRATOR_CREATE = "action.createAdministrator";
|
||||
const ADMINISTRATOR_UPDATE = "action.updateAdministrator";
|
||||
const ADMINISTRATOR_DELETE = "action.deleteAdministrator";
|
||||
|
||||
// -- Tax Rules management ---------------------------------------------
|
||||
|
||||
const TAX_RULE_CREATE = "action.createTaxRule";
|
||||
|
||||
@@ -37,16 +37,16 @@ final class AdminResources
|
||||
|
||||
static public function retrieve($name)
|
||||
{
|
||||
$contantName = strtoupper($name);
|
||||
$constantName = strtoupper($name);
|
||||
|
||||
if(null === self::$selfReflection) {
|
||||
self::$selfReflection = new \ReflectionClass(__CLASS__);
|
||||
}
|
||||
|
||||
if(self::$selfReflection->hasConstant($contantName)) {
|
||||
return self::$selfReflection->getConstant($contantName);
|
||||
if(self::$selfReflection->hasConstant($constantName)) {
|
||||
return self::$selfReflection->getConstant($constantName);
|
||||
} else {
|
||||
throw new ResourceException(sprintf('Resource `%s` not found', $contantName), ResourceException::RESOURCE_NOT_FOUND);
|
||||
throw new ResourceException(sprintf('Resource `%s` not found', $constantName), ResourceException::RESOURCE_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ final class AdminResources
|
||||
|
||||
const ADDRESS = "admin.address";
|
||||
|
||||
const ADMIN = "admin.configuration.admin";
|
||||
const ADMINISTRATOR = "admin.configuration.administrator";
|
||||
|
||||
const AREA = "admin.configuration.area";
|
||||
|
||||
|
||||
138
core/lib/Thelia/Form/AdministratorCreationForm.php
Normal file
138
core/lib/Thelia/Form/AdministratorCreationForm.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Form;
|
||||
|
||||
use Symfony\Component\Validator\Constraints;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Symfony\Component\Validator\ExecutionContextInterface;
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Model\AdminQuery;
|
||||
use Thelia\Model\ProfileQuery;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
|
||||
class AdministratorCreationForm extends BaseForm
|
||||
{
|
||||
const PROFILE_FIELD_PREFIX = "profile";
|
||||
|
||||
protected function buildForm()
|
||||
{
|
||||
$this->formBuilder
|
||||
->add("login", "text", array(
|
||||
"constraints" => array(
|
||||
new Constraints\NotBlank(),
|
||||
new Constraints\Callback(array(
|
||||
"methods" => array(
|
||||
array($this, "verifyExistingLogin"),
|
||||
)
|
||||
)),
|
||||
),
|
||||
"label" => Translator::getInstance()->trans("Login"),
|
||||
"label_attr" => array(
|
||||
"for" => "login"
|
||||
),
|
||||
))
|
||||
->add("firstname", "text", array(
|
||||
"constraints" => array(
|
||||
new Constraints\NotBlank()
|
||||
),
|
||||
"label" => Translator::getInstance()->trans("First Name"),
|
||||
"label_attr" => array(
|
||||
"for" => "firstname"
|
||||
),
|
||||
))
|
||||
->add("lastname", "text", array(
|
||||
"constraints" => array(
|
||||
new Constraints\NotBlank()
|
||||
),
|
||||
"label" => Translator::getInstance()->trans("Last Name"),
|
||||
"label_attr" => array(
|
||||
"for" => "lastname"
|
||||
)
|
||||
))
|
||||
->add("password", "password", array(
|
||||
"constraints" => array(),
|
||||
"label" => Translator::getInstance()->trans("Password"),
|
||||
"label_attr" => array(
|
||||
"for" => "password"
|
||||
),
|
||||
))
|
||||
->add("password_confirm", "password", array(
|
||||
"constraints" => array(
|
||||
new Constraints\Callback(array("methods" => array(
|
||||
array($this, "verifyPasswordField")
|
||||
)))
|
||||
),
|
||||
"label" => "Password confirmation",
|
||||
"label_attr" => array(
|
||||
"for" => "password_confirmation"
|
||||
),
|
||||
))
|
||||
->add(
|
||||
'profile',
|
||||
"choice",
|
||||
array(
|
||||
"choices" => ProfileQuery::getProfileList(),
|
||||
"constraints" => array(
|
||||
new Constraints\NotBlank(),
|
||||
),
|
||||
"label" => "Profile",
|
||||
"label_attr" => array(
|
||||
"for" => "profile"
|
||||
),
|
||||
)
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
public function verifyPasswordField($value, ExecutionContextInterface $context)
|
||||
{
|
||||
$data = $context->getRoot()->getData();
|
||||
|
||||
if($data["password"] === '' && $data["password_confirm"] === '') {
|
||||
$context->addViolation("password can't be empty");
|
||||
}
|
||||
|
||||
if ($data["password"] != $data["password_confirm"]) {
|
||||
$context->addViolation("password confirmation is not the same as password field");
|
||||
}
|
||||
|
||||
if(strlen($data["password"]) < 4) {
|
||||
$context->addViolation("password must be composed of at least 4 characters");
|
||||
}
|
||||
}
|
||||
|
||||
public function verifyExistingLogin($value, ExecutionContextInterface $context)
|
||||
{
|
||||
$administrator = AdminQuery::create()->findOneByLogin($value);
|
||||
if ($administrator !== null) {
|
||||
$context->addViolation("This login already exists");
|
||||
}
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return "thelia_admin_administrator_creation";
|
||||
}
|
||||
}
|
||||
84
core/lib/Thelia/Form/AdminProfileCreationForm.php → core/lib/Thelia/Form/AdministratorModificationForm.php
Normal file → Executable file
84
core/lib/Thelia/Form/AdminProfileCreationForm.php → core/lib/Thelia/Form/AdministratorModificationForm.php
Normal file → Executable file
@@ -4,7 +4,7 @@
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
@@ -20,46 +20,78 @@
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Form;
|
||||
|
||||
use Symfony\Component\Validator\Constraints;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Symfony\Component\Validator\ExecutionContextInterface;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Model\AdminQuery;
|
||||
|
||||
class AdminProfileCreationForm extends BaseForm
|
||||
class AdministratorModificationForm extends AdministratorCreationForm
|
||||
{
|
||||
protected function buildForm()
|
||||
{
|
||||
parent::buildForm();
|
||||
|
||||
$this->formBuilder
|
||||
->add("wording" , "text" , array(
|
||||
->add("id", "hidden", array(
|
||||
"required" => true,
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
new Constraints\NotBlank(),
|
||||
new Constraints\Callback(
|
||||
array(
|
||||
"methods" => array(
|
||||
array($this, "verifyAdministratorId"),
|
||||
),
|
||||
)
|
||||
),
|
||||
),
|
||||
"label" => Translator::getInstance()->trans("Wording *"),
|
||||
"label_attr" => array(
|
||||
"for" => "wording"
|
||||
))
|
||||
)
|
||||
->add("name" , "text" , array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
"attr" => array(
|
||||
"id" => "administrator_update_id",
|
||||
),
|
||||
"label" => Translator::getInstance()->trans("Name *"),
|
||||
"label_attr" => array(
|
||||
"for" => "name"
|
||||
))
|
||||
)
|
||||
->add("description" , "text" , array(
|
||||
"label" => Translator::getInstance()->trans("Description"),
|
||||
"label_attr" => array(
|
||||
"for" => "description"
|
||||
))
|
||||
)
|
||||
))
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the name of you form. This name must be unique
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return "thelia_admin_profile_creation";
|
||||
return "thelia_admin_administrator_modification";
|
||||
}
|
||||
}
|
||||
|
||||
public function verifyAdministratorId($value, ExecutionContextInterface $context)
|
||||
{
|
||||
$administrator = AdminQuery::create()
|
||||
->findPk($value);
|
||||
|
||||
if (null === $administrator) {
|
||||
$context->addViolation("Administrator ID not found");
|
||||
}
|
||||
}
|
||||
|
||||
public function verifyExistingLogin($value, ExecutionContextInterface $context)
|
||||
{
|
||||
$data = $context->getRoot()->getData();
|
||||
|
||||
$administrator = AdminQuery::create()->findOneByLogin($value);
|
||||
if ($administrator !== null && $administrator->getId() != $data['id']) {
|
||||
$context->addViolation("This login already exists");
|
||||
}
|
||||
}
|
||||
|
||||
public function verifyPasswordField($value, ExecutionContextInterface $context)
|
||||
{
|
||||
$data = $context->getRoot()->getData();
|
||||
|
||||
if ($data["password"] != $data["password_confirm"]) {
|
||||
$context->addViolation("password confirmation is not the same as password field");
|
||||
}
|
||||
|
||||
if($data["password"] !== '' && strlen($data["password"]) < 4) {
|
||||
$context->addViolation("password must be composed of at least 4 characters");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -71,7 +71,6 @@ class ProfileUpdateModuleAccessForm extends BaseForm
|
||||
"attr" => array(
|
||||
"tag" => "modules",
|
||||
"module_code" => $module->getCode(),
|
||||
"module_title" => $module->getTitle(),
|
||||
),
|
||||
"multiple" => true,
|
||||
"constraints" => array(
|
||||
|
||||
@@ -71,7 +71,6 @@ class ProfileUpdateResourceAccessForm extends BaseForm
|
||||
"attr" => array(
|
||||
"tag" => "resources",
|
||||
"resource_code" => $resource->getCode(),
|
||||
"resource_title" => $resource->getTitle(),
|
||||
),
|
||||
"multiple" => true,
|
||||
"constraints" => array(
|
||||
|
||||
@@ -10,6 +10,7 @@ use Thelia\Core\Security\Role\Role;
|
||||
|
||||
use Thelia\Model\Base\Admin as BaseAdmin;
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
use Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
|
||||
/**
|
||||
* Skeleton subclass for representing a row from the 'admin' table.
|
||||
@@ -24,6 +25,8 @@ use Propel\Runtime\Connection\ConnectionInterface;
|
||||
*/
|
||||
class Admin extends BaseAdmin implements UserInterface
|
||||
{
|
||||
use ModelEventDispatcherTrait;
|
||||
|
||||
public function getPermissions()
|
||||
{
|
||||
$profileId = $this->getProfileId();
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Thelia\Model\Base\ProfileQuery as BaseProfileQuery;
|
||||
|
||||
|
||||
@@ -17,5 +18,14 @@ use Thelia\Model\Base\ProfileQuery as BaseProfileQuery;
|
||||
*/
|
||||
class ProfileQuery extends BaseProfileQuery
|
||||
{
|
||||
|
||||
public static function getProfileList()
|
||||
{
|
||||
$profileList = array(
|
||||
0 => AdminResources::SUPERADMINISTRATOR,
|
||||
);
|
||||
foreach(ProfileQuery::create()->find() as $profile) {
|
||||
$profileList[$profile->getId()] = $profile->getCode();
|
||||
}
|
||||
return $profileList;
|
||||
}
|
||||
} // ProfileQuery
|
||||
|
||||
Reference in New Issue
Block a user