administrators management

This commit is contained in:
Etienne Roudeix
2013-10-23 16:31:37 +02:00
parent 3c69e38a3b
commit fb8b82093a
16 changed files with 1033 additions and 46 deletions

View 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),
);
}
}

View File

@@ -28,6 +28,7 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Thelia\Command\ContainerAwareCommand; use Thelia\Command\ContainerAwareCommand;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Model\Admin; use Thelia\Model\Admin;
use Thelia\Model\Map\ResourceI18nTableMap; use Thelia\Model\Map\ResourceI18nTableMap;
use Thelia\Model\Map\ResourceTableMap; use Thelia\Model\Map\ResourceTableMap;
@@ -72,7 +73,7 @@ class GenerateResources extends ContainerAwareCommand
); );
$compteur = 0; $compteur = 0;
foreach($constants as $constant => $value) { foreach($constants as $constant => $value) {
if($constant == 'SUPERADMINISTRATOR') { if($constant == AdminResources::SUPERADMINISTRATOR) {
continue; continue;
} }
$compteur++; $compteur++;
@@ -87,7 +88,7 @@ class GenerateResources extends ContainerAwareCommand
); );
$compteur = 0; $compteur = 0;
foreach($constants as $constant => $value) { foreach($constants as $constant => $value) {
if($constant == 'SUPERADMINISTRATOR') { if($constant == AdminResources::SUPERADMINISTRATOR) {
continue; continue;
} }
@@ -105,7 +106,7 @@ class GenerateResources extends ContainerAwareCommand
break; break;
default : default :
foreach($constants as $constant => $value) { foreach($constants as $constant => $value) {
if($constant == 'SUPERADMINISTRATOR') { if($constant == AdminResources::SUPERADMINISTRATOR) {
continue; continue;
} }
$output->writeln('[' . $constant . "] => " . $value); $output->writeln('[' . $constant . "] => " . $value);

View File

@@ -156,6 +156,11 @@
<tag name="kernel.event_subscriber"/> <tag name="kernel.event_subscriber"/>
</service> </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"> <service id="thelia.action.newsletter" class="Thelia\Action\Newsletter">
<argument type="service" id="service_container"/> <argument type="service" id="service_container"/>
<tag name="kernel.event_subscriber"/> <tag name="kernel.event_subscriber"/>

View File

@@ -133,6 +133,9 @@
<form name="thelia.admin.profile.resource-access.modification" class="Thelia\Form\ProfileUpdateResourceAccessForm"/> <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.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.creation" class="Thelia\Form\TemplateCreationForm"/>
<form name="thelia.admin.template.modification" class="Thelia\Form\TemplateModificationForm"/> <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.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.create" class="Thelia\Form\Area\AreaCreateForm"/>
<form name="thelia.admin.area.modification" class="Thelia\Form\Area\AreaModificationForm"/> <form name="thelia.admin.area.modification" class="Thelia\Form\Area\AreaModificationForm"/>
<form name="thelia.admin.area.country" class="Thelia\Form\Area\AreaCountryForm"/> <form name="thelia.admin.area.country" class="Thelia\Form\Area\AreaCountryForm"/>

View File

@@ -24,13 +24,6 @@
<default key="_controller">Thelia\Controller\Admin\SessionController::checkLoginAction</default> <default key="_controller">Thelia\Controller\Admin\SessionController::checkLoginAction</default>
</route> </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 to the catalog controller -->
<route id="admin.catalog" path="/admin/catalog"> <route id="admin.catalog" path="/admin/catalog">
@@ -791,6 +784,26 @@
<!-- end profiles management --> <!-- 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 --> <!-- feature and features value management -->
<route id="admin.configuration.features.default" path="/admin/configuration/features"> <route id="admin.configuration.features.default" path="/admin/configuration/features">

View 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"
);
}
}

View 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;
}
}

View File

