change http code status on different context
This commit is contained in:
@@ -97,14 +97,17 @@ class BaseAdminController extends BaseController
|
|||||||
*
|
*
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
*/
|
*/
|
||||||
protected function errorPage($message)
|
protected function errorPage($message, $status = 500)
|
||||||
{
|
{
|
||||||
if ($message instanceof \Exception) {
|
if ($message instanceof \Exception) {
|
||||||
$message = $this->getTranslator()->trans("Sorry, an error occured: %msg", array('%msg' => $message->getMessage()));
|
$message = $this->getTranslator()->trans("Sorry, an error occured: %msg", array('%msg' => $message->getMessage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->render('general_error', array(
|
return $this->render('general_error',
|
||||||
"error_message" => $message)
|
array(
|
||||||
|
"error_message" => $message
|
||||||
|
),
|
||||||
|
$status
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,14 +369,13 @@ class BaseAdminController extends BaseController
|
|||||||
* Render the given template, and returns the result as an Http Response.
|
* Render the given template, and returns the result as an Http Response.
|
||||||
*
|
*
|
||||||
* @param $templateName the complete template name, with extension
|
* @param $templateName the complete template name, with extension
|
||||||
* @param array $args the template arguments
|
* @param array $args the template arguments
|
||||||
|
* @param int $status http code status
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
*/
|
*/
|
||||||
protected function render($templateName, $args = array())
|
protected function render($templateName, $args = array(), $status = 200)
|
||||||
{
|
{
|
||||||
$response = new Response();
|
return Response::create($this->renderRaw($templateName, $args), $status);
|
||||||
|
|
||||||
return $response->setContent($this->renderRaw($templateName, $args));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -430,7 +432,7 @@ class BaseAdminController extends BaseController
|
|||||||
Redirect::exec(URL::getInstance()->absoluteUrl($ex->getLoginTemplate()));
|
Redirect::exec(URL::getInstance()->absoluteUrl($ex->getLoginTemplate()));
|
||||||
} catch (AuthorizationException $ex) {
|
} catch (AuthorizationException $ex) {
|
||||||
// User is not allowed to perform the required action. Return the error page instead of the requested page.
|
// User is not allowed to perform the required action. Return the error page instead of the requested page.
|
||||||
return $this->errorPage($this->getTranslator()->trans("Sorry, you are not allowed to perform this action."));
|
return $this->errorPage($this->getTranslator()->trans("Sorry, you are not allowed to perform this action."), 403);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -251,6 +251,6 @@ class CountryController extends AbstractCrudController
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->nullResponse($content, 500);
|
return $this->nullResponse(500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
namespace Thelia\Controller\Admin;
|
namespace Thelia\Controller\Admin;
|
||||||
|
|
||||||
|
use Thelia\Core\Event\Lang\LangToggleDefaultEvent;
|
||||||
use Thelia\Core\Event\Lang\LangUpdateEvent;
|
use Thelia\Core\Event\Lang\LangUpdateEvent;
|
||||||
use Thelia\Core\Event\TheliaEvents;
|
use Thelia\Core\Event\TheliaEvents;
|
||||||
use Thelia\Core\Security\AccessManager;
|
use Thelia\Core\Security\AccessManager;
|
||||||
@@ -109,6 +110,32 @@ class LangController extends BaseAdminController
|
|||||||
|
|
||||||
public function toggleDefaultAction($lang_id)
|
public function toggleDefaultAction($lang_id)
|
||||||
{
|
{
|
||||||
|
if (null !== $response = $this->checkAuth(AdminResources::LANGUAGE, AccessManager::UPDATE)) return $response;
|
||||||
|
|
||||||
|
$this->checkXmlHttpRequest();
|
||||||
|
$error = false;
|
||||||
|
try {
|
||||||
|
$event = new LangToggleDefaultEvent($lang_id);
|
||||||
|
|
||||||
|
$this->dispatch(TheliaEvents::LANG_TOGGLEDEFAULT, $event);
|
||||||
|
|
||||||
|
if (false === $event->hasLang()) {
|
||||||
|
throw new \LogicException(
|
||||||
|
$this->getTranslator()->trans("No %obj was updated.", array('%obj', 'Lang')));
|
||||||
|
}
|
||||||
|
|
||||||
|
$changedObject = $event->getLang();
|
||||||
|
$this->adminLogAppend(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()));
|
||||||
|
$error = $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
if($error) {
|
||||||
|
return $this->nullResponse(500);
|
||||||
|
} else {
|
||||||
|
return $this->nullResponse();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,8 +57,10 @@ class BaseController extends ContainerAware
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return an empty response (after an ajax request, for example)
|
* Return an empty response (after an ajax request, for example)
|
||||||
|
* @param int $status
|
||||||
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
*/
|
*/
|
||||||
protected function nullResponse($content = null, $status = 200)
|
protected function nullResponse($status = 200)
|
||||||
{
|
{
|
||||||
return new Response(null, $status);
|
return new Response(null, $status);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@
|
|||||||
<td>{$DATE_FORMAT}</td>
|
<td>{$DATE_FORMAT}</td>
|
||||||
<td>{$TIME_FORMAT}</td>
|
<td>{$TIME_FORMAT}</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="make-switch switch-small switch-radio lang-default-change" data-on="success" data-off="danger" data-on-label="<i class='glyphicon glyphicon-ok'></i>" data-off-label="<i class='glyphicon glyphicon-remove'></i>">
|
<div class="make-switch switch-small switch-radio lang-default-change" data-id="{$ID}" data-on="success" data-off="danger" data-on-label="<i class='glyphicon glyphicon-ok'></i>" data-off-label="<i class='glyphicon glyphicon-remove'></i>">
|
||||||
<input type="radio" name="is_default" {if $IS_DEFAULT}checked{/if}>
|
<input type="radio" name="is_default" {if $IS_DEFAULT}checked{/if}>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
@@ -287,8 +287,9 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$(".lang-default-change").on("switch-change", function(data, value){
|
$(".lang-default-change").on("switch-change", function(e, data){
|
||||||
var baseUrl = "{url path='/admin/configuration/languages/toggleDefault'}";
|
$('.lang-default-change').bootstrapSwitch('toggleRadioState');
|
||||||
|
var baseUrl = "{url path='/admin/configuration/languages/toggleDefault/'}";
|
||||||
if(data.value) {
|
if(data.value) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url : baseUrl+$(this).data('id')
|
url : baseUrl+$(this).data('id')
|
||||||
|
|||||||
Reference in New Issue
Block a user