Skip to content

Commit

Permalink
Merge cf0949b into 669d4a6
Browse files Browse the repository at this point in the history
  • Loading branch information
bladeroot committed Nov 27, 2019
2 parents 669d4a6 + cf0949b commit efcc4ce
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/controllers/BackupingController.php
Expand Up @@ -33,6 +33,7 @@ public function behaviors()
'actions' => [
'update' => 'account.update',
'delete' => 'account.delete',
'undelete' => 'account.update',
'*' => 'account.read',
],
],
Expand Down Expand Up @@ -70,6 +71,9 @@ public function actions()
'disable' => [
'class' => SmartPerformAction::class,
],
'undelete' => [
'class' => SmartPerformAction::class,
],
'enable' => [
'class' => SmartPerformAction::class,
],
Expand Down Expand Up @@ -126,4 +130,9 @@ public function getStateOptions()
'deleted' => Yii::t('hipanel', 'Deleted'),
];
}

public static function getTypeOptions()
{
return Backuping::getTypeOptions();
}
}
64 changes: 63 additions & 1 deletion src/menus/BackupingDetailMenu.php
Expand Up @@ -24,7 +24,69 @@ public function items()
'icon' => 'fa-pencil',
'url' => ['@backuping/update', 'id' => $this->model->id],
'encode' => false,
'visible' => Yii::$app->user->can('support'),
'visible' => Yii::$app->user->can('support') && !$this->model->isDeleted(),
],[
'label' => Yii::t('hipanel', 'Enable'),
'icon' => 'fa-activate',
'url' => ['@backuping/enable', 'id' => $this->model->id],
'encode' => false,
'visible' => $this->model->canBeEnabled(),
'linkOptions' => [
'data' => [
'method' => 'post',
'pjax' => '0',
'params' => [
'Backuping[id]' => $this->model->id,
],
],
],
], [
'label' => Yii::t('hipanel', 'Restore'),
'icon' => 'fa-archive',
'url' => ['@backuping/undelete', 'id' => $this->model->id],
'encode' => false,
'visible' => $this->model->canBeRestored(),
'linkOptions' => [
'data' => [
'method' => 'post',
'pjax' => '0',
'params' => [
'Backuping[id]' => $this->model->id,
],
],
],
], [
'label' => Yii::t('hipanel', 'Disable'),
'icon' => 'fa-ban',
'url' => ['@backuping/disable', 'id' => $this->model->id],
'encode' => false,
'visible' => $this->model->canBeDisabled(),
'linkOptions' => [
'data' => [
'method' => 'post',
'pjax' => '0',
'params' => [
'Backuping[id]' => $this->model->id,
],
],
],
], [
'label' => Yii::t('hipanel', 'Delete'),
'icon' => 'fa-trash',
'url' => ['@backuping/delete', 'id' => $this->model->id],
'encode' => false,
'visible' => $this->model->canBeDeleted(),
'linkOptions' => [
'data' => [
'confirm' => Yii::t('hipanel:hosting', 'Are you sure you want to delete backaping'),
'method' => 'post',
'pjax' => '0',
'params' => [
'Backuping[id]' => $this->model->id,
],
],
],

],
];
}
Expand Down
47 changes: 45 additions & 2 deletions src/models/Backuping.php
Expand Up @@ -19,6 +19,9 @@ class Backuping extends \hipanel\base\Model
{
use \hipanel\base\ModelTrait;

const STATE_DELETED = 'deleted';
const STATE_DISABLED = 'disabled';

/** {@inheritdoc} */
public function rules()
{
Expand All @@ -32,7 +35,7 @@ public function rules()
[['type', 'type_label', 'state', 'state_label'], 'safe'],

[['id', 'type'], 'safe', 'on' => ['update']],
[['id'], 'integer', 'on' => ['delete', 'disable', 'enable']],
[['id'], 'integer', 'on' => ['delete', 'disable', 'enable', 'undelete']],

// Update settings
[['id', 'service_id'], 'integer', 'on' => 'update'],
Expand Down Expand Up @@ -75,7 +78,42 @@ public function getObj()
]);
}

public function getTypeOptions(): array
public function canBeDeleted() : bool
{
return $this->can('account.delete') && !$this->isDeleted();
}

public function canBeDisabled() : bool
{
return $this->can('account.update') && $this->isEnabled();
}

public function canBeRestored() : bool
{
return $this->can('account.update') && $this->isDeleted();
}

public function canBeEnabled() : bool
{
return $this->can('account.update') && !$this->isEnabled() && !$this->isDeleted();
}

public function isDeleted() : bool
{
return $this->state === self::STATE_DELETED;
}

public function isDisabled() : bool
{
return $this->state === self::STATE_DISABLED;
}

public function isEnabled() : bool
{
return !$this->isDeleted() && !$this->isDisabled();
}

public static function getTypeOptions(): array
{
return Yii::$app->get('cache')->getOrSet([__METHOD__], function () {
return ArrayHelper::map(Ref::find()->where([
Expand All @@ -85,4 +123,9 @@ public function getTypeOptions(): array
});
}, 86400 * 24); // 24 days
}

protected function can(string $permission) : bool
{
return Yii::$app->user->can($permission);
}
}
2 changes: 2 additions & 0 deletions src/views/backuping/index.php
Expand Up @@ -12,6 +12,8 @@
<?php Pjax::begin(array_merge(Yii::$app->params['pjax'], ['enablePushState' => true])) ?>
<?php $page = IndexPage::begin(compact('model', 'dataProvider')) ?>

<?php $page->setSearchFormData(compact(['stateOptions'])) ?>

<?php $page->beginContent('main-actions') ?>
<?php $page->endContent() ?>

Expand Down
2 changes: 1 addition & 1 deletion src/views/backuping/view.php
Expand Up @@ -99,7 +99,7 @@
<?php $form = ActiveForm::begin(['action' => '@backuping/update']) ?>
<?= Html::activeHiddenInput($model, 'id') ?>
<?php $model->type = 'week' ?>
<?= $form->field($model, 'type')->dropDownList($this->context->getTypeOptions()) ?>
<?= $form->field($model, 'type')->dropDownList($model->typeOptions) ?>
<?= Html::submitButton(Yii::t('hipanel:hosting', 'Enable backup'), ['class' => 'btn btn-success']) ?>
<?php ActiveForm::end(); ?>
</div>
Expand Down

0 comments on commit efcc4ce

Please sign in to comment.