1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* HiPanel core package |
4
|
|
|
* |
5
|
|
|
* @link https://hipanel.com/ |
6
|
|
|
* @package hipanel-core |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2014-2019, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hipanel\filters; |
12
|
|
|
|
13
|
|
|
use Yii; |
14
|
|
|
use yii\base\Action; |
15
|
|
|
use yii\base\ActionFilter; |
16
|
|
|
use yii\helpers\StringHelper; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* EasyAccessControl provides easy access control based on a list of actions and permissions. |
20
|
|
|
* Like this: |
21
|
|
|
* ``` |
22
|
|
|
* 'class' => RedirectPanel::class, |
23
|
|
|
* 'actions' => 'index,view', |
24
|
|
|
* ```. |
25
|
|
|
* |
26
|
|
|
* @author Andrii Vasyliev <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
class RedirectPanel extends ActionFilter |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var string a list of actions requiring redirect to panel |
32
|
|
|
*/ |
33
|
|
|
public $actions = ''; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* This method is invoked right before an action is to be executed (after all possible filters.) |
37
|
|
|
* You may override this method to do last-minute preparation for the action. |
38
|
|
|
* @param Action $action the action to be executed |
39
|
|
|
* @return bool whether the action execution should be continued |
40
|
|
|
*/ |
41
|
|
|
public function beforeAction($action) |
42
|
|
|
{ |
43
|
|
|
if ($this->getModule()->isPanel()) { |
44
|
|
|
return true; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return $this->matchAction($action, $this->actions) ? $this->getModule()->redirectPanel() : true; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
protected function matchAction($action, $names) |
51
|
|
|
{ |
52
|
|
|
if ($names === '*') { |
53
|
|
|
return true; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return in_array($action->id, StringHelper::explode($names, ',', true, true), true); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
protected $_module; |
60
|
|
|
|
61
|
|
|
public function getModule() |
62
|
|
|
{ |
63
|
|
|
if ($this->_module === null) { |
64
|
|
|
$this->_module = Yii::$app->getModule('hipanel'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return $this->_module; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|