1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace app\models; |
4
|
|
|
|
5
|
|
|
use Yii; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* This is the model class for authManager.itemTable |
9
|
|
|
* |
10
|
|
|
* @property string $name |
11
|
|
|
* @property integer $type |
12
|
|
|
* @property string $description |
13
|
|
|
* @property string $rule_name |
14
|
|
|
* @property string $data |
15
|
|
|
* @property integer $created_at |
16
|
|
|
* @property integer $updated_at |
17
|
|
|
*/ |
18
|
|
|
class AuthItem extends \yii\db\ActiveRecord |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var array |
22
|
|
|
*/ |
23
|
|
|
public $roles; |
24
|
|
|
/** |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
public $permissions; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @inheritdoc |
31
|
|
|
*/ |
32
|
30 |
|
public static function tableName() |
33
|
|
|
{ |
34
|
30 |
|
return Yii::$app->authManager->itemTable; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @inheritdoc |
39
|
|
|
*/ |
40
|
1 |
|
public function rules() |
41
|
|
|
{ |
42
|
|
|
return [ |
43
|
|
|
[ |
44
|
1 |
|
['name', 'description'], 'required' |
45
|
|
|
], |
46
|
|
|
[ |
47
|
|
|
['roles', 'permissions'], 'safe' |
48
|
|
|
], |
49
|
|
|
|
50
|
|
|
['name', 'unique'], |
51
|
|
|
['name', 'string', 'max' => 64], |
52
|
|
|
['name', 'match', 'pattern' => '/^[a-z]\w*$/i'], |
53
|
|
|
]; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @inheritdoc |
58
|
|
|
*/ |
59
|
4 |
|
public function attributeLabels() |
60
|
|
|
{ |
61
|
|
|
return [ |
62
|
4 |
|
'name' => Yii::t('app', 'Name'), |
63
|
4 |
|
'description' => Yii::t('app', 'Description'), |
64
|
4 |
|
'roles' => Yii::t('app', 'Inherit role'), |
65
|
4 |
|
'permissions' => Yii::t('app', 'Permissions'), |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @inheritdoc |
71
|
|
|
* @codeCoverageIgnore |
72
|
|
|
*/ |
73
|
|
|
public function events() |
74
|
|
|
{ |
75
|
|
|
return [ |
76
|
|
|
ActiveRecord::EVENT_BEFORE_DELETE => 'beforeDelete', |
77
|
|
|
]; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Is SuperUser? |
82
|
|
|
* |
83
|
|
|
* @return bool |
84
|
|
|
*/ |
85
|
1 |
|
public function isSuperUser(): bool |
86
|
|
|
{ |
87
|
1 |
|
return $this->name === \app\models\User::ROLE_SUPERUSER; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Deleting a file from the db and from the file system |
92
|
|
|
* |
93
|
|
|
* @return bool |
94
|
|
|
*/ |
95
|
1 |
|
public function beforeDelete() |
96
|
|
|
{ |
97
|
1 |
|
return !$this->isSuperUser(); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|