diff --git a/src/controllers/AccountController.php b/src/controllers/AccountController.php index bf75fa1a..c33b72f6 100644 --- a/src/controllers/AccountController.php +++ b/src/controllers/AccountController.php @@ -7,6 +7,7 @@ namespace hipanel\modules\hosting\controllers; +use hipanel\helpers\ArrayHelper; use hipanel\models\Ref; use Yii; @@ -55,6 +56,20 @@ public function actions() 'success' => Yii::t('app', 'Account deleting task has been added to queue'), 'error' => Yii::t('app', 'An error occurred when trying to delete account') ], + 'get-directories-list' => [ + 'class' => 'hipanel\actions\SearchAction', + 'findOptions' => ['with_directories' => true], + 'ajaxResponseFormatter' => function ($action) { + $results = []; + + $model = $action->collection->first; + foreach ($model['path'] as $path) { + $results[] = ['id' => $path, 'text' => $path]; + } + + return $results; + } + ] ]; } diff --git a/src/models/Account.php b/src/models/Account.php index b9578402..024667d2 100644 --- a/src/models/Account.php +++ b/src/models/Account.php @@ -25,16 +25,16 @@ public function init() public function rules() { return [ - [['id', 'client_id', 'device_id', 'server_id'], 'integer'], + [['id', 'client_id', 'device_id', 'server_id', 'seller_id', 'uid', 'gid'], 'integer'], [ - ['login', 'password', 'uid', 'gid', 'shell', 'client', 'path', 'home', 'device', 'server', 'seller', 'seller_id'], + ['login', 'password', 'shell', 'client', 'path', 'home', 'device', 'server', 'seller'], 'safe' ], [['type', 'type_label', 'state', 'state_label'], 'safe'], [['ip', 'allowed_ips', 'objects_count', 'request_state', 'request_state_label', 'mail_settings'], 'safe'], [['login', 'server', 'password', 'sshftp_ips', 'type'], 'safe', 'on' => ['create', 'create-ftponly']], [['login', 'server', 'password', 'type'], 'required', 'on' => ['create', 'create-ftponly']], - [['id'], 'integer', 'on' => ['set-password', 'set-allowed-ips']], + [['account', 'path'], 'required', 'on' => ['create-ftponly']], [['login'], 'required', 'on' => ['set-password']], [['password'], 'required', 'on' => ['set-password']], [['password'], @@ -65,9 +65,8 @@ public function rules() 'rule' => [IpValidator::className(), 'negationChar' => true, 'subnet' => null], 'on' => ['create', 'create-ftponly', 'update', 'set-allowed-ips'] ], - [ - ['id'], 'integer', 'on' => ['delete'], - ] + [['id'], 'required', 'on' => ['set-password', 'set-allowed-ips', 'delete']], + [['account', 'server'], 'required', 'on' => ['get-directories-list']], ]; } diff --git a/src/models/AccountSearch.php b/src/models/AccountSearch.php index 2cb0defe..34aaeb2b 100644 --- a/src/models/AccountSearch.php +++ b/src/models/AccountSearch.php @@ -23,8 +23,9 @@ public function searchAttributes() { return ArrayHelper::merge($this->defaultSearchAttributes(), [ 'with_request', + 'with_counters', + 'with_directories', 'with_mail_settings', - 'with_counters' ]); } } diff --git a/src/views/account/_form.php b/src/views/account/_form.php index 8fd119a0..a75bf91d 100644 --- a/src/views/account/_form.php +++ b/src/views/account/_form.php @@ -6,6 +6,8 @@ use hipanel\base\View; use hipanel\modules\client\widgets\combo\ClientCombo; +use hipanel\modules\hosting\widgets\combo\AccountPathCombo; +use hipanel\modules\hosting\widgets\combo\SshAccountCombo; use hipanel\modules\server\widgets\combo\ServerCombo; use hipanel\widgets\PasswordInput; use yii\helpers\Html; @@ -38,10 +40,17 @@ field($model, "[$i]client")->widget(ClientCombo::className()); print $form->field($model, "[$i]server")->widget(ServerCombo::className()); + if ($model->scenario === 'create-ftponly') { + print $form->field($model, "[$i]account")->widget(SshAccountCombo::className()); + } print $form->field($model, "[$i]login"); print $form->field($model, "[$i]password")->widget(PasswordInput::className()); + if ($model->scenario === 'create-ftponly') { + print $form->field($model, "[$i]path")->widget(AccountPathCombo::className()); + } + print $form->field($model, "[$i]sshftp_ips")->hint(Yii::t('app', 'Access to the account is opened by default. Please input the IPs, for which the access to the server will be granted')) ->input('text', [ diff --git a/src/views/account/create-ftponly.php b/src/views/account/create-ftponly.php new file mode 100644 index 00000000..9dd81c82 --- /dev/null +++ b/src/views/account/create-ftponly.php @@ -0,0 +1,13 @@ +title = Yii::t('app', 'Create FTP account'); +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Accounts'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> + +
+ render('_form', compact('models')) ?> +
diff --git a/src/widgets/combo/AccountCombo.php b/src/widgets/combo/AccountCombo.php index 1c77fc13..7fcf9187 100644 --- a/src/widgets/combo/AccountCombo.php +++ b/src/widgets/combo/AccountCombo.php @@ -17,7 +17,7 @@ class AccountCombo extends Combo public $name = 'login'; /** @inheritdoc */ - public $url = '/hosting/account/search'; + public $url = '/hosting/account/index'; /** @inheritdoc */ public $_return = ['id', 'client', 'client_id', 'device', 'device_id']; @@ -43,7 +43,8 @@ public function getFilter() ]); } - public function getPluginOptions($config) + /** @inheritdoc */ + public function getPluginOptions($options = []) { return parent::getPluginOptions([ 'clearWhen' => ['client/client', 'server/server'], diff --git a/src/widgets/combo/AccountPathCombo.php b/src/widgets/combo/AccountPathCombo.php new file mode 100644 index 00000000..2a0032ed --- /dev/null +++ b/src/widgets/combo/AccountPathCombo.php @@ -0,0 +1,43 @@ + 'hosting/account', + 'server' => 'server/server', + ]); + } + + /** @inheritdoc */ + public function getPluginOptions($options = []) + { + return parent::getPluginOptions([ + 'clearWhen' => ['hosting/account'], + 'activeWhen' => ['hosting/account'], + + ]); + } +} \ No newline at end of file