<commit_before><?php

/*
 * Domain plugin for HiPanel
 *
 * @link      https://github.com/hiqdev/hipanel-module-domain
 * @package   hipanel-module-domain
 * @license   BSD-3-Clause
 * @copyright Copyright (c) 2014-2015, HiQDev (http://hiqdev.com/)
 */

/**
 * @link    http://hiqdev.com/hipanel-module-domain
 *
 * @license http://hiqdev.com/hipanel-module-domain/license
 * @copyright Copyright (c) 2015 HiQDev
 */
namespace hipanel\modules\domain\grid;

use hipanel\grid\ActionColumn;
use hipanel\grid\BoxedGridView;
use hipanel\grid\MainColumn;
use hipanel\grid\RefColumn;
use hipanel\modules\domain\models\Domain;
use hipanel\modules\domain\widgets\Expires;
use hipanel\modules\domain\widgets\State;
use hipanel\widgets\ArraySpoiler;
use hiqdev\bootstrap_switch\BootstrapSwitchColumn;
use Yii;
use yii\helpers\Html;
use yii\helpers\Url;

class DomainGridView extends BoxedGridView
{
    public static function defaultColumns()
    {
        return [
            'domain' => [
                'class'           => MainColumn::className(),
                'attribute'       => 'domain',
                'note'            => true,
                'filterAttribute' => 'domain_like',
            ],
            'state' => [
                'class'         => RefColumn::className(),
                'format'        => 'raw',
                'gtype'         => 'state,domain',
                'filterInputOptions' => ['style' => 'width:120px'],
                'value'         => function ($model) {
                    return State::widget(compact('model'));
                },
            ],
            'whois_protected' => [
                'class'         => BootstrapSwitchColumn::className(),
                'filter'        => false,
                'url'           => Url::toRoute('set-whois-protect'),
                'popover'       => 'WHOIS protection',
                'pluginOptions' => [
                    'onColor'  => 'success',
                    'offColor' => 'warning',
                ],
            ],
            'is_secured'      => [
                'class'     => BootstrapSwitchColumn::className(),
                'filter'    => false,
                'url'       => Url::toRoute('set-lock'),
                'attribute' => 'is_secured',
                'popover'   => Yii::t('app', 'Protection from transfer'),
            ],
            'note'            => [
                'class'         => 'hiqdev\xeditable\grid\XEditableColumn',
                'attribute'     => 'note',
                'filter'        => true,
                'popover'       => Yii::t('app', 'Make any notes for your convenience'),
                'pluginOptions' => [
                    'url' => 'set-note',
                ],
            ],
            'created_date'    => [
                'attribute'      => 'created_date',
                'format'         => 'date',
                'filter'         => false,
                'contentOptions' => ['class' => 'text-nowrap'],
            ],
            'expires'         => [
                'format'        => 'raw',
                'filter'        => false,
                'headerOptions' => ['style' => 'width:1em'],
                'value'         => function ($model) {
                    return Expires::widget(compact('model'));
                },
            ],
            'autorenewal'     => [
                'class'         => BootstrapSwitchColumn::className(),
                'label'         => Yii::t('app', 'Autorenew'),
                'filter'        => false,
                'url'           => Url::toRoute('set-autorenewal'),
                'popover'       => 'The domain will be autorenewed for one year in a week before it expires if you have enough credit on your account',
                'pluginOptions' => [
                    'onColor' => 'info',
                ],
            ],
            'nameservers'     => [
                'format' => 'raw',
                'value'  => function ($model) {
                    return ArraySpoiler::widget(['data' => $model->nameservers]);
                },
            ],
            'actions'         => [
                'class'    => ActionColumn::className(),
                'template' => '{view} {notify-transfer-in} {approve-preincoming} {reject-preincoming} {approve-transfer} {reject-transfer} {cancel-transfer} {sync} {enable-hold} {disable-hold} {enable-freeze} {disable-freeze} {delete-agp} {delete}', // {state}
                'header'   => Yii::t('app', 'Actions'),
                'buttons'  => [
                    'notify-transfer-in' => function ($url, $model, $key) {
                        return $model->state === 'preincoming'
                            ? Html::a('<i class="fa fa-envelope-o"></i>' . Yii::t('app', 'Send FOA again'), $url, [
                                'data' => [
                                    'method'  => 'post',
                                    'data-pjax' => '0',
                                ],
                            ]) : '';
                    },
                    'approve-preincoming' => function ($url, $model, $key) {
                    },
                    'reject-preincoming' => function ($url, $model, $key) {
                    },
                    'approve-transfer' => function ($url, $model, $key) {
                        return ($model->state === 'outgoing' && Yii::$app->user->can('support') && Domain::notDomainOwner($model))
                            ? Html::a('<i class="fa fa-exclamation-circle"></i>' . Yii::t('app', 'Approve transfer'), $url, [
                                'data' => [
                                    'confirm' => Yii::t('app', 'Are you sure you want to approve outgoing transfer of domain {domain}?', ['domain' => $model->domain]),
                                    'method'  => 'post',
                                    'data-pjax' => '0',
                                ],
                            ]) : '';
                    },
                    'reject-transfer' => function ($url, $model, $key) {
                        return $model->state === 'outgoing'
                            ? Html::a('<i class="fa fa-anchor"></i>' . Yii::t('app', 'Reject transfer'), $url, [
                                'data' => [
                                    'confirm' => Yii::t('app', 'Are you sure you want to reject outgoing transfer of domain {domain}?', ['domain' => $model->domain]),
                                    'method'  => 'post',
                                    'data-pjax' => '0',
                                ],
                            ]) : '';
                    },
                    'cancel-transfer' => function ($url, $model, $key) {
                        return $model->state === 'incoming'
                            ? Html::a('<i class="fa fa-exclamation-triangle"></i>' . Yii::t('app', 'Cancel transfer'), $url, [
                                'data' => [
                                    'confirm' => Yii::t('app', 'Are you sure you want to cancel incoming transfer of domain {domain}?', ['domain' => $model->domain]),
                                    'method'  => 'post',
                                    'data-pjax' => '0',
                                ],
                            ]) : '';
                    },
                    'sync'          => function ($url, $model, $key) {
                        return (in_array($model->state, ['ok', 'expired'], true) && Yii::$app->user->can('support') && Domain::notDomainOwner($model))
                            ? Html::a('<i class="fa ion-ios-loop-strong"></i>' . Yii::t('app', 'Synchronize contacts'), $url, [
                                'data' => [
                                    'method'  => 'post',
                                    'data-pjax' => '0',
                                ],
                            ]) : '';
                    },
                    'delete'        => function ($url, $model, $key) {
                        return in_array($model->state, ['ok', 'expired', 'outgoing'], true) ? Html::a('<i class="fa fa-trash-o"></i>' . Yii::t('yii', 'Delete'), $url, [
                                'title'        => Yii::t('yii', 'Delete'),
                                'aria-label'   => Yii::t('yii', 'Delete'),
                                'data' => [
                                    'confirm' => Yii::t('app', 'Are you sure you want to delete domain {domain}?', ['domain' => $model->domain]),
                                    'method'  => 'post',
                                    'data-pjax' => '0',
                                ],
                        ]) : '';
                    },
                    'delete-agp'    => function ($url, $model, $key) {<commit_msg>Add canSupport rule to delete button on domain index<commit_after><?php

/*
 * Domain plugin for HiPanel
 *
 * @link      https://github.com/hiqdev/hipanel-module-domain
 * @package   hipanel-module-domain
 * @license   BSD-3-Clause
 * @copyright Copyright (c) 2014-2015, HiQDev (http://hiqdev.com/)
 */

/**
 * @link    http://hiqdev.com/hipanel-module-domain
 *
 * @license http://hiqdev.com/hipanel-module-domain/license
 * @copyright Copyright (c) 2015 HiQDev
 */
namespace hipanel\modules\domain\grid;

use hipanel\grid\ActionColumn;
use hipanel\grid\BoxedGridView;
use hipanel\grid\MainColumn;
use hipanel\grid\RefColumn;
use hipanel\modules\domain\models\Domain;
use hipanel\modules\domain\widgets\Expires;
use hipanel\modules\domain\widgets\State;
use hipanel\widgets\ArraySpoiler;
use hiqdev\bootstrap_switch\BootstrapSwitchColumn;
use Yii;
use yii\helpers\Html;
use yii\helpers\Url;

class DomainGridView extends BoxedGridView
{
    public static function defaultColumns()
    {
        return [
            'domain' => [
                'class'           => MainColumn::className(),
                'attribute'       => 'domain',
                'note'            => true,
                'filterAttribute' => 'domain_like',
            ],
            'state' => [
                'class'         => RefColumn::className(),
                'format'        => 'raw',
                'gtype'         => 'state,domain',
                'filterInputOptions' => ['style' => 'width:120px'],
                'value'         => function ($model) {
                    return State::widget(compact('model'));
                },
            ],
            'whois_protected' => [
                'class'         => BootstrapSwitchColumn::className(),
                'filter'        => false,
                'url'           => Url::toRoute('set-whois-protect'),
                'popover'       => 'WHOIS protection',
                'pluginOptions' => [
                    'onColor'  => 'success',
                    'offColor' => 'warning',
                ],
            ],
            'is_secured'      => [
                'class'     => BootstrapSwitchColumn::className(),
                'filter'    => false,
                'url'       => Url::toRoute('set-lock'),
                'attribute' => 'is_secured',
                'popover'   => Yii::t('app', 'Protection from transfer'),
            ],
            'note'            => [
                'class'         => 'hiqdev\xeditable\grid\XEditableColumn',
                'attribute'     => 'note',
                'filter'        => true,
                'popover'       => Yii::t('app', 'Make any notes for your convenience'),
                'pluginOptions' => [
                    'url' => 'set-note',
                ],
            ],
            'created_date'    => [
                'attribute'      => 'created_date',
                'format'         => 'date',
                'filter'         => false,
                'contentOptions' => ['class' => 'text-nowrap'],
            ],
            'expires'         => [
                'format'        => 'raw',
                'filter'        => false,
                'headerOptions' => ['style' => 'width:1em'],
                'value'         => function ($model) {
                    return Expires::widget(compact('model'));
                },
            ],
            'autorenewal'     => [
                'class'         => BootstrapSwitchColumn::className(),
                'label'         => Yii::t('app', 'Autorenew'),
                'filter'        => false,
                'url'           => Url::toRoute('set-autorenewal'),
                'popover'       => 'The domain will be autorenewed for one year in a week before it expires if you have enough credit on your account',
                'pluginOptions' => [
                    'onColor' => 'info',
                ],
            ],
            'nameservers'     => [
                'format' => 'raw',
                'value'  => function ($model) {
                    return ArraySpoiler::widget(['data' => $model->nameservers]);
                },
            ],
            'actions'         => [
                'class'    => ActionColumn::className(),
                'template' => '{view} {notify-transfer-in} {approve-preincoming} {reject-preincoming} {approve-transfer} {reject-transfer} {cancel-transfer} {sync} {enable-hold} {disable-hold} {enable-freeze} {disable-freeze} {delete-agp} {delete}', // {state}
                'header'   => Yii::t('app', 'Actions'),
                'buttons'  => [
                    'notify-transfer-in' => function ($url, $model, $key) {
                        return $model->state === 'preincoming'
                            ? Html::a('<i class="fa fa-envelope-o"></i>' . Yii::t('app', 'Send FOA again'), $url, [
                                'data' => [
                                    'method'  => 'post',
                                    'data-pjax' => '0',
                                ],
                            ]) : '';
                    },
                    'approve-preincoming' => function ($url, $model, $key) {
                    },
                    'reject-preincoming' => function ($url, $model, $key) {
                    },
                    'approve-transfer' => function ($url, $model, $key) {
                        return ($model->state === 'outgoing' && Yii::$app->user->can('support') && Domain::notDomainOwner($model))
                            ? Html::a('<i class="fa fa-exclamation-circle"></i>' . Yii::t('app', 'Approve transfer'), $url, [
                                'data' => [
                                    'confirm' => Yii::t('app', 'Are you sure you want to approve outgoing transfer of domain {domain}?', ['domain' => $model->domain]),
                                    'method'  => 'post',
                                    'data-pjax' => '0',
                                ],
                            ]) : '';
                    },
                    'reject-transfer' => function ($url, $model, $key) {
                        return $model->state === 'outgoing'
                            ? Html::a('<i class="fa fa-anchor"></i>' . Yii::t('app', 'Reject transfer'), $url, [
                                'data' => [
                                    'confirm' => Yii::t('app', 'Are you sure you want to reject outgoing transfer of domain {domain}?', ['domain' => $model->domain]),
                                    'method'  => 'post',
                                    'data-pjax' => '0',
                                ],
                            ]) : '';
                    },
                    'cancel-transfer' => function ($url, $model, $key) {
                        return $model->state === 'incoming'
                            ? Html::a('<i class="fa fa-exclamation-triangle"></i>' . Yii::t('app', 'Cancel transfer'), $url, [
                                'data' => [
                                    'confirm' => Yii::t('app', 'Are you sure you want to cancel incoming transfer of domain {domain}?', ['domain' => $model->domain]),
                                    'method'  => 'post',
                                    'data-pjax' => '0',
                                ],
                            ]) : '';
                    },
                    'sync'          => function ($url, $model, $key) {
                        return (in_array($model->state, ['ok', 'expired'], true) && Yii::$app->user->can('support') && Domain::notDomainOwner($model))
                            ? Html::a('<i class="fa ion-ios-loop-strong"></i>' . Yii::t('app', 'Synchronize contacts'), $url, [
                                'data' => [
                                    'method'  => 'post',
                                    'data-pjax' => '0',
                                ],
                            ]) : '';
                    },
                    'delete'        => function ($url, $model, $key) {
                        return in_array($model->state, ['ok', 'expired', 'outgoing'], true) && Yii::$app->user->can('support') ? Html::a('<i class="fa fa-trash-o"></i>' . Yii::t('yii', 'Delete'), $url, [
                                'title'        => Yii::t('yii', 'Delete'),
                                'aria-label'   => Yii::t('yii', 'Delete'),
                                'data' => [
                                    'confirm' => Yii::t('app', 'Are you sure you want to delete domain {domain}?', ['domain' => $model->domain]),
                                    'method'  => 'post',
                                    'data-pjax' => '0',
                                ],
                        ]) : '';
                    },
                    'delete-agp'    => function ($url, $model, $key) {
{'fraction_non_alphanumeric': 0.15858061604422882, 'fraction_numerical': 0.0025950581067358683, 'mean_word_length': 1.1500303214069132, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 257, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6786448', 'n_tokens_mistral': 4742, 'n_tokens_neox': 4482, 'n_words': 877}