@@ -555,6 +555,12 @@ final class TheliaEvents
const PROFILE_RESOURCE_ACCESS_UPDATE = "action.updateProfileResourceAccess"; const PROFILE_RESOURCE_ACCESS_UPDATE = "action.updateProfileResourceAccess";
const PROFILE_MODULE_ACCESS_UPDATE = "action.updateProfileModuleAccess"; 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 --------------------------------------------- // -- Tax Rules management ---------------------------------------------
const TAX_RULE_CREATE = "action.createTaxRule"; const TAX_RULE_CREATE = "action.createTaxRule";

View File

@@ -37,16 +37,16 @@ final class AdminResources
static public function retrieve($name) static public function retrieve($name)
{ {
$contantName = strtoupper($name); $constantName = strtoupper($name);
if(null === self::$selfReflection) { if(null === self::$selfReflection) {
self::$selfReflection = new \ReflectionClass(__CLASS__); self::$selfReflection = new \ReflectionClass(__CLASS__);
} }
if(self::$selfReflection->hasConstant($contantName)) { if(self::$selfReflection->hasConstant($constantName)) {
return self::$selfReflection->getConstant($contantName); return self::$selfReflection->getConstant($constantName);
} else { } 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 ADDRESS = "admin.address";
const ADMIN = "admin.configuration.admin"; const ADMINISTRATOR = "admin.configuration.administrator";
const AREA = "admin.configuration.area"; const AREA = "admin.configuration.area";

View 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";
}
}

View File

@@ -20,46 +20,78 @@
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */ /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */ /* */
/*************************************************************************************/ /*************************************************************************************/
namespace Thelia\Form; namespace Thelia\Form;
use Symfony\Component\Validator\Constraints; use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Constraints\NotBlank; use Symfony\Component\Validator\ExecutionContextInterface;
use Thelia\Core\Translation\Translator; use Thelia\Core\Translation\Translator;
use Thelia\Model\AdminQuery;
class AdminProfileCreationForm extends BaseForm class AdministratorModificationForm extends AdministratorCreationForm
{ {
protected function buildForm() protected function buildForm()
{ {
parent::buildForm();
$this->formBuilder $this->formBuilder
->add("wording" , "text" , array( ->add("id", "hidden", array(
"required" => true,
"constraints" => array( "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()
), ),
"label" => Translator::getInstance()->trans("Name *"), ),
"label_attr" => array( "attr" => array(
"for" => "name" "id" => "administrator_update_id",
),
)) ))
)
->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() 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");
}
} }
} }

View File

