| @@ 25-86 (lines=62) @@ | ||
| 22 | use yii\helpers\ArrayHelper; |
|
| 23 | use Yii; |
|
| 24 | ||
| 25 | class AggregateController extends CrudController |
|
| 26 | { |
|
| 27 | public function behaviors(): array |
|
| 28 | { |
|
| 29 | return ArrayHelper::merge(parent::behaviors(), [ |
|
| 30 | [ |
|
| 31 | 'class' => EasyAccessControl::class, |
|
| 32 | 'actions' => [ |
|
| 33 | 'create' => 'admin', |
|
| 34 | 'update' => 'admin', |
|
| 35 | 'delete' => 'admin', |
|
| 36 | '*' => 'ip.read', |
|
| 37 | ], |
|
| 38 | ], |
|
| 39 | ]); |
|
| 40 | } |
|
| 41 | ||
| 42 | public function actions() |
|
| 43 | { |
|
| 44 | return array_merge(parent::actions(), [ |
|
| 45 | 'index' => [ |
|
| 46 | 'class' => IndexAction::class, |
|
| 47 | ], |
|
| 48 | 'view' => [ |
|
| 49 | 'class' => ViewAction::class, |
|
| 50 | 'data' => static function ($action) { |
|
| 51 | $prefixSearch = new PrefixSearch(); |
|
| 52 | $dataProvider = $prefixSearch->search([ |
|
| 53 | $prefixSearch->formName() => [ |
|
| 54 | 'aggregate' => $action->getCollection()->first->ip, |
|
| 55 | ], |
|
| 56 | ]); |
|
| 57 | // $dataProvider->query->withSuggestions(); |
|
| 58 | ||
| 59 | return ['childPrefixesDataProvider' => $dataProvider]; |
|
| 60 | }, |
|
| 61 | ], |
|
| 62 | 'create' => [ |
|
| 63 | 'class' => SmartCreateAction::class, |
|
| 64 | 'success' => Yii::t('hipanel.hosting.ipam', 'Aggregate was created successfully'), |
|
| 65 | 'error' => Yii::t('hipanel.hosting.ipam', 'An error occurred when trying to add an aggregate'), |
|
| 66 | ], |
|
| 67 | 'update' => [ |
|
| 68 | 'class' => SmartUpdateAction::class, |
|
| 69 | 'success' => Yii::t('hipanel.hosting.ipam', 'IP address was updated successfully'), |
|
| 70 | 'error' => Yii::t('hipanel.hosting.ipam', 'An error occurred when trying to update an aggregate'), |
|
| 71 | ], |
|
| 72 | 'delete' => [ |
|
| 73 | 'class' => SmartDeleteAction::class, |
|
| 74 | 'success' => Yii::t('hipanel.hosting.ipam', 'Aggregate was deleted successfully'), |
|
| 75 | ], |
|
| 76 | 'validate-form' => [ |
|
| 77 | 'class' => ValidateFormAction::class, |
|
| 78 | ], |
|
| 79 | 'set-note' => [ |
|
| 80 | 'class' => SmartUpdateAction::class, |
|
| 81 | 'success' => Yii::t('hipanel.hosting.ipam', 'Description was changed'), |
|
| 82 | 'error' => Yii::t('hipanel.hosting.ipam', 'Failed to change description'), |
|
| 83 | ], |
|
| 84 | ]); |
|
| 85 | } |
|
| 86 | } |
|
| 87 | ||
| @@ 17-77 (lines=61) @@ | ||
| 14 | use yii\helpers\ArrayHelper; |
|
| 15 | use Yii; |
|
| 16 | ||
| 17 | class PrefixController 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', 'Prefix 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', 'Prefix 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', 'Prefix 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 | ||