Skip to content

Commit

Permalink
Mail password change, delete implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverFire committed Nov 15, 2015
1 parent 2de8ba1 commit d8d9ee4
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 18 deletions.
14 changes: 13 additions & 1 deletion src/controllers/MailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,19 @@ public function actions() {
'error' => Yii::t('app', 'An error occurred when trying to create mailbox')
],
'update' => [
'class' => 'hipanel\actions\SmartUpdateAction'
'class' => 'hipanel\actions\SmartUpdateAction',
'success' => Yii::t('app', 'Mailbox updating task has been added to queue'),
'error' => Yii::t('app', 'An error occurred when trying to update mailbox')
],
'set-password' => [
'class' => 'hipanel\actions\SmartUpdateAction',
'success' => Yii::t('app', 'Mailbox password change task has been added to queue'),
'error' => Yii::t('app', 'An error occurred when trying to change mailbox password')
],
'delete' => [
'class' => 'hipanel\actions\SmartDeleteAction',
'success' => Yii::t('app', 'Mailbox delete task has been created successfully'),
'error' => Yii::t('app', 'An error occurred when trying to delete mailbox')
],
'validate-form' => [
'class' => 'hipanel\actions\ValidateFormAction',
Expand Down
42 changes: 31 additions & 11 deletions src/grid/MailGridView.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
use hipanel\grid\ActionColumn;
use hipanel\grid\MainColumn;
use hipanel\grid\RefColumn;
use hipanel\modules\hosting\models\Mail;
use hipanel\modules\hosting\widgets\mail\State;
use hipanel\modules\hosting\widgets\mail\Type;
use hipanel\modules\server\grid\ServerColumn;
use hipanel\widgets\ArraySpoiler;
use hipanel\widgets\Label;
use Yii;
use yii\helpers\Html;

Expand All @@ -37,16 +39,13 @@ static public function defaultColumns()
'server_id' => [
'class' => ServerColumn::className()
],
// 'sshftp_ips' => [
// 'attribute' => 'sshftp_ips',
// 'format' => 'raw',
// 'value' => function ($model) {
// return ArraySpoiler::widget([
// 'data' => $model->sshftp_ips,
// 'visibleCount' => 3
// ]);
// }
// ],
'domain' => [
'attribute' => 'hdomain_id',
'format' => 'raw',
'value' => function ($model) {
return Html::a($model->domain, ['@hdomain/view', 'id' => $model->hdomain_id]);
}
],
'type' => [
'format' => 'raw',
'filter' => function ($column, $model, $attribute) {
Expand All @@ -68,6 +67,7 @@ static public function defaultColumns()
'value' => function ($model) {
return ArraySpoiler::widget([
'delimiter' => '<br>',
'visibleCount' => 2,
'data' => $model->forwards,
'button' => [
'label' => '+{count}',
Expand All @@ -77,8 +77,28 @@ static public function defaultColumns()
}
],
'spam_action' => [
'format' => 'raw',
'value' => function ($model) {
return $model->spam_action; // TODO
/** @var $model Mail */
if ($model->spam_action === $model::SPAM_ACTION_DELETE) {
return Label::widget([
'color' => 'danger',
'label' => Yii::t('app', 'Delete')
]);
} elseif ($model->spam_action === '') {
return Label::widget([
'color' => 'info',
'label' => Yii::t('app', 'Do nothing')
]);
} else {
return Label::widget([
'color' => 'primary',
'label' => Yii::t('app', 'Forward to')
]) . ' ' . ArraySpoiler::widget([
'data' => $model->spam_action,
'visibleCount' => 2
]);
}
}
],
'actions' => [
Expand Down
14 changes: 11 additions & 3 deletions src/models/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class Mail extends \hipanel\base\Model
const TYPE_BOX_WITH_FORWARDS = 'mailbox_with_forwards';
const TYPE_MAILBOX = 'mailbox';

const SPAM_ACTION_NONE = '';
const SPAM_ACTION_DELETE = 'delete';

/** @inheritdoc */
public function rules()
{
Expand All @@ -30,8 +33,8 @@ public function rules()
[['hdomain_id'], 'integer', 'on' => ['create']],
[['server', 'account'], 'safe', 'on' => ['create']],
[['password'], 'safe', 'on' => ['create']],
[['password'], 'safe', 'on' => ['update'], 'when' => function ($model) {
return !$model->is_alias;
[['password'], 'safe', 'on' => ['update', 'set-password'], 'when' => function ($model) {
return !$model->canChangePassword();
}],
[['nick'], EmailLocalPartValidator::className(), 'on' => ['create']],
[['forwards', 'spam_forward_mail'], 'filter', 'filter' => function ($value) {
Expand All @@ -55,10 +58,15 @@ public function attributeLabels()
'du_limit' => Yii::t('app', 'Disk usage limit'),
'mail' => Yii::t('app', 'E-mail'),
'mail_like' => Yii::t('app', 'E-mail'),
'autoanswer' => Yii::t('app', 'Auto answer')
'autoanswer' => Yii::t('app', 'Auto answer'),
'hdomain_id' => Yii::t('app', 'Domain'),
]);
}

public function canChangePassword() {
return $this->type !== static::TYPE_FORWARD_ONLY;
}

public function attributeHints() {
return [
'forwards' => Yii::t('app', 'All messages will be forwarded on the specified addresses. You can select email from the list of existing or wright down your own.'),
Expand Down
39 changes: 36 additions & 3 deletions src/views/mail/view.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
<?php

use hipanel\modules\hosting\grid\DbGridView;
use hipanel\modules\hosting\grid\MailGridView;
use hipanel\modules\hosting\models\Mail;
use hipanel\widgets\Box;
use hipanel\widgets\ModalButton;
use hipanel\widgets\PasswordInput;
use yii\bootstrap\Modal;
use yii\helpers\Html;
use yii\web\View;

$this->title = $model->mail;
$this->subtitle = Yii::t('app', 'Mailbox detailed information') . ' #' . $model->id;
$this->breadcrumbs->setItems([
['label' => Yii::t('app', 'Mailboxes'), 'url' => ['index']],
$this->title,
]);

/**
* @var $this View
* @var $model Mail
*/
?>

<div class="row">
Expand All @@ -38,6 +43,33 @@
<div class="profile-usermenu">
<ul class="nav">
<li><?= Html::a('<i class="fa fa-pencil"></i>' . Yii::t('app', 'Edit'), ['update', 'id' => $model->id]) ?></li>
<?php if ($model->canChangePassword()) { ?>
<li>
<?php
$modalButton = ModalButton::begin([
'model' => $model,
'scenario' => 'set-password',
'button' => [
'label' => '<i class="fa fa-lock"></i>' . Yii::t('app', 'Change password'),
],
'modal' => [
'header' => Html::tag('h4', Yii::t('app', 'Enter a new password')),
'headerOptions' => ['class' => 'label-info'],
'footer' => [
'label' => Yii::t('app', 'Change'),
'data-loading-text' => Yii::t('app', 'Changing...'),
'class' => 'btn btn-warning',
]
]
]);
?>

<?php echo $modalButton->form->field($model, 'password')->widget(PasswordInput::className())->label(false);

ModalButton::end();
?>
</li>
<?php } ?>
<li>
<?= ModalButton::widget([
'model' => $model,
Expand Down Expand Up @@ -81,10 +113,11 @@
'client_id',
'seller_id',
'server_id',
'type',
'domain',
'forwards',
'spam_action',
'state',
'type',
],
]);
$box->endBody();
Expand Down

0 comments on commit d8d9ee4

Please sign in to comment.