Completed the backoffice variable management
This commit is contained in:
@@ -49,34 +49,4 @@ class BaseAction
|
||||
{
|
||||
return $this->container->get('event_dispatcher');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check current user authorisations.
|
||||
*
|
||||
* @param mixed $roles a single role or an array of roles.
|
||||
* @param mixed $permissions a single permission or an array of permissions.
|
||||
*
|
||||
* @throws AuthenticationException if permissions are not granted to the current user.
|
||||
*/
|
||||
protected function checkAuth($roles, $permissions) {
|
||||
|
||||
if (! $this->getSecurityContext()->isGranted(
|
||||
is_array($roles) ? $roles : array($roles),
|
||||
is_array($permissions) ? $permissions : array($permissions)) ) {
|
||||
|
||||
Tlog::getInstance()->addAlert("Authorization roles:", $roles, " permissions:", $permissions, " refused.");
|
||||
|
||||
throw new AuthorizationException("Sorry, you're not allowed to perform this action");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the security context
|
||||
*
|
||||
* @return Thelia\Core\Security\SecurityContext
|
||||
*/
|
||||
protected function getSecurityContext()
|
||||
{
|
||||
return $this->container->get('thelia.securityContext');
|
||||
}
|
||||
}
|
||||
@@ -42,8 +42,6 @@ class Category extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
public function create(CategoryCreateEvent $event)
|
||||
{
|
||||
$this->checkAuth("ADMIN", "admin.category.create");
|
||||
|
||||
$category = new CategoryModel();
|
||||
|
||||
$category
|
||||
@@ -57,9 +55,6 @@ class Category extends BaseAction implements EventSubscriberInterface
|
||||
|
||||
public function modify(CategoryChangeEvent $event)
|
||||
{
|
||||
$this->checkAuth("ADMIN", "admin.category.change");
|
||||
|
||||
// TODO !!
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,8 +64,6 @@ class Category extends BaseAction implements EventSubscriberInterface
|
||||
*/
|
||||
public function delete(CategoryDeleteEvent $event)
|
||||
{
|
||||
$this->checkAuth("ADMIN", "admin.category.delete");
|
||||
|
||||
$category = CategoryQuery::create()->findPk($event->getCategoryId());
|
||||
|
||||
if ($category !== null) {
|
||||
@@ -86,8 +79,6 @@ class Category extends BaseAction implements EventSubscriberInterface
|
||||
*/
|
||||
public function toggleVisibility(CategoryToggleVisibilityEvent $event)
|
||||
{
|
||||
$this->checkAuth("ADMIN", "admin.category.edit");
|
||||
|
||||
$category = CategoryQuery::create()->findPk($event->getCategoryId());
|
||||
|
||||
if ($category !== null) {
|
||||
@@ -107,8 +98,6 @@ class Category extends BaseAction implements EventSubscriberInterface
|
||||
*/
|
||||
public function changePosition(CategoryChangePositionEvent $event)
|
||||
{
|
||||
$this->checkAuth("ADMIN", "admin.category.edit");
|
||||
|
||||
if ($event->getMode() == CategoryChangePositionEvent::POSITION_ABSOLUTE)
|
||||
return $this->changeAbsolutePosition($event);
|
||||
else
|
||||
@@ -177,8 +166,6 @@ class Category extends BaseAction implements EventSubscriberInterface
|
||||
*/
|
||||
protected function changeAbsolutePosition(CategoryChangePositionEvent $event)
|
||||
{
|
||||
$this->checkAuth("ADMIN", "admin.category.edit");
|
||||
|
||||
$category = CategoryQuery::create()->findPk($event->getCategoryId());
|
||||
|
||||
if ($category !== null) {
|
||||
|
||||
@@ -44,26 +44,20 @@ class Config extends BaseAction implements EventSubscriberInterface
|
||||
*/
|
||||
public function create(ConfigCreateEvent $event)
|
||||
{
|
||||
$this->checkAuth("ADMIN", "admin.configuration.variables.create");
|
||||
|
||||
$config = new ConfigModel();
|
||||
|
||||
$config
|
||||
->setDispatcher($this->getDispatcher())
|
||||
|
||||
->setName($event->getName())
|
||||
->setName($event->getEventName())
|
||||
->setValue($event->getValue())
|
||||
->setHidden($evetn->getHidden())
|
||||
->setSecured($event->getSecured())
|
||||
|
||||
->setLocale($event->getLocale())
|
||||
->setTitle($event->getTitle())
|
||||
->setDescription($event->getDescription())
|
||||
->setChapo($event->getChapo())
|
||||
->setPostscriptum($event->getPostscriptum())
|
||||
|
||||
->save()
|
||||
;
|
||||
|
||||
$event->setConfig($config);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,17 +67,20 @@ class Config extends BaseAction implements EventSubscriberInterface
|
||||
*/
|
||||
public function setValue(ConfigChangeEvent $event)
|
||||
{
|
||||
$this->checkAuth("ADMIN", "admin.configuration.variables.change");
|
||||
|
||||
$search = ConfigQuery::create();
|
||||
|
||||
if (null !== $config = $search->findOneById($event->getConfigId())) {
|
||||
if (null !== $config = $search->findOneById($event->getConfigId())
|
||||
&&
|
||||
$event->getValue() != $config->getValue()) {
|
||||
|
||||
$config
|
||||
->setDispatcher($this->getDispatcher())
|
||||
|
||||
->setValue($event->getValue())
|
||||
->save()
|
||||
;
|
||||
|
||||
$event->setConfig($config);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,8 +91,6 @@ class Config extends BaseAction implements EventSubscriberInterface
|
||||
*/
|
||||
public function modify(ConfigChangeEvent $event)
|
||||
{
|
||||
$this->checkAuth("ADMIN", "admin.configuration.variables.change");
|
||||
|
||||
$search = ConfigQuery::create();
|
||||
|
||||
if (null !== $config = ConfigQuery::create()->findOneById($event->getConfigId())) {
|
||||
@@ -103,9 +98,9 @@ class Config extends BaseAction implements EventSubscriberInterface
|
||||
$config
|
||||
->setDispatcher($this->getDispatcher())
|
||||
|
||||
->setName($event->getName())
|
||||
->setName($event->getEventName())
|
||||
->setValue($event->getValue())
|
||||
->setHidden($evetn->getHidden())
|
||||
->setHidden($event->getHidden())
|
||||
->setSecured($event->getSecured())
|
||||
|
||||
->setLocale($event->getLocale())
|
||||
@@ -115,6 +110,8 @@ class Config extends BaseAction implements EventSubscriberInterface
|
||||
->setPostscriptum($event->getPostscriptum())
|
||||
|
||||
->save();
|
||||
|
||||
$event->setConfig($config);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,22 +122,22 @@ class Config extends BaseAction implements EventSubscriberInterface
|
||||
*/
|
||||
public function delete(ConfigDeleteEvent $event)
|
||||
{
|
||||
$this->checkAuth("ADMIN", "admin.configuration.variables.delete");
|
||||
|
||||
if (null !== ($config = ConfigQuery::create()->findOneById($event->getConfigId()))) {
|
||||
|
||||
if (! $config->getSecured()) {
|
||||
$config->setDispatcher($this->getDispatcher());
|
||||
$config->delete();
|
||||
|
||||
$config
|
||||
->setDispatcher($this->getDispatcher())
|
||||
->delete()
|
||||
;
|
||||
|
||||
$event->setConfig($config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of event names this subscriber listens to.
|
||||
*
|
||||
* @return array The event names to listen to
|
||||
*
|
||||
* @api
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
|
||||
@@ -109,6 +109,16 @@ class Customer extends BaseAction implements EventSubscriberInterface
|
||||
// TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the security context
|
||||
*
|
||||
* @return Thelia\Core\Security\SecurityContext
|
||||
*/
|
||||
protected function getSecurityContext()
|
||||
{
|
||||
return $this->container->get('thelia.securityContext');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of event names this subscriber wants to listen to.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user