Skip to content

Commit

Permalink
x fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
bladeroot committed Sep 16, 2015
2 parents 2e58313 + 639dfab commit 7f037b9
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 71 deletions.
48 changes: 28 additions & 20 deletions src/controllers/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,48 +17,56 @@ public function actions()
{
return [
'index' => [
'class' => 'hipanel\actions\IndexAction',
'data' => function ($action) {
'class' => 'hipanel\actions\IndexAction',
'data' => function ($action) {
return [
'stateData' => $action->controller->getStateData(),
'typeData' => $action->controller->getTypeData(),
];
}
],
'view' => [
'class' => 'hipanel\actions\ViewAction'
'class' => 'hipanel\actions\ViewAction',
'findOptions' => [
'with_mail_settings' => true
]
],
'create' => [
'class' => 'hipanel\actions\SmartCreateAction',
'create' => [
'class' => 'hipanel\actions\SmartCreateAction',
'success' => Yii::t('app', 'Account creating task has been added to queue'),
'error' => Yii::t('app', 'An error occurred when trying to create account')
'error' => Yii::t('app', 'An error occurred when trying to create account')
],
'create-ftponly' => [
'class' => 'hipanel\actions\SmartCreateAction',
'create-ftponly' => [
'class' => 'hipanel\actions\SmartCreateAction',
'success' => Yii::t('app', 'Account creating task has been added to queue'),
'error' => Yii::t('app', 'An error occurred when trying to create account')
'error' => Yii::t('app', 'An error occurred when trying to create account')
],
'set-password' => [
'class' => 'hipanel\actions\SmartUpdateAction',
'set-password' => [
'class' => 'hipanel\actions\SmartUpdateAction',
'success' => Yii::t('app', 'Password changed'),
'error' => Yii::t('app', 'Failed to change password'),
'error' => Yii::t('app', 'Failed to change password'),
],
'set-allowed-ips' => [
'class' => 'hipanel\actions\SmartUpdateAction',
'class' => 'hipanel\actions\SmartUpdateAction',
'success' => Yii::t('app', 'Allowed IPs changing task has been successfully added to queue'),
'error' => Yii::t('app', 'An error occurred when trying to change allowed IPs'),
'error' => Yii::t('app', 'An error occurred when trying to change allowed IPs'),
],
'validate-form' => [
'set-mail-settings' => [
'class' => 'hipanel\actions\SmartUpdateAction',
'success' => Yii::t('app', 'Mail settings where changed'),
'error' => Yii::t('app', 'An error occurred when trying to change mail settings'),
],
'validate-form' => [
'class' => 'hipanel\actions\ValidateFormAction',
],
'delete' => [
'class' => 'hipanel\actions\SmartDeleteAction',
'delete' => [
'class' => 'hipanel\actions\SmartDeleteAction',
'success' => Yii::t('app', 'Account deleting task has been added to queue'),
'error' => Yii::t('app', 'An error occurred when trying to delete account')
'error' => Yii::t('app', 'An error occurred when trying to delete account')
],
'get-directories-list' => [
'class' => 'hipanel\actions\SearchAction',
'findOptions' => ['with_directories' => true],
'class' => 'hipanel\actions\SearchAction',
'findOptions' => ['with_directories' => true],
'ajaxResponseFormatter' => function ($action) {
$results = [];

Expand Down
81 changes: 53 additions & 28 deletions src/models/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,59 +14,71 @@

class Account extends \hipanel\base\Model
{

use \hipanel\base\ModelTrait;

const TYPE_SSH = 'user';
const TYPE_FTP = 'ftponly';

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', 'uid', 'gid'], 'integer'],
[
['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']],
[['account', 'path'], 'required', 'on' => ['create-ftponly']],
[['login'], 'required', 'on' => ['set-password']],
[['password'], 'required', 'on' => ['set-password']],
[['password'],
[['type', 'type_label', 'state', 'state_label'], 'safe'],
[['ip', 'allowed_ips', 'objects_count', 'request_state', 'request_state_label', 'mail_settings', 'per_hour_limit'], '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']],
[['login'], 'required', 'on' => ['set-password']],
[['password'], 'required', 'on' => ['set-password']],
[
['password'],
'compare',
'compareAttribute' => 'login',
'message' => Yii::t('app', 'Password must not be equal to login'),
'operator' => '!=',
'on' => ['create', 'create-ftponly', 'update', 'set-password'],
'message' => Yii::t('app', 'Password must not be equal to login'),
'operator' => '!=',
'on' => ['create', 'create-ftponly', 'update', 'set-password'],
],
[['login'], LoginValidator::className(), 'on' => ['create', 'create-ftponly', 'set-password']],
[['login'], LoginValidator::className(), 'on' => ['create', 'create-ftponly', 'set-password']],
[
['login'],
'in',
'range' => ['root', 'toor'],
'not' => true,
'on' => ['create', 'create-ftponly'],
'range' => ['root', 'toor'],
'not' => true,
'on' => ['create', 'create-ftponly'],
'message' => Yii::t('app', 'You can not use this login')
],
[
['sshftp_ips'],
'filter',
'filter' => function ($value) { return StringHelper::explode($value); },
'on' => ['create', 'create-ftponly', 'update', 'set-allowed-ips']
'filter' => function ($value) {
return StringHelper::explode($value);
},
'on' => ['create', 'create-ftponly', 'update', 'set-allowed-ips']
],
[
['sshftp_ips'],
'each',
'rule' => [IpValidator::className(), 'negationChar' => true, 'subnet' => null],
'on' => ['create', 'create-ftponly', 'update', 'set-allowed-ips']
'on' => ['create', 'create-ftponly', 'update', 'set-allowed-ips']
],
[
['id'],
'required',
'on' => ['set-password', 'set-allowed-ips', 'set-mail-settings', 'delete']
],
[['id'], 'required', 'on' => ['set-password', 'set-allowed-ips', 'delete']],
[['account', 'server'], 'required', 'on' => ['get-directories-list']],
[['id'], 'canSetMailSettings', 'on' => ['set-mail-settings']],
[['block_send'], 'boolean', 'on' => ['set-mail-settings']],
[['account', 'server'], 'required', 'on' => ['get-directories-list']],
];
}

Expand All @@ -76,12 +88,14 @@ public function rules()
public function attributeLabels()
{
return $this->mergeAttributeLabels([
'login_like' => Yii::t('app', 'Login'),
'type_label' => Yii::t('app', 'state'),
'login_like' => Yii::t('app', 'Login'),
'type_label' => Yii::t('app', 'state'),
'state_label' => Yii::t('app', 'state'),
'allowed_ips' => Yii::t('app', 'Allowed IPs'),
'sshftp_ips' => Yii::t('app', 'IP to access on the server via SSH or FTP'),
'server_id' => Yii::t('app', 'Server'),
'sshftp_ips' => Yii::t('app', 'IP to access on the server via SSH or FTP'),
'server_id' => Yii::t('app', 'Server'),
'block_send' => Yii::t('app', 'Block outgoing post'),
'per_hour_limit' => Yii::t('app', 'Maximum letters per hour'),
]);
}

Expand All @@ -95,7 +109,6 @@ public function goodStates()
*/
public function isOperable()
{
return false;
/// TODO: all is operable for admin
if (!in_array($this->state, $this->goodStates())) {
return false;
Expand All @@ -114,11 +127,15 @@ public function getKnownTypes()
return ['user', 'ftponly'];
}

public function canSetMailSettings() {
return $this->type === self::TYPE_SSH && Yii::$app->user->can('support');
}

public function scenarioCommands()
{
return [
'set-allowed-ips' => [null, 'SetAllowedIPs'],
'create-ftponly' => 'create',
'create-ftponly' => 'create',
];
}

Expand All @@ -131,4 +148,12 @@ public function onBeforeValidate()
}
return true;
}

public function onAfterFind() {
if (!empty($this->mail_settings)) {
foreach ($this->mail_settings as $k => $v) {
$this->{$k} = $v;
}
}
}
}
69 changes: 69 additions & 0 deletions src/views/account/set-mail-settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

/* @var $this View */
/* @var $model hipanel\modules\hosting\models\Account */
/* @var $type string */

use hipanel\base\View;
use hipanel\helpers\Url;
use hipanel\modules\client\widgets\combo\ClientCombo;
use hipanel\modules\hosting\widgets\combo\SshAccountCombo;
use hipanel\modules\server\widgets\combo\ServerCombo;
use hiqdev\combo\StaticCombo;
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;

$this->title = $model->login;
$this->subtitle = Yii::t('app', 'account mail config') . ' #' . $model->id;
$this->breadcrumbs->setItems([
['label' => 'Accounts', 'url' => ['index']],
['label' => $model->login, 'url' => ['view', 'id' => $model->id]],
Yii::t('app', 'Mail config')
]);


$form = ActiveForm::begin([
'id' => 'dynamic-form',
'enableClientValidation' => true,
'validateOnBlur' => true,
'enableAjaxValidation' => true,
'validationUrl' => Url::toRoute(['validate-form', 'scenario' => $model->scenario]),
]); ?>

<div class="container-items">
<?php foreach ($models as $i => $model) { ?>
<div class="row">
<div class="col-md-9">
<div class="box box-danger">
<div class="box-body">
<div class="form-instance" xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html">
<?= $form->field($model, "[$i]id")->hiddenInput()->label(false) ?>

<div class="row">
<?php if (Yii::$app->user->can('support')) { ?>
<div class="col-md-4">
<?= $form->field($model, "[$i]client")->widget(ClientCombo::className(), ['inputOptions' => ['readonly' => true]]) ?>
</div>
<?php } ?>
<div class="col-md-4">
<?= $form->field($model, "[$i]server")->widget(ServerCombo::className(), ['inputOptions' => ['readonly' => true]]) ?>
</div>
<div class="col-md-4">
<?= $form->field($model, "[$i]login")->widget(SshAccountCombo::className(), ['inputOptions' => ['readonly' => true]]) ?>
</div>
</div>
<?php
echo $form->field($model, 'per_hour_limit');
echo $form->field($model, 'block_send')->checkbox();
?>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
</div>
<?= Html::submitButton(Yii::t('app', 'Save'), ['class' => 'btn btn-default']) ?>
&nbsp;
<?= Html::button(Yii::t('app', 'Cancel'), ['class' => 'btn btn-default', 'onclick' => 'history.go(-1)']) ?>
<?php ActiveForm::end();
Loading

0 comments on commit 7f037b9

Please sign in to comment.