@@ -71,7 +71,6 @@ class ProfileUpdateModuleAccessForm extends BaseForm
"attr" => array( "attr" => array(
"tag" => "modules", "tag" => "modules",
"module_code" => $module->getCode(), "module_code" => $module->getCode(),
"module_title" => $module->getTitle(),
), ),
"multiple" => true, "multiple" => true,
"constraints" => array( "constraints" => array(

View File

@@ -71,7 +71,6 @@ class ProfileUpdateResourceAccessForm extends BaseForm
"attr" => array( "attr" => array(
"tag" => "resources", "tag" => "resources",
"resource_code" => $resource->getCode(), "resource_code" => $resource->getCode(),
"resource_title" => $resource->getTitle(),
), ),
"multiple" => true, "multiple" => true,
"constraints" => array( "constraints" => array(

View File

@@ -10,6 +10,7 @@ use Thelia\Core\Security\Role\Role;
use Thelia\Model\Base\Admin as BaseAdmin; use Thelia\Model\Base\Admin as BaseAdmin;
use Propel\Runtime\Connection\ConnectionInterface; use Propel\Runtime\Connection\ConnectionInterface;
use Thelia\Model\Tools\ModelEventDispatcherTrait;
/** /**
* Skeleton subclass for representing a row from the 'admin' table. * 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 class Admin extends BaseAdmin implements UserInterface
{ {
use ModelEventDispatcherTrait;
public function getPermissions() public function getPermissions()
{ {
$profileId = $this->getProfileId(); $profileId = $this->getProfileId();

View File

@@ -2,6 +2,7 @@
namespace Thelia\Model; namespace Thelia\Model;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Model\Base\ProfileQuery as BaseProfileQuery; use Thelia\Model\Base\ProfileQuery as BaseProfileQuery;
@@ -17,5 +18,14 @@ use Thelia\Model\Base\ProfileQuery as BaseProfileQuery;
*/ */
class ProfileQuery extends 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 } // ProfileQuery

View File

@@ -0,0 +1,351 @@
{extends file="admin-layout.tpl"}
{block name="page-title"}{intl l='Taxes rules'}{/block}
{block name="check-resource"}admin.configuration.administrator{/block}
{block name="check-access"}view{/block}
{block name="main-content"}
<div>
<div id="wrapper" class="container">
<div class="clearfix">
<ul class="breadcrumb">
<li><a href="{url path='/admin/home'}">{intl l="Home"}</a></li>
<li><a href="{url path='/admin/configuration'}">{intl l="Configuration"}</a></li>
<li><a href="{url path='/admin/configuration/administrators'}">{intl l="Administrators"}</a></li>
</ul>
</div>
{module_include location='administrators_top'}
<div class="row">
<div class="col-md-12">
<div class="general-block-decorator">
<div class="table-responsive">
<table class="table table-striped table-condensed table-left-aligned">
<caption class="clearfix">
{intl l="Taxes"}
{loop type="auth" name="can_create" role="ADMIN" resource="admin.administrator" access="CREATE"}
<a class="btn btn-default btn-primary pull-right" title="{intl l='Create a new administrator'}" href="#administrator_create_dialog" data-toggle="modal">
<span class="glyphicon glyphicon-plus"></span>
</a>
{/loop}
</caption>
<thead>
<tr>
<th>{intl l="Login"}</th>
<th>{intl l="FirstName"}</th>
<th>{intl l="LastName"}</th>
<th>{intl l="Profile"}</th>
<th class="col-md-1">{intl l="Actions"}</th>
</tr>
</thead>
<tbody>
{loop type="admin" name="administrators" backend_context="1"}
<tr>
<td data-field-class="js-login">{$LOGIN}</td>
<td data-field-class="js-firstname">{$FIRSTNAME}</td>
<td data-field-class="js-lastname">{$LASTNAME}</td>
<td data-field-class="js-profile" data-value="{$PROFILE}">
{if $PROFILE}
{loop type="profile" name="admin-profile" id=$PROFILE}
{$TITLE}
{/loop}
{else}
{intl l='Superadministrator'}
{/if}
</td>
<td>
<div class="btn-group">
{loop type="auth" name="can_change" role="ADMIN" resource="admin.configuration.administrator" access="UPDATE"}
<a class="btn btn-default btn-xs js-update-administrator" title="{intl l='Change this administrator'}" href="#administrator_update_dialog" data-id="{$ID}" data-toggle="modal"><span class="glyphicon glyphicon-edit"></span></a>
{/loop}
{loop type="auth" name="can_delete" role="ADMIN" resource="admin.configuration.administrator" access="DELETE"}
<a class="btn btn-default btn-xs js-delete-administrator" title="{intl l='Delete this administrator'}" href="#administrator_delete_dialog" data-id="{$ID}" data-toggle="modal"><span class="glyphicon glyphicon-trash"></span></a>
{/loop}
</div>
</td>
</tr>
{/loop}
</tbody>
</table>
</div>
</div>
</div>
</div>
{module_include location='administrators_bottom'}
</div>
</div>
{* -- Add administrator confirmation dialog ----------------------------------- *}
{form name="thelia.admin.administrator.add"}
{if $form_error_message}
{$administratorCreateError = true}
{else}
{$administratorCreateError = false}
{/if}
{* Capture the dialog body, to pass it to the generic dialog *}
{capture "administrator_create_dialog"}
{form_hidden_fields form=$form}
{form_field form=$form field='login'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{intl l=$label} : </label>
<input type="text" id="{$label_attr.for}" name="{$name}" required="required" title="{intl l='Login'}" placeholder="{intl l='Login'}" class="form-control" value="{if $form_error}{$value}{/if}">
</div>
{/form_field}
{form_field form=$form field='firstname'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{intl l=$label} : </label>
<input type="text" id="{$label_attr.for}" name="{$name}" required="required" title="{intl l='FirstName'}" placeholder="{intl l='FirstName'}" class="form-control" value="{if $form_error}{$value}{/if}">
</div>
{/form_field}
{form_field form=$form field='lastname'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{intl l=$label} : </label>
<input type="text" id="{$label_attr.for}" name="{$name}" required="required" title="{intl l='LastName'}" placeholder="{intl l='LastName'}" class="form-control" value="{if $form_error}{$value}{/if}">
</div>
{/form_field}
{form_field form=$form field='password_confirm'}
{$passwordError = $error}
{/form_field}
{form_field form=$form field='password'}
<div class="form-group {if $passwordError}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{intl l=$label} : </label>
<input type="password" id="{$label_attr.for}" name="{$name}" required="required" title="{intl l='Password'}" class="form-control">
</div>
{/form_field}
{form_field form=$form field='password_confirm'}
<div class="form-group {if $passwordError}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{intl l=$label} : </label>
<input type="password" id="{$label_attr.for}" name="{$name}" required="required" title="{intl l='Password'}" class="form-control">
</div>
{/form_field}
{form_field form=$form field='profile'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{intl l=$label} : </label>
<select id="{$label_attr.for}" name="{$name}" required="required" data-toggle="selectpicker">
{foreach $choices as $choice}
{if $choice->value == 0}
<option value="0">{intl l='Superadministrator'}</option>
{else}
{loop name='profile' type="profile" id=$choice->value}
<option value="{$ID}">{$TITLE}</option>
{/loop}
{/if}
{/foreach}
</select>
</div>
{/form_field}
{/capture}
{include
file = "includes/generic-create-dialog.html"
dialog_id = "administrator_create_dialog"
dialog_title = {intl l="Create a new administrator"}
dialog_body = {$smarty.capture.administrator_create_dialog nofilter}
dialog_ok_label = {intl l="Create"}
dialog_cancel_label = {intl l="Cancel"}
form_action = {url path="/admin/configuration/administrators/add"}
form_enctype = {form_enctype form=$form}
form_error_message = $form_error_message
}
{/form}
{* -- Update administrator confirmation dialog ----------------------------------- *}
{form name="thelia.admin.administrator.update"}
{if $form_error_message}
{$administratorUpdateError = true}
{else}
{$administratorUpdateError = false}
{/if}
{* Capture the dialog body, to pass it to the generic dialog *}
{capture "administrator_update_dialog"}
{form_hidden_fields form=$form}
{form_field form=$form field='login'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{intl l=$label} : </label>
<input type="text" id="{$label_attr.for}" name="{$name}" required="required" title="{intl l='Login'}" placeholder="{intl l='Login'}" class="form-control js-login" value="{if $form_error}{$value}{/if}">
</div>
{/form_field}
{form_field form=$form field='firstname'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{intl l=$label} : </label>
<input type="text" id="{$label_attr.for}" name="{$name}" required="required" title="{intl l='FirstName'}" placeholder="{intl l='FirstName'}" class="form-control js-firstname" value="{if $form_error}{$value}{/if}">
</div>
{/form_field}
{form_field form=$form field='lastname'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{intl l=$label} : </label>
<input type="text" id="{$label_attr.for}" name="{$name}" required="required" title="{intl l='LastName'}" placeholder="{intl l='LastName'}" class="form-control js-lastname" value="{if $form_error}{$value}{/if}">
</div>
{/form_field}
{form_field form=$form field='password_confirm'}
{$passwordError = $error}
{/form_field}
{form_field form=$form field='password'}
<div class="form-group {if $passwordError}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{intl l=$label} : </label>
<input type="password" id="{$label_attr.for}" name="{$name}" title="{intl l='Password'}" placeholder="{intl l='Leave empty to keep current password'}" class="form-control">
</div>
{/form_field}
{form_field form=$form field='password_confirm'}
<div class="form-group {if $passwordError}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{intl l=$label} : </label>
<input type="password" id="{$label_attr.for}" name="{$name}" title="{intl l='Password'}" placeholder="{intl l='Leave empty to keep current password'}" class="form-control">
</div>
{/form_field}
{form_field form=$form field='profile'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{intl l=$label} : </label>
<select id="{$label_attr.for}" name="{$name}" required="required" data-toggle="selectpicker" class="js-profile">
{foreach $choices as $choice}
{if $choice->value == 0}
<option value="0">{intl l='Superadministrator'}</option>
{else}
{loop name='profile' type="profile" id=$choice->value}
<option value="{$ID}">{$TITLE}</option>
{/loop}
{/if}
{/foreach}
</select>
</div>
{/form_field}
{/capture}
{include
file = "includes/generic-create-dialog.html"
dialog_id = "administrator_update_dialog"
dialog_title = {intl l="Update a new administrator"}
dialog_body = {$smarty.capture.administrator_update_dialog nofilter}
dialog_ok_label = {intl l="Update"}
dialog_cancel_label = {intl l="Cancel"}
form_action = {url path="/admin/configuration/administrators/save"}
form_enctype = {form_enctype form=$form}
form_error_message = $form_error_message
}
{/form}
{* -- Delete administrator confirmation dialog ----------------------------------- *}
{capture "administrator_delete_dialog"}
<input type="hidden" name="administrator_id" id="administrator_delete_id" value="" />
{module_include location='administrator_delete_form'}
{/capture}
{include
file = "includes/generic-confirm-dialog.html"
dialog_id = "administrator_delete_dialog"
dialog_title = {intl l="Delete administrator"}
dialog_message = {intl l="Do you really want to delete this administrator ?"}
form_action = {url path='/admin/configuration/administrators/delete'}
form_content = {$smarty.capture.administrator_delete_dialog nofilter}
}
{include
file = "includes/generic-warning-dialog.html"
dialog_id = "administrator_cannot_delete_dialog"
dialog_title = {intl l="You can't delete this administrator"}
dialog_body = {intl l="They are some administrator which are linked to this administrator. Please edit/remove them before deleting this administrator."}
}
{/block}
{block name="javascript-initialization"}
{javascripts file='assets/js/bootstrap-select/bootstrap-select.js'}
<script src='{$asset_url}'></script>
{/javascripts}
{javascripts file='assets/js/main.js'}
<script src='{$asset_url}'></script>
{/javascripts}
<script type="text/javascript">
jQuery(function($) {
{if $administratorCreateError == true}
$('#administrator_create_dialog').modal();
{/if}
{if $administratorUpdateError == true}
$('#administrator_update_dialog').modal();
{/if}
$(".js-delete-administrator").click(function(e){
$('#administrator_delete_id').val($(this).data('id'))
});
$(".js-update-administrator").click(function(e){
$('#administrator_update_id').val($(this).data('id'))
$(this).parents('tr').find('td').each(function(k, v) {
if(!$(v).data('field-class')) {
return true;
}
if($(v).data('value')) {
var fieldValue = $(v).data('value');
} else {
var fieldValue = $(v).text();
}
$('.' + $(v).data('field-class')).val(fieldValue);
if($('.' + $(v).data('field-class')).is('select')) {
$('.' + $(v).data('field-class')).selectpicker('refresh');
}
});
});
})
</script>
{/block}