Skip to content

Commit

Permalink
added ghost settings and system settings props updating in account (#34)
Browse files Browse the repository at this point in the history
* added system settings props update to account

* added ghost settings updating

* creating account with values logic

* fixed validation and AccountValues model submitting

* added translations

* minor

* moved mail settings from Account to AccountValues model

* simplisfied scenarios

* removed useless legends

* minor

* updated 'set-system-settings' action params validation type
  • Loading branch information
strorch authored and SilverFire committed Oct 29, 2019
1 parent d709545 commit 669d4a6
Show file tree
Hide file tree
Showing 11 changed files with 327 additions and 30 deletions.
51 changes: 43 additions & 8 deletions src/controllers/AccountController.php
Expand Up @@ -27,6 +27,8 @@
use hipanel\actions\ValidateFormAction;
use hipanel\actions\ViewAction;
use hipanel\filters\EasyAccessControl;
use hipanel\modules\hosting\models\AccountValues;
use hiqdev\hiart\Collection;
use Yii;
use yii\base\Event;

Expand Down Expand Up @@ -60,6 +62,13 @@ public function actions()
'typeData' => $action->controller->getTypeData(),
];
},
'collection' => [
'class' => Collection::class,
'model' => new AccountValues(['scenario' => 'default']),
],
'on beforeFetchLoad' => function (Event $event): void {
$event->sender->getDataProvider()->query->withValues();
},
'filterStorageMap' => [
'login_like' => 'hosting.account.login',
'server' => 'server.server.name',
Expand All @@ -71,15 +80,8 @@ public function actions()
],
'view' => [
'class' => ViewAction::class,
'findOptions' => [
'with_mail_settings' => true,
],
'on beforePerform' => function (Event $event) {
/** @var \hipanel\actions\SearchAction $action */
$action = $event->sender;
$dataProvider = $action->getDataProvider();
$dataProvider->query->joinWith(['blocking']);
$dataProvider->query->andWhere(['with_blocking' => 1]);
$event->sender->getDataProvider()->query->withBlocking();
},
'data' => function ($action) {
return [
Expand Down Expand Up @@ -119,9 +121,42 @@ public function actions()
'set-mail-settings' => [
'class' => SmartUpdateAction::class,
'view' => '_setMailSettings',
'collection' => [
'class' => Collection::class,
'model' => new AccountValues(['scenario' => 'set-mail-settings']),
],
'on beforeFetchLoad' => function (Event $event): void {
$event->sender->getDataProvider()->query->withValues();
},
'success' => Yii::t('hipanel:hosting', 'Mail settings where changed'),
'error' => Yii::t('hipanel:hosting', 'An error occurred when trying to change mail settings'),
],
'set-system-settings' => [
'class' => SmartUpdateAction::class,
'view' => '_setSystemSettings',
'success' => Yii::t('hipanel:hosting:account', 'System settings where changed'),
'error' => Yii::t('hipanel:hosting:account', 'An error occurred when trying to change system settings'),
],
'set-ghost-options' => [
'class' => SmartUpdateAction::class,
'view' => '_setGhostOptions',
'collection' => [
'class' => Collection::class,
'model' => new AccountValues(['scenario' => 'set-ghost-options']),
],
'on beforeFetchLoad' => function (Event $event): void {
$event->sender->getDataProvider()->query->withValues();
},
'success' => Yii::t('hipanel:hosting:account', 'Global vhost options where changed'),
'error' => Yii::t('hipanel:hosting:account', 'An error occurred when trying to change global vhost options'),
],
'validate-sgo-form' => [
'class' => ValidateFormAction::class,
'collection' => [
'class' => Collection::class,
'model' => new AccountValues(['scenario' => 'default']),
],
],
'enable-block' => [
'class' => SmartUpdateAction::class,
'success' => Yii::t('hipanel:hosting', 'Account was blocked successfully'),
Expand Down
22 changes: 21 additions & 1 deletion src/menus/AccountDetailMenu.php
Expand Up @@ -35,7 +35,7 @@ public function items()
'encode' => false,
'visible' => true,
],
[
[
'label' => SettingsModal::widget([
'model' => $this->model,
'title' => Yii::t('hipanel:hosting:account', 'IP address restrictions'),
Expand All @@ -58,6 +58,26 @@ public function items()
'visible' => $this->model->canSetMailSettings(),
'disabled' => $this->model->isOperable(),
],
[
'label' => SettingsModal::widget([
'model' => $this->model,
'title' => Yii::t('hipanel:hosting:account', 'System settings'),
'headerOptions' => ['class' => 'label-info'],
'icon' => 'fa fa-fw fa-cog',
'scenario' => 'set-system-settings',
]),
'encode' => false,
],
[
'label' => SettingsModal::widget([
'model' => $this->model,
'title' => Yii::t('hipanel:hosting:account', 'Global vhost options'),
'headerOptions' => ['class' => 'label-info'],
'icon' => 'fa fa-fw fa-bars',
'scenario' => 'set-ghost-options',
]),
'encode' => false,
],
[
'label' => BlockModalButton::widget(['model' => $this->model]),
'encode' => false,
Expand Down
1 change: 0 additions & 1 deletion src/messages/ru/hipanel:hosting.php
Expand Up @@ -38,7 +38,6 @@
'Account information' => 'Информация об аккаунте',
'Confirm account deleting' => 'Подтвердите удаление аккаунта',
'Are you sure you want to delete account {name}? You will loose all data, that relates this account!' => 'Вы уверены, что хотите удалить аккаунт {name}? Вы потеряете все данные, что связаны с ним!',
'Enter mail settings' => 'Введите настройки почты',
'Mail settings' => 'Настройки почты',
'This will immediately terminate all sessions of the user!' => 'Это немедленно прервет все сеансы пользователя!',
'Enter new restrictions' => 'Введите новые ограничения',
Expand Down
19 changes: 19 additions & 0 deletions src/messages/ru/hipanel:hosting:account.php
Expand Up @@ -16,4 +16,23 @@
'IP address restrictions' => 'Ограничение доступа по IP',
'Home directory' => 'Домашний каталог',
'Access data' => 'Данные для доступа',
'System settings where changed' => 'Системные настройки изменены',
'An error occurred when trying to change system settings' => 'Ошибка при изменении системных настроек',
'Global vhost options where changed' => 'Глобальные vhost настройки изменены',
'An error occurred when trying to change global vhost options' => 'Ошибка при изменении глобальных vhost настроек',
'System settings' => 'Системные настройки',
'Global vhost options' => 'Глобальные vhost настройки',
'Group' => 'Группа',
'No Suexec' => 'Без Suexec',
'Allow scripts' => 'Разрешить скрипты',
'Dont enable Ssi' => 'Выключить Ssi',
'Port' => 'Порт',
'Global Apache configuration' => 'Глобальная конфигурация Apache',
'Global Nginx configuration' => 'Глобальная конфигурация Nginx',
'Apache configuration' => 'Конфигурация Apache',
'Nginx configuration' => 'Конфигурация Nginx',
'Domain prefix' => 'Префикс домена',
'Nginx listen' => 'Nginx слушает',
'Document root postfix' => 'Постфикс корня документа',
'Cgibin postfix' => 'Постфикс Cgibin',
];
41 changes: 27 additions & 14 deletions src/models/Account.php
Expand Up @@ -11,9 +11,16 @@
namespace hipanel\modules\hosting\models;

use hipanel\helpers\StringHelper;
use hipanel\modules\hosting\models\query\AccountQuery;
use hipanel\modules\hosting\validators\LoginValidator;
use Yii;

/**
* Class Account
* @package hipanel\modules\hosting\models
*
* @property $values
*/
class Account extends \hipanel\base\Model
{
use \hipanel\base\ModelTrait;
Expand All @@ -30,19 +37,18 @@ class Account extends \hipanel\base\Model
public function init()
{
$this->on(static::EVENT_BEFORE_VALIDATE, [$this, 'onBeforeValidate']);
$this->on(static::EVENT_AFTER_FIND, [$this, 'onAfterFind']);
}

public function rules()
{
return [
[['id', 'client_id', 'device_id', 'server_id', 'seller_id', 'uid', 'gid'], 'integer'],
[['id', 'client_id', 'device_id', 'server_id', 'seller_id'], 'integer'],
[
['login', 'password', 'shell', 'client', 'path', 'home', 'device', 'server', 'seller'],
['login', 'password', 'shell', 'client', 'path', 'home', 'device', 'server', 'seller', 'uid', 'gid'],
'safe',
],
[['type', 'type_label', 'state', 'state_label'], 'safe'],
[['ip', 'allowed_ips', 'objects_count', 'request_state', 'request_state_label', 'mail_settings', 'per_hour_limit'], 'safe'],
[['ip', 'allowed_ips', 'objects_count', 'request_state', 'request_state_label'], 'safe'],
[['login', 'server', 'password', 'sshftp_ips', 'type'], 'safe', 'on' => ['create', 'create-ftponly']],
[['login', 'server', 'password', 'type'], 'required', 'on' => ['create', 'create-ftponly']],
[['account', 'path'], 'required', 'on' => ['create-ftponly']],
Expand Down Expand Up @@ -82,10 +88,10 @@ public function rules()
[
['id'],
'required',
'on' => ['change-password', 'set-allowed-ips', 'set-mail-settings', 'delete'],
'on' => ['change-password', 'set-allowed-ips', 'set-mail-settings', 'set-system-settings', 'set-ghost-options', 'delete'],
],
[['id'], 'canSetMailSettings', 'on' => ['set-mail-settings']],
[['block_send'], 'boolean', 'on' => ['set-mail-settings']],
[['path', 'gid', 'uid'], 'string', 'on' => ['set-system-settings']],
[['account', 'server'], 'required', 'on' => ['get-directories-list']],
[['type', 'comment'], 'required', 'on' => ['enable-block']],
[['comment'], 'safe', 'on' => ['disable-block']],
Expand All @@ -100,9 +106,9 @@ public function attributeLabels()
return $this->mergeAttributeLabels([
'allowed_ips' => Yii::t('hipanel:hosting', 'Allowed IPs'),
'sshftp_ips' => Yii::t('hipanel:hosting', 'IP to access on the server via SSH or FTP'),
'block_send' => Yii::t('hipanel:hosting', 'Block outgoing post'),
'per_hour_limit' => Yii::t('hipanel:hosting', 'Maximum letters per hour'),
'path' => Yii::t('hipanel:hosting:account', 'Home directory'),
'gid' => Yii::t('hipanel:hosting:account', 'Group'),
'uid' => Yii::t('hipanel:hosting:account', 'ID'),
]);
}

Expand All @@ -111,6 +117,11 @@ public function goodStates()
return [self::STATE_OK];
}

public function getValues()
{
return $this->hasOne(AccountValues::class, ['id' => 'id']);
}

/**
* @return bool
*/
Expand Down Expand Up @@ -163,12 +174,14 @@ public function onBeforeValidate()
return true;
}

public function onAfterFind()
/**
* {@inheritdoc}
* @return AccountQuery
*/
public static function find(array $options = []): AccountQuery
{
if (!empty($this->mail_settings)) {
foreach ($this->mail_settings as $k => $v) {
$this->{$k} = $v;
}
}
return new AccountQuery(get_called_class(), [
'options' => $options,
]);
}
}
1 change: 0 additions & 1 deletion src/models/AccountSearch.php
Expand Up @@ -34,7 +34,6 @@ public function searchAttributes()
'with_request',
'with_counters',
'with_directories',
'with_mail_settings',
]);
}
}
85 changes: 85 additions & 0 deletions src/models/AccountValues.php
@@ -0,0 +1,85 @@
<?php
/**
* Hosting Plugin for HiPanel
*
* @link https://github.com/hiqdev/hipanel-module-hosting
* @package hipanel-module-hosting
* @license BSD-3-Clause
* @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
*/

namespace hipanel\modules\hosting\models;

use Yii;

/**
* Class AccountValues
* @package hipanel\modules\hosting\models
*/
class AccountValues extends \hipanel\base\Model
{
use \hipanel\base\ModelTrait;

const SCENARIO_DEFAULT = 'dumb';

/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'account';
}

/**
* {@inheritdoc}
*/
public function rules()
{
return array_merge(parent::rules(), [
[['id'], 'integer'],
[['no_suexec', 'allow_scripts', 'dont_enable_ssi', 'block_send'], 'boolean'],
[
[
'id', 'per_hour_limit', 'block_send',
'no_suexec', 'allow_scripts', 'dont_enable_ssi',
'port', 'global_apache_conf', 'global_nginx_conf',
'apache_conf', 'nginx_conf', 'nginx_listen',
'domain_prefix', 'docroot_postfix', 'cgibin_postfix',
],
'safe',
'on' => ['default', 'set-ghost-options', 'set-mail-settings'],
],
]);
}

/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return $this->mergeAttributeLabels([
'no_suexec' => Yii::t('hipanel:hosting:account', 'No Suexec'),
'allow_scripts' => Yii::t('hipanel:hosting:account', 'Allow scripts'),
'dont_enable_ssi' => Yii::t('hipanel:hosting:account', 'Dont enable Ssi'),
'port' => Yii::t('hipanel:hosting:account', 'Port'),
'global_apache_conf' => Yii::t('hipanel:hosting:account', 'Global Apache configuration'),
'global_nginx_conf' => Yii::t('hipanel:hosting:account', 'Global Nginx configuration'),
'apache_conf' => Yii::t('hipanel:hosting:account', 'Apache configuration'),
'nginx_conf' => Yii::t('hipanel:hosting:account', 'Nginx configuration'),
'domain_prefix' => Yii::t('hipanel:hosting:account', 'Domain prefix'),
'nginx_listen' => Yii::t('hipanel:hosting:account', 'Nginx listen'),
'docroot_postfix' => Yii::t('hipanel:hosting:account', 'Document root postfix'),
'cgibin_postfix' => Yii::t('hipanel:hosting:account', 'Cgibin postfix'),
'block_send' => Yii::t('hipanel:hosting', 'Block outgoing post'),
'per_hour_limit' => Yii::t('hipanel:hosting', 'Maximum letters per hour'),
]);
}

/**
* {@inheritdoc}
*/
public static function primaryKey()
{
return ['id'];
}
}
42 changes: 42 additions & 0 deletions src/models/query/AccountQuery.php
@@ -0,0 +1,42 @@
<?php
/**
* Hosting module for HiPanel
*
* @link https://github.com/hiqdev/hipanel-module-hosting
* @package hipanel-module-hosting
* @license BSD-3-Clause
* @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
*/

namespace hipanel\modules\hosting\models\query;

use hiqdev\hiart\ActiveQuery;

/**
* Class AccountQuery
* @package hipanel\modules\hosting\models\query
*/
class AccountQuery extends ActiveQuery
{
/**
* @return $this
*/
public function withValues(): self
{
$this->joinWith('values');
$this->andWhere(['with_values' => true]);

return $this;
}

/**
* @return $this
*/
public function withBlocking(): self
{
$this->joinWith('blocking');
$this->andWhere(['with_blocking' => true]);

return $this;
}
}

0 comments on commit 669d4a6

Please sign in to comment.