1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace hipanel\modules\hosting\controllers; |
4
|
|
|
|
5
|
|
|
use hipanel\actions\IndexAction; |
6
|
|
|
use hipanel\actions\SmartCreateAction; |
7
|
|
|
use hipanel\actions\SmartDeleteAction; |
8
|
|
|
use hipanel\actions\SmartUpdateAction; |
9
|
|
|
use hipanel\actions\ValidateFormAction; |
10
|
|
|
use hipanel\actions\ViewAction; |
11
|
|
|
use hipanel\base\CrudController; |
12
|
|
|
use hipanel\filters\EasyAccessControl; |
13
|
|
|
use hipanel\modules\hosting\models\PrefixSearch; |
14
|
|
|
use yii\helpers\ArrayHelper; |
15
|
|
|
use Yii; |
16
|
|
|
|
17
|
|
|
class AddressController extends CrudController |
18
|
|
|
{ |
19
|
|
|
public function behaviors(): array |
20
|
|
|
{ |
21
|
|
|
return ArrayHelper::merge(parent::behaviors(), [ |
22
|
|
|
[ |
23
|
|
|
'class' => EasyAccessControl::class, |
24
|
|
|
'actions' => [ |
25
|
|
|
'create' => 'admin', |
26
|
|
|
'update' => 'admin', |
27
|
|
|
'delete' => 'admin', |
28
|
|
|
'*' => 'ip.read', |
29
|
|
|
], |
30
|
|
|
], |
31
|
|
|
]); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function actions() |
35
|
|
|
{ |
36
|
|
|
return array_merge(parent::actions(), [ |
37
|
|
|
'index' => [ |
38
|
|
|
'class' => IndexAction::class, |
39
|
|
|
], |
40
|
|
|
'view' => [ |
41
|
|
|
'class' => ViewAction::class, |
42
|
|
|
'data' => static function ($action) { |
43
|
|
|
$prefixSearch = new PrefixSearch(); |
44
|
|
|
$dataProvider = $prefixSearch->search([ |
45
|
|
|
$prefixSearch->formName() => [ |
46
|
|
|
'prefix' => $action->getCollection()->first->ip, |
47
|
|
|
], |
48
|
|
|
]); |
49
|
|
|
|
50
|
|
|
return ['childPrefixesDataProvider' => $dataProvider]; |
51
|
|
|
}, |
52
|
|
|
], |
53
|
|
|
'create' => [ |
54
|
|
|
'class' => SmartCreateAction::class, |
55
|
|
|
'success' => Yii::t('hipanel.hosting.ipam', 'IP Address was created successfully'), |
56
|
|
|
'error' => Yii::t('hipanel.hosting.ipam', 'An error occurred when trying to add a prefix'), |
57
|
|
|
], |
58
|
|
|
'update' => [ |
59
|
|
|
'class' => SmartUpdateAction::class, |
60
|
|
|
'success' => Yii::t('hipanel.hosting.ipam', 'IP Address was updated successfully'), |
61
|
|
|
'error' => Yii::t('hipanel.hosting.ipam', 'An error occurred when trying to update a prefix'), |
62
|
|
|
], |
63
|
|
|
'delete' => [ |
64
|
|
|
'class' => SmartDeleteAction::class, |
65
|
|
|
'success' => Yii::t('hipanel.hosting.ipam', 'IP Address was deleted successfully'), |
66
|
|
|
], |
67
|
|
|
'validate-form' => [ |
68
|
|
|
'class' => ValidateFormAction::class, |
69
|
|
|
], |
70
|
|
|
'set-note' => [ |
71
|
|
|
'class' => SmartUpdateAction::class, |
72
|
|
|
'success' => Yii::t('hipanel.hosting.ipam', 'Description was changed'), |
73
|
|
|
'error' => Yii::t('hipanel.hosting.ipam', 'Failed to change description'), |
74
|
|
|
], |
75
|
|
|
]); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|