Skip to content

Commit

Permalink
BO: add isEditGranted method in AdminThemes controller
Browse files Browse the repository at this point in the history
  • Loading branch information
maximebiloe committed Jul 12, 2017
1 parent 06cf154 commit e48cd0b
Showing 1 changed file with 20 additions and 31 deletions.
51 changes: 20 additions & 31 deletions controllers/admin/AdminThemesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ public function downloadAddonsThemes()
{
if (
!$this->logged_on_addons
|| !in_array(
$this->authorizationLevel(),
array(AdminController::LEVEL_ADD, AdminController::LEVEL_DELETE)
)
|| !$this->isEditGranted()
|| _PS_MODE_DEMO_
) {
return false;
Expand Down Expand Up @@ -142,13 +139,7 @@ public function initPageHeaderToolbar()
parent::initPageHeaderToolbar();

if (empty($this->display)) {
if (!in_array(
$this->authorizationLevel(),
array(
AdminController::LEVEL_VIEW,
AdminController::LEVEL_EDIT,
)
)) {
if ($this->isEditGranted()) {
$this->page_header_toolbar_btn['import_theme'] = array(
'href' => self::$currentIndex.'&action=importtheme&token='.$this->token,
'desc' => $this->trans('Add new theme', array(), 'Admin.Design.Feature'),
Expand Down Expand Up @@ -251,13 +242,7 @@ public function postProcess()
}

if ('exporttheme' === Tools::getValue('action')) {
if (!in_array(
$this->authorizationLevel(),
array(
AdminController::LEVEL_ADD,
AdminController::LEVEL_DELETE,
)
)) {
if (!$this->isEditGranted()) {
$this->errors[] = $this->trans('You do not have permission to edit this.', array(), 'Admin.Notifications.Error');
return false;
}
Expand All @@ -271,9 +256,7 @@ public function postProcess()
} elseif (Tools::isSubmit('submitAddconfiguration')) {
try {
if (
!in_array(
$this->authorizationLevel(),
array(AdminController::LEVEL_ADD, AdminController::LEVEL_DELETE))
!$this->isEditGranted()
|| _PS_MODE_DEMO_
) {
Throw new Exception ($this->trans('You do not have permission to add this.', array(), 'Admin.Notifications.Error'));
Expand Down Expand Up @@ -402,9 +385,7 @@ public function postProcess()
public function processUploadFile($dest)
{
if (
!in_array(
$this->authorizationLevel(),
array(AdminController::LEVEL_ADD, AdminController::LEVEL_DELETE))
!$this->isEditGranted()
|| _PS_MODE_DEMO_
) {
$this->errors[] = $this->trans('You do not have permission to upload this.', array(), 'Admin.Notifications.Error');
Expand Down Expand Up @@ -594,13 +575,7 @@ public function renderOptions()

public function renderImportTheme()
{
if (!in_array(
$this->authorizationLevel(),
array(
AdminController::LEVEL_ADD,
AdminController::LEVEL_DELETE,
)
)) {
if (!$this->isEditGranted()) {
$this->errors[] = $this->trans('You do not have permission to add this.', array(), 'Admin.Notifications.Error');
return false;
}
Expand Down Expand Up @@ -789,4 +764,18 @@ public function processSubmitConfigureLayouts()
Tools::clearCache();
}
}

/**
* @return bool
*/
protected function isEditGranted()
{
return in_array(
$this->authorizationLevel(),
array(
AdminController::LEVEL_ADD,
AdminController::LEVEL_DELETE,
)
);
}
}

0 comments on commit e48cd0b

Please sign in to comment.