1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* RBAC implementation for HiPanel |
5
|
|
|
* |
6
|
|
|
* @link https://github.com/hiqdev/hipanel-rbac |
7
|
|
|
* @package hipanel-rbac |
8
|
|
|
* @license BSD-3-Clause |
9
|
|
|
* @copyright Copyright (c) 2016, HiQDev (http://hiqdev.com/) |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace hipanel\rbac; |
13
|
|
|
|
14
|
|
|
use Yii; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* HiPanel AuthManager. |
18
|
|
|
* |
19
|
|
|
* @author Andrii Vasyliev <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class AuthManager extends \yii\rbac\PhpManager |
22
|
|
|
{ |
23
|
|
|
public $itemFile = '@hipanel/rbac/files/items.php'; |
24
|
|
|
public $ruleFile = '@hipanel/rbac/files/rules.php'; |
25
|
|
|
public $assignmentFile = '@hipanel/rbac/files/assignments.php'; |
26
|
|
|
|
27
|
|
|
use SetterTrait; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* We don't keep all the assignments, only persistent. |
31
|
|
|
* @see persistAssignments |
32
|
|
|
*/ |
33
|
6 |
|
protected function saveAssignments() |
34
|
|
|
{ |
35
|
6 |
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Does real assignments saving. |
39
|
|
|
* The idea is to split persistent assignments from session only. |
40
|
|
|
*/ |
41
|
3 |
|
public function persistAssignments() |
42
|
|
|
{ |
43
|
3 |
|
parent::saveAssignments(); |
|
|
|
|
44
|
3 |
|
} |
45
|
|
|
|
46
|
6 |
|
public function checkAccess($userId, $permission, $params = []) |
47
|
|
|
{ |
48
|
6 |
|
$this->setCurrentUserRole(); |
49
|
6 |
|
if ($userId === $this->getIdentity()->id) { |
50
|
|
|
$userId = $this->getIdentity()->username; |
51
|
|
|
} |
52
|
|
|
|
53
|
6 |
|
return parent::checkAccess($userId, $permission, $params); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
protected $_currentUserRole; |
57
|
|
|
|
58
|
6 |
|
public function setCurrentUserRole() |
59
|
|
|
{ |
60
|
6 |
|
if ($this->_currentUserRole === null) { |
61
|
6 |
|
$this->_currentUserRole = $this->getIdentity()->type ?: ''; |
62
|
6 |
|
if ($this->_currentUserRole) { |
63
|
|
|
$this->setAssignment($this->_currentUserRole, $this->getIdentity()->username); |
64
|
|
|
} |
65
|
6 |
|
} |
66
|
6 |
|
} |
67
|
|
|
|
68
|
6 |
|
public function getIdentity() |
69
|
|
|
{ |
70
|
6 |
|
return Yii::$app->user->identity; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.